aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/acpi/acpica/evxface.c1
-rw-r--r--drivers/acpi/acpica/evxfevnt.c1
-rw-r--r--drivers/acpi/acpica/evxfgpe.c1
-rw-r--r--drivers/acpi/acpica/evxfregn.c1
-rw-r--r--drivers/acpi/acpica/hwsleep.c1
-rw-r--r--drivers/acpi/acpica/hwtimer.c1
-rw-r--r--drivers/acpi/acpica/hwxface.c1
-rw-r--r--drivers/acpi/acpica/nsxfeval.c1
-rw-r--r--drivers/acpi/acpica/nsxfname.c1
-rw-r--r--drivers/acpi/acpica/nsxfobj.c1
-rw-r--r--drivers/acpi/acpica/rsxface.c1
-rw-r--r--drivers/acpi/acpica/tbxface.c1
-rw-r--r--drivers/acpi/acpica/utdebug.c1
-rw-r--r--drivers/acpi/acpica/utdecode.c1
-rw-r--r--drivers/acpi/acpica/utglobal.c1
-rw-r--r--drivers/acpi/acpica/utxface.c1
-rw-r--r--drivers/acpi/acpica/utxferror.c1
-rw-r--r--drivers/acpi/atomicio.c2
-rw-r--r--drivers/acpi/blacklist.c1
-rw-r--r--drivers/acpi/debugfs.c1
-rw-r--r--drivers/acpi/ec_sys.c1
-rw-r--r--drivers/acpi/event.c1
-rw-r--r--drivers/acpi/glue.c1
-rw-r--r--drivers/acpi/proc.c1
-rw-r--r--drivers/acpi/processor_core.c1
-rw-r--r--drivers/acpi/sbshc.c1
-rw-r--r--drivers/acpi/sleep.c8
-rw-r--r--drivers/acpi/video_detect.c1
-rw-r--r--drivers/ata/ahci_platform.c7
-rw-r--r--drivers/ata/libata-eh.c1
-rw-r--r--drivers/ata/libata-pmp.c1
-rw-r--r--drivers/ata/libata-scsi.c1
-rw-r--r--drivers/ata/libata-sff.c1
-rw-r--r--drivers/base/base.h1
-rw-r--r--drivers/base/dma-coherent.c1
-rw-r--r--drivers/base/dma-mapping.c1
-rw-r--r--drivers/base/hypervisor.c1
-rw-r--r--drivers/base/power/common.c2
-rw-r--r--drivers/base/power/generic_ops.c1
-rw-r--r--drivers/base/power/main.c1
-rw-r--r--drivers/base/power/qos.c1
-rw-r--r--drivers/base/power/runtime.c24
-rw-r--r--drivers/base/power/sysfs.c1
-rw-r--r--drivers/base/power/trace.c1
-rw-r--r--drivers/base/power/wakeup.c1
-rw-r--r--drivers/base/regmap/regcache.c1
-rw-r--r--drivers/base/transport_class.c1
-rw-r--r--drivers/bcma/core.c1
-rw-r--r--drivers/bcma/driver_chipcommon.c1
-rw-r--r--drivers/bcma/driver_chipcommon_pmu.c1
-rw-r--r--drivers/bcma/driver_pci.c1
-rw-r--r--drivers/bcma/host_pci.c1
-rw-r--r--drivers/bcma/main.c1
-rw-r--r--drivers/block/aoe/aoeblk.c15
-rw-r--r--drivers/block/aoe/aoechr.c1
-rw-r--r--drivers/block/brd.c4
-rw-r--r--drivers/block/cciss.c76
-rw-r--r--drivers/block/cciss.h1
-rw-r--r--drivers/block/cpqarray.c2
-rw-r--r--drivers/block/drbd/drbd_int.h2
-rw-r--r--drivers/block/drbd/drbd_req.c8
-rw-r--r--drivers/block/loop.c251
-rw-r--r--drivers/block/nbd.c69
-rw-r--r--drivers/block/pktcdvd.c11
-rw-r--r--drivers/block/ps3disk.c1
-rw-r--r--drivers/block/ps3vram.c7
-rw-r--r--drivers/block/umem.c4
-rw-r--r--drivers/block/virtio_blk.c31
-rw-r--r--drivers/block/xen-blkback/blkback.c130
-rw-r--r--drivers/block/xen-blkback/common.h103
-rw-r--r--drivers/block/xen-blkback/xenbus.c130
-rw-r--r--drivers/block/xen-blkfront.c123
-rw-r--r--drivers/bluetooth/btmrvl_main.c2
-rw-r--r--drivers/bluetooth/btmrvl_sdio.c1
-rw-r--r--drivers/bluetooth/btwilink.c1
-rw-r--r--drivers/char/Kconfig6
-rw-r--r--drivers/char/agp/hp-agp.c6
-rw-r--r--drivers/char/hw_random/Kconfig15
-rw-r--r--drivers/char/hw_random/virtio-rng.c1
-rw-r--r--drivers/char/mem.c1
-rw-r--r--drivers/char/ps3flash.c1
-rw-r--r--drivers/char/ramoops.c1
-rw-r--r--drivers/char/ttyprintk.c3
-rw-r--r--drivers/char/virtio_console.c121
-rw-r--r--drivers/clocksource/sh_cmt.c1
-rw-r--r--drivers/clocksource/sh_mtu2.c1
-rw-r--r--drivers/clocksource/sh_tmu.c1
-rw-r--r--drivers/cpufreq/cpufreq_stats.c1
-rw-r--r--drivers/cpufreq/db8500-cpufreq.c38
-rw-r--r--drivers/cpufreq/e_powersaver.c135
-rw-r--r--drivers/cpufreq/exynos4210-cpufreq.c129
-rw-r--r--drivers/cpufreq/s3c64xx-cpufreq.c1
-rw-r--r--drivers/cpuidle/cpuidle.c1
-rw-r--r--drivers/cpuidle/governors/ladder.c2
-rw-r--r--drivers/cpuidle/governors/menu.c1
-rw-r--r--drivers/crypto/mv_cesa.c1
-rw-r--r--drivers/dca/dca-core.c1
-rw-r--r--drivers/dca/dca-sysfs.c1
-rw-r--r--drivers/dma/Kconfig3
-rw-r--r--drivers/dma/amba-pl08x.c640
-rw-r--r--drivers/dma/at_hdmac.c164
-rw-r--r--drivers/dma/at_hdmac_regs.h24
-rw-r--r--drivers/dma/dmatest.c23
-rw-r--r--drivers/dma/dw_dmac.c5
-rw-r--r--drivers/dma/ep93xx_dma.c1
-rw-r--r--drivers/dma/imx-dma.c2
-rw-r--r--drivers/dma/imx-sdma.c49
-rw-r--r--drivers/dma/intel_mid_dma.c10
-rw-r--r--drivers/dma/ipu/ipu_idmac.c66
-rw-r--r--drivers/dma/mpc512x_dma.c1
-rw-r--r--drivers/dma/mxs-dma.c45
-rw-r--r--drivers/dma/pch_dma.c7
-rw-r--r--drivers/dma/pl330.c231
-rw-r--r--drivers/dma/shdma.c129
-rw-r--r--drivers/dma/shdma.h7
-rw-r--r--drivers/dma/ste_dma40.c1
-rw-r--r--drivers/dma/timb_dma.c5
-rw-r--r--drivers/edac/Kconfig16
-rw-r--r--drivers/edac/Makefile2
-rw-r--r--drivers/edac/cpc925_edac.c67
-rw-r--r--drivers/edac/edac_core.h350
-rw-r--r--drivers/edac/edac_mce.c61
-rw-r--r--drivers/edac/i7300_edac.c51
-rw-r--r--drivers/edac/i7core_edac.c415
-rw-r--r--drivers/edac/mce_amd_inj.c1
-rw-r--r--drivers/edac/ppc4xx_edac.c2
-rw-r--r--drivers/edac/sb_edac.c1893
-rw-r--r--drivers/firewire/core-iso.c1
-rw-r--r--drivers/firmware/edd.c6
-rw-r--r--drivers/firmware/google/gsmi.c1
-rw-r--r--drivers/gpio/Kconfig27
-rw-r--r--drivers/gpio/Makefile7
-rw-r--r--drivers/gpio/gpio-74x164.c1
-rw-r--r--drivers/gpio/gpio-ep93xx.c1
-rw-r--r--drivers/gpio/gpio-exynos4.c385
-rw-r--r--drivers/gpio/gpio-mc33880.c1
-rw-r--r--drivers/gpio/gpio-mcp23s08.c1
-rw-r--r--drivers/gpio/gpio-ml-ioh.c1
-rw-r--r--drivers/gpio/gpio-mpc5200.c1
-rw-r--r--drivers/gpio/gpio-mpc8xxx.c398
-rw-r--r--drivers/gpio/gpio-mxc.c1
-rw-r--r--drivers/gpio/gpio-mxs.c1
-rw-r--r--drivers/gpio/gpio-pcf857x.c1
-rw-r--r--drivers/gpio/gpio-pch.c1
-rw-r--r--drivers/gpio/gpio-plat-samsung.c205
-rw-r--r--drivers/gpio/gpio-s5pc100.c354
-rw-r--r--drivers/gpio/gpio-s5pv210.c287
-rw-r--r--drivers/gpio/gpio-samsung.c2712
-rw-r--r--drivers/gpio/gpio-xilinx.c1
-rw-r--r--drivers/gpu/drm/ati_pcigart.c1
-rw-r--r--drivers/gpu/drm/drm_buffer.c1
-rw-r--r--drivers/gpu/drm/drm_bufs.c1
-rw-r--r--drivers/gpu/drm/drm_cache.c1
-rw-r--r--drivers/gpu/drm/drm_crtc.c1
-rw-r--r--drivers/gpu/drm/drm_crtc_helper.c3
-rw-r--r--drivers/gpu/drm/drm_debugfs.c1
-rw-r--r--drivers/gpu/drm/drm_dma.c1
-rw-r--r--drivers/gpu/drm/drm_drv.c1
-rw-r--r--drivers/gpu/drm/drm_edid.c1
-rw-r--r--drivers/gpu/drm/drm_encoder_slave.c2
-rw-r--r--drivers/gpu/drm/drm_fb_helper.c1
-rw-r--r--drivers/gpu/drm/drm_fops.c1
-rw-r--r--drivers/gpu/drm/drm_hashtab.c1
-rw-r--r--drivers/gpu/drm/drm_ioc32.c1
-rw-r--r--drivers/gpu/drm/drm_irq.c1
-rw-r--r--drivers/gpu/drm/drm_memory.c1
-rw-r--r--drivers/gpu/drm/drm_mm.c1
-rw-r--r--drivers/gpu/drm/drm_modes.c1
-rw-r--r--drivers/gpu/drm/drm_pci.c1
-rw-r--r--drivers/gpu/drm/drm_platform.c1
-rw-r--r--drivers/gpu/drm/drm_proc.c1
-rw-r--r--drivers/gpu/drm/drm_sman.c1
-rw-r--r--drivers/gpu/drm/drm_sysfs.c1
-rw-r--r--drivers/gpu/drm/drm_usb.c1
-rw-r--r--drivers/gpu/drm/drm_vm.c1
-rw-r--r--drivers/gpu/drm/i2c/ch7006_drv.c2
-rw-r--r--drivers/gpu/drm/i2c/sil164_drv.c2
-rw-r--r--drivers/gpu/drm/i810/i810_drv.c2
-rw-r--r--drivers/gpu/drm/i915/i915_debugfs.c1
-rw-r--r--drivers/gpu/drm/i915/i915_dma.c1
-rw-r--r--drivers/gpu/drm/i915/i915_drv.c1
-rw-r--r--drivers/gpu/drm/i915/intel_dp.c1
-rw-r--r--drivers/gpu/drm/i915/intel_i2c.c1
-rw-r--r--drivers/gpu/drm/i915/intel_sdvo.c1
-rw-r--r--drivers/gpu/drm/mga/mga_drv.c2
-rw-r--r--drivers/gpu/drm/mga/mga_warp.c1
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_drv.c1
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_i2c.c2
-rw-r--r--drivers/gpu/drm/nouveau/nouveau_temp.c2
-rw-r--r--drivers/gpu/drm/nouveau/nvc0_graph.c1
-rw-r--r--drivers/gpu/drm/r128/r128_cce.c1
-rw-r--r--drivers/gpu/drm/r128/r128_drv.c2
-rw-r--r--drivers/gpu/drm/radeon/ni.c1
-rw-r--r--drivers/gpu/drm/radeon/r100.c1
-rw-r--r--drivers/gpu/drm/radeon/r600.c1
-rw-r--r--drivers/gpu/drm/radeon/r600_cp.c2
-rw-r--r--drivers/gpu/drm/radeon/radeon_cp.c2
-rw-r--r--drivers/gpu/drm/radeon/radeon_drv.c1
-rw-r--r--drivers/gpu/drm/radeon/radeon_i2c.c2
-rw-r--r--drivers/gpu/drm/savage/savage_drv.c2
-rw-r--r--drivers/gpu/drm/sis/sis_drv.c2
-rw-r--r--drivers/gpu/drm/tdfx/tdfx_drv.c2
-rw-r--r--drivers/gpu/drm/ttm/ttm_tt.c1
-rw-r--r--drivers/gpu/drm/via/via_drv.c2
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_drv.c1
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_fb.c2
-rw-r--r--drivers/hid/hid-apple.c12
-rw-r--r--drivers/hid/hid-axff.c1
-rw-r--r--drivers/hid/hid-core.c7
-rw-r--r--drivers/hid/hid-debug.c1
-rw-r--r--drivers/hid/hid-dr.c1
-rw-r--r--drivers/hid/hid-emsff.c1
-rw-r--r--drivers/hid/hid-gaff.c1
-rw-r--r--drivers/hid/hid-holtekff.c1
-rw-r--r--drivers/hid/hid-ids.h4
-rw-r--r--drivers/hid/hid-multitouch.c47
-rw-r--r--drivers/hid/hid-picolcd.c1
-rw-r--r--drivers/hid/hid-pl.c1
-rw-r--r--drivers/hid/hid-roccat-common.c1
-rw-r--r--drivers/hid/hid-roccat.c19
-rw-r--r--drivers/hid/hid-sjoy.c1
-rw-r--r--drivers/hid/hid-tmff.c1
-rw-r--r--drivers/hid/hid-zpff.c1
-rw-r--r--drivers/hid/usbhid/hid-quirks.c1
-rw-r--r--drivers/hwmon/Kconfig20
-rw-r--r--drivers/hwmon/ad7414.c7
-rw-r--r--drivers/hwmon/ad7418.c27
-rw-r--r--drivers/hwmon/ads1015.c21
-rw-r--r--drivers/hwmon/ads7828.c12
-rw-r--r--drivers/hwmon/asb100.c10
-rw-r--r--drivers/hwmon/coretemp.c3
-rw-r--r--drivers/hwmon/ds1621.c24
-rw-r--r--drivers/hwmon/ds620.c42
-rw-r--r--drivers/hwmon/gl518sm.c4
-rw-r--r--drivers/hwmon/gl520sm.c4
-rw-r--r--drivers/hwmon/ibmaem.c60
-rw-r--r--drivers/hwmon/jc42.c52
-rw-r--r--drivers/hwmon/lm73.c30
-rw-r--r--drivers/hwmon/lm75.c9
-rw-r--r--drivers/hwmon/lm77.c4
-rw-r--r--drivers/hwmon/lm90.c146
-rw-r--r--drivers/hwmon/lm92.c26
-rw-r--r--drivers/hwmon/max16065.c4
-rw-r--r--drivers/hwmon/mc13783-adc.c12
-rw-r--r--drivers/hwmon/sht21.c26
-rw-r--r--drivers/hwmon/smm665.c15
-rw-r--r--drivers/hwmon/smsc47b397.c13
-rw-r--r--drivers/hwmon/tmp102.c44
-rw-r--r--drivers/hwmon/ultra45_env.c1
-rw-r--r--drivers/hwmon/w83627ehf.c213
-rw-r--r--drivers/hwmon/w83781d.c10
-rw-r--r--drivers/hwspinlock/Kconfig27
-rw-r--r--drivers/hwspinlock/Makefile1
-rw-r--r--drivers/hwspinlock/hwspinlock_core.c204
-rw-r--r--drivers/hwspinlock/hwspinlock_internal.h40
-rw-r--r--drivers/hwspinlock/omap_hwspinlock.c127
-rw-r--r--drivers/hwspinlock/u8500_hsem.c198
-rw-r--r--drivers/i2c/busses/Kconfig3
-rw-r--r--drivers/i2c/busses/i2c-au1550.c2
-rw-r--r--drivers/i2c/busses/i2c-pxa-pci.c1
-rw-r--r--drivers/i2c/busses/i2c-sh7760.c1
-rw-r--r--drivers/i2c/busses/i2c-tegra.c1
-rw-r--r--drivers/i2c/i2c-boardinfo.c1
-rw-r--r--drivers/ide/Kconfig6
-rw-r--r--drivers/ide/au1xxx-ide.c46
-rw-r--r--drivers/ide/buddha.c1
-rw-r--r--drivers/ide/cmd640.c1
-rw-r--r--drivers/ide/ide-acpi.c1
-rw-r--r--drivers/ide/ide-atapi.c1
-rw-r--r--drivers/ide/ide-disk_proc.c1
-rw-r--r--drivers/ide/ide-dma-sff.c1
-rw-r--r--drivers/ide/ide-dma.c1
-rw-r--r--drivers/ide/ide-eh.c1
-rw-r--r--drivers/ide/ide-floppy_proc.c1
-rw-r--r--drivers/ide/ide-io-std.c1
-rw-r--r--drivers/ide/ide-ioctls.c1
-rw-r--r--drivers/ide/ide-legacy.c1
-rw-r--r--drivers/ide/ide-lib.c1
-rw-r--r--drivers/ide/ide-pnp.c1
-rw-r--r--drivers/ide/ide-taskfile.c1
-rw-r--r--drivers/ide/ide-xfer-mode.c1
-rw-r--r--drivers/ide/macide.c1
-rw-r--r--drivers/ide/pmac.c1
-rw-r--r--drivers/ide/q40ide.c1
-rw-r--r--drivers/ide/setup-pci.c1
-rw-r--r--drivers/ide/tc86c001.c1
-rw-r--r--drivers/idle/intel_idle.c1
-rw-r--r--drivers/infiniband/core/addr.c1
-rw-r--r--drivers/infiniband/core/cm.c1
-rw-r--r--drivers/infiniband/core/cma.c1
-rw-r--r--drivers/infiniband/core/fmr_pool.c1
-rw-r--r--drivers/infiniband/core/iwcm.c1
-rw-r--r--drivers/infiniband/core/mad.c1
-rw-r--r--drivers/infiniband/core/multicast.c1
-rw-r--r--drivers/infiniband/core/netlink.c1
-rw-r--r--drivers/infiniband/core/packer.c1
-rw-r--r--drivers/infiniband/core/sysfs.c1
-rw-r--r--drivers/infiniband/core/ucma.c1
-rw-r--r--drivers/infiniband/core/ud_header.c1
-rw-r--r--drivers/infiniband/core/umem.c1
-rw-r--r--drivers/infiniband/core/uverbs_marshall.c1
-rw-r--r--drivers/infiniband/core/verbs.c1
-rw-r--r--drivers/infiniband/hw/cxgb4/qp.c3
-rw-r--r--drivers/infiniband/hw/ipath/ipath_diag.c1
-rw-r--r--drivers/infiniband/hw/ipath/ipath_driver.c1
-rw-r--r--drivers/infiniband/hw/ipath/ipath_file_ops.c1
-rw-r--r--drivers/infiniband/hw/ipath/ipath_init_chip.c1
-rw-r--r--drivers/infiniband/hw/ipath/ipath_sysfs.c1
-rw-r--r--drivers/infiniband/hw/ipath/ipath_verbs.c1
-rw-r--r--drivers/infiniband/hw/mthca/mthca_catas.c1
-rw-r--r--drivers/infiniband/hw/mthca/mthca_cmd.c1
-rw-r--r--drivers/infiniband/hw/mthca/mthca_mr.c2
-rw-r--r--drivers/infiniband/hw/mthca/mthca_provider.c2
-rw-r--r--drivers/infiniband/hw/qib/qib_diag.c1
-rw-r--r--drivers/infiniband/hw/qib/qib_driver.c1
-rw-r--r--drivers/infiniband/hw/qib/qib_file_ops.c1
-rw-r--r--drivers/infiniband/hw/qib/qib_iba7220.c1
-rw-r--r--drivers/infiniband/hw/qib/qib_iba7322.c1
-rw-r--r--drivers/infiniband/hw/qib/qib_init.c1
-rw-r--r--drivers/infiniband/hw/qib/qib_pcie.c1
-rw-r--r--drivers/infiniband/hw/qib/qib_rc.c10
-rw-r--r--drivers/infiniband/hw/qib/qib_sd7220.c1
-rw-r--r--drivers/infiniband/hw/qib/qib_sdma.c1
-rw-r--r--drivers/infiniband/hw/qib/qib_tx.c1
-rw-r--r--drivers/infiniband/hw/qib/qib_verbs.c1
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_cm.c1
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_fs.c1
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_ib.c1
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_multicast.c1
-rw-r--r--drivers/infiniband/ulp/iser/iscsi_iser.c12
-rw-r--r--drivers/infiniband/ulp/iser/iscsi_iser.h4
-rw-r--r--drivers/infiniband/ulp/iser/iser_initiator.c31
-rw-r--r--drivers/infiniband/ulp/iser/iser_verbs.c33
-rw-r--r--drivers/input/Kconfig2
-rw-r--r--drivers/input/input-compat.c1
-rw-r--r--drivers/input/input-mt.c1
-rw-r--r--drivers/input/input-polldev.c1
-rw-r--r--drivers/input/joystick/as5011.c1
-rw-r--r--drivers/input/keyboard/nomadik-ske-keypad.c1
-rw-r--r--drivers/input/keyboard/tnetv107x-keypad.c1
-rw-r--r--drivers/input/misc/Kconfig10
-rw-r--r--drivers/input/misc/Makefile1
-rw-r--r--drivers/input/misc/ad714x.c1
-rw-r--r--drivers/input/misc/adxl34x.c1
-rw-r--r--drivers/input/misc/ati_remote2.c1
-rw-r--r--drivers/input/misc/cma3000_d0x.c1
-rw-r--r--drivers/input/misc/dm355evm_keys.c1
-rw-r--r--drivers/input/misc/mc13783-pwrbutton.c282
-rw-r--r--drivers/input/sparse-keymap.c1
-rw-r--r--drivers/input/touchscreen/ad7877.c1
-rw-r--r--drivers/input/touchscreen/ad7879-spi.c1
-rw-r--r--drivers/input/touchscreen/ad7879.c1
-rw-r--r--drivers/input/touchscreen/ads7846.c1
-rw-r--r--drivers/input/touchscreen/bu21013_ts.c1
-rw-r--r--drivers/input/touchscreen/mc13783_ts.c34
-rw-r--r--drivers/iommu/intel-iommu.c1
-rw-r--r--drivers/isdn/Kconfig2
-rw-r--r--drivers/isdn/capi/kcapi_proc.c1
-rw-r--r--drivers/isdn/gigaset/asyncdata.c1
-rw-r--r--drivers/isdn/gigaset/capi.c1
-rw-r--r--drivers/isdn/gigaset/dummyll.c1
-rw-r--r--drivers/isdn/gigaset/ev-layer.c1
-rw-r--r--drivers/isdn/gigaset/i4l.c1
-rw-r--r--drivers/isdn/gigaset/interface.c1
-rw-r--r--drivers/isdn/hardware/mISDN/mISDNisar.c1
-rw-r--r--drivers/isdn/hisax/l3dss1.c6
-rw-r--r--drivers/isdn/i4l/isdn_tty.c1
-rw-r--r--drivers/isdn/mISDN/clock.c1
-rw-r--r--drivers/isdn/mISDN/dsp_audio.c1
-rw-r--r--drivers/isdn/mISDN/dsp_pipeline.c1
-rw-r--r--drivers/isdn/mISDN/socket.c1
-rw-r--r--drivers/leds/dell-led.c1
-rw-r--r--drivers/leds/leds-88pm860x.c1
-rw-r--r--drivers/leds/leds-asic3.c36
-rw-r--r--drivers/leds/leds-atmel-pwm.c1
-rw-r--r--drivers/leds/leds-cobalt-raq.c1
-rw-r--r--drivers/leds/leds-fsg.c1
-rw-r--r--drivers/leds/leds-gpio.c1
-rw-r--r--drivers/leds/leds-lm3530.c1
-rw-r--r--drivers/leds/leds-locomo.c1
-rw-r--r--drivers/leds/leds-lt3593.c1
-rw-r--r--drivers/leds/leds-mc13783.c60
-rw-r--r--drivers/leds/leds-net48xx.c1
-rw-r--r--drivers/leds/leds-net5501.c1
-rw-r--r--drivers/leds/leds-ns2.c1
-rw-r--r--drivers/leds/leds-s3c24xx.c1
-rw-r--r--drivers/leds/leds-wm831x-status.c1
-rw-r--r--drivers/leds/leds-wm8350.c1
-rw-r--r--drivers/leds/leds-wrap.c1
-rw-r--r--drivers/lguest/lguest_device.c1
-rw-r--r--drivers/lguest/lguest_user.c1
-rw-r--r--drivers/md/Kconfig36
-rw-r--r--drivers/md/Makefile4
-rw-r--r--drivers/md/dm-bufio.c1699
-rw-r--r--drivers/md/dm-bufio.h112
-rw-r--r--drivers/md/dm-exception-store.c1
-rw-r--r--drivers/md/dm-ioctl.c11
-rw-r--r--drivers/md/dm-kcopyd.c31
-rw-r--r--drivers/md/dm-log-userspace-base.c38
-rw-r--r--drivers/md/dm-path-selector.c1
-rw-r--r--drivers/md/dm-raid.c49
-rw-r--r--drivers/md/dm-round-robin.c1
-rw-r--r--drivers/md/dm-service-time.c1
-rw-r--r--drivers/md/dm-snap-persistent.c1
-rw-r--r--drivers/md/dm-snap-transient.c1
-rw-r--r--drivers/md/dm-table.c73
-rw-r--r--drivers/md/dm-thin-metadata.c1391
-rw-r--r--drivers/md/dm-thin-metadata.h156
-rw-r--r--drivers/md/dm-thin.c2428
-rw-r--r--drivers/md/dm-uevent.c1
-rw-r--r--drivers/md/dm.c46
-rw-r--r--drivers/md/dm.h2
-rw-r--r--drivers/md/faulty.c15
-rw-r--r--drivers/md/linear.c18
-rw-r--r--drivers/md/md.c13
-rw-r--r--drivers/md/md.h2
-rw-r--r--drivers/md/multipath.c9
-rw-r--r--drivers/md/persistent-data/Kconfig8
-rw-r--r--drivers/md/persistent-data/Makefile11
-rw-r--r--drivers/md/persistent-data/dm-block-manager.c620
-rw-r--r--drivers/md/persistent-data/dm-block-manager.h123
-rw-r--r--drivers/md/persistent-data/dm-btree-internal.h137
-rw-r--r--drivers/md/persistent-data/dm-btree-remove.c566
-rw-r--r--drivers/md/persistent-data/dm-btree-spine.c244
-rw-r--r--drivers/md/persistent-data/dm-btree.c805
-rw-r--r--drivers/md/persistent-data/dm-btree.h145
-rw-r--r--drivers/md/persistent-data/dm-persistent-data-internal.h19
-rw-r--r--drivers/md/persistent-data/dm-space-map-checker.c437
-rw-r--r--drivers/md/persistent-data/dm-space-map-checker.h26
-rw-r--r--drivers/md/persistent-data/dm-space-map-common.c705
-rw-r--r--drivers/md/persistent-data/dm-space-map-common.h126
-rw-r--r--drivers/md/persistent-data/dm-space-map-disk.c335
-rw-r--r--drivers/md/persistent-data/dm-space-map-disk.h25
-rw-r--r--drivers/md/persistent-data/dm-space-map-metadata.c596
-rw-r--r--drivers/md/persistent-data/dm-space-map-metadata.h33
-rw-r--r--drivers/md/persistent-data/dm-space-map.h134
-rw-r--r--drivers/md/persistent-data/dm-transaction-manager.c400
-rw-r--r--drivers/md/persistent-data/dm-transaction-manager.h130
-rw-r--r--drivers/md/raid0.c23
-rw-r--r--drivers/md/raid1.c10
-rw-r--r--drivers/md/raid10.c20
-rw-r--r--drivers/md/raid5.c9
-rw-r--r--drivers/media/common/saa7146_core.c1
-rw-r--r--drivers/media/common/saa7146_fops.c1
-rw-r--r--drivers/media/common/saa7146_hlp.c1
-rw-r--r--drivers/media/common/saa7146_video.c1
-rw-r--r--drivers/media/common/tuners/tuner-types.c1
-rw-r--r--drivers/media/dvb/ddbridge/Makefile2
-rw-r--r--drivers/media/dvb/dvb-usb/Makefile1
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-ids.h2
-rw-r--r--drivers/media/dvb/dvb-usb/it913x.c105
-rw-r--r--drivers/media/dvb/dvb-usb/mxl111sf-demod.c614
-rw-r--r--drivers/media/dvb/dvb-usb/mxl111sf-demod.h55
-rw-r--r--drivers/media/dvb/dvb-usb/mxl111sf.c228
-rw-r--r--drivers/media/dvb/dvb-usb/mxl111sf.h2
-rw-r--r--drivers/media/dvb/frontends/dibx000_common.c1
-rw-r--r--drivers/media/dvb/ngene/Makefile2
-rw-r--r--drivers/media/dvb/siano/sms-cards.c1
-rw-r--r--drivers/media/dvb/siano/smsendian.c1
-rw-r--r--drivers/media/dvb/siano/smssdio.c1
-rw-r--r--drivers/media/dvb/siano/smsusb.c1
-rw-r--r--drivers/media/media-device.c1
-rw-r--r--drivers/media/radio/Kconfig1
-rw-r--r--drivers/media/radio/radio-tea5764.c4
-rw-r--r--drivers/media/radio/radio-timb.c1
-rw-r--r--drivers/media/radio/radio-wl1273.c1
-rw-r--r--drivers/media/radio/si4713-i2c.c1
-rw-r--r--drivers/media/radio/wl128x/fmdrv_v4l2.c2
-rw-r--r--drivers/media/rc/ir-jvc-decoder.c1
-rw-r--r--drivers/media/rc/ir-lirc-codec.c1
-rw-r--r--drivers/media/rc/ir-nec-decoder.c1
-rw-r--r--drivers/media/rc/ir-raw.c2
-rw-r--r--drivers/media/rc/ir-rc5-decoder.c1
-rw-r--r--drivers/media/rc/ir-rc5-sz-decoder.c1
-rw-r--r--drivers/media/rc/ir-rc6-decoder.c1
-rw-r--r--drivers/media/rc/ir-sony-decoder.c1
-rw-r--r--drivers/media/rc/keymaps/rc-adstech-dvb-t-pci.c1
-rw-r--r--drivers/media/rc/keymaps/rc-alink-dtu-m.c1
-rw-r--r--drivers/media/rc/keymaps/rc-anysee.c1
-rw-r--r--drivers/media/rc/keymaps/rc-apac-viewcomp.c1
-rw-r--r--drivers/media/rc/keymaps/rc-asus-pc39.c1
-rw-r--r--drivers/media/rc/keymaps/rc-ati-tv-wonder-hd-600.c1
-rw-r--r--drivers/media/rc/keymaps/rc-avermedia-a16d.c1
-rw-r--r--drivers/media/rc/keymaps/rc-avermedia-cardbus.c1
-rw-r--r--drivers/media/rc/keymaps/rc-avermedia-dvbt.c1
-rw-r--r--drivers/media/rc/keymaps/rc-avermedia-m135a.c1
-rw-r--r--drivers/media/rc/keymaps/rc-avermedia-m733a-rm-k6.c1
-rw-r--r--drivers/media/rc/keymaps/rc-avermedia-rm-ks.c1
-rw-r--r--drivers/media/rc/keymaps/rc-avermedia.c1
-rw-r--r--drivers/media/rc/keymaps/rc-avertv-303.c1
-rw-r--r--drivers/media/rc/keymaps/rc-azurewave-ad-tu700.c1
-rw-r--r--drivers/media/rc/keymaps/rc-behold-columbus.c1
-rw-r--r--drivers/media/rc/keymaps/rc-behold.c1
-rw-r--r--drivers/media/rc/keymaps/rc-budget-ci-old.c1
-rw-r--r--drivers/media/rc/keymaps/rc-cinergy-1400.c1
-rw-r--r--drivers/media/rc/keymaps/rc-cinergy.c1
-rw-r--r--drivers/media/rc/keymaps/rc-dib0700-nec.c1
-rw-r--r--drivers/media/rc/keymaps/rc-dib0700-rc5.c1
-rw-r--r--drivers/media/rc/keymaps/rc-digitalnow-tinytwin.c1
-rw-r--r--drivers/media/rc/keymaps/rc-digittrade.c1
-rw-r--r--drivers/media/rc/keymaps/rc-dm1105-nec.c1
-rw-r--r--drivers/media/rc/keymaps/rc-dntv-live-dvb-t.c1
-rw-r--r--drivers/media/rc/keymaps/rc-dntv-live-dvbt-pro.c1
-rw-r--r--drivers/media/rc/keymaps/rc-em-terratec.c1
-rw-r--r--drivers/media/rc/keymaps/rc-encore-enltv-fm53.c1
-rw-r--r--drivers/media/rc/keymaps/rc-encore-enltv.c1
-rw-r--r--drivers/media/rc/keymaps/rc-encore-enltv2.c1
-rw-r--r--drivers/media/rc/keymaps/rc-evga-indtube.c1
-rw-r--r--drivers/media/rc/keymaps/rc-eztv.c1
-rw-r--r--drivers/media/rc/keymaps/rc-flydvb.c1
-rw-r--r--drivers/media/rc/keymaps/rc-flyvideo.c1
-rw-r--r--drivers/media/rc/keymaps/rc-fusionhdtv-mce.c1
-rw-r--r--drivers/media/rc/keymaps/rc-gadmei-rm008z.c1
-rw-r--r--drivers/media/rc/keymaps/rc-genius-tvgo-a11mce.c1
-rw-r--r--drivers/media/rc/keymaps/rc-gotview7135.c1
-rw-r--r--drivers/media/rc/keymaps/rc-hauppauge.c1
-rw-r--r--drivers/media/rc/keymaps/rc-imon-mce.c1
-rw-r--r--drivers/media/rc/keymaps/rc-imon-pad.c1
-rw-r--r--drivers/media/rc/keymaps/rc-iodata-bctv7e.c1
-rw-r--r--drivers/media/rc/keymaps/rc-kaiomy.c1
-rw-r--r--drivers/media/rc/keymaps/rc-kworld-315u.c1
-rw-r--r--drivers/media/rc/keymaps/rc-kworld-plus-tv-analog.c1
-rw-r--r--drivers/media/rc/keymaps/rc-leadtek-y04g0051.c1
-rw-r--r--drivers/media/rc/keymaps/rc-lirc.c1
-rw-r--r--drivers/media/rc/keymaps/rc-lme2510.c1
-rw-r--r--drivers/media/rc/keymaps/rc-manli.c1
-rw-r--r--drivers/media/rc/keymaps/rc-msi-digivox-ii.c1
-rw-r--r--drivers/media/rc/keymaps/rc-msi-digivox-iii.c1
-rw-r--r--drivers/media/rc/keymaps/rc-msi-tvanywhere-plus.c1
-rw-r--r--drivers/media/rc/keymaps/rc-msi-tvanywhere.c1
-rw-r--r--drivers/media/rc/keymaps/rc-nebula.c1
-rw-r--r--drivers/media/rc/keymaps/rc-nec-terratec-cinergy-xs.c1
-rw-r--r--drivers/media/rc/keymaps/rc-norwood.c1
-rw-r--r--drivers/media/rc/keymaps/rc-npgtech.c1
-rw-r--r--drivers/media/rc/keymaps/rc-pctv-sedna.c1
-rw-r--r--drivers/media/rc/keymaps/rc-pinnacle-color.c1
-rw-r--r--drivers/media/rc/keymaps/rc-pinnacle-grey.c1
-rw-r--r--drivers/media/rc/keymaps/rc-pinnacle-pctv-hd.c1
-rw-r--r--drivers/media/rc/keymaps/rc-pixelview-002t.c1
-rw-r--r--drivers/media/rc/keymaps/rc-pixelview-mk12.c1
-rw-r--r--drivers/media/rc/keymaps/rc-pixelview-new.c1
-rw-r--r--drivers/media/rc/keymaps/rc-pixelview.c1
-rw-r--r--drivers/media/rc/keymaps/rc-powercolor-real-angel.c1
-rw-r--r--drivers/media/rc/keymaps/rc-proteus-2309.c1
-rw-r--r--drivers/media/rc/keymaps/rc-purpletv.c1
-rw-r--r--drivers/media/rc/keymaps/rc-pv951.c1
-rw-r--r--drivers/media/rc/keymaps/rc-rc6-mce.c1
-rw-r--r--drivers/media/rc/keymaps/rc-real-audio-220-32-keys.c1
-rw-r--r--drivers/media/rc/keymaps/rc-streamzap.c1
-rw-r--r--drivers/media/rc/keymaps/rc-tbs-nec.c1
-rw-r--r--drivers/media/rc/keymaps/rc-technisat-usb2.c1
-rw-r--r--drivers/media/rc/keymaps/rc-terratec-cinergy-xs.c1
-rw-r--r--drivers/media/rc/keymaps/rc-terratec-slim-2.c1
-rw-r--r--drivers/media/rc/keymaps/rc-terratec-slim.c1
-rw-r--r--drivers/media/rc/keymaps/rc-tevii-nec.c1
-rw-r--r--drivers/media/rc/keymaps/rc-tivo.c1
-rw-r--r--drivers/media/rc/keymaps/rc-total-media-in-hand.c1
-rw-r--r--drivers/media/rc/keymaps/rc-trekstor.c1
-rw-r--r--drivers/media/rc/keymaps/rc-tt-1500.c1
-rw-r--r--drivers/media/rc/keymaps/rc-twinhan1027.c1
-rw-r--r--drivers/media/rc/keymaps/rc-videomate-m1f.c1
-rw-r--r--drivers/media/rc/keymaps/rc-videomate-s350.c1
-rw-r--r--drivers/media/rc/keymaps/rc-videomate-tv-pvr.c1
-rw-r--r--drivers/media/rc/keymaps/rc-winfast-usbii-deluxe.c1
-rw-r--r--drivers/media/rc/keymaps/rc-winfast.c1
-rw-r--r--drivers/media/rc/rc-main.c1
-rw-r--r--drivers/media/video/Kconfig9
-rw-r--r--drivers/media/video/Makefile2
-rw-r--r--drivers/media/video/adp1653.c1
-rw-r--r--drivers/media/video/ak881x.c1
-rw-r--r--drivers/media/video/atmel-isi.c142
-rw-r--r--drivers/media/video/cpia2/cpia2_usb.c1
-rw-r--r--drivers/media/video/cx18/cx18-driver.c2
-rw-r--r--drivers/media/video/cx25821/Kconfig (renamed from drivers/staging/cx25821/Kconfig)0
-rw-r--r--drivers/media/video/cx25821/Makefile (renamed from drivers/staging/cx25821/Makefile)0
-rw-r--r--drivers/media/video/cx25821/cx25821-alsa.c (renamed from drivers/staging/cx25821/cx25821-alsa.c)0
-rw-r--r--drivers/media/video/cx25821/cx25821-audio-upstream.c (renamed from drivers/staging/cx25821/cx25821-audio-upstream.c)0
-rw-r--r--drivers/media/video/cx25821/cx25821-audio-upstream.h (renamed from drivers/staging/cx25821/cx25821-audio-upstream.h)0
-rw-r--r--drivers/media/video/cx25821/cx25821-audio.h (renamed from drivers/staging/cx25821/cx25821-audio.h)0
-rw-r--r--drivers/media/video/cx25821/cx25821-biffuncs.h (renamed from drivers/staging/cx25821/cx25821-biffuncs.h)0
-rw-r--r--drivers/media/video/cx25821/cx25821-cards.c (renamed from drivers/staging/cx25821/cx25821-cards.c)0
-rw-r--r--drivers/media/video/cx25821/cx25821-core.c (renamed from drivers/staging/cx25821/cx25821-core.c)0
-rw-r--r--drivers/media/video/cx25821/cx25821-gpio.c (renamed from drivers/staging/cx25821/cx25821-gpio.c)0
-rw-r--r--drivers/media/video/cx25821/cx25821-i2c.c (renamed from drivers/staging/cx25821/cx25821-i2c.c)0
-rw-r--r--drivers/media/video/cx25821/cx25821-medusa-defines.h (renamed from drivers/staging/cx25821/cx25821-medusa-defines.h)0
-rw-r--r--drivers/media/video/cx25821/cx25821-medusa-reg.h (renamed from drivers/staging/cx25821/cx25821-medusa-reg.h)0
-rw-r--r--drivers/media/video/cx25821/cx25821-medusa-video.c (renamed from drivers/staging/cx25821/cx25821-medusa-video.c)0
-rw-r--r--drivers/media/video/cx25821/cx25821-medusa-video.h (renamed from drivers/staging/cx25821/cx25821-medusa-video.h)0
-rw-r--r--drivers/media/video/cx25821/cx25821-reg.h (renamed from drivers/staging/cx25821/cx25821-reg.h)0
-rw-r--r--drivers/media/video/cx25821/cx25821-sram.h (renamed from drivers/staging/cx25821/cx25821-sram.h)0
-rw-r--r--drivers/media/video/cx25821/cx25821-video-upstream-ch2.c (renamed from drivers/staging/cx25821/cx25821-video-upstream-ch2.c)0
-rw-r--r--drivers/media/video/cx25821/cx25821-video-upstream-ch2.h (renamed from drivers/staging/cx25821/cx25821-video-upstream-ch2.h)0
-rw-r--r--drivers/media/video/cx25821/cx25821-video-upstream.c (renamed from drivers/staging/cx25821/cx25821-video-upstream.c)0
-rw-r--r--drivers/media/video/cx25821/cx25821-video-upstream.h (renamed from drivers/staging/cx25821/cx25821-video-upstream.h)0
-rw-r--r--drivers/media/video/cx25821/cx25821-video.c (renamed from drivers/staging/cx25821/cx25821-video.c)2
-rw-r--r--drivers/media/video/cx25821/cx25821-video.h (renamed from drivers/staging/cx25821/cx25821-video.h)0
-rw-r--r--drivers/media/video/cx25821/cx25821.h (renamed from drivers/staging/cx25821/cx25821.h)3
-rw-r--r--drivers/media/video/cx25840/cx25840-ir.c1
-rw-r--r--drivers/media/video/davinci/dm355_ccdc.c1
-rw-r--r--drivers/media/video/davinci/dm644x_ccdc.c1
-rw-r--r--drivers/media/video/em28xx/em28xx-cards.c2
-rw-r--r--drivers/media/video/hdpvr/hdpvr-i2c.c1
-rw-r--r--drivers/media/video/hexium_gemini.c1
-rw-r--r--drivers/media/video/hexium_orion.c1
-rw-r--r--drivers/media/video/imx074.c55
-rw-r--r--drivers/media/video/ivtv/ivtv-driver.c2
-rw-r--r--drivers/media/video/m5mols/m5mols_core.c1
-rw-r--r--drivers/media/video/marvell-ccic/mcam-core.c3
-rw-r--r--drivers/media/video/mem2mem_testdev.c7
-rw-r--r--drivers/media/video/mt9m001.c329
-rw-r--r--drivers/media/video/mt9m111.c261
-rw-r--r--drivers/media/video/mt9t031.c348
-rw-r--r--drivers/media/video/mt9t112.c269
-rw-r--r--drivers/media/video/mt9v011.c1
-rw-r--r--drivers/media/video/mt9v022.c448
-rw-r--r--drivers/media/video/mt9v032.c1
-rw-r--r--drivers/media/video/mx1_camera.c71
-rw-r--r--drivers/media/video/mx2_camera.c78
-rw-r--r--drivers/media/video/mx3_camera.c359
-rw-r--r--drivers/media/video/mxb.c1
-rw-r--r--drivers/media/video/noon010pc30.c1
-rw-r--r--drivers/media/video/omap/omap_vout.c10
-rw-r--r--drivers/media/video/omap1_camera.c62
-rw-r--r--drivers/media/video/omap24xxcam.c1
-rw-r--r--drivers/media/video/omap3isp/isp.c3
-rw-r--r--drivers/media/video/omap3isp/ispccdc.c86
-rw-r--r--drivers/media/video/omap3isp/ispccp2.c125
-rw-r--r--drivers/media/video/omap3isp/ispcsi2.c91
-rw-r--r--drivers/media/video/omap3isp/isph3a_aewb.c2
-rw-r--r--drivers/media/video/omap3isp/isph3a_af.c2
-rw-r--r--drivers/media/video/omap3isp/isphist.c2
-rw-r--r--drivers/media/video/omap3isp/isppreview.c419
-rw-r--r--drivers/media/video/omap3isp/isppreview.h9
-rw-r--r--drivers/media/video/omap3isp/ispreg.h3
-rw-r--r--drivers/media/video/omap3isp/ispresizer.c104
-rw-r--r--drivers/media/video/omap3isp/ispstat.c52
-rw-r--r--drivers/media/video/omap3isp/ispstat.h2
-rw-r--r--drivers/media/video/omap3isp/ispvideo.c11
-rw-r--r--drivers/media/video/omap3isp/ispvideo.h1
-rw-r--r--drivers/media/video/ov2640.c178
-rw-r--r--drivers/media/video/ov5642.c288
-rw-r--r--drivers/media/video/ov6650.c505
-rw-r--r--drivers/media/video/ov772x.c198
-rw-r--r--drivers/media/video/ov9640.c186
-rw-r--r--drivers/media/video/ov9640.h4
-rw-r--r--drivers/media/video/ov9740.c151
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-devattr.c1
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw.c1
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-i2c-core.c1
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-v4l2.c1
-rw-r--r--drivers/media/video/pwc/pwc-if.c6
-rw-r--r--drivers/media/video/pxa_camera.c140
-rw-r--r--drivers/media/video/rj54n1cb0c.c224
-rw-r--r--drivers/media/video/s5k6aa.c1680
-rw-r--r--drivers/media/video/s5p-fimc/fimc-capture.c6
-rw-r--r--drivers/media/video/s5p-fimc/fimc-core.c6
-rw-r--r--drivers/media/video/s5p-mfc/s5p_mfc_ctrl.c4
-rw-r--r--drivers/media/video/s5p-mfc/s5p_mfc_dec.c7
-rw-r--r--drivers/media/video/s5p-mfc/s5p_mfc_enc.c5
-rw-r--r--drivers/media/video/s5p-tv/mixer_video.c4
-rw-r--r--drivers/media/video/saa7134/saa7134.h12
-rw-r--r--drivers/media/video/sh_mobile_ceu_camera.c491
-rw-r--r--drivers/media/video/sh_mobile_csi2.c133
-rw-r--r--drivers/media/video/sh_vou.c1
-rw-r--r--drivers/media/video/soc_camera.c273
-rw-r--r--drivers/media/video/soc_camera_platform.c45
-rw-r--r--drivers/media/video/soc_mediabus.c33
-rw-r--r--drivers/media/video/sr030pc30.c1
-rw-r--r--drivers/media/video/tcm825x.c1
-rw-r--r--drivers/media/video/timblogiw.c1
-rw-r--r--drivers/media/video/tvp514x.c1
-rw-r--r--drivers/media/video/tvp5150.c1
-rw-r--r--drivers/media/video/tvp7002.c1
-rw-r--r--drivers/media/video/tw9910.c268
-rw-r--r--drivers/media/video/usbvision/usbvision-cards.c1
-rw-r--r--drivers/media/video/v4l2-compat-ioctl32.c76
-rw-r--r--drivers/media/video/v4l2-ctrls.c2
-rw-r--r--drivers/media/video/v4l2-device.c37
-rw-r--r--drivers/media/video/v4l2-event.c1
-rw-r--r--drivers/media/video/v4l2-fh.c1
-rw-r--r--drivers/media/video/v4l2-int-device.c1
-rw-r--r--drivers/media/video/v4l2-ioctl.c36
-rw-r--r--drivers/media/video/v4l2-subdev.c1
-rw-r--r--drivers/media/video/videobuf2-core.c391
-rw-r--r--drivers/media/video/vivi.c6
-rw-r--r--drivers/memstick/core/memstick.c1
-rw-r--r--drivers/memstick/core/mspro_block.c1
-rw-r--r--drivers/memstick/host/jmb38x_ms.c1
-rw-r--r--drivers/memstick/host/tifm_ms.c1
-rw-r--r--drivers/message/i2o/pci.c1
-rw-r--r--drivers/mfd/Kconfig64
-rw-r--r--drivers/mfd/Makefile4
-rw-r--r--drivers/mfd/aat2870-core.c2
-rw-r--r--drivers/mfd/ab3100-core.c3
-rw-r--r--drivers/mfd/ab3550-core.c1380
-rw-r--r--drivers/mfd/ab5500-core.c1439
-rw-r--r--drivers/mfd/ab5500-core.h87
-rw-r--r--drivers/mfd/ab5500-debugfs.c806
-rw-r--r--drivers/mfd/ab5500-debugfs.h22
-rw-r--r--drivers/mfd/ab8500-core.c33
-rw-r--r--drivers/mfd/ab8500-debugfs.c1
-rw-r--r--drivers/mfd/ab8500-gpadc.c56
-rw-r--r--drivers/mfd/ab8500-sysctrl.c1
-rw-r--r--drivers/mfd/abx500-core.c1
-rw-r--r--drivers/mfd/asic3.c27
-rw-r--r--drivers/mfd/da903x.c2
-rw-r--r--drivers/mfd/db5500-prcmu.c29
-rw-r--r--drivers/mfd/db8500-prcmu-regs.h166
-rw-r--r--drivers/mfd/db8500-prcmu.c629
-rw-r--r--drivers/mfd/dbx500-prcmu-regs.h (renamed from drivers/mfd/db5500-prcmu-regs.h)105
-rw-r--r--drivers/mfd/dm355evm_msp.c1
-rw-r--r--drivers/mfd/intel_msic.c502
-rw-r--r--drivers/mfd/jz4740-adc.c2
-rw-r--r--drivers/mfd/max8997.c28
-rw-r--r--drivers/mfd/mc13xxx-core.c116
-rw-r--r--drivers/mfd/menelaus.c2
-rw-r--r--drivers/mfd/mfd-core.c1
-rw-r--r--drivers/mfd/pcf50633-core.c114
-rw-r--r--drivers/mfd/pcf50633-irq.c1
-rw-r--r--drivers/mfd/tc3589x.c2
-rw-r--r--drivers/mfd/timberdale.c9
-rw-r--r--drivers/mfd/tmio_core.c1
-rw-r--r--drivers/mfd/tps65912-core.c6
-rw-r--r--drivers/mfd/twl-core.c3
-rw-r--r--drivers/mfd/twl4030-irq.c342
-rw-r--r--drivers/mfd/twl4030-madc.c22
-rw-r--r--drivers/mfd/twl6030-irq.c76
-rw-r--r--drivers/mfd/wl1273-core.c1
-rw-r--r--drivers/mfd/wm831x-irq.c24
-rw-r--r--drivers/mfd/wm8400-core.c1
-rw-r--r--drivers/mfd/wm8994-core.c53
-rw-r--r--drivers/misc/ab8500-pwm.c1
-rw-r--r--drivers/misc/atmel-ssc.c1
-rw-r--r--drivers/misc/atmel_tclib.c1
-rw-r--r--drivers/misc/bh1780gli.c1
-rw-r--r--drivers/misc/kgdbts.c1
-rw-r--r--drivers/misc/sgi-gru/grukservices.c1
-rw-r--r--drivers/misc/ti-st/st_kim.c1
-rw-r--r--drivers/misc/tifm_7xx1.c1
-rw-r--r--drivers/misc/tifm_core.c1
-rw-r--r--drivers/misc/vmw_balloon.c4
-rw-r--r--drivers/mmc/core/bus.c2
-rw-r--r--drivers/mmc/core/debugfs.c1
-rw-r--r--drivers/mmc/core/host.c1
-rw-r--r--drivers/mmc/core/mmc.c1
-rw-r--r--drivers/mmc/core/mmc_ops.c1
-rw-r--r--drivers/mmc/core/quirks.c1
-rw-r--r--drivers/mmc/core/sd.c1
-rw-r--r--drivers/mmc/core/sd_ops.c1
-rw-r--r--drivers/mmc/core/sdio_bus.c1
-rw-r--r--drivers/mmc/core/sdio_io.c1
-rw-r--r--drivers/mmc/core/sdio_irq.c1
-rw-r--r--drivers/mmc/host/Kconfig2
-rw-r--r--drivers/mmc/host/au1xmmc.c92
-rw-r--r--drivers/mmc/host/omap_hsmmc.c2
-rw-r--r--drivers/mmc/host/s3cmci.c6
-rw-r--r--drivers/mmc/host/sdhci-tegra.c1
-rw-r--r--drivers/mtd/ar7part.c1
-rw-r--r--drivers/mtd/cmdlinepart.c1
-rw-r--r--drivers/mtd/lpddr/lpddr_cmds.c1
-rw-r--r--drivers/mtd/maps/lantiq-flash.c4
-rw-r--r--drivers/mtd/mtdblock_ro.c1
-rw-r--r--drivers/mtd/mtdchar.c2
-rw-r--r--drivers/mtd/mtdsuper.c1
-rw-r--r--drivers/mtd/nand/Kconfig2
-rw-r--r--drivers/mtd/nand/au1550nd.c6
-rw-r--r--drivers/mtd/nand/cafe_nand.c1
-rw-r--r--drivers/mtd/nand/cmx270_nand.c1
-rw-r--r--drivers/mtd/nand/diskonchip.c1
-rw-r--r--drivers/mtd/nand/nand_bbt.c1
-rw-r--r--drivers/mtd/nand/omap2.c1
-rw-r--r--drivers/mtd/nand/sm_common.c1
-rw-r--r--drivers/mtd/onenand/onenand_bbt.c1
-rw-r--r--drivers/mtd/redboot.c1
-rw-r--r--drivers/mtd/rfd_ftl.c1
-rw-r--r--drivers/mtd/ubi/vmt.c1
-rw-r--r--drivers/net/bonding/bond_main.c37
-rw-r--r--drivers/net/bonding/bond_procfs.c13
-rw-r--r--drivers/net/ethernet/Kconfig1
-rw-r--r--drivers/net/ethernet/Makefile1
-rw-r--r--drivers/net/ethernet/amd/au1000_eth.c48
-rw-r--r--drivers/net/ethernet/amd/au1000_eth.h2
-rw-r--r--drivers/net/ethernet/apple/Kconfig12
-rw-r--r--drivers/net/ethernet/apple/Makefile1
-rw-r--r--drivers/net/ethernet/brocade/bna/bnad.c1
-rw-r--r--drivers/net/ethernet/chelsio/cxgb3/cxgb3_offload.c1
-rw-r--r--drivers/net/ethernet/chelsio/cxgb3/l2t.c1
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4/l2t.c7
-rw-r--r--drivers/net/ethernet/chelsio/cxgb4/sge.c1
-rw-r--r--drivers/net/ethernet/cirrus/Kconfig14
-rw-r--r--drivers/net/ethernet/cirrus/Makefile1
-rw-r--r--drivers/net/ethernet/cirrus/mac89x0.c (renamed from drivers/net/ethernet/apple/mac89x0.c)0
-rw-r--r--drivers/net/ethernet/emulex/benet/be_cmds.c12
-rw-r--r--drivers/net/ethernet/emulex/benet/be_hw.h2
-rw-r--r--drivers/net/ethernet/emulex/benet/be_main.c67
-rw-r--r--drivers/net/ethernet/ethoc.c1
-rw-r--r--drivers/net/ethernet/freescale/ucc_geth.c1
-rw-r--r--drivers/net/ethernet/i825xx/3c505.c6
-rw-r--r--drivers/net/ethernet/intel/e100.c4
-rw-r--r--drivers/net/ethernet/intel/e1000e/ich8lan.c3
-rw-r--r--drivers/net/ethernet/intel/e1000e/param.c1
-rw-r--r--drivers/net/ethernet/intel/igb/e1000_phy.c2
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_common.c20
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_dcb_nl.c10
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_main.c48
-rw-r--r--drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.h2
-rw-r--r--drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c2
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/alloc.c1
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/catas.c1
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/cmd.c1
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/cq.c1
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/en_tx.c1
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/eq.c1
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/fw.c1
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/intf.c1
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/mcg.c1
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/mr.c1
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/pd.c1
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/port.c1
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/qp.c1
-rw-r--r--drivers/net/ethernet/mellanox/mlx4/srq.c1
-rw-r--r--drivers/net/ethernet/neterion/vxge/vxge-main.c1
-rw-r--r--drivers/net/ethernet/octeon/octeon_mgmt.c1
-rw-r--r--drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c1
-rw-r--r--drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_param.c1
-rw-r--r--drivers/net/ethernet/realtek/Kconfig12
-rw-r--r--drivers/net/ethernet/realtek/Makefile1
-rw-r--r--drivers/net/ethernet/sfc/rx.c1
-rw-r--r--drivers/net/ethernet/silan/Kconfig33
-rw-r--r--drivers/net/ethernet/silan/Makefile5
-rw-r--r--drivers/net/ethernet/silan/sc92031.c (renamed from drivers/net/ethernet/realtek/sc92031.c)0
-rw-r--r--drivers/net/ethernet/smsc/smsc9420.c1
-rw-r--r--drivers/net/ethernet/stmicro/stmmac/Kconfig9
-rw-r--r--drivers/net/ethernet/toshiba/ps3_gelic_net.c3
-rw-r--r--drivers/net/ethernet/toshiba/ps3_gelic_net.h6
-rw-r--r--drivers/net/ethernet/xilinx/ll_temac_main.c4
-rw-r--r--drivers/net/ethernet/xscale/ixp4xx_eth.c1
-rw-r--r--drivers/net/irda/Kconfig2
-rw-r--r--drivers/net/phy/realtek.c1
-rw-r--r--drivers/net/rionet.c4
-rw-r--r--drivers/net/usb/lg-vl600.c1
-rw-r--r--drivers/net/veth.c1
-rw-r--r--drivers/net/virtio_net.c14
-rw-r--r--drivers/net/vmxnet3/vmxnet3_drv.c1
-rw-r--r--drivers/net/wimax/i2400m/control.c2
-rw-r--r--drivers/net/wimax/i2400m/debugfs.c1
-rw-r--r--drivers/net/wimax/i2400m/fw.c1
-rw-r--r--drivers/net/wimax/i2400m/netdev.c1
-rw-r--r--drivers/net/wimax/i2400m/rx.c2
-rw-r--r--drivers/net/wimax/i2400m/sdio.c1
-rw-r--r--drivers/net/wimax/i2400m/tx.c1
-rw-r--r--drivers/net/wimax/i2400m/usb.c1
-rw-r--r--drivers/net/wireless/adm8211.c1
-rw-r--r--drivers/net/wireless/ath/Kconfig2
-rw-r--r--drivers/net/wireless/ath/ath5k/debug.c3
-rw-r--r--drivers/net/wireless/ath/ath5k/pci.c1
-rw-r--r--drivers/net/wireless/ath/ath6kl/cfg80211.c2
-rw-r--r--drivers/net/wireless/ath/ath6kl/debug.c1
-rw-r--r--drivers/net/wireless/ath/ath6kl/sdio.c1
-rw-r--r--drivers/net/wireless/ath/ath9k/ahb.c1
-rw-r--r--drivers/net/wireless/ath/ath9k/ani.c1
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9002_hw.c1
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9002_mac.c1
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_mac.c1
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_paprd.c1
-rw-r--r--drivers/net/wireless/ath/ath9k/ar9003_phy.c1
-rw-r--r--drivers/net/wireless/ath/ath9k/btcoex.c1
-rw-r--r--drivers/net/wireless/ath/ath9k/calib.c1
-rw-r--r--drivers/net/wireless/ath/ath9k/debug.c1
-rw-r--r--drivers/net/wireless/ath/ath9k/hw.c1
-rw-r--r--drivers/net/wireless/ath/ath9k/init.c1
-rw-r--r--drivers/net/wireless/ath/ath9k/mac.c1
-rw-r--r--drivers/net/wireless/ath/ath9k/pci.c1
-rw-r--r--drivers/net/wireless/ath/ath9k/rc.c1
-rw-r--r--drivers/net/wireless/ath/carl9170/fw.c1
-rw-r--r--drivers/net/wireless/ath/debug.c1
-rw-r--r--drivers/net/wireless/ath/hw.c1
-rw-r--r--drivers/net/wireless/ath/key.c1
-rw-r--r--drivers/net/wireless/ath/regd.c1
-rw-r--r--drivers/net/wireless/b43/main.c2
-rw-r--r--drivers/net/wireless/b43/pcmcia.c1
-rw-r--r--drivers/net/wireless/b43legacy/main.c2
-rw-r--r--drivers/net/wireless/brcm80211/brcmfmac/bcmsdh.c1
-rw-r--r--drivers/net/wireless/brcm80211/brcmsmac/mac80211_if.c1
-rw-r--r--drivers/net/wireless/hostap/hostap_80211_rx.c1
-rw-r--r--drivers/net/wireless/hostap/hostap_80211_tx.c1
-rw-r--r--drivers/net/wireless/hostap/hostap_ap.c2
-rw-r--r--drivers/net/wireless/hostap/hostap_info.c1
-rw-r--r--drivers/net/wireless/hostap/hostap_ioctl.c1
-rw-r--r--drivers/net/wireless/hostap/hostap_proc.c1
-rw-r--r--drivers/net/wireless/iwlegacy/iwl-debugfs.c1
-rw-r--r--drivers/net/wireless/iwlegacy/iwl-rx.c1
-rw-r--r--drivers/net/wireless/iwlegacy/iwl-scan.c1
-rw-r--r--drivers/net/wireless/iwlegacy/iwl-sta.c1
-rw-r--r--drivers/net/wireless/iwlegacy/iwl-tx.c1
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-pci.c1
-rw-r--r--drivers/net/wireless/iwmc3200wifi/commands.c1
-rw-r--r--drivers/net/wireless/iwmc3200wifi/debugfs.c1
-rw-r--r--drivers/net/wireless/iwmc3200wifi/main.c1
-rw-r--r--drivers/net/wireless/iwmc3200wifi/sdio.c1
-rw-r--r--drivers/net/wireless/libertas/cmd.c1
-rw-r--r--drivers/net/wireless/libertas/debugfs.c1
-rw-r--r--drivers/net/wireless/libertas/if_sdio.c2
-rw-r--r--drivers/net/wireless/libertas/if_spi.c2
-rw-r--r--drivers/net/wireless/libertas/if_usb.c2
-rw-r--r--drivers/net/wireless/libertas/main.c2
-rw-r--r--drivers/net/wireless/libertas/rx.c1
-rw-r--r--drivers/net/wireless/libertas/tx.c1
-rw-r--r--drivers/net/wireless/libertas_tf/cmd.c1
-rw-r--r--drivers/net/wireless/libertas_tf/if_usb.c2
-rw-r--r--drivers/net/wireless/libertas_tf/main.c1
-rw-r--r--drivers/net/wireless/mac80211_hwsim.c1
-rw-r--r--drivers/net/wireless/orinoco/fw.c1
-rw-r--r--drivers/net/wireless/p54/eeprom.c1
-rw-r--r--drivers/net/wireless/p54/fwio.c1
-rw-r--r--drivers/net/wireless/p54/main.c1
-rw-r--r--drivers/net/wireless/p54/p54pci.c1
-rw-r--r--drivers/net/wireless/p54/p54usb.c1
-rw-r--r--drivers/net/wireless/p54/txrx.c1
-rw-r--r--drivers/net/wireless/rtl818x/rtl8180/dev.c1
-rw-r--r--drivers/net/wireless/rtl818x/rtl8187/dev.c1
-rw-r--r--drivers/net/wireless/rtlwifi/Kconfig4
-rw-r--r--drivers/net/wireless/rtlwifi/base.c1
-rw-r--r--drivers/net/wireless/rtlwifi/cam.c1
-rw-r--r--drivers/net/wireless/rtlwifi/efuse.c1
-rw-r--r--drivers/net/wireless/rtlwifi/pci.c1
-rw-r--r--drivers/net/wireless/rtlwifi/ps.c1
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c1
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192c/fw_common.c1
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192c/main.c1
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c1
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192ce/sw.c1
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192cu/sw.c1
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192de/sw.c1
-rw-r--r--drivers/net/wireless/rtlwifi/rtl8192se/sw.c1
-rw-r--r--drivers/net/wireless/rtlwifi/usb.c1
-rw-r--r--drivers/net/wireless/wl12xx/boot.c1
-rw-r--r--drivers/net/wireless/zd1211rw/zd_usb.c1
-rw-r--r--drivers/net/xen-netback/common.h11
-rw-r--r--drivers/net/xen-netback/netback.c80
-rw-r--r--drivers/nfc/nfcwilink.c1
-rw-r--r--drivers/of/fdt.c7
-rw-r--r--drivers/of/of_net.c1
-rw-r--r--drivers/of/of_pci.c1
-rw-r--r--drivers/of/of_pci_irq.c1
-rw-r--r--drivers/of/of_spi.c1
-rw-r--r--drivers/of/platform.c28
-rw-r--r--drivers/parisc/ccio-dma.c1
-rw-r--r--drivers/parisc/sba_iommu.c1
-rw-r--r--drivers/pci/Kconfig11
-rw-r--r--drivers/pci/ats.c1
-rw-r--r--drivers/pci/hotplug-pci.c1
-rw-r--r--drivers/pci/hotplug/pciehp_acpi.c1
-rw-r--r--drivers/pci/hotplug/pcihp_slot.c1
-rw-r--r--drivers/pci/hotplug/rpadlpar_core.c1
-rw-r--r--drivers/pci/htirq.c1
-rw-r--r--drivers/pci/ioapic.c1
-rw-r--r--drivers/pci/iov.c1
-rw-r--r--drivers/pci/irq.c1
-rw-r--r--drivers/pci/msi.c1
-rw-r--r--drivers/pci/pci-sysfs.c1
-rw-r--r--drivers/pci/quirks.c1
-rw-r--r--drivers/pci/rom.c1
-rw-r--r--drivers/pci/setup-res.c1
-rw-r--r--drivers/pci/slot.c1
-rw-r--r--drivers/pci/vpd.c1
-rw-r--r--drivers/pcmcia/db1xxx_ss.c1
-rw-r--r--drivers/pcmcia/pxa2xx_base.c1
-rw-r--r--drivers/pcmcia/pxa2xx_cm_x255.c1
-rw-r--r--drivers/pcmcia/pxa2xx_cm_x270.c1
-rw-r--r--drivers/pcmcia/pxa2xx_cm_x2xx.c3
-rw-r--r--drivers/pinctrl/core.c1
-rw-r--r--drivers/platform/x86/intel_scu_ipc.c1
-rw-r--r--drivers/platform/x86/msi-wmi.c1
-rw-r--r--drivers/platform/x86/wmi.c1
-rw-r--r--drivers/pnp/pnpacpi/core.c1
-rw-r--r--drivers/power/Kconfig1
-rw-r--r--drivers/power/ds2780_battery.c86
-rw-r--r--drivers/power/max17042_battery.c1
-rw-r--r--drivers/power/max8903_charger.c1
-rw-r--r--drivers/power/max8997_charger.c1
-rw-r--r--drivers/power/max8998_charger.c1
-rw-r--r--drivers/power/power_supply_sysfs.c1
-rw-r--r--drivers/pps/clients/Kconfig9
-rw-r--r--drivers/pps/clients/Makefile1
-rw-r--r--drivers/pps/clients/pps-gpio.c227
-rw-r--r--drivers/pps/clients/pps-ktimer.c12
-rw-r--r--drivers/pps/clients/pps_parport.c9
-rw-r--r--drivers/pps/kapi.c20
-rw-r--r--drivers/ps3/ps3stor_lib.c1
-rw-r--r--drivers/ps3/sys-manager-core.c1
-rw-r--r--drivers/rapidio/Kconfig6
-rw-r--r--drivers/rapidio/Makefile1
-rw-r--r--drivers/rapidio/devices/Kconfig10
-rw-r--r--drivers/rapidio/devices/Makefile5
-rw-r--r--drivers/rapidio/devices/tsi721.c2360
-rw-r--r--drivers/rapidio/devices/tsi721.h766
-rw-r--r--drivers/rapidio/rio-scan.c6
-rw-r--r--drivers/rapidio/switches/idt_gen2.c1
-rw-r--r--drivers/regulator/88pm8607.c1
-rw-r--r--drivers/regulator/ab8500.c1
-rw-r--r--drivers/regulator/bq24022.c1
-rw-r--r--drivers/regulator/core.c1
-rw-r--r--drivers/regulator/da903x.c1
-rw-r--r--drivers/regulator/db8500-prcmu.c3
-rw-r--r--drivers/regulator/dummy.c1
-rw-r--r--drivers/regulator/fixed.c1
-rw-r--r--drivers/regulator/lp3971.c1
-rw-r--r--drivers/regulator/lp3972.c1
-rw-r--r--drivers/regulator/max8925-regulator.c1
-rw-r--r--drivers/regulator/max8997.c1
-rw-r--r--drivers/regulator/mc13783-regulator.c7
-rw-r--r--drivers/regulator/mc13892-regulator.c1
-rw-r--r--drivers/regulator/mc13xxx-regulator-core.c1
-rw-r--r--drivers/regulator/tps6586x-regulator.c1
-rw-r--r--drivers/regulator/userspace-consumer.c1
-rw-r--r--drivers/regulator/virtual.c1
-rw-r--r--drivers/regulator/wm8400-regulator.c1
-rw-r--r--drivers/rtc/Kconfig2
-rw-r--r--drivers/rtc/class.c32
-rw-r--r--drivers/rtc/interface.c1
-rw-r--r--drivers/rtc/rtc-dm355evm.c1
-rw-r--r--drivers/rtc/rtc-ds1305.c1
-rw-r--r--drivers/rtc/rtc-ds1307.c27
-rw-r--r--drivers/rtc/rtc-ds1511.c1
-rw-r--r--drivers/rtc/rtc-ds1553.c1
-rw-r--r--drivers/rtc/rtc-ds1672.c1
-rw-r--r--drivers/rtc/rtc-ds1742.c1
-rw-r--r--drivers/rtc/rtc-em3027.c1
-rw-r--r--drivers/rtc/rtc-isl12022.c1
-rw-r--r--drivers/rtc/rtc-mc13xxx.c6
-rw-r--r--drivers/rtc/rtc-mv.c1
-rw-r--r--drivers/rtc/rtc-pcf2123.c1
-rw-r--r--drivers/rtc/rtc-pcf8563.c1
-rw-r--r--drivers/rtc/rtc-rs5c348.c1
-rw-r--r--drivers/rtc/rtc-rs5c372.c1
-rw-r--r--drivers/rtc/rtc-stk17ta8.c1
-rw-r--r--drivers/rtc/rtc-tx4939.c1
-rw-r--r--drivers/rtc/rtc-x1205.c1
-rw-r--r--drivers/s390/block/dcssblk.c7
-rw-r--r--drivers/s390/block/xpram.c5
-rw-r--r--drivers/s390/char/fs3270.c1
-rw-r--r--drivers/s390/char/sclp_cpi_sys.c1
-rw-r--r--drivers/s390/char/vmcp.c1
-rw-r--r--drivers/s390/char/vmur.c1
-rw-r--r--drivers/s390/cio/chp.c2
-rw-r--r--drivers/s390/cio/qdio_debug.c2
-rw-r--r--drivers/s390/cio/qdio_setup.c1
-rw-r--r--drivers/s390/kvm/kvm_virtio.c1
-rw-r--r--drivers/s390/scsi/zfcp_aux.c1
-rw-r--r--drivers/s390/scsi/zfcp_ccw.c1
-rw-r--r--drivers/s390/scsi/zfcp_dbf.c1
-rw-r--r--drivers/s390/scsi/zfcp_qdio.c1
-rw-r--r--drivers/s390/scsi/zfcp_scsi.c1
-rw-r--r--drivers/scsi/Kconfig14
-rw-r--r--drivers/scsi/a2091.c1
-rw-r--r--drivers/scsi/a3000.c1
-rw-r--r--drivers/scsi/aacraid/aachba.c1
-rw-r--r--drivers/scsi/be2iscsi/be_main.c1
-rw-r--r--drivers/scsi/bfa/bfad_debugfs.c1
-rw-r--r--drivers/scsi/bfa/bfad_im.c2
-rw-r--r--drivers/scsi/bnx2fc/bnx2fc.h5
-rw-r--r--drivers/scsi/bnx2fc/bnx2fc_els.c23
-rw-r--r--drivers/scsi/bnx2fc/bnx2fc_fcoe.c2
-rw-r--r--drivers/scsi/bnx2fc/bnx2fc_io.c37
-rw-r--r--drivers/scsi/cxgbi/libcxgbi.c1
-rw-r--r--drivers/scsi/device_handler/scsi_dh.c11
-rw-r--r--drivers/scsi/device_handler/scsi_dh_alua.c4
-rw-r--r--drivers/scsi/device_handler/scsi_dh_emc.c1
-rw-r--r--drivers/scsi/device_handler/scsi_dh_hp_sw.c1
-rw-r--r--drivers/scsi/device_handler/scsi_dh_rdac.c1
-rw-r--r--drivers/scsi/fcoe/fcoe.c13
-rw-r--r--drivers/scsi/gvp11.c1
-rw-r--r--drivers/scsi/hosts.c9
-rw-r--r--drivers/scsi/hpsa.c228
-rw-r--r--drivers/scsi/hpsa.h10
-rw-r--r--drivers/scsi/hpsa_cmd.h5
-rw-r--r--drivers/scsi/ipr.c2
-rw-r--r--drivers/scsi/ipr.h1
-rw-r--r--drivers/scsi/isci/host.c23
-rw-r--r--drivers/scsi/isci/init.c2
-rw-r--r--drivers/scsi/isci/port.c146
-rw-r--r--drivers/scsi/isci/port.h6
-rw-r--r--drivers/scsi/isci/probe_roms.h4
-rw-r--r--drivers/scsi/isci/remote_device.c85
-rw-r--r--drivers/scsi/isci/remote_device.h5
-rw-r--r--drivers/scsi/isci/request.c52
-rw-r--r--drivers/scsi/isci/request.h6
-rw-r--r--drivers/scsi/isci/task.c698
-rw-r--r--drivers/scsi/isci/task.h35
-rw-r--r--drivers/scsi/iscsi_tcp.c1
-rw-r--r--drivers/scsi/libfc/fc_disc.c1
-rw-r--r--drivers/scsi/libfc/fc_elsct.c1
-rw-r--r--drivers/scsi/libfc/fc_exch.c8
-rw-r--r--drivers/scsi/libfc/fc_libfc.c1
-rw-r--r--drivers/scsi/libfc/fc_lport.c101
-rw-r--r--drivers/scsi/libfc/fc_npiv.c1
-rw-r--r--drivers/scsi/libfc/fc_rport.c1
-rw-r--r--drivers/scsi/libiscsi.c1
-rw-r--r--drivers/scsi/libiscsi_tcp.c1
-rw-r--r--drivers/scsi/libsas/sas_host_smp.c1
-rw-r--r--drivers/scsi/libsas/sas_scsi_host.c1
-rw-r--r--drivers/scsi/libsas/sas_task.c1
-rw-r--r--drivers/scsi/libsrp.c1
-rw-r--r--drivers/scsi/lpfc/lpfc_attr.c1
-rw-r--r--drivers/scsi/lpfc/lpfc_debugfs.c1
-rw-r--r--drivers/scsi/lpfc/lpfc_init.c1
-rw-r--r--drivers/scsi/lpfc/lpfc_scsi.c1
-rw-r--r--drivers/scsi/mac53c94.c1
-rw-r--r--drivers/scsi/megaraid/megaraid_mbox.c1
-rw-r--r--drivers/scsi/mpt2sas/mpi/mpi2.h11
-rw-r--r--drivers/scsi/mpt2sas/mpi/mpi2_cnfg.h153
-rw-r--r--drivers/scsi/mpt2sas/mpi/mpi2_ioc.h113
-rw-r--r--drivers/scsi/mpt2sas/mpt2sas_base.c247
-rw-r--r--drivers/scsi/mpt2sas/mpt2sas_base.h32
-rw-r--r--drivers/scsi/mpt2sas/mpt2sas_config.c67
-rw-r--r--drivers/scsi/mpt2sas/mpt2sas_ctl.c9
-rw-r--r--drivers/scsi/mpt2sas/mpt2sas_scsih.c634
-rw-r--r--drivers/scsi/mvsas/mv_init.c10
-rw-r--r--drivers/scsi/osd/osd_initiator.c1
-rw-r--r--drivers/scsi/pmcraid.c2
-rw-r--r--drivers/scsi/ps3rom.c1
-rw-r--r--drivers/scsi/qla2xxx/qla_isr.c2
-rw-r--r--drivers/scsi/scsi_lib.c10
-rw-r--r--drivers/scsi/scsi_lib_dma.c1
-rw-r--r--drivers/scsi/scsi_netlink.c1
-rw-r--r--drivers/scsi/scsi_pm.c1
-rw-r--r--drivers/scsi/scsi_scan.c1
-rw-r--r--drivers/scsi/scsi_tgt_if.c1
-rw-r--r--drivers/scsi/scsi_transport_iscsi.c2
-rw-r--r--drivers/scsi/sd.c12
-rw-r--r--drivers/scsi/sd.h6
-rw-r--r--drivers/scsi/sr_ioctl.c1
-rw-r--r--drivers/scsi/st.c4
-rw-r--r--drivers/sfi/sfi_core.h3
-rw-r--r--drivers/sh/intc/chip.c11
-rw-r--r--drivers/sh/intc/core.c2
-rw-r--r--drivers/sh/intc/dynamic.c1
-rw-r--r--drivers/sh/intc/userimask.c1
-rw-r--r--drivers/sh/intc/virq.c1
-rw-r--r--drivers/sh/maple/maple.c1
-rw-r--r--drivers/sh/pfc.c29
-rw-r--r--drivers/spi/Kconfig2
-rw-r--r--drivers/spi/spi-altera.c1
-rw-r--r--drivers/spi/spi-au1550.c1
-rw-r--r--drivers/spi/spi-bitbang.c1
-rw-r--r--drivers/spi/spi-butterfly.c1
-rw-r--r--drivers/spi/spi-dw-mmio.c1
-rw-r--r--drivers/spi/spi-dw-pci.c1
-rw-r--r--drivers/spi/spi-dw.c1
-rw-r--r--drivers/spi/spi-gpio.c1
-rw-r--r--drivers/spi/spi-oc-tiny.c1
-rw-r--r--drivers/spi/spi-omap-uwire.c1
-rw-r--r--drivers/spi/spi-orion.c1
-rw-r--r--drivers/spi/spi-pxa2xx-pci.c1
-rw-r--r--drivers/spi/spi-s3c24xx.c1
-rw-r--r--drivers/spi/spi-s3c64xx.c175
-rw-r--r--drivers/spi/spi-sh-msiof.c1
-rw-r--r--drivers/spi/spi-sh-sci.c1
-rw-r--r--drivers/spi/spi-ti-ssp.c1
-rw-r--r--drivers/spi/spi-tle62x0.c1
-rw-r--r--drivers/spi/spi-txx9.c1
-rw-r--r--drivers/spi/spi.c1
-rw-r--r--drivers/ssb/b43_pci_bridge.c1
-rw-r--r--drivers/ssb/driver_chipcommon.c1
-rw-r--r--drivers/ssb/driver_chipcommon_pmu.c1
-rw-r--r--drivers/ssb/driver_gige.c1
-rw-r--r--drivers/ssb/driver_pcicore.c1
-rw-r--r--drivers/ssb/embedded.c1
-rw-r--r--drivers/ssb/main.c1
-rw-r--r--drivers/ssb/pcihost_wrapper.c1
-rw-r--r--drivers/staging/Kconfig16
-rw-r--r--drivers/staging/Makefile8
-rw-r--r--drivers/staging/cx25821/README6
-rw-r--r--drivers/staging/cxt1e1/linux.c1
-rw-r--r--drivers/staging/gma500/intel_i2c.c1
-rw-r--r--drivers/staging/gma500/mdfld_dsi_output.c1
-rw-r--r--drivers/staging/gma500/mdfld_output.c3
-rw-r--r--drivers/staging/gma500/mid_bios.c1
-rw-r--r--drivers/staging/gma500/mrst_hdmi_i2c.c1
-rw-r--r--drivers/staging/gma500/psb_drv.c1
-rw-r--r--drivers/staging/iio/accel/adis16201_ring.c1
-rw-r--r--drivers/staging/iio/accel/adis16201_trigger.c1
-rw-r--r--drivers/staging/iio/accel/adis16203_ring.c1
-rw-r--r--drivers/staging/iio/accel/adis16203_trigger.c1
-rw-r--r--drivers/staging/iio/accel/adis16204_ring.c1
-rw-r--r--drivers/staging/iio/accel/adis16204_trigger.c1
-rw-r--r--drivers/staging/iio/accel/adis16209_ring.c1
-rw-r--r--drivers/staging/iio/accel/adis16209_trigger.c1
-rw-r--r--drivers/staging/iio/accel/adis16240_ring.c1
-rw-r--r--drivers/staging/iio/accel/adis16240_trigger.c1
-rw-r--r--drivers/staging/iio/accel/lis3l02dq_ring.c1
-rw-r--r--drivers/staging/iio/adc/ad7793.c1
-rw-r--r--drivers/staging/iio/dac/ad5686.c1
-rw-r--r--drivers/staging/iio/gyro/adis16060_core.c1
-rw-r--r--drivers/staging/iio/gyro/adis16260_ring.c1
-rw-r--r--drivers/staging/iio/gyro/adis16260_trigger.c1
-rw-r--r--drivers/staging/iio/iio_simple_dummy_buffer.c1
-rw-r--r--drivers/staging/iio/imu/adis16400_ring.c1
-rw-r--r--drivers/staging/iio/imu/adis16400_trigger.c1
-rw-r--r--drivers/staging/iio/industrialio-buffer.c1
-rw-r--r--drivers/staging/iio/meter/ade7758_ring.c1
-rw-r--r--drivers/staging/iio/meter/ade7758_trigger.c1
-rw-r--r--drivers/staging/intel_sst/intel_sst.c1
-rw-r--r--drivers/staging/intel_sst/intel_sst_drv_interface.c1
-rw-r--r--drivers/staging/line6/audio.c1
-rw-r--r--drivers/staging/media/Kconfig37
-rw-r--r--drivers/staging/media/Makefile7
-rw-r--r--drivers/staging/media/as102/Kconfig7
-rw-r--r--drivers/staging/media/as102/Makefile6
-rw-r--r--drivers/staging/media/as102/as102_drv.c351
-rw-r--r--drivers/staging/media/as102/as102_drv.h141
-rw-r--r--drivers/staging/media/as102/as102_fe.c603
-rw-r--r--drivers/staging/media/as102/as102_fw.c251
-rw-r--r--drivers/staging/media/as102/as102_fw.h42
-rw-r--r--drivers/staging/media/as102/as102_usb_drv.c478
-rw-r--r--drivers/staging/media/as102/as102_usb_drv.h59
-rw-r--r--drivers/staging/media/as102/as10x_cmd.c452
-rw-r--r--drivers/staging/media/as102/as10x_cmd.h540
-rw-r--r--drivers/staging/media/as102/as10x_cmd_cfg.c215
-rw-r--r--drivers/staging/media/as102/as10x_cmd_stream.c223
-rw-r--r--drivers/staging/media/as102/as10x_handle.h58
-rw-r--r--drivers/staging/media/as102/as10x_types.h198
-rw-r--r--drivers/staging/media/cxd2099/Kconfig (renamed from drivers/staging/cxd2099/Kconfig)0
-rw-r--r--drivers/staging/media/cxd2099/Makefile (renamed from drivers/staging/cxd2099/Makefile)0
-rw-r--r--drivers/staging/media/cxd2099/TODO (renamed from drivers/staging/cxd2099/TODO)0
-rw-r--r--drivers/staging/media/cxd2099/cxd2099.c (renamed from drivers/staging/cxd2099/cxd2099.c)0
-rw-r--r--drivers/staging/media/cxd2099/cxd2099.h (renamed from drivers/staging/cxd2099/cxd2099.h)0
-rw-r--r--drivers/staging/media/dt3155v4l/Kconfig (renamed from drivers/staging/dt3155v4l/Kconfig)0
-rw-r--r--drivers/staging/media/dt3155v4l/Makefile (renamed from drivers/staging/dt3155v4l/Makefile)0
-rw-r--r--drivers/staging/media/dt3155v4l/dt3155v4l.c (renamed from drivers/staging/dt3155v4l/dt3155v4l.c)0
-rw-r--r--drivers/staging/media/dt3155v4l/dt3155v4l.h (renamed from drivers/staging/dt3155v4l/dt3155v4l.h)0
-rw-r--r--drivers/staging/media/easycap/Kconfig (renamed from drivers/staging/easycap/Kconfig)0
-rw-r--r--drivers/staging/media/easycap/Makefile (renamed from drivers/staging/easycap/Makefile)0
-rw-r--r--drivers/staging/media/easycap/README (renamed from drivers/staging/easycap/README)0
-rw-r--r--drivers/staging/media/easycap/easycap.h (renamed from drivers/staging/easycap/easycap.h)0
-rw-r--r--drivers/staging/media/easycap/easycap_ioctl.c (renamed from drivers/staging/easycap/easycap_ioctl.c)0
-rw-r--r--drivers/staging/media/easycap/easycap_low.c (renamed from drivers/staging/easycap/easycap_low.c)0
-rw-r--r--drivers/staging/media/easycap/easycap_main.c (renamed from drivers/staging/easycap/easycap_main.c)0
-rw-r--r--drivers/staging/media/easycap/easycap_settings.c (renamed from drivers/staging/easycap/easycap_settings.c)0
-rw-r--r--drivers/staging/media/easycap/easycap_sound.c (renamed from drivers/staging/easycap/easycap_sound.c)0
-rw-r--r--drivers/staging/media/easycap/easycap_testcard.c (renamed from drivers/staging/easycap/easycap_testcard.c)0
-rw-r--r--drivers/staging/media/go7007/Kconfig (renamed from drivers/staging/go7007/Kconfig)0
-rw-r--r--drivers/staging/media/go7007/Makefile (renamed from drivers/staging/go7007/Makefile)0
-rw-r--r--drivers/staging/media/go7007/README (renamed from drivers/staging/go7007/README)0
-rw-r--r--drivers/staging/media/go7007/go7007-driver.c (renamed from drivers/staging/go7007/go7007-driver.c)0
-rw-r--r--drivers/staging/media/go7007/go7007-fw.c (renamed from drivers/staging/go7007/go7007-fw.c)0
-rw-r--r--drivers/staging/media/go7007/go7007-i2c.c (renamed from drivers/staging/go7007/go7007-i2c.c)0
-rw-r--r--drivers/staging/media/go7007/go7007-priv.h (renamed from drivers/staging/go7007/go7007-priv.h)0
-rw-r--r--drivers/staging/media/go7007/go7007-usb.c (renamed from drivers/staging/go7007/go7007-usb.c)0
-rw-r--r--drivers/staging/media/go7007/go7007-v4l2.c (renamed from drivers/staging/go7007/go7007-v4l2.c)0
-rw-r--r--drivers/staging/media/go7007/go7007.h (renamed from drivers/staging/go7007/go7007.h)0
-rw-r--r--drivers/staging/media/go7007/go7007.txt (renamed from drivers/staging/go7007/go7007.txt)0
-rw-r--r--drivers/staging/media/go7007/s2250-board.c (renamed from drivers/staging/go7007/s2250-board.c)0
-rw-r--r--drivers/staging/media/go7007/s2250-loader.c (renamed from drivers/staging/go7007/s2250-loader.c)0
-rw-r--r--drivers/staging/media/go7007/s2250-loader.h (renamed from drivers/staging/go7007/s2250-loader.h)0
-rw-r--r--drivers/staging/media/go7007/saa7134-go7007.c (renamed from drivers/staging/go7007/saa7134-go7007.c)0
-rw-r--r--drivers/staging/media/go7007/snd-go7007.c (renamed from drivers/staging/go7007/snd-go7007.c)0
-rw-r--r--drivers/staging/media/go7007/wis-i2c.h (renamed from drivers/staging/go7007/wis-i2c.h)0
-rw-r--r--drivers/staging/media/go7007/wis-ov7640.c (renamed from drivers/staging/go7007/wis-ov7640.c)0
-rw-r--r--drivers/staging/media/go7007/wis-saa7113.c (renamed from drivers/staging/go7007/wis-saa7113.c)0
-rw-r--r--drivers/staging/media/go7007/wis-saa7115.c (renamed from drivers/staging/go7007/wis-saa7115.c)0
-rw-r--r--drivers/staging/media/go7007/wis-sony-tuner.c (renamed from drivers/staging/go7007/wis-sony-tuner.c)0
-rw-r--r--drivers/staging/media/go7007/wis-tw2804.c (renamed from drivers/staging/go7007/wis-tw2804.c)0
-rw-r--r--drivers/staging/media/go7007/wis-tw9903.c (renamed from drivers/staging/go7007/wis-tw9903.c)0
-rw-r--r--drivers/staging/media/go7007/wis-uda1342.c (renamed from drivers/staging/go7007/wis-uda1342.c)0
-rw-r--r--drivers/staging/media/lirc/Kconfig (renamed from drivers/staging/lirc/Kconfig)0
-rw-r--r--drivers/staging/media/lirc/Makefile (renamed from drivers/staging/lirc/Makefile)0
-rw-r--r--drivers/staging/media/lirc/TODO (renamed from drivers/staging/lirc/TODO)0
-rw-r--r--drivers/staging/media/lirc/TODO.lirc_zilog (renamed from drivers/staging/lirc/TODO.lirc_zilog)0
-rw-r--r--drivers/staging/media/lirc/lirc_bt829.c (renamed from drivers/staging/lirc/lirc_bt829.c)0
-rw-r--r--drivers/staging/media/lirc/lirc_ene0100.h (renamed from drivers/staging/lirc/lirc_ene0100.h)0
-rw-r--r--drivers/staging/media/lirc/lirc_igorplugusb.c (renamed from drivers/staging/lirc/lirc_igorplugusb.c)0
-rw-r--r--drivers/staging/media/lirc/lirc_imon.c (renamed from drivers/staging/lirc/lirc_imon.c)0
-rw-r--r--drivers/staging/media/lirc/lirc_parallel.c (renamed from drivers/staging/lirc/lirc_parallel.c)0
-rw-r--r--drivers/staging/media/lirc/lirc_parallel.h (renamed from drivers/staging/lirc/lirc_parallel.h)0
-rw-r--r--drivers/staging/media/lirc/lirc_sasem.c (renamed from drivers/staging/lirc/lirc_sasem.c)0
-rw-r--r--drivers/staging/media/lirc/lirc_serial.c (renamed from drivers/staging/lirc/lirc_serial.c)0
-rw-r--r--drivers/staging/media/lirc/lirc_sir.c (renamed from drivers/staging/lirc/lirc_sir.c)0
-rw-r--r--drivers/staging/media/lirc/lirc_ttusbir.c (renamed from drivers/staging/lirc/lirc_ttusbir.c)0
-rw-r--r--drivers/staging/media/lirc/lirc_zilog.c (renamed from drivers/staging/lirc/lirc_zilog.c)0
-rw-r--r--drivers/staging/media/solo6x10/Kconfig (renamed from drivers/staging/solo6x10/Kconfig)0
-rw-r--r--drivers/staging/media/solo6x10/Makefile (renamed from drivers/staging/solo6x10/Makefile)0
-rw-r--r--drivers/staging/media/solo6x10/TODO (renamed from drivers/staging/solo6x10/TODO)0
-rw-r--r--drivers/staging/media/solo6x10/core.c (renamed from drivers/staging/solo6x10/core.c)0
-rw-r--r--drivers/staging/media/solo6x10/disp.c (renamed from drivers/staging/solo6x10/disp.c)0
-rw-r--r--drivers/staging/media/solo6x10/enc.c (renamed from drivers/staging/solo6x10/enc.c)0
-rw-r--r--drivers/staging/media/solo6x10/g723.c (renamed from drivers/staging/solo6x10/g723.c)1
-rw-r--r--drivers/staging/media/solo6x10/gpio.c (renamed from drivers/staging/solo6x10/gpio.c)0
-rw-r--r--drivers/staging/media/solo6x10/i2c.c (renamed from drivers/staging/solo6x10/i2c.c)0
-rw-r--r--drivers/staging/media/solo6x10/jpeg.h (renamed from drivers/staging/solo6x10/jpeg.h)0
-rw-r--r--drivers/staging/media/solo6x10/offsets.h (renamed from drivers/staging/solo6x10/offsets.h)0
-rw-r--r--drivers/staging/media/solo6x10/osd-font.h (renamed from drivers/staging/solo6x10/osd-font.h)0
-rw-r--r--drivers/staging/media/solo6x10/p2m.c (renamed from drivers/staging/solo6x10/p2m.c)0
-rw-r--r--drivers/staging/media/solo6x10/registers.h (renamed from drivers/staging/solo6x10/registers.h)0
-rw-r--r--drivers/staging/media/solo6x10/solo6x10.h (renamed from drivers/staging/solo6x10/solo6x10.h)0
-rw-r--r--drivers/staging/media/solo6x10/tw28.c (renamed from drivers/staging/solo6x10/tw28.c)0
-rw-r--r--drivers/staging/media/solo6x10/tw28.h (renamed from drivers/staging/solo6x10/tw28.h)0
-rw-r--r--drivers/staging/media/solo6x10/v4l2-enc.c (renamed from drivers/staging/solo6x10/v4l2-enc.c)0
-rw-r--r--drivers/staging/media/solo6x10/v4l2.c (renamed from drivers/staging/solo6x10/v4l2.c)0
-rw-r--r--drivers/staging/pohmelfs/inode.c2
-rw-r--r--drivers/staging/rts5139/rts51x_scsi.c1
-rw-r--r--drivers/staging/usbip/usbip_common.c1
-rw-r--r--drivers/staging/usbip/usbip_event.c1
-rw-r--r--drivers/staging/winbond/wbusb.c1
-rw-r--r--drivers/staging/wlags49_h2/wl_cs.c1
-rw-r--r--drivers/staging/zram/zram_drv.c5
-rw-r--r--drivers/target/iscsi/iscsi_target.c12
-rw-r--r--drivers/target/iscsi/iscsi_target_configfs.c1
-rw-r--r--drivers/target/iscsi/iscsi_target_stat.c1
-rw-r--r--drivers/target/loopback/tcm_loop.c23
-rw-r--r--drivers/target/target_core_alua.c12
-rw-r--r--drivers/target/target_core_alua.h4
-rw-r--r--drivers/target/target_core_cdb.c216
-rw-r--r--drivers/target/target_core_cdb.h14
-rw-r--r--drivers/target/target_core_device.c15
-rw-r--r--drivers/target/target_core_fabric_lib.c1
-rw-r--r--drivers/target/target_core_file.c1
-rw-r--r--drivers/target/target_core_hba.c1
-rw-r--r--drivers/target/target_core_iblock.c1
-rw-r--r--drivers/target/target_core_pr.c349
-rw-r--r--drivers/target/target_core_pr.h7
-rw-r--r--drivers/target/target_core_pscsi.c3
-rw-r--r--drivers/target/target_core_tmr.c24
-rw-r--r--drivers/target/target_core_tpg.c1
-rw-r--r--drivers/target/target_core_transport.c393
-rw-r--r--drivers/target/tcm_fc/tcm_fc.h2
-rw-r--r--drivers/target/tcm_fc/tfc_cmd.c3
-rw-r--r--drivers/tty/Kconfig2
-rw-r--r--drivers/tty/hvc/Kconfig9
-rw-r--r--drivers/tty/hvc/Makefile1
-rw-r--r--drivers/tty/hvc/hvc_iseries.c1
-rw-r--r--drivers/tty/hvc/hvc_opal.c424
-rw-r--r--drivers/tty/hvc/hvc_vio.c1
-rw-r--r--drivers/tty/hvc/hvcs.c6
-rw-r--r--drivers/tty/hvc/hvsi_lib.c4
-rw-r--r--drivers/tty/serial/8250.c23
-rw-r--r--drivers/tty/serial/jsm/jsm_driver.c2
-rw-r--r--drivers/tty/serial/kgdboc.c1
-rw-r--r--drivers/tty/serial/max3100.c1
-rw-r--r--drivers/tty/serial/max3107-aava.c1
-rw-r--r--drivers/tty/serial/max3107.c1
-rw-r--r--drivers/tty/serial/nwpserial.c1
-rw-r--r--drivers/tty/serial/sh-sci.c25
-rw-r--r--drivers/tty/serial/timbuart.c1
-rw-r--r--drivers/tty/serial/xilinx_uartps.c1
-rw-r--r--drivers/tty/vt/vc_screen.c1
-rw-r--r--drivers/uio/uio_pdrv.c1
-rw-r--r--drivers/uio/uio_pdrv_genirq.c1
-rw-r--r--drivers/usb/Kconfig1
-rw-r--r--drivers/usb/c67x00/c67x00-drv.c1
-rw-r--r--drivers/usb/core/driver.c6
-rw-r--r--drivers/usb/core/notify.c1
-rw-r--r--drivers/usb/gadget/cdc2.c1
-rw-r--r--drivers/usb/gadget/composite.c1
-rw-r--r--drivers/usb/gadget/dbgp.c1
-rw-r--r--drivers/usb/gadget/f_fs.c1
-rw-r--r--drivers/usb/gadget/f_obex.c1
-rw-r--r--drivers/usb/gadget/f_sourcesink.c1
-rw-r--r--drivers/usb/gadget/file_storage.c1
-rw-r--r--drivers/usb/gadget/fusb300_udc.c1
-rw-r--r--drivers/usb/gadget/gmidi.c1
-rw-r--r--drivers/usb/gadget/u_serial.c1
-rw-r--r--drivers/usb/host/Makefile1
-rw-r--r--drivers/usb/host/alchemy-common.c337
-rw-r--r--drivers/usb/host/ehci-au1xxx.c77
-rw-r--r--drivers/usb/host/ehci-hcd.c2
-rw-r--r--drivers/usb/host/fsl-mph-dr-of.c1
-rw-r--r--drivers/usb/host/isp1760-if.c1
-rw-r--r--drivers/usb/host/ohci-au1xxx.c110
-rw-r--r--drivers/usb/host/pci-quirks.c1
-rw-r--r--drivers/usb/host/whci/debug.c1
-rw-r--r--drivers/usb/host/whci/hcd.c1
-rw-r--r--drivers/usb/host/xhci-hub.c1
-rw-r--r--drivers/usb/host/xhci-pci.c1
-rw-r--r--drivers/usb/mon/mon_bin.c1
-rw-r--r--drivers/usb/mon/mon_stat.c1
-rw-r--r--drivers/usb/mon/mon_text.c1
-rw-r--r--drivers/usb/otg/gpio_vbus.c1
-rw-r--r--drivers/usb/otg/otg.c1
-rw-r--r--drivers/usb/otg/ulpi.c1
-rw-r--r--drivers/usb/serial/aircable.c1
-rw-r--r--drivers/usb/serial/qcserial.c1
-rw-r--r--drivers/usb/storage/option_ms.c1
-rw-r--r--drivers/usb/storage/protocol.c1
-rw-r--r--drivers/usb/storage/sierra_ms.c1
-rw-r--r--drivers/usb/storage/transport.c1
-rw-r--r--drivers/usb/storage/uas.c1
-rw-r--r--drivers/usb/wusbcore/devconnect.c1
-rw-r--r--drivers/usb/wusbcore/mmc.c1
-rw-r--r--drivers/usb/wusbcore/rh.c1
-rw-r--r--drivers/usb/wusbcore/security.c1
-rw-r--r--drivers/usb/wusbcore/wa-hc.c1
-rw-r--r--drivers/usb/wusbcore/wa-rpipe.c1
-rw-r--r--drivers/usb/wusbcore/wa-xfer.c1
-rw-r--r--drivers/uwb/est.c1
-rw-r--r--drivers/uwb/i1480/dfu/dfu.c1
-rw-r--r--drivers/uwb/ie.c1
-rw-r--r--drivers/uwb/lc-dev.c2
-rw-r--r--drivers/uwb/lc-rc.c1
-rw-r--r--drivers/uwb/neh.c1
-rw-r--r--drivers/uwb/pal.c1
-rw-r--r--drivers/uwb/radio.c1
-rw-r--r--drivers/uwb/reset.c1
-rw-r--r--drivers/uwb/rsv.c1
-rw-r--r--drivers/uwb/scan.c1
-rw-r--r--drivers/uwb/umc-bus.c1
-rw-r--r--drivers/uwb/umc-dev.c1
-rw-r--r--drivers/uwb/umc-drv.c1
-rw-r--r--drivers/uwb/whci.c1
-rw-r--r--drivers/video/Kconfig4
-rw-r--r--drivers/video/atmel_lcdfb.c1
-rw-r--r--drivers/video/backlight/88pm860x_bl.c1
-rw-r--r--drivers/video/backlight/adp5520_bl.c1
-rw-r--r--drivers/video/backlight/ams369fg06.c1
-rw-r--r--drivers/video/backlight/da903x_bl.c1
-rw-r--r--drivers/video/backlight/ep93xx_bl.c1
-rw-r--r--drivers/video/backlight/l4f00242t03.c1
-rw-r--r--drivers/video/backlight/ld9040.c1
-rw-r--r--drivers/video/backlight/lms283gf05.c1
-rw-r--r--drivers/video/backlight/max8925_bl.c1
-rw-r--r--drivers/video/backlight/s6e63m0.c1
-rw-r--r--drivers/video/backlight/wm831x_bl.c1
-rw-r--r--drivers/video/carminefb.c1
-rw-r--r--drivers/video/cobalt_lcdfb.c1
-rw-r--r--drivers/video/ep93xx-fb.c1
-rw-r--r--drivers/video/fb_ddc.c3
-rw-r--r--drivers/video/fb_notify.c1
-rw-r--r--drivers/video/mb862xx/mb862xx-i2c.c1
-rw-r--r--drivers/video/mb862xx/mb862xxfbdrv.c1
-rw-r--r--drivers/video/msm/mdp.c1
-rw-r--r--drivers/video/omap/lcd_mipid.c1
-rw-r--r--drivers/video/omap/omapfb_main.c1
-rw-r--r--drivers/video/omap2/dss/dispc.c1
-rw-r--r--drivers/video/omap2/dss/dpi.c1
-rw-r--r--drivers/video/omap2/dss/dsi.c1
-rw-r--r--drivers/video/omap2/dss/dss.c1
-rw-r--r--drivers/video/omap2/dss/rfbi.c1
-rw-r--r--drivers/video/omap2/dss/sdi.c1
-rw-r--r--drivers/video/omap2/omapfb/omapfb-ioctl.c1
-rw-r--r--drivers/video/savage/savagefb_accel.c1
-rw-r--r--drivers/video/sh_mipi_dsi.c1
-rw-r--r--drivers/video/sh_mobile_lcdcfb.c1
-rw-r--r--drivers/video/via/via-gpio.c1
-rw-r--r--drivers/video/w100fb.c1
-rw-r--r--drivers/virt/fsl_hypervisor.c1
-rw-r--r--drivers/virtio/Kconfig11
-rw-r--r--drivers/virtio/Makefile1
-rw-r--r--drivers/virtio/virtio.c1
-rw-r--r--drivers/virtio/virtio_balloon.c1
-rw-r--r--drivers/virtio/virtio_mmio.c479
-rw-r--r--drivers/virtio/virtio_pci.c10
-rw-r--r--drivers/virtio/virtio_ring.c1
-rw-r--r--drivers/w1/slaves/w1_ds2760.c48
-rw-r--r--drivers/w1/slaves/w1_ds2780.c96
-rw-r--r--drivers/w1/slaves/w1_ds2780.h2
-rw-r--r--drivers/w1/w1_family.c1
-rw-r--r--drivers/w1/w1_int.c3
-rw-r--r--drivers/w1/w1_io.c5
-rw-r--r--drivers/watchdog/Kconfig8
-rw-r--r--drivers/watchdog/coh901327_wdt.c2
-rw-r--r--drivers/watchdog/eurotechwdt.c2
-rw-r--r--drivers/watchdog/iTCO_wdt.c19
-rw-r--r--drivers/watchdog/mpcore_wdt.c3
-rw-r--r--drivers/watchdog/octeon-wdt-main.c2
-rw-r--r--drivers/watchdog/s3c2410_wdt.c176
-rw-r--r--drivers/watchdog/sb_wdog.c4
-rw-r--r--drivers/watchdog/sc520_wdt.c2
-rw-r--r--drivers/watchdog/stmp3xxx_wdt.c1
-rw-r--r--drivers/watchdog/w83627hf_wdt.c33
-rw-r--r--drivers/watchdog/wdt.c2
-rw-r--r--drivers/watchdog/wdt_pci.c2
-rw-r--r--drivers/watchdog/wm831x_wdt.c318
-rw-r--r--drivers/xen/balloon.c1
-rw-r--r--drivers/xen/manage.c1
-rw-r--r--drivers/xen/swiotlb-xen.c1
-rw-r--r--drivers/xen/xen-pciback/conf_space.c1
-rw-r--r--drivers/xen/xenbus/xenbus_client.c7
-rw-r--r--drivers/xen/xenbus/xenbus_probe.c1
-rw-r--r--drivers/xen/xenbus/xenbus_probe_backend.c1
-rw-r--r--drivers/xen/xenbus/xenbus_probe_frontend.c1
-rw-r--r--drivers/zorro/proc.c1
1482 files changed, 43307 insertions, 12033 deletions
diff --git a/drivers/acpi/acpica/evxface.c b/drivers/acpi/acpica/evxface.c
index e1141402dbed..f4f523bf5939 100644
--- a/drivers/acpi/acpica/evxface.c
+++ b/drivers/acpi/acpica/evxface.c
@@ -41,6 +41,7 @@
41 * POSSIBILITY OF SUCH DAMAGES. 41 * POSSIBILITY OF SUCH DAMAGES.
42 */ 42 */
43 43
44#include <linux/export.h>
44#include <acpi/acpi.h> 45#include <acpi/acpi.h>
45#include "accommon.h" 46#include "accommon.h"
46#include "acnamesp.h" 47#include "acnamesp.h"
diff --git a/drivers/acpi/acpica/evxfevnt.c b/drivers/acpi/acpica/evxfevnt.c
index c57b5c707a77..20516e599476 100644
--- a/drivers/acpi/acpica/evxfevnt.c
+++ b/drivers/acpi/acpica/evxfevnt.c
@@ -41,6 +41,7 @@
41 * POSSIBILITY OF SUCH DAMAGES. 41 * POSSIBILITY OF SUCH DAMAGES.
42 */ 42 */
43 43
44#include <linux/export.h>
44#include <acpi/acpi.h> 45#include <acpi/acpi.h>
45#include "accommon.h" 46#include "accommon.h"
46#include "actables.h" 47#include "actables.h"
diff --git a/drivers/acpi/acpica/evxfgpe.c b/drivers/acpi/acpica/evxfgpe.c
index 52aaff3df562..f06a3ee356ba 100644
--- a/drivers/acpi/acpica/evxfgpe.c
+++ b/drivers/acpi/acpica/evxfgpe.c
@@ -41,6 +41,7 @@
41 * POSSIBILITY OF SUCH DAMAGES. 41 * POSSIBILITY OF SUCH DAMAGES.
42 */ 42 */
43 43
44#include <linux/export.h>
44#include <acpi/acpi.h> 45#include <acpi/acpi.h>
45#include "accommon.h" 46#include "accommon.h"
46#include "acevents.h" 47#include "acevents.h"
diff --git a/drivers/acpi/acpica/evxfregn.c b/drivers/acpi/acpica/evxfregn.c
index 00cd95692a91..aee887e3ca5c 100644
--- a/drivers/acpi/acpica/evxfregn.c
+++ b/drivers/acpi/acpica/evxfregn.c
@@ -42,6 +42,7 @@
42 * POSSIBILITY OF SUCH DAMAGES. 42 * POSSIBILITY OF SUCH DAMAGES.
43 */ 43 */
44 44
45#include <linux/export.h>
45#include <acpi/acpi.h> 46#include <acpi/acpi.h>
46#include "accommon.h" 47#include "accommon.h"
47#include "acnamesp.h" 48#include "acnamesp.h"
diff --git a/drivers/acpi/acpica/hwsleep.c b/drivers/acpi/acpica/hwsleep.c
index 2ac28bbe8827..d52da3073650 100644
--- a/drivers/acpi/acpica/hwsleep.c
+++ b/drivers/acpi/acpica/hwsleep.c
@@ -46,6 +46,7 @@
46#include "accommon.h" 46#include "accommon.h"
47#include "actables.h" 47#include "actables.h"
48#include <linux/tboot.h> 48#include <linux/tboot.h>
49#include <linux/module.h>
49 50
50#define _COMPONENT ACPI_HARDWARE 51#define _COMPONENT ACPI_HARDWARE
51ACPI_MODULE_NAME("hwsleep") 52ACPI_MODULE_NAME("hwsleep")
diff --git a/drivers/acpi/acpica/hwtimer.c b/drivers/acpi/acpica/hwtimer.c
index 9c8eb71a12fb..50d21c40b5c1 100644
--- a/drivers/acpi/acpica/hwtimer.c
+++ b/drivers/acpi/acpica/hwtimer.c
@@ -42,6 +42,7 @@
42 * POSSIBILITY OF SUCH DAMAGES. 42 * POSSIBILITY OF SUCH DAMAGES.
43 */ 43 */
44 44
45#include <linux/export.h>
45#include <acpi/acpi.h> 46#include <acpi/acpi.h>
46#include "accommon.h" 47#include "accommon.h"
47 48
diff --git a/drivers/acpi/acpica/hwxface.c b/drivers/acpi/acpica/hwxface.c
index f75f81ad15c9..c2793a82f120 100644
--- a/drivers/acpi/acpica/hwxface.c
+++ b/drivers/acpi/acpica/hwxface.c
@@ -42,6 +42,7 @@
42 * POSSIBILITY OF SUCH DAMAGES. 42 * POSSIBILITY OF SUCH DAMAGES.
43 */ 43 */
44 44
45#include <linux/export.h>
45#include <acpi/acpi.h> 46#include <acpi/acpi.h>
46#include "accommon.h" 47#include "accommon.h"
47#include "acnamesp.h" 48#include "acnamesp.h"
diff --git a/drivers/acpi/acpica/nsxfeval.c b/drivers/acpi/acpica/nsxfeval.c
index c53f0040e490..e7f016d1b226 100644
--- a/drivers/acpi/acpica/nsxfeval.c
+++ b/drivers/acpi/acpica/nsxfeval.c
@@ -42,6 +42,7 @@
42 * POSSIBILITY OF SUCH DAMAGES. 42 * POSSIBILITY OF SUCH DAMAGES.
43 */ 43 */
44 44
45#include <linux/export.h>
45#include <acpi/acpi.h> 46#include <acpi/acpi.h>
46#include "accommon.h" 47#include "accommon.h"
47#include "acnamesp.h" 48#include "acnamesp.h"
diff --git a/drivers/acpi/acpica/nsxfname.c b/drivers/acpi/acpica/nsxfname.c
index 3fd4526f3dba..83bf93024303 100644
--- a/drivers/acpi/acpica/nsxfname.c
+++ b/drivers/acpi/acpica/nsxfname.c
@@ -42,6 +42,7 @@
42 * POSSIBILITY OF SUCH DAMAGES. 42 * POSSIBILITY OF SUCH DAMAGES.
43 */ 43 */
44 44
45#include <linux/export.h>
45#include <acpi/acpi.h> 46#include <acpi/acpi.h>
46#include "accommon.h" 47#include "accommon.h"
47#include "acnamesp.h" 48#include "acnamesp.h"
diff --git a/drivers/acpi/acpica/nsxfobj.c b/drivers/acpi/acpica/nsxfobj.c
index db7660f8b869..57e6d825ed84 100644
--- a/drivers/acpi/acpica/nsxfobj.c
+++ b/drivers/acpi/acpica/nsxfobj.c
@@ -42,6 +42,7 @@
42 * POSSIBILITY OF SUCH DAMAGES. 42 * POSSIBILITY OF SUCH DAMAGES.
43 */ 43 */
44 44
45#include <linux/export.h>
45#include <acpi/acpi.h> 46#include <acpi/acpi.h>
46#include "accommon.h" 47#include "accommon.h"
47#include "acnamesp.h" 48#include "acnamesp.h"
diff --git a/drivers/acpi/acpica/rsxface.c b/drivers/acpi/acpica/rsxface.c
index 2ff657a28f26..fe86b37b16ce 100644
--- a/drivers/acpi/acpica/rsxface.c
+++ b/drivers/acpi/acpica/rsxface.c
@@ -41,6 +41,7 @@
41 * POSSIBILITY OF SUCH DAMAGES. 41 * POSSIBILITY OF SUCH DAMAGES.
42 */ 42 */
43 43
44#include <linux/export.h>
44#include <acpi/acpi.h> 45#include <acpi/acpi.h>
45#include "accommon.h" 46#include "accommon.h"
46#include "acresrc.h" 47#include "acresrc.h"
diff --git a/drivers/acpi/acpica/tbxface.c b/drivers/acpi/acpica/tbxface.c
index 4b7085dfc683..e7d13f5d3f2d 100644
--- a/drivers/acpi/acpica/tbxface.c
+++ b/drivers/acpi/acpica/tbxface.c
@@ -42,6 +42,7 @@
42 * POSSIBILITY OF SUCH DAMAGES. 42 * POSSIBILITY OF SUCH DAMAGES.
43 */ 43 */
44 44
45#include <linux/export.h>
45#include <acpi/acpi.h> 46#include <acpi/acpi.h>
46#include "accommon.h" 47#include "accommon.h"
47#include "acnamesp.h" 48#include "acnamesp.h"
diff --git a/drivers/acpi/acpica/utdebug.c b/drivers/acpi/acpica/utdebug.c
index a9bcd816dc29..a1f8d7509e66 100644
--- a/drivers/acpi/acpica/utdebug.c
+++ b/drivers/acpi/acpica/utdebug.c
@@ -41,6 +41,7 @@
41 * POSSIBILITY OF SUCH DAMAGES. 41 * POSSIBILITY OF SUCH DAMAGES.
42 */ 42 */
43 43
44#include <linux/export.h>
44#include <acpi/acpi.h> 45#include <acpi/acpi.h>
45#include "accommon.h" 46#include "accommon.h"
46 47
diff --git a/drivers/acpi/acpica/utdecode.c b/drivers/acpi/acpica/utdecode.c
index 97cb36f85ce9..8b087e2d64f4 100644
--- a/drivers/acpi/acpica/utdecode.c
+++ b/drivers/acpi/acpica/utdecode.c
@@ -41,6 +41,7 @@
41 * POSSIBILITY OF SUCH DAMAGES. 41 * POSSIBILITY OF SUCH DAMAGES.
42 */ 42 */
43 43
44#include <linux/export.h>
44#include <acpi/acpi.h> 45#include <acpi/acpi.h>
45#include "accommon.h" 46#include "accommon.h"
46#include "acnamesp.h" 47#include "acnamesp.h"
diff --git a/drivers/acpi/acpica/utglobal.c b/drivers/acpi/acpica/utglobal.c
index 833a38a9c905..ffba0a39c3e8 100644
--- a/drivers/acpi/acpica/utglobal.c
+++ b/drivers/acpi/acpica/utglobal.c
@@ -43,6 +43,7 @@
43 43
44#define DEFINE_ACPI_GLOBALS 44#define DEFINE_ACPI_GLOBALS
45 45
46#include <linux/export.h>
46#include <acpi/acpi.h> 47#include <acpi/acpi.h>
47#include "accommon.h" 48#include "accommon.h"
48 49
diff --git a/drivers/acpi/acpica/utxface.c b/drivers/acpi/acpica/utxface.c
index 98ad125e14ff..420ebfe08c72 100644
--- a/drivers/acpi/acpica/utxface.c
+++ b/drivers/acpi/acpica/utxface.c
@@ -41,6 +41,7 @@
41 * POSSIBILITY OF SUCH DAMAGES. 41 * POSSIBILITY OF SUCH DAMAGES.
42 */ 42 */
43 43
44#include <linux/export.h>
44#include <acpi/acpi.h> 45#include <acpi/acpi.h>
45#include "accommon.h" 46#include "accommon.h"
46#include "acevents.h" 47#include "acevents.h"
diff --git a/drivers/acpi/acpica/utxferror.c b/drivers/acpi/acpica/utxferror.c
index 916ae097c43c..8d0245ec4315 100644
--- a/drivers/acpi/acpica/utxferror.c
+++ b/drivers/acpi/acpica/utxferror.c
@@ -41,6 +41,7 @@
41 * POSSIBILITY OF SUCH DAMAGES. 41 * POSSIBILITY OF SUCH DAMAGES.
42 */ 42 */
43 43
44#include <linux/export.h>
44#include <acpi/acpi.h> 45#include <acpi/acpi.h>
45#include "accommon.h" 46#include "accommon.h"
46#include "acnamesp.h" 47#include "acnamesp.h"
diff --git a/drivers/acpi/atomicio.c b/drivers/acpi/atomicio.c
index 7489b89c300f..04ae1c88c03c 100644
--- a/drivers/acpi/atomicio.c
+++ b/drivers/acpi/atomicio.c
@@ -24,7 +24,7 @@
24 */ 24 */
25 25
26#include <linux/kernel.h> 26#include <linux/kernel.h>
27#include <linux/module.h> 27#include <linux/export.h>
28#include <linux/init.h> 28#include <linux/init.h>
29#include <linux/acpi.h> 29#include <linux/acpi.h>
30#include <linux/io.h> 30#include <linux/io.h>
diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
index af308d03f492..cb9629638def 100644
--- a/drivers/acpi/blacklist.c
+++ b/drivers/acpi/blacklist.c
@@ -28,7 +28,6 @@
28 */ 28 */
29 29
30#include <linux/kernel.h> 30#include <linux/kernel.h>
31#include <linux/module.h>
32#include <linux/init.h> 31#include <linux/init.h>
33#include <linux/acpi.h> 32#include <linux/acpi.h>
34#include <acpi/acpi_bus.h> 33#include <acpi/acpi_bus.h>
diff --git a/drivers/acpi/debugfs.c b/drivers/acpi/debugfs.c
index 182a9fc36355..b55d6a20dc0e 100644
--- a/drivers/acpi/debugfs.c
+++ b/drivers/acpi/debugfs.c
@@ -2,6 +2,7 @@
2 * debugfs.c - ACPI debugfs interface to userspace. 2 * debugfs.c - ACPI debugfs interface to userspace.
3 */ 3 */
4 4
5#include <linux/export.h>
5#include <linux/init.h> 6#include <linux/init.h>
6#include <linux/debugfs.h> 7#include <linux/debugfs.h>
7#include <acpi/acpi_drivers.h> 8#include <acpi/acpi_drivers.h>
diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
index 22f918bacd35..6c47ae9793a7 100644
--- a/drivers/acpi/ec_sys.c
+++ b/drivers/acpi/ec_sys.c
@@ -11,6 +11,7 @@
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/acpi.h> 12#include <linux/acpi.h>
13#include <linux/debugfs.h> 13#include <linux/debugfs.h>
14#include <linux/module.h>
14#include "internal.h" 15#include "internal.h"
15 16
16MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>"); 17MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
diff --git a/drivers/acpi/event.c b/drivers/acpi/event.c
index 85d908993809..1442737cedec 100644
--- a/drivers/acpi/event.c
+++ b/drivers/acpi/event.c
@@ -7,6 +7,7 @@
7 */ 7 */
8 8
9#include <linux/spinlock.h> 9#include <linux/spinlock.h>
10#include <linux/export.h>
10#include <linux/proc_fs.h> 11#include <linux/proc_fs.h>
11#include <linux/init.h> 12#include <linux/init.h>
12#include <linux/poll.h> 13#include <linux/poll.h>
diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c
index 7c47ed55e528..29a4a5c8ee00 100644
--- a/drivers/acpi/glue.c
+++ b/drivers/acpi/glue.c
@@ -6,6 +6,7 @@
6 * 6 *
7 * This file is released under the GPLv2. 7 * This file is released under the GPLv2.
8 */ 8 */
9#include <linux/export.h>
9#include <linux/init.h> 10#include <linux/init.h>
10#include <linux/list.h> 11#include <linux/list.h>
11#include <linux/device.h> 12#include <linux/device.h>
diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
index f5f986991b52..251c7b6273a9 100644
--- a/drivers/acpi/proc.c
+++ b/drivers/acpi/proc.c
@@ -1,5 +1,6 @@
1#include <linux/proc_fs.h> 1#include <linux/proc_fs.h>
2#include <linux/seq_file.h> 2#include <linux/seq_file.h>
3#include <linux/export.h>
3#include <linux/suspend.h> 4#include <linux/suspend.h>
4#include <linux/bcd.h> 5#include <linux/bcd.h>
5#include <asm/uaccess.h> 6#include <asm/uaccess.h>
diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c
index 02d2a4c9084d..3a0428e8435c 100644
--- a/drivers/acpi/processor_core.c
+++ b/drivers/acpi/processor_core.c
@@ -7,6 +7,7 @@
7 * Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> 7 * Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
8 * - Added _PDC for platforms with Intel CPUs 8 * - Added _PDC for platforms with Intel CPUs
9 */ 9 */
10#include <linux/export.h>
10#include <linux/dmi.h> 11#include <linux/dmi.h>
11#include <linux/slab.h> 12#include <linux/slab.h>
12 13
diff --git a/drivers/acpi/sbshc.c b/drivers/acpi/sbshc.c
index f8be23b6c129..f8d2a472795c 100644
--- a/drivers/acpi/sbshc.c
+++ b/drivers/acpi/sbshc.c
@@ -13,6 +13,7 @@
13#include <linux/wait.h> 13#include <linux/wait.h>
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/delay.h> 15#include <linux/delay.h>
16#include <linux/module.h>
16#include <linux/interrupt.h> 17#include <linux/interrupt.h>
17#include "sbshc.h" 18#include "sbshc.h"
18 19
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
index 0e46faef1d30..6d9a3ab58db2 100644
--- a/drivers/acpi/sleep.c
+++ b/drivers/acpi/sleep.c
@@ -398,6 +398,14 @@ static struct dmi_system_id __initdata acpisleep_dmi_table[] = {
398 }, 398 },
399 { 399 {
400 .callback = init_nvs_nosave, 400 .callback = init_nvs_nosave,
401 .ident = "Sony Vaio VPCEB17FX",
402 .matches = {
403 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
404 DMI_MATCH(DMI_PRODUCT_NAME, "VPCEB17FX"),
405 },
406 },
407 {
408 .callback = init_nvs_nosave,
401 .ident = "Sony Vaio VGN-SR11M", 409 .ident = "Sony Vaio VGN-SR11M",
402 .matches = { 410 .matches = {
403 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"), 411 DMI_MATCH(DMI_SYS_VENDOR, "Sony Corporation"),
diff --git a/drivers/acpi/video_detect.c b/drivers/acpi/video_detect.c
index 5af3479714f6..f3f0fe7e255a 100644
--- a/drivers/acpi/video_detect.c
+++ b/drivers/acpi/video_detect.c
@@ -33,6 +33,7 @@
33 * 33 *
34 */ 34 */
35 35
36#include <linux/export.h>
36#include <linux/acpi.h> 37#include <linux/acpi.h>
37#include <linux/dmi.h> 38#include <linux/dmi.h>
38#include <linux/pci.h> 39#include <linux/pci.h>
diff --git a/drivers/ata/ahci_platform.c b/drivers/ata/ahci_platform.c
index c03277d37748..004f2ce3dc73 100644
--- a/drivers/ata/ahci_platform.c
+++ b/drivers/ata/ahci_platform.c
@@ -202,11 +202,18 @@ static int __devexit ahci_remove(struct platform_device *pdev)
202 return 0; 202 return 0;
203} 203}
204 204
205static const struct of_device_id ahci_of_match[] = {
206 { .compatible = "calxeda,hb-ahci", },
207 {},
208};
209MODULE_DEVICE_TABLE(of, ahci_of_match);
210
205static struct platform_driver ahci_driver = { 211static struct platform_driver ahci_driver = {
206 .remove = __devexit_p(ahci_remove), 212 .remove = __devexit_p(ahci_remove),
207 .driver = { 213 .driver = {
208 .name = "ahci", 214 .name = "ahci",
209 .owner = THIS_MODULE, 215 .owner = THIS_MODULE,
216 .of_match_table = ahci_of_match,
210 }, 217 },
211 .id_table = ahci_devtype, 218 .id_table = ahci_devtype,
212}; 219};
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index c021186736e9..f22957c2769a 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -34,6 +34,7 @@
34 34
35#include <linux/kernel.h> 35#include <linux/kernel.h>
36#include <linux/blkdev.h> 36#include <linux/blkdev.h>
37#include <linux/export.h>
37#include <linux/pci.h> 38#include <linux/pci.h>
38#include <scsi/scsi.h> 39#include <scsi/scsi.h>
39#include <scsi/scsi_host.h> 40#include <scsi/scsi_host.h>
diff --git a/drivers/ata/libata-pmp.c b/drivers/ata/libata-pmp.c
index 3eb2b816eb2a..104462dbc524 100644
--- a/drivers/ata/libata-pmp.c
+++ b/drivers/ata/libata-pmp.c
@@ -8,6 +8,7 @@
8 */ 8 */
9 9
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <linux/export.h>
11#include <linux/libata.h> 12#include <linux/libata.h>
12#include <linux/slab.h> 13#include <linux/slab.h>
13#include "libata.h" 14#include "libata.h"
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 19ba77032ac2..72a9770ac42f 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -37,6 +37,7 @@
37#include <linux/kernel.h> 37#include <linux/kernel.h>
38#include <linux/blkdev.h> 38#include <linux/blkdev.h>
39#include <linux/spinlock.h> 39#include <linux/spinlock.h>
40#include <linux/export.h>
40#include <scsi/scsi.h> 41#include <scsi/scsi.h>
41#include <scsi/scsi_host.h> 42#include <scsi/scsi_host.h>
42#include <scsi/scsi_cmnd.h> 43#include <scsi/scsi_cmnd.h>
diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c
index 239bfa67d032..63d53277d6a9 100644
--- a/drivers/ata/libata-sff.c
+++ b/drivers/ata/libata-sff.c
@@ -35,6 +35,7 @@
35#include <linux/kernel.h> 35#include <linux/kernel.h>
36#include <linux/gfp.h> 36#include <linux/gfp.h>
37#include <linux/pci.h> 37#include <linux/pci.h>
38#include <linux/module.h>
38#include <linux/libata.h> 39#include <linux/libata.h>
39#include <linux/highmem.h> 40#include <linux/highmem.h>
40 41
diff --git a/drivers/base/base.h b/drivers/base/base.h
index a34dca0ad041..21c1b96c34c6 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -1,3 +1,4 @@
1#include <linux/notifier.h>
1 2
2/** 3/**
3 * struct subsys_private - structure to hold the private to the driver core portions of the bus_type/class structure. 4 * struct subsys_private - structure to hold the private to the driver core portions of the bus_type/class structure.
diff --git a/drivers/base/dma-coherent.c b/drivers/base/dma-coherent.c
index f369e2795985..bb0025c510b3 100644
--- a/drivers/base/dma-coherent.c
+++ b/drivers/base/dma-coherent.c
@@ -4,6 +4,7 @@
4 */ 4 */
5#include <linux/slab.h> 5#include <linux/slab.h>
6#include <linux/kernel.h> 6#include <linux/kernel.h>
7#include <linux/module.h>
7#include <linux/dma-mapping.h> 8#include <linux/dma-mapping.h>
8 9
9struct dma_coherent_mem { 10struct dma_coherent_mem {
diff --git a/drivers/base/dma-mapping.c b/drivers/base/dma-mapping.c
index 763d59c1eb65..6f3676f1559f 100644
--- a/drivers/base/dma-mapping.c
+++ b/drivers/base/dma-mapping.c
@@ -8,6 +8,7 @@
8 */ 8 */
9 9
10#include <linux/dma-mapping.h> 10#include <linux/dma-mapping.h>
11#include <linux/export.h>
11#include <linux/gfp.h> 12#include <linux/gfp.h>
12 13
13/* 14/*
diff --git a/drivers/base/hypervisor.c b/drivers/base/hypervisor.c
index 6428cba3aadd..4f8b741f4615 100644
--- a/drivers/base/hypervisor.c
+++ b/drivers/base/hypervisor.c
@@ -10,6 +10,7 @@
10 10
11#include <linux/kobject.h> 11#include <linux/kobject.h>
12#include <linux/device.h> 12#include <linux/device.h>
13#include <linux/export.h>
13#include "base.h" 14#include "base.h"
14 15
15struct kobject *hypervisor_kobj; 16struct kobject *hypervisor_kobj;
diff --git a/drivers/base/power/common.c b/drivers/base/power/common.c
index 29820c396182..4af7c1cbf909 100644
--- a/drivers/base/power/common.c
+++ b/drivers/base/power/common.c
@@ -8,7 +8,7 @@
8 8
9#include <linux/init.h> 9#include <linux/init.h>
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <linux/module.h> 11#include <linux/export.h>
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/pm_clock.h> 13#include <linux/pm_clock.h>
14 14
diff --git a/drivers/base/power/generic_ops.c b/drivers/base/power/generic_ops.c
index 9508df71274b..265a0ee3b49e 100644
--- a/drivers/base/power/generic_ops.c
+++ b/drivers/base/power/generic_ops.c
@@ -8,6 +8,7 @@
8 8
9#include <linux/pm.h> 9#include <linux/pm.h>
10#include <linux/pm_runtime.h> 10#include <linux/pm_runtime.h>
11#include <linux/export.h>
11 12
12#ifdef CONFIG_PM_RUNTIME 13#ifdef CONFIG_PM_RUNTIME
13/** 14/**
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 59f8ab235486..7fa098464dae 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -19,6 +19,7 @@
19 19
20#include <linux/device.h> 20#include <linux/device.h>
21#include <linux/kallsyms.h> 21#include <linux/kallsyms.h>
22#include <linux/export.h>
22#include <linux/mutex.h> 23#include <linux/mutex.h>
23#include <linux/pm.h> 24#include <linux/pm.h>
24#include <linux/pm_runtime.h> 25#include <linux/pm_runtime.h>
diff --git a/drivers/base/power/qos.c b/drivers/base/power/qos.c
index 91e061417382..30a94eadc200 100644
--- a/drivers/base/power/qos.c
+++ b/drivers/base/power/qos.c
@@ -39,6 +39,7 @@
39#include <linux/slab.h> 39#include <linux/slab.h>
40#include <linux/device.h> 40#include <linux/device.h>
41#include <linux/mutex.h> 41#include <linux/mutex.h>
42#include <linux/export.h>
42 43
43 44
44static DEFINE_MUTEX(dev_pm_qos_mtx); 45static DEFINE_MUTEX(dev_pm_qos_mtx);
diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c
index 6bb3aafa85ed..8c78443bca8f 100644
--- a/drivers/base/power/runtime.c
+++ b/drivers/base/power/runtime.c
@@ -8,6 +8,7 @@
8 */ 8 */
9 9
10#include <linux/sched.h> 10#include <linux/sched.h>
11#include <linux/export.h>
11#include <linux/pm_runtime.h> 12#include <linux/pm_runtime.h>
12#include <trace/events/rpm.h> 13#include <trace/events/rpm.h>
13#include "power.h" 14#include "power.h"
@@ -29,13 +30,10 @@ static int rpm_suspend(struct device *dev, int rpmflags);
29void update_pm_runtime_accounting(struct device *dev) 30void update_pm_runtime_accounting(struct device *dev)
30{ 31{
31 unsigned long now = jiffies; 32 unsigned long now = jiffies;
32 int delta; 33 unsigned long delta;
33 34
34 delta = now - dev->power.accounting_timestamp; 35 delta = now - dev->power.accounting_timestamp;
35 36
36 if (delta < 0)
37 delta = 0;
38
39 dev->power.accounting_timestamp = now; 37 dev->power.accounting_timestamp = now;
40 38
41 if (dev->power.disable_depth > 0) 39 if (dev->power.disable_depth > 0)
@@ -296,6 +294,9 @@ static int rpm_callback(int (*cb)(struct device *), struct device *dev)
296 * the callback was running then carry it out, otherwise send an idle 294 * the callback was running then carry it out, otherwise send an idle
297 * notification for its parent (if the suspend succeeded and both 295 * notification for its parent (if the suspend succeeded and both
298 * ignore_children of parent->power and irq_safe of dev->power are not set). 296 * ignore_children of parent->power and irq_safe of dev->power are not set).
297 * If ->runtime_suspend failed with -EAGAIN or -EBUSY, and if the RPM_AUTO
298 * flag is set and the next autosuspend-delay expiration time is in the
299 * future, schedule another autosuspend attempt.
299 * 300 *
300 * This function must be called under dev->power.lock with interrupts disabled. 301 * This function must be called under dev->power.lock with interrupts disabled.
301 */ 302 */
@@ -416,10 +417,21 @@ static int rpm_suspend(struct device *dev, int rpmflags)
416 if (retval) { 417 if (retval) {
417 __update_runtime_status(dev, RPM_ACTIVE); 418 __update_runtime_status(dev, RPM_ACTIVE);
418 dev->power.deferred_resume = false; 419 dev->power.deferred_resume = false;
419 if (retval == -EAGAIN || retval == -EBUSY) 420 if (retval == -EAGAIN || retval == -EBUSY) {
420 dev->power.runtime_error = 0; 421 dev->power.runtime_error = 0;
421 else 422
423 /*
424 * If the callback routine failed an autosuspend, and
425 * if the last_busy time has been updated so that there
426 * is a new autosuspend expiration time, automatically
427 * reschedule another autosuspend.
428 */
429 if ((rpmflags & RPM_AUTO) &&
430 pm_runtime_autosuspend_expiration(dev) != 0)
431 goto repeat;
432 } else {
422 pm_runtime_cancel_pending(dev); 433 pm_runtime_cancel_pending(dev);
434 }
423 wake_up_all(&dev->power.wait_queue); 435 wake_up_all(&dev->power.wait_queue);
424 goto out; 436 goto out;
425 } 437 }
diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
index 17b7934f31cb..adf41be0ea66 100644
--- a/drivers/base/power/sysfs.c
+++ b/drivers/base/power/sysfs.c
@@ -4,6 +4,7 @@
4 4
5#include <linux/device.h> 5#include <linux/device.h>
6#include <linux/string.h> 6#include <linux/string.h>
7#include <linux/export.h>
7#include <linux/pm_runtime.h> 8#include <linux/pm_runtime.h>
8#include <linux/atomic.h> 9#include <linux/atomic.h>
9#include <linux/jiffies.h> 10#include <linux/jiffies.h>
diff --git a/drivers/base/power/trace.c b/drivers/base/power/trace.c
index af10abecb99b..d94a1f5121cf 100644
--- a/drivers/base/power/trace.c
+++ b/drivers/base/power/trace.c
@@ -8,6 +8,7 @@
8 */ 8 */
9 9
10#include <linux/resume-trace.h> 10#include <linux/resume-trace.h>
11#include <linux/export.h>
11#include <linux/rtc.h> 12#include <linux/rtc.h>
12 13
13#include <asm/rtc.h> 14#include <asm/rtc.h>
diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
index 14ee07e9cc43..caf995fb774b 100644
--- a/drivers/base/power/wakeup.c
+++ b/drivers/base/power/wakeup.c
@@ -10,6 +10,7 @@
10#include <linux/slab.h> 10#include <linux/slab.h>
11#include <linux/sched.h> 11#include <linux/sched.h>
12#include <linux/capability.h> 12#include <linux/capability.h>
13#include <linux/export.h>
13#include <linux/suspend.h> 14#include <linux/suspend.h>
14#include <linux/seq_file.h> 15#include <linux/seq_file.h>
15#include <linux/debugfs.h> 16#include <linux/debugfs.h>
diff --git a/drivers/base/regmap/regcache.c b/drivers/base/regmap/regcache.c
index afcfef838263..666f6f5011dc 100644
--- a/drivers/base/regmap/regcache.c
+++ b/drivers/base/regmap/regcache.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/export.h>
14#include <trace/events/regmap.h> 15#include <trace/events/regmap.h>
15#include <linux/bsearch.h> 16#include <linux/bsearch.h>
16#include <linux/sort.h> 17#include <linux/sort.h>
diff --git a/drivers/base/transport_class.c b/drivers/base/transport_class.c
index 84997efdb23d..f6c453c3816e 100644
--- a/drivers/base/transport_class.c
+++ b/drivers/base/transport_class.c
@@ -27,6 +27,7 @@
27 * transport class is framed entirely in terms of generic devices to 27 * transport class is framed entirely in terms of generic devices to
28 * allow it to be used by any physical HBA in the system. 28 * allow it to be used by any physical HBA in the system.
29 */ 29 */
30#include <linux/export.h>
30#include <linux/attribute_container.h> 31#include <linux/attribute_container.h>
31#include <linux/transport_class.h> 32#include <linux/transport_class.h>
32 33
diff --git a/drivers/bcma/core.c b/drivers/bcma/core.c
index 189a97b51be9..893f6e0c759f 100644
--- a/drivers/bcma/core.c
+++ b/drivers/bcma/core.c
@@ -6,6 +6,7 @@
6 */ 6 */
7 7
8#include "bcma_private.h" 8#include "bcma_private.h"
9#include <linux/export.h>
9#include <linux/bcma/bcma.h> 10#include <linux/bcma/bcma.h>
10 11
11bool bcma_core_is_enabled(struct bcma_device *core) 12bool bcma_core_is_enabled(struct bcma_device *core)
diff --git a/drivers/bcma/driver_chipcommon.c b/drivers/bcma/driver_chipcommon.c
index 47cce9d69630..e9f1b3fd252c 100644
--- a/drivers/bcma/driver_chipcommon.c
+++ b/drivers/bcma/driver_chipcommon.c
@@ -9,6 +9,7 @@
9 */ 9 */
10 10
11#include "bcma_private.h" 11#include "bcma_private.h"
12#include <linux/export.h>
12#include <linux/bcma/bcma.h> 13#include <linux/bcma/bcma.h>
13 14
14static inline u32 bcma_cc_write32_masked(struct bcma_drv_cc *cc, u16 offset, 15static inline u32 bcma_cc_write32_masked(struct bcma_drv_cc *cc, u16 offset,
diff --git a/drivers/bcma/driver_chipcommon_pmu.c b/drivers/bcma/driver_chipcommon_pmu.c
index 2968d809d49f..800163c8c2e7 100644
--- a/drivers/bcma/driver_chipcommon_pmu.c
+++ b/drivers/bcma/driver_chipcommon_pmu.c
@@ -9,6 +9,7 @@
9 */ 9 */
10 10
11#include "bcma_private.h" 11#include "bcma_private.h"
12#include <linux/export.h>
12#include <linux/bcma/bcma.h> 13#include <linux/bcma/bcma.h>
13 14
14static u32 bcma_chipco_pll_read(struct bcma_drv_cc *cc, u32 offset) 15static u32 bcma_chipco_pll_read(struct bcma_drv_cc *cc, u32 offset)
diff --git a/drivers/bcma/driver_pci.c b/drivers/bcma/driver_pci.c
index 81f3d0a4b856..4fde6254f04e 100644
--- a/drivers/bcma/driver_pci.c
+++ b/drivers/bcma/driver_pci.c
@@ -9,6 +9,7 @@
9 */ 9 */
10 10
11#include "bcma_private.h" 11#include "bcma_private.h"
12#include <linux/export.h>
12#include <linux/bcma/bcma.h> 13#include <linux/bcma/bcma.h>
13 14
14/************************************************** 15/**************************************************
diff --git a/drivers/bcma/host_pci.c b/drivers/bcma/host_pci.c
index ac4bc626c149..1b51d8b7ac80 100644
--- a/drivers/bcma/host_pci.c
+++ b/drivers/bcma/host_pci.c
@@ -9,6 +9,7 @@
9#include <linux/slab.h> 9#include <linux/slab.h>
10#include <linux/bcma/bcma.h> 10#include <linux/bcma/bcma.h>
11#include <linux/pci.h> 11#include <linux/pci.h>
12#include <linux/module.h>
12 13
13static void bcma_host_pci_switch_core(struct bcma_device *core) 14static void bcma_host_pci_switch_core(struct bcma_device *core)
14{ 15{
diff --git a/drivers/bcma/main.c b/drivers/bcma/main.c
index 8c09c3e547cd..70c84b951098 100644
--- a/drivers/bcma/main.c
+++ b/drivers/bcma/main.c
@@ -6,6 +6,7 @@
6 */ 6 */
7 7
8#include "bcma_private.h" 8#include "bcma_private.h"
9#include <linux/module.h>
9#include <linux/bcma/bcma.h> 10#include <linux/bcma/bcma.h>
10#include <linux/slab.h> 11#include <linux/slab.h>
11 12
diff --git a/drivers/block/aoe/aoeblk.c b/drivers/block/aoe/aoeblk.c
index 528f6318ded1..321de7b6c442 100644
--- a/drivers/block/aoe/aoeblk.c
+++ b/drivers/block/aoe/aoeblk.c
@@ -15,6 +15,7 @@
15#include <linux/genhd.h> 15#include <linux/genhd.h>
16#include <linux/netdevice.h> 16#include <linux/netdevice.h>
17#include <linux/mutex.h> 17#include <linux/mutex.h>
18#include <linux/export.h>
18#include "aoe.h" 19#include "aoe.h"
19 20
20static DEFINE_MUTEX(aoeblk_mutex); 21static DEFINE_MUTEX(aoeblk_mutex);
@@ -159,7 +160,7 @@ aoeblk_release(struct gendisk *disk, fmode_t mode)
159 return 0; 160 return 0;
160} 161}
161 162
162static int 163static void
163aoeblk_make_request(struct request_queue *q, struct bio *bio) 164aoeblk_make_request(struct request_queue *q, struct bio *bio)
164{ 165{
165 struct sk_buff_head queue; 166 struct sk_buff_head queue;
@@ -172,25 +173,25 @@ aoeblk_make_request(struct request_queue *q, struct bio *bio)
172 if (bio == NULL) { 173 if (bio == NULL) {
173 printk(KERN_ERR "aoe: bio is NULL\n"); 174 printk(KERN_ERR "aoe: bio is NULL\n");
174 BUG(); 175 BUG();
175 return 0; 176 return;
176 } 177 }
177 d = bio->bi_bdev->bd_disk->private_data; 178 d = bio->bi_bdev->bd_disk->private_data;
178 if (d == NULL) { 179 if (d == NULL) {
179 printk(KERN_ERR "aoe: bd_disk->private_data is NULL\n"); 180 printk(KERN_ERR "aoe: bd_disk->private_data is NULL\n");
180 BUG(); 181 BUG();
181 bio_endio(bio, -ENXIO); 182 bio_endio(bio, -ENXIO);
182 return 0; 183 return;
183 } else if (bio->bi_io_vec == NULL) { 184 } else if (bio->bi_io_vec == NULL) {
184 printk(KERN_ERR "aoe: bi_io_vec is NULL\n"); 185 printk(KERN_ERR "aoe: bi_io_vec is NULL\n");
185 BUG(); 186 BUG();
186 bio_endio(bio, -ENXIO); 187 bio_endio(bio, -ENXIO);
187 return 0; 188 return;
188 } 189 }
189 buf = mempool_alloc(d->bufpool, GFP_NOIO); 190 buf = mempool_alloc(d->bufpool, GFP_NOIO);
190 if (buf == NULL) { 191 if (buf == NULL) {
191 printk(KERN_INFO "aoe: buf allocation failure\n"); 192 printk(KERN_INFO "aoe: buf allocation failure\n");
192 bio_endio(bio, -ENOMEM); 193 bio_endio(bio, -ENOMEM);
193 return 0; 194 return;
194 } 195 }
195 memset(buf, 0, sizeof(*buf)); 196 memset(buf, 0, sizeof(*buf));
196 INIT_LIST_HEAD(&buf->bufs); 197 INIT_LIST_HEAD(&buf->bufs);
@@ -211,7 +212,7 @@ aoeblk_make_request(struct request_queue *q, struct bio *bio)
211 spin_unlock_irqrestore(&d->lock, flags); 212 spin_unlock_irqrestore(&d->lock, flags);
212 mempool_free(buf, d->bufpool); 213 mempool_free(buf, d->bufpool);
213 bio_endio(bio, -ENXIO); 214 bio_endio(bio, -ENXIO);
214 return 0; 215 return;
215 } 216 }
216 217
217 list_add_tail(&buf->bufs, &d->bufq); 218 list_add_tail(&buf->bufs, &d->bufq);
@@ -222,8 +223,6 @@ aoeblk_make_request(struct request_queue *q, struct bio *bio)
222 223
223 spin_unlock_irqrestore(&d->lock, flags); 224 spin_unlock_irqrestore(&d->lock, flags);
224 aoenet_xmit(&queue); 225 aoenet_xmit(&queue);
225
226 return 0;
227} 226}
228 227
229static int 228static int
diff --git a/drivers/block/aoe/aoechr.c b/drivers/block/aoe/aoechr.c
index 146296ca4965..5f8e39c43ae5 100644
--- a/drivers/block/aoe/aoechr.c
+++ b/drivers/block/aoe/aoechr.c
@@ -11,6 +11,7 @@
11#include <linux/slab.h> 11#include <linux/slab.h>
12#include <linux/mutex.h> 12#include <linux/mutex.h>
13#include <linux/skbuff.h> 13#include <linux/skbuff.h>
14#include <linux/export.h>
14#include "aoe.h" 15#include "aoe.h"
15 16
16enum { 17enum {
diff --git a/drivers/block/brd.c b/drivers/block/brd.c
index dba1c32e1ddf..d22119d49e53 100644
--- a/drivers/block/brd.c
+++ b/drivers/block/brd.c
@@ -323,7 +323,7 @@ out:
323 return err; 323 return err;
324} 324}
325 325
326static int brd_make_request(struct request_queue *q, struct bio *bio) 326static void brd_make_request(struct request_queue *q, struct bio *bio)
327{ 327{
328 struct block_device *bdev = bio->bi_bdev; 328 struct block_device *bdev = bio->bi_bdev;
329 struct brd_device *brd = bdev->bd_disk->private_data; 329 struct brd_device *brd = bdev->bd_disk->private_data;
@@ -359,8 +359,6 @@ static int brd_make_request(struct request_queue *q, struct bio *bio)
359 359
360out: 360out:
361 bio_endio(bio, err); 361 bio_endio(bio, err);
362
363 return 0;
364} 362}
365 363
366#ifdef CONFIG_BLK_DEV_XIP 364#ifdef CONFIG_BLK_DEV_XIP
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index 8f4ef656a1af..486f94ef24d4 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -68,6 +68,10 @@ static int cciss_tape_cmds = 6;
68module_param(cciss_tape_cmds, int, 0644); 68module_param(cciss_tape_cmds, int, 0644);
69MODULE_PARM_DESC(cciss_tape_cmds, 69MODULE_PARM_DESC(cciss_tape_cmds,
70 "number of commands to allocate for tape devices (default: 6)"); 70 "number of commands to allocate for tape devices (default: 6)");
71static int cciss_simple_mode;
72module_param(cciss_simple_mode, int, S_IRUGO|S_IWUSR);
73MODULE_PARM_DESC(cciss_simple_mode,
74 "Use 'simple mode' rather than 'performant mode'");
71 75
72static DEFINE_MUTEX(cciss_mutex); 76static DEFINE_MUTEX(cciss_mutex);
73static struct proc_dir_entry *proc_cciss; 77static struct proc_dir_entry *proc_cciss;
@@ -176,6 +180,7 @@ static void cciss_geometry_inquiry(ctlr_info_t *h, int logvol,
176 unsigned int block_size, InquiryData_struct *inq_buff, 180 unsigned int block_size, InquiryData_struct *inq_buff,
177 drive_info_struct *drv); 181 drive_info_struct *drv);
178static void __devinit cciss_interrupt_mode(ctlr_info_t *); 182static void __devinit cciss_interrupt_mode(ctlr_info_t *);
183static int __devinit cciss_enter_simple_mode(struct ctlr_info *h);
179static void start_io(ctlr_info_t *h); 184static void start_io(ctlr_info_t *h);
180static int sendcmd_withirq(ctlr_info_t *h, __u8 cmd, void *buff, size_t size, 185static int sendcmd_withirq(ctlr_info_t *h, __u8 cmd, void *buff, size_t size,
181 __u8 page_code, unsigned char scsi3addr[], 186 __u8 page_code, unsigned char scsi3addr[],
@@ -388,7 +393,7 @@ static void cciss_seq_show_header(struct seq_file *seq)
388 h->product_name, 393 h->product_name,
389 (unsigned long)h->board_id, 394 (unsigned long)h->board_id,
390 h->firm_ver[0], h->firm_ver[1], h->firm_ver[2], 395 h->firm_ver[0], h->firm_ver[1], h->firm_ver[2],
391 h->firm_ver[3], (unsigned int)h->intr[PERF_MODE_INT], 396 h->firm_ver[3], (unsigned int)h->intr[h->intr_mode],
392 h->num_luns, 397 h->num_luns,
393 h->Qdepth, h->commands_outstanding, 398 h->Qdepth, h->commands_outstanding,
394 h->maxQsinceinit, h->max_outstanding, h->maxSG); 399 h->maxQsinceinit, h->max_outstanding, h->maxSG);
@@ -636,6 +641,18 @@ static ssize_t host_store_rescan(struct device *dev,
636} 641}
637static DEVICE_ATTR(rescan, S_IWUSR, NULL, host_store_rescan); 642static DEVICE_ATTR(rescan, S_IWUSR, NULL, host_store_rescan);
638 643
644static ssize_t host_show_transport_mode(struct device *dev,
645 struct device_attribute *attr,
646 char *buf)
647{
648 struct ctlr_info *h = to_hba(dev);
649
650 return snprintf(buf, 20, "%s\n",
651 h->transMethod & CFGTBL_Trans_Performant ?
652 "performant" : "simple");
653}
654static DEVICE_ATTR(transport_mode, S_IRUGO, host_show_transport_mode, NULL);
655
639static ssize_t dev_show_unique_id(struct device *dev, 656static ssize_t dev_show_unique_id(struct device *dev,
640 struct device_attribute *attr, 657 struct device_attribute *attr,
641 char *buf) 658 char *buf)
@@ -808,6 +825,7 @@ static DEVICE_ATTR(usage_count, S_IRUGO, cciss_show_usage_count, NULL);
808static struct attribute *cciss_host_attrs[] = { 825static struct attribute *cciss_host_attrs[] = {
809 &dev_attr_rescan.attr, 826 &dev_attr_rescan.attr,
810 &dev_attr_resettable.attr, 827 &dev_attr_resettable.attr,
828 &dev_attr_transport_mode.attr,
811 NULL 829 NULL
812}; 830};
813 831
@@ -3984,6 +4002,9 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
3984{ 4002{
3985 __u32 trans_support; 4003 __u32 trans_support;
3986 4004
4005 if (cciss_simple_mode)
4006 return;
4007
3987 dev_dbg(&h->pdev->dev, "Trying to put board into Performant mode\n"); 4008 dev_dbg(&h->pdev->dev, "Trying to put board into Performant mode\n");
3988 /* Attempt to put controller into performant mode if supported */ 4009 /* Attempt to put controller into performant mode if supported */
3989 /* Does board support performant mode? */ 4010 /* Does board support performant mode? */
@@ -4081,7 +4102,7 @@ static void __devinit cciss_interrupt_mode(ctlr_info_t *h)
4081default_int_mode: 4102default_int_mode:
4082#endif /* CONFIG_PCI_MSI */ 4103#endif /* CONFIG_PCI_MSI */
4083 /* if we get here we're going to use the default interrupt mode */ 4104 /* if we get here we're going to use the default interrupt mode */
4084 h->intr[PERF_MODE_INT] = h->pdev->irq; 4105 h->intr[h->intr_mode] = h->pdev->irq;
4085 return; 4106 return;
4086} 4107}
4087 4108
@@ -4341,6 +4362,9 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
4341 } 4362 }
4342 cciss_enable_scsi_prefetch(h); 4363 cciss_enable_scsi_prefetch(h);
4343 cciss_p600_dma_prefetch_quirk(h); 4364 cciss_p600_dma_prefetch_quirk(h);
4365 err = cciss_enter_simple_mode(h);
4366 if (err)
4367 goto err_out_free_res;
4344 cciss_put_controller_into_performant_mode(h); 4368 cciss_put_controller_into_performant_mode(h);
4345 return 0; 4369 return 0;
4346 4370
@@ -4533,6 +4557,13 @@ static int cciss_controller_hard_reset(struct pci_dev *pdev,
4533 pmcsr &= ~PCI_PM_CTRL_STATE_MASK; 4557 pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
4534 pmcsr |= PCI_D0; 4558 pmcsr |= PCI_D0;
4535 pci_write_config_word(pdev, pos + PCI_PM_CTRL, pmcsr); 4559 pci_write_config_word(pdev, pos + PCI_PM_CTRL, pmcsr);
4560
4561 /*
4562 * The P600 requires a small delay when changing states.
4563 * Otherwise we may think the board did not reset and we bail.
4564 * This for kdump only and is particular to the P600.
4565 */
4566 msleep(500);
4536 } 4567 }
4537 return 0; 4568 return 0;
4538} 4569}
@@ -4843,20 +4874,20 @@ static int cciss_request_irq(ctlr_info_t *h,
4843 irqreturn_t (*intxhandler)(int, void *)) 4874 irqreturn_t (*intxhandler)(int, void *))
4844{ 4875{
4845 if (h->msix_vector || h->msi_vector) { 4876 if (h->msix_vector || h->msi_vector) {
4846 if (!request_irq(h->intr[PERF_MODE_INT], msixhandler, 4877 if (!request_irq(h->intr[h->intr_mode], msixhandler,
4847 IRQF_DISABLED, h->devname, h)) 4878 IRQF_DISABLED, h->devname, h))
4848 return 0; 4879 return 0;
4849 dev_err(&h->pdev->dev, "Unable to get msi irq %d" 4880 dev_err(&h->pdev->dev, "Unable to get msi irq %d"
4850 " for %s\n", h->intr[PERF_MODE_INT], 4881 " for %s\n", h->intr[h->intr_mode],
4851 h->devname); 4882 h->devname);
4852 return -1; 4883 return -1;
4853 } 4884 }
4854 4885
4855 if (!request_irq(h->intr[PERF_MODE_INT], intxhandler, 4886 if (!request_irq(h->intr[h->intr_mode], intxhandler,
4856 IRQF_DISABLED, h->devname, h)) 4887 IRQF_DISABLED, h->devname, h))
4857 return 0; 4888 return 0;
4858 dev_err(&h->pdev->dev, "Unable to get irq %d for %s\n", 4889 dev_err(&h->pdev->dev, "Unable to get irq %d for %s\n",
4859 h->intr[PERF_MODE_INT], h->devname); 4890 h->intr[h->intr_mode], h->devname);
4860 return -1; 4891 return -1;
4861} 4892}
4862 4893
@@ -4887,7 +4918,7 @@ static void cciss_undo_allocations_after_kdump_soft_reset(ctlr_info_t *h)
4887{ 4918{
4888 int ctlr = h->ctlr; 4919 int ctlr = h->ctlr;
4889 4920
4890 free_irq(h->intr[PERF_MODE_INT], h); 4921 free_irq(h->intr[h->intr_mode], h);
4891#ifdef CONFIG_PCI_MSI 4922#ifdef CONFIG_PCI_MSI
4892 if (h->msix_vector) 4923 if (h->msix_vector)
4893 pci_disable_msix(h->pdev); 4924 pci_disable_msix(h->pdev);
@@ -4953,6 +4984,7 @@ reinit_after_soft_reset:
4953 h = hba[i]; 4984 h = hba[i];
4954 h->pdev = pdev; 4985 h->pdev = pdev;
4955 h->busy_initializing = 1; 4986 h->busy_initializing = 1;
4987 h->intr_mode = cciss_simple_mode ? SIMPLE_MODE_INT : PERF_MODE_INT;
4956 INIT_LIST_HEAD(&h->cmpQ); 4988 INIT_LIST_HEAD(&h->cmpQ);
4957 INIT_LIST_HEAD(&h->reqQ); 4989 INIT_LIST_HEAD(&h->reqQ);
4958 mutex_init(&h->busy_shutting_down); 4990 mutex_init(&h->busy_shutting_down);
@@ -5009,7 +5041,7 @@ reinit_after_soft_reset:
5009 5041
5010 dev_info(&h->pdev->dev, "%s: <0x%x> at PCI %s IRQ %d%s using DAC\n", 5042 dev_info(&h->pdev->dev, "%s: <0x%x> at PCI %s IRQ %d%s using DAC\n",
5011 h->devname, pdev->device, pci_name(pdev), 5043 h->devname, pdev->device, pci_name(pdev),
5012 h->intr[PERF_MODE_INT], dac ? "" : " not"); 5044 h->intr[h->intr_mode], dac ? "" : " not");
5013 5045
5014 if (cciss_allocate_cmd_pool(h)) 5046 if (cciss_allocate_cmd_pool(h))
5015 goto clean4; 5047 goto clean4;
@@ -5056,7 +5088,7 @@ reinit_after_soft_reset:
5056 spin_lock_irqsave(&h->lock, flags); 5088 spin_lock_irqsave(&h->lock, flags);
5057 h->access.set_intr_mask(h, CCISS_INTR_OFF); 5089 h->access.set_intr_mask(h, CCISS_INTR_OFF);
5058 spin_unlock_irqrestore(&h->lock, flags); 5090 spin_unlock_irqrestore(&h->lock, flags);
5059 free_irq(h->intr[PERF_MODE_INT], h); 5091 free_irq(h->intr[h->intr_mode], h);
5060 rc = cciss_request_irq(h, cciss_msix_discard_completions, 5092 rc = cciss_request_irq(h, cciss_msix_discard_completions,
5061 cciss_intx_discard_completions); 5093 cciss_intx_discard_completions);
5062 if (rc) { 5094 if (rc) {
@@ -5133,7 +5165,7 @@ clean4:
5133 cciss_free_cmd_pool(h); 5165 cciss_free_cmd_pool(h);
5134 cciss_free_scatterlists(h); 5166 cciss_free_scatterlists(h);
5135 cciss_free_sg_chain_blocks(h->cmd_sg_list, h->nr_cmds); 5167 cciss_free_sg_chain_blocks(h->cmd_sg_list, h->nr_cmds);
5136 free_irq(h->intr[PERF_MODE_INT], h); 5168 free_irq(h->intr[h->intr_mode], h);
5137clean2: 5169clean2:
5138 unregister_blkdev(h->major, h->devname); 5170 unregister_blkdev(h->major, h->devname);
5139clean1: 5171clean1:
@@ -5172,9 +5204,31 @@ static void cciss_shutdown(struct pci_dev *pdev)
5172 if (return_code != IO_OK) 5204 if (return_code != IO_OK)
5173 dev_warn(&h->pdev->dev, "Error flushing cache\n"); 5205 dev_warn(&h->pdev->dev, "Error flushing cache\n");
5174 h->access.set_intr_mask(h, CCISS_INTR_OFF); 5206 h->access.set_intr_mask(h, CCISS_INTR_OFF);
5175 free_irq(h->intr[PERF_MODE_INT], h); 5207 free_irq(h->intr[h->intr_mode], h);
5208}
5209
5210static int __devinit cciss_enter_simple_mode(struct ctlr_info *h)
5211{
5212 u32 trans_support;
5213
5214 trans_support = readl(&(h->cfgtable->TransportSupport));
5215 if (!(trans_support & SIMPLE_MODE))
5216 return -ENOTSUPP;
5217
5218 h->max_commands = readl(&(h->cfgtable->CmdsOutMax));
5219 writel(CFGTBL_Trans_Simple, &(h->cfgtable->HostWrite.TransportRequest));
5220 writel(CFGTBL_ChangeReq, h->vaddr + SA5_DOORBELL);
5221 cciss_wait_for_mode_change_ack(h);
5222 print_cfg_table(h);
5223 if (!(readl(&(h->cfgtable->TransportActive)) & CFGTBL_Trans_Simple)) {
5224 dev_warn(&h->pdev->dev, "unable to get board into simple mode\n");
5225 return -ENODEV;
5226 }
5227 h->transMethod = CFGTBL_Trans_Simple;
5228 return 0;
5176} 5229}
5177 5230
5231
5178static void __devexit cciss_remove_one(struct pci_dev *pdev) 5232static void __devexit cciss_remove_one(struct pci_dev *pdev)
5179{ 5233{
5180 ctlr_info_t *h; 5234 ctlr_info_t *h;
diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
index c049548e68b7..7fda30e4a241 100644
--- a/drivers/block/cciss.h
+++ b/drivers/block/cciss.h
@@ -92,6 +92,7 @@ struct ctlr_info
92 unsigned int intr[4]; 92 unsigned int intr[4];
93 unsigned int msix_vector; 93 unsigned int msix_vector;
94 unsigned int msi_vector; 94 unsigned int msi_vector;
95 int intr_mode;
95 int cciss_max_sectors; 96 int cciss_max_sectors;
96 BYTE cciss_read; 97 BYTE cciss_read;
97 BYTE cciss_write; 98 BYTE cciss_write;
diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
index b2fceb53e809..9125bbeacd4d 100644
--- a/drivers/block/cpqarray.c
+++ b/drivers/block/cpqarray.c
@@ -620,6 +620,7 @@ static int cpqarray_pci_init(ctlr_info_t *c, struct pci_dev *pdev)
620 } 620 }
621 vendor_id = pdev->vendor; 621 vendor_id = pdev->vendor;
622 device_id = pdev->device; 622 device_id = pdev->device;
623 revision = pdev->revision;
623 irq = pdev->irq; 624 irq = pdev->irq;
624 625
625 for(i=0; i<6; i++) 626 for(i=0; i<6; i++)
@@ -632,7 +633,6 @@ static int cpqarray_pci_init(ctlr_info_t *c, struct pci_dev *pdev)
632 } 633 }
633 634
634 pci_read_config_word(pdev, PCI_COMMAND, &command); 635 pci_read_config_word(pdev, PCI_COMMAND, &command);
635 pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
636 pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &cache_line_size); 636 pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &cache_line_size);
637 pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency_timer); 637 pci_read_config_byte(pdev, PCI_LATENCY_TIMER, &latency_timer);
638 638
diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
index 1706d60b8c99..9cf20355ceec 100644
--- a/drivers/block/drbd/drbd_int.h
+++ b/drivers/block/drbd/drbd_int.h
@@ -1506,7 +1506,7 @@ extern void drbd_free_mdev(struct drbd_conf *mdev);
1506extern int proc_details; 1506extern int proc_details;
1507 1507
1508/* drbd_req */ 1508/* drbd_req */
1509extern int drbd_make_request(struct request_queue *q, struct bio *bio); 1509extern void drbd_make_request(struct request_queue *q, struct bio *bio);
1510extern int drbd_read_remote(struct drbd_conf *mdev, struct drbd_request *req); 1510extern int drbd_read_remote(struct drbd_conf *mdev, struct drbd_request *req);
1511extern int drbd_merge_bvec(struct request_queue *q, struct bvec_merge_data *bvm, struct bio_vec *bvec); 1511extern int drbd_merge_bvec(struct request_queue *q, struct bvec_merge_data *bvm, struct bio_vec *bvec);
1512extern int is_valid_ar_handle(struct drbd_request *, sector_t); 1512extern int is_valid_ar_handle(struct drbd_request *, sector_t);
diff --git a/drivers/block/drbd/drbd_req.c b/drivers/block/drbd/drbd_req.c
index 3424d675b769..4a0f314086e5 100644
--- a/drivers/block/drbd/drbd_req.c
+++ b/drivers/block/drbd/drbd_req.c
@@ -1073,7 +1073,7 @@ static int drbd_fail_request_early(struct drbd_conf *mdev, int is_write)
1073 return 0; 1073 return 0;
1074} 1074}
1075 1075
1076int drbd_make_request(struct request_queue *q, struct bio *bio) 1076void drbd_make_request(struct request_queue *q, struct bio *bio)
1077{ 1077{
1078 unsigned int s_enr, e_enr; 1078 unsigned int s_enr, e_enr;
1079 struct drbd_conf *mdev = (struct drbd_conf *) q->queuedata; 1079 struct drbd_conf *mdev = (struct drbd_conf *) q->queuedata;
@@ -1081,7 +1081,7 @@ int drbd_make_request(struct request_queue *q, struct bio *bio)
1081 1081
1082 if (drbd_fail_request_early(mdev, bio_data_dir(bio) & WRITE)) { 1082 if (drbd_fail_request_early(mdev, bio_data_dir(bio) & WRITE)) {
1083 bio_endio(bio, -EPERM); 1083 bio_endio(bio, -EPERM);
1084 return 0; 1084 return;
1085 } 1085 }
1086 1086
1087 start_time = jiffies; 1087 start_time = jiffies;
@@ -1100,7 +1100,8 @@ int drbd_make_request(struct request_queue *q, struct bio *bio)
1100 1100
1101 if (likely(s_enr == e_enr)) { 1101 if (likely(s_enr == e_enr)) {
1102 inc_ap_bio(mdev, 1); 1102 inc_ap_bio(mdev, 1);
1103 return drbd_make_request_common(mdev, bio, start_time); 1103 drbd_make_request_common(mdev, bio, start_time);
1104 return;
1104 } 1105 }
1105 1106
1106 /* can this bio be split generically? 1107 /* can this bio be split generically?
@@ -1148,7 +1149,6 @@ int drbd_make_request(struct request_queue *q, struct bio *bio)
1148 1149
1149 bio_pair_release(bp); 1150 bio_pair_release(bp);
1150 } 1151 }
1151 return 0;
1152} 1152}
1153 1153
1154/* This is called by bio_add_page(). With this function we reduce 1154/* This is called by bio_add_page(). With this function we reduce
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 4720c7ade0ae..3d806820280e 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -76,6 +76,8 @@
76#include <linux/splice.h> 76#include <linux/splice.h>
77#include <linux/sysfs.h> 77#include <linux/sysfs.h>
78#include <linux/miscdevice.h> 78#include <linux/miscdevice.h>
79#include <linux/falloc.h>
80
79#include <asm/uaccess.h> 81#include <asm/uaccess.h>
80 82
81static DEFINE_IDR(loop_index_idr); 83static DEFINE_IDR(loop_index_idr);
@@ -203,74 +205,6 @@ lo_do_transfer(struct loop_device *lo, int cmd,
203} 205}
204 206
205/** 207/**
206 * do_lo_send_aops - helper for writing data to a loop device
207 *
208 * This is the fast version for backing filesystems which implement the address
209 * space operations write_begin and write_end.
210 */
211static int do_lo_send_aops(struct loop_device *lo, struct bio_vec *bvec,
212 loff_t pos, struct page *unused)
213{
214 struct file *file = lo->lo_backing_file; /* kudos to NFsckingS */
215 struct address_space *mapping = file->f_mapping;
216 pgoff_t index;
217 unsigned offset, bv_offs;
218 int len, ret;
219
220 mutex_lock(&mapping->host->i_mutex);
221 index = pos >> PAGE_CACHE_SHIFT;
222 offset = pos & ((pgoff_t)PAGE_CACHE_SIZE - 1);
223 bv_offs = bvec->bv_offset;
224 len = bvec->bv_len;
225 while (len > 0) {
226 sector_t IV;
227 unsigned size, copied;
228 int transfer_result;
229 struct page *page;
230 void *fsdata;
231
232 IV = ((sector_t)index << (PAGE_CACHE_SHIFT - 9))+(offset >> 9);
233 size = PAGE_CACHE_SIZE - offset;
234 if (size > len)
235 size = len;
236
237 ret = pagecache_write_begin(file, mapping, pos, size, 0,
238 &page, &fsdata);
239 if (ret)
240 goto fail;
241
242 file_update_time(file);
243
244 transfer_result = lo_do_transfer(lo, WRITE, page, offset,
245 bvec->bv_page, bv_offs, size, IV);
246 copied = size;
247 if (unlikely(transfer_result))
248 copied = 0;
249
250 ret = pagecache_write_end(file, mapping, pos, size, copied,
251 page, fsdata);
252 if (ret < 0 || ret != copied)
253 goto fail;
254
255 if (unlikely(transfer_result))
256 goto fail;
257
258 bv_offs += copied;
259 len -= copied;
260 offset = 0;
261 index++;
262 pos += copied;
263 }
264 ret = 0;
265out:
266 mutex_unlock(&mapping->host->i_mutex);
267 return ret;
268fail:
269 ret = -1;
270 goto out;
271}
272
273/**
274 * __do_lo_send_write - helper for writing data to a loop device 208 * __do_lo_send_write - helper for writing data to a loop device
275 * 209 *
276 * This helper just factors out common code between do_lo_send_direct_write() 210 * This helper just factors out common code between do_lo_send_direct_write()
@@ -297,10 +231,8 @@ static int __do_lo_send_write(struct file *file,
297/** 231/**
298 * do_lo_send_direct_write - helper for writing data to a loop device 232 * do_lo_send_direct_write - helper for writing data to a loop device
299 * 233 *
300 * This is the fast, non-transforming version for backing filesystems which do 234 * This is the fast, non-transforming version that does not need double
301 * not implement the address space operations write_begin and write_end. 235 * buffering.
302 * It uses the write file operation which should be present on all writeable
303 * filesystems.
304 */ 236 */
305static int do_lo_send_direct_write(struct loop_device *lo, 237static int do_lo_send_direct_write(struct loop_device *lo,
306 struct bio_vec *bvec, loff_t pos, struct page *page) 238 struct bio_vec *bvec, loff_t pos, struct page *page)
@@ -316,15 +248,9 @@ static int do_lo_send_direct_write(struct loop_device *lo,
316/** 248/**
317 * do_lo_send_write - helper for writing data to a loop device 249 * do_lo_send_write - helper for writing data to a loop device
318 * 250 *
319 * This is the slow, transforming version for filesystems which do not 251 * This is the slow, transforming version that needs to double buffer the
320 * implement the address space operations write_begin and write_end. It 252 * data as it cannot do the transformations in place without having direct
321 * uses the write file operation which should be present on all writeable 253 * access to the destination pages of the backing file.
322 * filesystems.
323 *
324 * Using fops->write is slower than using aops->{prepare,commit}_write in the
325 * transforming case because we need to double buffer the data as we cannot do
326 * the transformations in place as we do not have direct access to the
327 * destination pages of the backing file.
328 */ 254 */
329static int do_lo_send_write(struct loop_device *lo, struct bio_vec *bvec, 255static int do_lo_send_write(struct loop_device *lo, struct bio_vec *bvec,
330 loff_t pos, struct page *page) 256 loff_t pos, struct page *page)
@@ -350,17 +276,16 @@ static int lo_send(struct loop_device *lo, struct bio *bio, loff_t pos)
350 struct page *page = NULL; 276 struct page *page = NULL;
351 int i, ret = 0; 277 int i, ret = 0;
352 278
353 do_lo_send = do_lo_send_aops; 279 if (lo->transfer != transfer_none) {
354 if (!(lo->lo_flags & LO_FLAGS_USE_AOPS)) { 280 page = alloc_page(GFP_NOIO | __GFP_HIGHMEM);
281 if (unlikely(!page))
282 goto fail;
283 kmap(page);
284 do_lo_send = do_lo_send_write;
285 } else {
355 do_lo_send = do_lo_send_direct_write; 286 do_lo_send = do_lo_send_direct_write;
356 if (lo->transfer != transfer_none) {
357 page = alloc_page(GFP_NOIO | __GFP_HIGHMEM);
358 if (unlikely(!page))
359 goto fail;
360 kmap(page);
361 do_lo_send = do_lo_send_write;
362 }
363 } 287 }
288
364 bio_for_each_segment(bvec, bio, i) { 289 bio_for_each_segment(bvec, bio, i) {
365 ret = do_lo_send(lo, bvec, pos, page); 290 ret = do_lo_send(lo, bvec, pos, page);
366 if (ret < 0) 291 if (ret < 0)
@@ -484,6 +409,29 @@ static int do_bio_filebacked(struct loop_device *lo, struct bio *bio)
484 } 409 }
485 } 410 }
486 411
412 /*
413 * We use punch hole to reclaim the free space used by the
414 * image a.k.a. discard. However we do support discard if
415 * encryption is enabled, because it may give an attacker
416 * useful information.
417 */
418 if (bio->bi_rw & REQ_DISCARD) {
419 struct file *file = lo->lo_backing_file;
420 int mode = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE;
421
422 if ((!file->f_op->fallocate) ||
423 lo->lo_encrypt_key_size) {
424 ret = -EOPNOTSUPP;
425 goto out;
426 }
427 ret = file->f_op->fallocate(file, mode, pos,
428 bio->bi_size);
429 if (unlikely(ret && ret != -EINVAL &&
430 ret != -EOPNOTSUPP))
431 ret = -EIO;
432 goto out;
433 }
434
487 ret = lo_send(lo, bio, pos); 435 ret = lo_send(lo, bio, pos);
488 436
489 if ((bio->bi_rw & REQ_FUA) && !ret) { 437 if ((bio->bi_rw & REQ_FUA) && !ret) {
@@ -514,7 +462,7 @@ static struct bio *loop_get_bio(struct loop_device *lo)
514 return bio_list_pop(&lo->lo_bio_list); 462 return bio_list_pop(&lo->lo_bio_list);
515} 463}
516 464
517static int loop_make_request(struct request_queue *q, struct bio *old_bio) 465static void loop_make_request(struct request_queue *q, struct bio *old_bio)
518{ 466{
519 struct loop_device *lo = q->queuedata; 467 struct loop_device *lo = q->queuedata;
520 int rw = bio_rw(old_bio); 468 int rw = bio_rw(old_bio);
@@ -532,12 +480,11 @@ static int loop_make_request(struct request_queue *q, struct bio *old_bio)
532 loop_add_bio(lo, old_bio); 480 loop_add_bio(lo, old_bio);
533 wake_up(&lo->lo_event); 481 wake_up(&lo->lo_event);
534 spin_unlock_irq(&lo->lo_lock); 482 spin_unlock_irq(&lo->lo_lock);
535 return 0; 483 return;
536 484
537out: 485out:
538 spin_unlock_irq(&lo->lo_lock); 486 spin_unlock_irq(&lo->lo_lock);
539 bio_io_error(old_bio); 487 bio_io_error(old_bio);
540 return 0;
541} 488}
542 489
543struct switch_request { 490struct switch_request {
@@ -700,7 +647,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
700 goto out_putf; 647 goto out_putf;
701 648
702 fput(old_file); 649 fput(old_file);
703 if (max_part > 0) 650 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
704 ioctl_by_bdev(bdev, BLKRRPART, 0); 651 ioctl_by_bdev(bdev, BLKRRPART, 0);
705 return 0; 652 return 0;
706 653
@@ -777,16 +724,25 @@ static ssize_t loop_attr_autoclear_show(struct loop_device *lo, char *buf)
777 return sprintf(buf, "%s\n", autoclear ? "1" : "0"); 724 return sprintf(buf, "%s\n", autoclear ? "1" : "0");
778} 725}
779 726
727static ssize_t loop_attr_partscan_show(struct loop_device *lo, char *buf)
728{
729 int partscan = (lo->lo_flags & LO_FLAGS_PARTSCAN);
730
731 return sprintf(buf, "%s\n", partscan ? "1" : "0");
732}
733
780LOOP_ATTR_RO(backing_file); 734LOOP_ATTR_RO(backing_file);
781LOOP_ATTR_RO(offset); 735LOOP_ATTR_RO(offset);
782LOOP_ATTR_RO(sizelimit); 736LOOP_ATTR_RO(sizelimit);
783LOOP_ATTR_RO(autoclear); 737LOOP_ATTR_RO(autoclear);
738LOOP_ATTR_RO(partscan);
784 739
785static struct attribute *loop_attrs[] = { 740static struct attribute *loop_attrs[] = {
786 &loop_attr_backing_file.attr, 741 &loop_attr_backing_file.attr,
787 &loop_attr_offset.attr, 742 &loop_attr_offset.attr,
788 &loop_attr_sizelimit.attr, 743 &loop_attr_sizelimit.attr,
789 &loop_attr_autoclear.attr, 744 &loop_attr_autoclear.attr,
745 &loop_attr_partscan.attr,
790 NULL, 746 NULL,
791}; 747};
792 748
@@ -807,6 +763,35 @@ static void loop_sysfs_exit(struct loop_device *lo)
807 &loop_attribute_group); 763 &loop_attribute_group);
808} 764}
809 765
766static void loop_config_discard(struct loop_device *lo)
767{
768 struct file *file = lo->lo_backing_file;
769 struct inode *inode = file->f_mapping->host;
770 struct request_queue *q = lo->lo_queue;
771
772 /*
773 * We use punch hole to reclaim the free space used by the
774 * image a.k.a. discard. However we do support discard if
775 * encryption is enabled, because it may give an attacker
776 * useful information.
777 */
778 if ((!file->f_op->fallocate) ||
779 lo->lo_encrypt_key_size) {
780 q->limits.discard_granularity = 0;
781 q->limits.discard_alignment = 0;
782 q->limits.max_discard_sectors = 0;
783 q->limits.discard_zeroes_data = 0;
784 queue_flag_clear_unlocked(QUEUE_FLAG_DISCARD, q);
785 return;
786 }
787
788 q->limits.discard_granularity = inode->i_sb->s_blocksize;
789 q->limits.discard_alignment = inode->i_sb->s_blocksize;
790 q->limits.max_discard_sectors = UINT_MAX >> 9;
791 q->limits.discard_zeroes_data = 1;
792 queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, q);
793}
794
810static int loop_set_fd(struct loop_device *lo, fmode_t mode, 795static int loop_set_fd(struct loop_device *lo, fmode_t mode,
811 struct block_device *bdev, unsigned int arg) 796 struct block_device *bdev, unsigned int arg)
812{ 797{
@@ -849,35 +834,23 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
849 mapping = file->f_mapping; 834 mapping = file->f_mapping;
850 inode = mapping->host; 835 inode = mapping->host;
851 836
852 if (!(file->f_mode & FMODE_WRITE))
853 lo_flags |= LO_FLAGS_READ_ONLY;
854
855 error = -EINVAL; 837 error = -EINVAL;
856 if (S_ISREG(inode->i_mode) || S_ISBLK(inode->i_mode)) { 838 if (!S_ISREG(inode->i_mode) && !S_ISBLK(inode->i_mode))
857 const struct address_space_operations *aops = mapping->a_ops; 839 goto out_putf;
858
859 if (aops->write_begin)
860 lo_flags |= LO_FLAGS_USE_AOPS;
861 if (!(lo_flags & LO_FLAGS_USE_AOPS) && !file->f_op->write)
862 lo_flags |= LO_FLAGS_READ_ONLY;
863 840
864 lo_blocksize = S_ISBLK(inode->i_mode) ? 841 if (!(file->f_mode & FMODE_WRITE) || !(mode & FMODE_WRITE) ||
865 inode->i_bdev->bd_block_size : PAGE_SIZE; 842 !file->f_op->write)
843 lo_flags |= LO_FLAGS_READ_ONLY;
866 844
867 error = 0; 845 lo_blocksize = S_ISBLK(inode->i_mode) ?
868 } else { 846 inode->i_bdev->bd_block_size : PAGE_SIZE;
869 goto out_putf;
870 }
871 847
848 error = -EFBIG;
872 size = get_loop_size(lo, file); 849 size = get_loop_size(lo, file);
873 850 if ((loff_t)(sector_t)size != size)
874 if ((loff_t)(sector_t)size != size) {
875 error = -EFBIG;
876 goto out_putf; 851 goto out_putf;
877 }
878 852
879 if (!(mode & FMODE_WRITE)) 853 error = 0;
880 lo_flags |= LO_FLAGS_READ_ONLY;
881 854
882 set_device_ro(bdev, (lo_flags & LO_FLAGS_READ_ONLY) != 0); 855 set_device_ro(bdev, (lo_flags & LO_FLAGS_READ_ONLY) != 0);
883 856
@@ -919,7 +892,9 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
919 } 892 }
920 lo->lo_state = Lo_bound; 893 lo->lo_state = Lo_bound;
921 wake_up_process(lo->lo_thread); 894 wake_up_process(lo->lo_thread);
922 if (max_part > 0) 895 if (part_shift)
896 lo->lo_flags |= LO_FLAGS_PARTSCAN;
897 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
923 ioctl_by_bdev(bdev, BLKRRPART, 0); 898 ioctl_by_bdev(bdev, BLKRRPART, 0);
924 return 0; 899 return 0;
925 900
@@ -980,10 +955,11 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
980 return err; 955 return err;
981} 956}
982 957
983static int loop_clr_fd(struct loop_device *lo, struct block_device *bdev) 958static int loop_clr_fd(struct loop_device *lo)
984{ 959{
985 struct file *filp = lo->lo_backing_file; 960 struct file *filp = lo->lo_backing_file;
986 gfp_t gfp = lo->old_gfp_mask; 961 gfp_t gfp = lo->old_gfp_mask;
962 struct block_device *bdev = lo->lo_device;
987 963
988 if (lo->lo_state != Lo_bound) 964 if (lo->lo_state != Lo_bound)
989 return -ENXIO; 965 return -ENXIO;
@@ -1012,7 +988,6 @@ static int loop_clr_fd(struct loop_device *lo, struct block_device *bdev)
1012 lo->lo_offset = 0; 988 lo->lo_offset = 0;
1013 lo->lo_sizelimit = 0; 989 lo->lo_sizelimit = 0;
1014 lo->lo_encrypt_key_size = 0; 990 lo->lo_encrypt_key_size = 0;
1015 lo->lo_flags = 0;
1016 lo->lo_thread = NULL; 991 lo->lo_thread = NULL;
1017 memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE); 992 memset(lo->lo_encrypt_key, 0, LO_KEY_SIZE);
1018 memset(lo->lo_crypt_name, 0, LO_NAME_SIZE); 993 memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
@@ -1030,8 +1005,11 @@ static int loop_clr_fd(struct loop_device *lo, struct block_device *bdev)
1030 lo->lo_state = Lo_unbound; 1005 lo->lo_state = Lo_unbound;
1031 /* This is safe: open() is still holding a reference. */ 1006 /* This is safe: open() is still holding a reference. */
1032 module_put(THIS_MODULE); 1007 module_put(THIS_MODULE);
1033 if (max_part > 0 && bdev) 1008 if (lo->lo_flags & LO_FLAGS_PARTSCAN && bdev)
1034 ioctl_by_bdev(bdev, BLKRRPART, 0); 1009 ioctl_by_bdev(bdev, BLKRRPART, 0);
1010 lo->lo_flags = 0;
1011 if (!part_shift)
1012 lo->lo_disk->flags |= GENHD_FL_NO_PART_SCAN;
1035 mutex_unlock(&lo->lo_ctl_mutex); 1013 mutex_unlock(&lo->lo_ctl_mutex);
1036 /* 1014 /*
1037 * Need not hold lo_ctl_mutex to fput backing file. 1015 * Need not hold lo_ctl_mutex to fput backing file.
@@ -1085,6 +1063,7 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info)
1085 if (figure_loop_size(lo)) 1063 if (figure_loop_size(lo))
1086 return -EFBIG; 1064 return -EFBIG;
1087 } 1065 }
1066 loop_config_discard(lo);
1088 1067
1089 memcpy(lo->lo_file_name, info->lo_file_name, LO_NAME_SIZE); 1068 memcpy(lo->lo_file_name, info->lo_file_name, LO_NAME_SIZE);
1090 memcpy(lo->lo_crypt_name, info->lo_crypt_name, LO_NAME_SIZE); 1069 memcpy(lo->lo_crypt_name, info->lo_crypt_name, LO_NAME_SIZE);
@@ -1100,6 +1079,13 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info)
1100 (info->lo_flags & LO_FLAGS_AUTOCLEAR)) 1079 (info->lo_flags & LO_FLAGS_AUTOCLEAR))
1101 lo->lo_flags ^= LO_FLAGS_AUTOCLEAR; 1080 lo->lo_flags ^= LO_FLAGS_AUTOCLEAR;
1102 1081
1082 if ((info->lo_flags & LO_FLAGS_PARTSCAN) &&
1083 !(lo->lo_flags & LO_FLAGS_PARTSCAN)) {
1084 lo->lo_flags |= LO_FLAGS_PARTSCAN;
1085 lo->lo_disk->flags &= ~GENHD_FL_NO_PART_SCAN;
1086 ioctl_by_bdev(lo->lo_device, BLKRRPART, 0);
1087 }
1088
1103 lo->lo_encrypt_key_size = info->lo_encrypt_key_size; 1089 lo->lo_encrypt_key_size = info->lo_encrypt_key_size;
1104 lo->lo_init[0] = info->lo_init[0]; 1090 lo->lo_init[0] = info->lo_init[0];
1105 lo->lo_init[1] = info->lo_init[1]; 1091 lo->lo_init[1] = info->lo_init[1];
@@ -1293,7 +1279,7 @@ static int lo_ioctl(struct block_device *bdev, fmode_t mode,
1293 break; 1279 break;
1294 case LOOP_CLR_FD: 1280 case LOOP_CLR_FD:
1295 /* loop_clr_fd would have unlocked lo_ctl_mutex on success */ 1281 /* loop_clr_fd would have unlocked lo_ctl_mutex on success */
1296 err = loop_clr_fd(lo, bdev); 1282 err = loop_clr_fd(lo);
1297 if (!err) 1283 if (!err)
1298 goto out_unlocked; 1284 goto out_unlocked;
1299 break; 1285 break;
@@ -1513,7 +1499,7 @@ static int lo_release(struct gendisk *disk, fmode_t mode)
1513 * In autoclear mode, stop the loop thread 1499 * In autoclear mode, stop the loop thread
1514 * and remove configuration after last close. 1500 * and remove configuration after last close.
1515 */ 1501 */
1516 err = loop_clr_fd(lo, NULL); 1502 err = loop_clr_fd(lo);
1517 if (!err) 1503 if (!err)
1518 goto out_unlocked; 1504 goto out_unlocked;
1519 } else { 1505 } else {
@@ -1635,6 +1621,27 @@ static int loop_add(struct loop_device **l, int i)
1635 if (!disk) 1621 if (!disk)
1636 goto out_free_queue; 1622 goto out_free_queue;
1637 1623
1624 /*
1625 * Disable partition scanning by default. The in-kernel partition
1626 * scanning can be requested individually per-device during its
1627 * setup. Userspace can always add and remove partitions from all
1628 * devices. The needed partition minors are allocated from the
1629 * extended minor space, the main loop device numbers will continue
1630 * to match the loop minors, regardless of the number of partitions
1631 * used.
1632 *
1633 * If max_part is given, partition scanning is globally enabled for
1634 * all loop devices. The minors for the main loop devices will be
1635 * multiples of max_part.
1636 *
1637 * Note: Global-for-all-devices, set-only-at-init, read-only module
1638 * parameteters like 'max_loop' and 'max_part' make things needlessly
1639 * complicated, are too static, inflexible and may surprise
1640 * userspace tools. Parameters like this in general should be avoided.
1641 */
1642 if (!part_shift)
1643 disk->flags |= GENHD_FL_NO_PART_SCAN;
1644 disk->flags |= GENHD_FL_EXT_DEVT;
1638 mutex_init(&lo->lo_ctl_mutex); 1645 mutex_init(&lo->lo_ctl_mutex);
1639 lo->lo_number = i; 1646 lo->lo_number = i;
1640 lo->lo_thread = NULL; 1647 lo->lo_thread = NULL;
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index f533f3375e24..c3f0ee16594d 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -127,8 +127,7 @@ static void sock_shutdown(struct nbd_device *lo, int lock)
127 if (lock) 127 if (lock)
128 mutex_lock(&lo->tx_lock); 128 mutex_lock(&lo->tx_lock);
129 if (lo->sock) { 129 if (lo->sock) {
130 printk(KERN_WARNING "%s: shutting down socket\n", 130 dev_warn(disk_to_dev(lo->disk), "shutting down socket\n");
131 lo->disk->disk_name);
132 kernel_sock_shutdown(lo->sock, SHUT_RDWR); 131 kernel_sock_shutdown(lo->sock, SHUT_RDWR);
133 lo->sock = NULL; 132 lo->sock = NULL;
134 } 133 }
@@ -158,8 +157,9 @@ static int sock_xmit(struct nbd_device *lo, int send, void *buf, int size,
158 sigset_t blocked, oldset; 157 sigset_t blocked, oldset;
159 158
160 if (unlikely(!sock)) { 159 if (unlikely(!sock)) {
161 printk(KERN_ERR "%s: Attempted %s on closed socket in sock_xmit\n", 160 dev_err(disk_to_dev(lo->disk),
162 lo->disk->disk_name, (send ? "send" : "recv")); 161 "Attempted %s on closed socket in sock_xmit\n",
162 (send ? "send" : "recv"));
163 return -EINVAL; 163 return -EINVAL;
164 } 164 }
165 165
@@ -250,8 +250,8 @@ static int nbd_send_req(struct nbd_device *lo, struct request *req)
250 result = sock_xmit(lo, 1, &request, sizeof(request), 250 result = sock_xmit(lo, 1, &request, sizeof(request),
251 (nbd_cmd(req) == NBD_CMD_WRITE) ? MSG_MORE : 0); 251 (nbd_cmd(req) == NBD_CMD_WRITE) ? MSG_MORE : 0);
252 if (result <= 0) { 252 if (result <= 0) {
253 printk(KERN_ERR "%s: Send control failed (result %d)\n", 253 dev_err(disk_to_dev(lo->disk),
254 lo->disk->disk_name, result); 254 "Send control failed (result %d)\n", result);
255 goto error_out; 255 goto error_out;
256 } 256 }
257 257
@@ -270,8 +270,9 @@ static int nbd_send_req(struct nbd_device *lo, struct request *req)
270 lo->disk->disk_name, req, bvec->bv_len); 270 lo->disk->disk_name, req, bvec->bv_len);
271 result = sock_send_bvec(lo, bvec, flags); 271 result = sock_send_bvec(lo, bvec, flags);
272 if (result <= 0) { 272 if (result <= 0) {
273 printk(KERN_ERR "%s: Send data failed (result %d)\n", 273 dev_err(disk_to_dev(lo->disk),
274 lo->disk->disk_name, result); 274 "Send data failed (result %d)\n",
275 result);
275 goto error_out; 276 goto error_out;
276 } 277 }
277 } 278 }
@@ -328,14 +329,13 @@ static struct request *nbd_read_stat(struct nbd_device *lo)
328 reply.magic = 0; 329 reply.magic = 0;
329 result = sock_xmit(lo, 0, &reply, sizeof(reply), MSG_WAITALL); 330 result = sock_xmit(lo, 0, &reply, sizeof(reply), MSG_WAITALL);
330 if (result <= 0) { 331 if (result <= 0) {
331 printk(KERN_ERR "%s: Receive control failed (result %d)\n", 332 dev_err(disk_to_dev(lo->disk),
332 lo->disk->disk_name, result); 333 "Receive control failed (result %d)\n", result);
333 goto harderror; 334 goto harderror;
334 } 335 }
335 336
336 if (ntohl(reply.magic) != NBD_REPLY_MAGIC) { 337 if (ntohl(reply.magic) != NBD_REPLY_MAGIC) {
337 printk(KERN_ERR "%s: Wrong magic (0x%lx)\n", 338 dev_err(disk_to_dev(lo->disk), "Wrong magic (0x%lx)\n",
338 lo->disk->disk_name,
339 (unsigned long)ntohl(reply.magic)); 339 (unsigned long)ntohl(reply.magic));
340 result = -EPROTO; 340 result = -EPROTO;
341 goto harderror; 341 goto harderror;
@@ -347,15 +347,15 @@ static struct request *nbd_read_stat(struct nbd_device *lo)
347 if (result != -ENOENT) 347 if (result != -ENOENT)
348 goto harderror; 348 goto harderror;
349 349
350 printk(KERN_ERR "%s: Unexpected reply (%p)\n", 350 dev_err(disk_to_dev(lo->disk), "Unexpected reply (%p)\n",
351 lo->disk->disk_name, reply.handle); 351 reply.handle);
352 result = -EBADR; 352 result = -EBADR;
353 goto harderror; 353 goto harderror;
354 } 354 }
355 355
356 if (ntohl(reply.error)) { 356 if (ntohl(reply.error)) {
357 printk(KERN_ERR "%s: Other side returned error (%d)\n", 357 dev_err(disk_to_dev(lo->disk), "Other side returned error (%d)\n",
358 lo->disk->disk_name, ntohl(reply.error)); 358 ntohl(reply.error));
359 req->errors++; 359 req->errors++;
360 return req; 360 return req;
361 } 361 }
@@ -369,8 +369,8 @@ static struct request *nbd_read_stat(struct nbd_device *lo)
369 rq_for_each_segment(bvec, req, iter) { 369 rq_for_each_segment(bvec, req, iter) {
370 result = sock_recv_bvec(lo, bvec); 370 result = sock_recv_bvec(lo, bvec);
371 if (result <= 0) { 371 if (result <= 0) {
372 printk(KERN_ERR "%s: Receive data failed (result %d)\n", 372 dev_err(disk_to_dev(lo->disk), "Receive data failed (result %d)\n",
373 lo->disk->disk_name, result); 373 result);
374 req->errors++; 374 req->errors++;
375 return req; 375 return req;
376 } 376 }
@@ -405,10 +405,10 @@ static int nbd_do_it(struct nbd_device *lo)
405 405
406 BUG_ON(lo->magic != LO_MAGIC); 406 BUG_ON(lo->magic != LO_MAGIC);
407 407
408 lo->pid = current->pid; 408 lo->pid = task_pid_nr(current);
409 ret = sysfs_create_file(&disk_to_dev(lo->disk)->kobj, &pid_attr.attr); 409 ret = device_create_file(disk_to_dev(lo->disk), &pid_attr);
410 if (ret) { 410 if (ret) {
411 printk(KERN_ERR "nbd: sysfs_create_file failed!"); 411 dev_err(disk_to_dev(lo->disk), "device_create_file failed!\n");
412 lo->pid = 0; 412 lo->pid = 0;
413 return ret; 413 return ret;
414 } 414 }
@@ -416,7 +416,7 @@ static int nbd_do_it(struct nbd_device *lo)
416 while ((req = nbd_read_stat(lo)) != NULL) 416 while ((req = nbd_read_stat(lo)) != NULL)
417 nbd_end_request(req); 417 nbd_end_request(req);
418 418
419 sysfs_remove_file(&disk_to_dev(lo->disk)->kobj, &pid_attr.attr); 419 device_remove_file(disk_to_dev(lo->disk), &pid_attr);
420 lo->pid = 0; 420 lo->pid = 0;
421 return 0; 421 return 0;
422} 422}
@@ -457,8 +457,8 @@ static void nbd_handle_req(struct nbd_device *lo, struct request *req)
457 if (rq_data_dir(req) == WRITE) { 457 if (rq_data_dir(req) == WRITE) {
458 nbd_cmd(req) = NBD_CMD_WRITE; 458 nbd_cmd(req) = NBD_CMD_WRITE;
459 if (lo->flags & NBD_READ_ONLY) { 459 if (lo->flags & NBD_READ_ONLY) {
460 printk(KERN_ERR "%s: Write on read-only\n", 460 dev_err(disk_to_dev(lo->disk),
461 lo->disk->disk_name); 461 "Write on read-only\n");
462 goto error_out; 462 goto error_out;
463 } 463 }
464 } 464 }
@@ -468,16 +468,15 @@ static void nbd_handle_req(struct nbd_device *lo, struct request *req)
468 mutex_lock(&lo->tx_lock); 468 mutex_lock(&lo->tx_lock);
469 if (unlikely(!lo->sock)) { 469 if (unlikely(!lo->sock)) {
470 mutex_unlock(&lo->tx_lock); 470 mutex_unlock(&lo->tx_lock);
471 printk(KERN_ERR "%s: Attempted send on closed socket\n", 471 dev_err(disk_to_dev(lo->disk),
472 lo->disk->disk_name); 472 "Attempted send on closed socket\n");
473 goto error_out; 473 goto error_out;
474 } 474 }
475 475
476 lo->active_req = req; 476 lo->active_req = req;
477 477
478 if (nbd_send_req(lo, req) != 0) { 478 if (nbd_send_req(lo, req) != 0) {
479 printk(KERN_ERR "%s: Request send failed\n", 479 dev_err(disk_to_dev(lo->disk), "Request send failed\n");
480 lo->disk->disk_name);
481 req->errors++; 480 req->errors++;
482 nbd_end_request(req); 481 nbd_end_request(req);
483 } else { 482 } else {
@@ -549,8 +548,8 @@ static void do_nbd_request(struct request_queue *q)
549 BUG_ON(lo->magic != LO_MAGIC); 548 BUG_ON(lo->magic != LO_MAGIC);
550 549
551 if (unlikely(!lo->sock)) { 550 if (unlikely(!lo->sock)) {
552 printk(KERN_ERR "%s: Attempted send on closed socket\n", 551 dev_err(disk_to_dev(lo->disk),
553 lo->disk->disk_name); 552 "Attempted send on closed socket\n");
554 req->errors++; 553 req->errors++;
555 nbd_end_request(req); 554 nbd_end_request(req);
556 spin_lock_irq(q->queue_lock); 555 spin_lock_irq(q->queue_lock);
@@ -576,7 +575,7 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo,
576 case NBD_DISCONNECT: { 575 case NBD_DISCONNECT: {
577 struct request sreq; 576 struct request sreq;
578 577
579 printk(KERN_INFO "%s: NBD_DISCONNECT\n", lo->disk->disk_name); 578 dev_info(disk_to_dev(lo->disk), "NBD_DISCONNECT\n");
580 579
581 blk_rq_init(NULL, &sreq); 580 blk_rq_init(NULL, &sreq);
582 sreq.cmd_type = REQ_TYPE_SPECIAL; 581 sreq.cmd_type = REQ_TYPE_SPECIAL;
@@ -674,7 +673,7 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo,
674 file = lo->file; 673 file = lo->file;
675 lo->file = NULL; 674 lo->file = NULL;
676 nbd_clear_que(lo); 675 nbd_clear_que(lo);
677 printk(KERN_WARNING "%s: queue cleared\n", lo->disk->disk_name); 676 dev_warn(disk_to_dev(lo->disk), "queue cleared\n");
678 if (file) 677 if (file)
679 fput(file); 678 fput(file);
680 lo->bytesize = 0; 679 lo->bytesize = 0;
@@ -694,8 +693,8 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *lo,
694 return 0; 693 return 0;
695 694
696 case NBD_PRINT_DEBUG: 695 case NBD_PRINT_DEBUG:
697 printk(KERN_INFO "%s: next = %p, prev = %p, head = %p\n", 696 dev_info(disk_to_dev(lo->disk),
698 bdev->bd_disk->disk_name, 697 "next = %p, prev = %p, head = %p\n",
699 lo->queue_head.next, lo->queue_head.prev, 698 lo->queue_head.next, lo->queue_head.prev,
700 &lo->queue_head); 699 &lo->queue_head);
701 return 0; 700 return 0;
@@ -745,7 +744,7 @@ static int __init nbd_init(void)
745 BUILD_BUG_ON(sizeof(struct nbd_request) != 28); 744 BUILD_BUG_ON(sizeof(struct nbd_request) != 28);
746 745
747 if (max_part < 0) { 746 if (max_part < 0) {
748 printk(KERN_CRIT "nbd: max_part must be >= 0\n"); 747 printk(KERN_ERR "nbd: max_part must be >= 0\n");
749 return -EINVAL; 748 return -EINVAL;
750 } 749 }
751 750
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index e133f094ab08..a63b0a2b7805 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -2444,7 +2444,7 @@ static void pkt_end_io_read_cloned(struct bio *bio, int err)
2444 pkt_bio_finished(pd); 2444 pkt_bio_finished(pd);
2445} 2445}
2446 2446
2447static int pkt_make_request(struct request_queue *q, struct bio *bio) 2447static void pkt_make_request(struct request_queue *q, struct bio *bio)
2448{ 2448{
2449 struct pktcdvd_device *pd; 2449 struct pktcdvd_device *pd;
2450 char b[BDEVNAME_SIZE]; 2450 char b[BDEVNAME_SIZE];
@@ -2473,7 +2473,7 @@ static int pkt_make_request(struct request_queue *q, struct bio *bio)
2473 cloned_bio->bi_end_io = pkt_end_io_read_cloned; 2473 cloned_bio->bi_end_io = pkt_end_io_read_cloned;
2474 pd->stats.secs_r += bio->bi_size >> 9; 2474 pd->stats.secs_r += bio->bi_size >> 9;
2475 pkt_queue_bio(pd, cloned_bio); 2475 pkt_queue_bio(pd, cloned_bio);
2476 return 0; 2476 return;
2477 } 2477 }
2478 2478
2479 if (!test_bit(PACKET_WRITABLE, &pd->flags)) { 2479 if (!test_bit(PACKET_WRITABLE, &pd->flags)) {
@@ -2509,7 +2509,7 @@ static int pkt_make_request(struct request_queue *q, struct bio *bio)
2509 pkt_make_request(q, &bp->bio1); 2509 pkt_make_request(q, &bp->bio1);
2510 pkt_make_request(q, &bp->bio2); 2510 pkt_make_request(q, &bp->bio2);
2511 bio_pair_release(bp); 2511 bio_pair_release(bp);
2512 return 0; 2512 return;
2513 } 2513 }
2514 } 2514 }
2515 2515
@@ -2533,7 +2533,7 @@ static int pkt_make_request(struct request_queue *q, struct bio *bio)
2533 } 2533 }
2534 spin_unlock(&pkt->lock); 2534 spin_unlock(&pkt->lock);
2535 spin_unlock(&pd->cdrw.active_list_lock); 2535 spin_unlock(&pd->cdrw.active_list_lock);
2536 return 0; 2536 return;
2537 } else { 2537 } else {
2538 blocked_bio = 1; 2538 blocked_bio = 1;
2539 } 2539 }
@@ -2584,10 +2584,9 @@ static int pkt_make_request(struct request_queue *q, struct bio *bio)
2584 */ 2584 */
2585 wake_up(&pd->wqueue); 2585 wake_up(&pd->wqueue);
2586 } 2586 }
2587 return 0; 2587 return;
2588end_io: 2588end_io:
2589 bio_io_error(bio); 2589 bio_io_error(bio);
2590 return 0;
2591} 2590}
2592 2591
2593 2592
diff --git a/drivers/block/ps3disk.c b/drivers/block/ps3disk.c
index 8e1ce2e2916a..da0abc1838c1 100644
--- a/drivers/block/ps3disk.c
+++ b/drivers/block/ps3disk.c
@@ -21,6 +21,7 @@
21#include <linux/ata.h> 21#include <linux/ata.h>
22#include <linux/blkdev.h> 22#include <linux/blkdev.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/module.h>
24 25
25#include <asm/lv1call.h> 26#include <asm/lv1call.h>
26#include <asm/ps3stor.h> 27#include <asm/ps3stor.h>
diff --git a/drivers/block/ps3vram.c b/drivers/block/ps3vram.c
index b3bdb8af89cf..f58cdcfb305f 100644
--- a/drivers/block/ps3vram.c
+++ b/drivers/block/ps3vram.c
@@ -10,6 +10,7 @@
10 10
11#include <linux/blkdev.h> 11#include <linux/blkdev.h>
12#include <linux/delay.h> 12#include <linux/delay.h>
13#include <linux/module.h>
13#include <linux/proc_fs.h> 14#include <linux/proc_fs.h>
14#include <linux/seq_file.h> 15#include <linux/seq_file.h>
15#include <linux/slab.h> 16#include <linux/slab.h>
@@ -596,7 +597,7 @@ out:
596 return next; 597 return next;
597} 598}
598 599
599static int ps3vram_make_request(struct request_queue *q, struct bio *bio) 600static void ps3vram_make_request(struct request_queue *q, struct bio *bio)
600{ 601{
601 struct ps3_system_bus_device *dev = q->queuedata; 602 struct ps3_system_bus_device *dev = q->queuedata;
602 struct ps3vram_priv *priv = ps3_system_bus_get_drvdata(dev); 603 struct ps3vram_priv *priv = ps3_system_bus_get_drvdata(dev);
@@ -610,13 +611,11 @@ static int ps3vram_make_request(struct request_queue *q, struct bio *bio)
610 spin_unlock_irq(&priv->lock); 611 spin_unlock_irq(&priv->lock);
611 612
612 if (busy) 613 if (busy)
613 return 0; 614 return;
614 615
615 do { 616 do {
616 bio = ps3vram_do_bio(dev, bio); 617 bio = ps3vram_do_bio(dev, bio);
617 } while (bio); 618 } while (bio);
618
619 return 0;
620} 619}
621 620
622static int __devinit ps3vram_probe(struct ps3_system_bus_device *dev) 621static int __devinit ps3vram_probe(struct ps3_system_bus_device *dev)
diff --git a/drivers/block/umem.c b/drivers/block/umem.c
index 031ca720d926..aa2712060bfb 100644
--- a/drivers/block/umem.c
+++ b/drivers/block/umem.c
@@ -513,7 +513,7 @@ static void process_page(unsigned long data)
513 } 513 }
514} 514}
515 515
516static int mm_make_request(struct request_queue *q, struct bio *bio) 516static void mm_make_request(struct request_queue *q, struct bio *bio)
517{ 517{
518 struct cardinfo *card = q->queuedata; 518 struct cardinfo *card = q->queuedata;
519 pr_debug("mm_make_request %llu %u\n", 519 pr_debug("mm_make_request %llu %u\n",
@@ -525,7 +525,7 @@ static int mm_make_request(struct request_queue *q, struct bio *bio)
525 card->biotail = &bio->bi_next; 525 card->biotail = &bio->bi_next;
526 spin_unlock_irq(&card->lock); 526 spin_unlock_irq(&card->lock);
527 527
528 return 0; 528 return;
529} 529}
530 530
531static irqreturn_t mm_interrupt(int irq, void *__card) 531static irqreturn_t mm_interrupt(int irq, void *__card)
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c
index 079c08808d8a..4d0b70adf5f7 100644
--- a/drivers/block/virtio_blk.c
+++ b/drivers/block/virtio_blk.c
@@ -3,15 +3,19 @@
3#include <linux/slab.h> 3#include <linux/slab.h>
4#include <linux/blkdev.h> 4#include <linux/blkdev.h>
5#include <linux/hdreg.h> 5#include <linux/hdreg.h>
6#include <linux/module.h>
6#include <linux/virtio.h> 7#include <linux/virtio.h>
7#include <linux/virtio_blk.h> 8#include <linux/virtio_blk.h>
8#include <linux/scatterlist.h> 9#include <linux/scatterlist.h>
9#include <linux/string_helpers.h> 10#include <linux/string_helpers.h>
10#include <scsi/scsi_cmnd.h> 11#include <scsi/scsi_cmnd.h>
12#include <linux/idr.h>
11 13
12#define PART_BITS 4 14#define PART_BITS 4
13 15
14static int major, index; 16static int major;
17static DEFINE_IDA(vd_index_ida);
18
15struct workqueue_struct *virtblk_wq; 19struct workqueue_struct *virtblk_wq;
16 20
17struct virtio_blk 21struct virtio_blk
@@ -35,6 +39,9 @@ struct virtio_blk
35 /* What host tells us, plus 2 for header & tailer. */ 39 /* What host tells us, plus 2 for header & tailer. */
36 unsigned int sg_elems; 40 unsigned int sg_elems;
37 41
42 /* Ida index - used to track minor number allocations. */
43 int index;
44
38 /* Scatterlist: can be too big for stack. */ 45 /* Scatterlist: can be too big for stack. */
39 struct scatterlist sg[/*sg_elems*/]; 46 struct scatterlist sg[/*sg_elems*/];
40}; 47};
@@ -276,6 +283,11 @@ static int index_to_minor(int index)
276 return index << PART_BITS; 283 return index << PART_BITS;
277} 284}
278 285
286static int minor_to_index(int minor)
287{
288 return minor >> PART_BITS;
289}
290
279static ssize_t virtblk_serial_show(struct device *dev, 291static ssize_t virtblk_serial_show(struct device *dev,
280 struct device_attribute *attr, char *buf) 292 struct device_attribute *attr, char *buf)
281{ 293{
@@ -341,14 +353,17 @@ static int __devinit virtblk_probe(struct virtio_device *vdev)
341{ 353{
342 struct virtio_blk *vblk; 354 struct virtio_blk *vblk;
343 struct request_queue *q; 355 struct request_queue *q;
344 int err; 356 int err, index;
345 u64 cap; 357 u64 cap;
346 u32 v, blk_size, sg_elems, opt_io_size; 358 u32 v, blk_size, sg_elems, opt_io_size;
347 u16 min_io_size; 359 u16 min_io_size;
348 u8 physical_block_exp, alignment_offset; 360 u8 physical_block_exp, alignment_offset;
349 361
350 if (index_to_minor(index) >= 1 << MINORBITS) 362 err = ida_simple_get(&vd_index_ida, 0, minor_to_index(1 << MINORBITS),
351 return -ENOSPC; 363 GFP_KERNEL);
364 if (err < 0)
365 goto out;
366 index = err;
352 367
353 /* We need to know how many segments before we allocate. */ 368 /* We need to know how many segments before we allocate. */
354 err = virtio_config_val(vdev, VIRTIO_BLK_F_SEG_MAX, 369 err = virtio_config_val(vdev, VIRTIO_BLK_F_SEG_MAX,
@@ -365,7 +380,7 @@ static int __devinit virtblk_probe(struct virtio_device *vdev)
365 sizeof(vblk->sg[0]) * sg_elems, GFP_KERNEL); 380 sizeof(vblk->sg[0]) * sg_elems, GFP_KERNEL);
366 if (!vblk) { 381 if (!vblk) {
367 err = -ENOMEM; 382 err = -ENOMEM;
368 goto out; 383 goto out_free_index;
369 } 384 }
370 385
371 INIT_LIST_HEAD(&vblk->reqs); 386 INIT_LIST_HEAD(&vblk->reqs);
@@ -421,7 +436,7 @@ static int __devinit virtblk_probe(struct virtio_device *vdev)
421 vblk->disk->private_data = vblk; 436 vblk->disk->private_data = vblk;
422 vblk->disk->fops = &virtblk_fops; 437 vblk->disk->fops = &virtblk_fops;
423 vblk->disk->driverfs_dev = &vdev->dev; 438 vblk->disk->driverfs_dev = &vdev->dev;
424 index++; 439 vblk->index = index;
425 440
426 /* configure queue flush support */ 441 /* configure queue flush support */
427 if (virtio_has_feature(vdev, VIRTIO_BLK_F_FLUSH)) 442 if (virtio_has_feature(vdev, VIRTIO_BLK_F_FLUSH))
@@ -516,6 +531,8 @@ out_free_vq:
516 vdev->config->del_vqs(vdev); 531 vdev->config->del_vqs(vdev);
517out_free_vblk: 532out_free_vblk:
518 kfree(vblk); 533 kfree(vblk);
534out_free_index:
535 ida_simple_remove(&vd_index_ida, index);
519out: 536out:
520 return err; 537 return err;
521} 538}
@@ -523,6 +540,7 @@ out:
523static void __devexit virtblk_remove(struct virtio_device *vdev) 540static void __devexit virtblk_remove(struct virtio_device *vdev)
524{ 541{
525 struct virtio_blk *vblk = vdev->priv; 542 struct virtio_blk *vblk = vdev->priv;
543 int index = vblk->index;
526 544
527 flush_work(&vblk->config_work); 545 flush_work(&vblk->config_work);
528 546
@@ -538,6 +556,7 @@ static void __devexit virtblk_remove(struct virtio_device *vdev)
538 mempool_destroy(vblk->pool); 556 mempool_destroy(vblk->pool);
539 vdev->config->del_vqs(vdev); 557 vdev->config->del_vqs(vdev);
540 kfree(vblk); 558 kfree(vblk);
559 ida_simple_remove(&vd_index_ida, index);
541} 560}
542 561
543static const struct virtio_device_id id_table[] = { 562static const struct virtio_device_id id_table[] = {
diff --git a/drivers/block/xen-blkback/blkback.c b/drivers/block/xen-blkback/blkback.c
index 1540792b1e54..15ec4db194d1 100644
--- a/drivers/block/xen-blkback/blkback.c
+++ b/drivers/block/xen-blkback/blkback.c
@@ -39,6 +39,9 @@
39#include <linux/list.h> 39#include <linux/list.h>
40#include <linux/delay.h> 40#include <linux/delay.h>
41#include <linux/freezer.h> 41#include <linux/freezer.h>
42#include <linux/loop.h>
43#include <linux/falloc.h>
44#include <linux/fs.h>
42 45
43#include <xen/events.h> 46#include <xen/events.h>
44#include <xen/page.h> 47#include <xen/page.h>
@@ -258,13 +261,16 @@ irqreturn_t xen_blkif_be_int(int irq, void *dev_id)
258 261
259static void print_stats(struct xen_blkif *blkif) 262static void print_stats(struct xen_blkif *blkif)
260{ 263{
261 pr_info("xen-blkback (%s): oo %3d | rd %4d | wr %4d | f %4d\n", 264 pr_info("xen-blkback (%s): oo %3d | rd %4d | wr %4d | f %4d"
265 " | ds %4d\n",
262 current->comm, blkif->st_oo_req, 266 current->comm, blkif->st_oo_req,
263 blkif->st_rd_req, blkif->st_wr_req, blkif->st_f_req); 267 blkif->st_rd_req, blkif->st_wr_req,
268 blkif->st_f_req, blkif->st_ds_req);
264 blkif->st_print = jiffies + msecs_to_jiffies(10 * 1000); 269 blkif->st_print = jiffies + msecs_to_jiffies(10 * 1000);
265 blkif->st_rd_req = 0; 270 blkif->st_rd_req = 0;
266 blkif->st_wr_req = 0; 271 blkif->st_wr_req = 0;
267 blkif->st_oo_req = 0; 272 blkif->st_oo_req = 0;
273 blkif->st_ds_req = 0;
268} 274}
269 275
270int xen_blkif_schedule(void *arg) 276int xen_blkif_schedule(void *arg)
@@ -410,6 +416,59 @@ static int xen_blkbk_map(struct blkif_request *req,
410 return ret; 416 return ret;
411} 417}
412 418
419static void xen_blk_discard(struct xen_blkif *blkif, struct blkif_request *req)
420{
421 int err = 0;
422 int status = BLKIF_RSP_OKAY;
423 struct block_device *bdev = blkif->vbd.bdev;
424
425 if (blkif->blk_backend_type == BLKIF_BACKEND_PHY)
426 /* just forward the discard request */
427 err = blkdev_issue_discard(bdev,
428 req->u.discard.sector_number,
429 req->u.discard.nr_sectors,
430 GFP_KERNEL, 0);
431 else if (blkif->blk_backend_type == BLKIF_BACKEND_FILE) {
432 /* punch a hole in the backing file */
433 struct loop_device *lo = bdev->bd_disk->private_data;
434 struct file *file = lo->lo_backing_file;
435
436 if (file->f_op->fallocate)
437 err = file->f_op->fallocate(file,
438 FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE,
439 req->u.discard.sector_number << 9,
440 req->u.discard.nr_sectors << 9);
441 else
442 err = -EOPNOTSUPP;
443 } else
444 err = -EOPNOTSUPP;
445
446 if (err == -EOPNOTSUPP) {
447 pr_debug(DRV_PFX "discard op failed, not supported\n");
448 status = BLKIF_RSP_EOPNOTSUPP;
449 } else if (err)
450 status = BLKIF_RSP_ERROR;
451
452 make_response(blkif, req->id, req->operation, status);
453}
454
455static void xen_blk_drain_io(struct xen_blkif *blkif)
456{
457 atomic_set(&blkif->drain, 1);
458 do {
459 /* The initial value is one, and one refcnt taken at the
460 * start of the xen_blkif_schedule thread. */
461 if (atomic_read(&blkif->refcnt) <= 2)
462 break;
463 wait_for_completion_interruptible_timeout(
464 &blkif->drain_complete, HZ);
465
466 if (!atomic_read(&blkif->drain))
467 break;
468 } while (!kthread_should_stop());
469 atomic_set(&blkif->drain, 0);
470}
471
413/* 472/*
414 * Completion callback on the bio's. Called as bh->b_end_io() 473 * Completion callback on the bio's. Called as bh->b_end_io()
415 */ 474 */
@@ -422,6 +481,11 @@ static void __end_block_io_op(struct pending_req *pending_req, int error)
422 pr_debug(DRV_PFX "flush diskcache op failed, not supported\n"); 481 pr_debug(DRV_PFX "flush diskcache op failed, not supported\n");
423 xen_blkbk_flush_diskcache(XBT_NIL, pending_req->blkif->be, 0); 482 xen_blkbk_flush_diskcache(XBT_NIL, pending_req->blkif->be, 0);
424 pending_req->status = BLKIF_RSP_EOPNOTSUPP; 483 pending_req->status = BLKIF_RSP_EOPNOTSUPP;
484 } else if ((pending_req->operation == BLKIF_OP_WRITE_BARRIER) &&
485 (error == -EOPNOTSUPP)) {
486 pr_debug(DRV_PFX "write barrier op failed, not supported\n");
487 xen_blkbk_barrier(XBT_NIL, pending_req->blkif->be, 0);
488 pending_req->status = BLKIF_RSP_EOPNOTSUPP;
425 } else if (error) { 489 } else if (error) {
426 pr_debug(DRV_PFX "Buffer not up-to-date at end of operation," 490 pr_debug(DRV_PFX "Buffer not up-to-date at end of operation,"
427 " error=%d\n", error); 491 " error=%d\n", error);
@@ -438,6 +502,10 @@ static void __end_block_io_op(struct pending_req *pending_req, int error)
438 make_response(pending_req->blkif, pending_req->id, 502 make_response(pending_req->blkif, pending_req->id,
439 pending_req->operation, pending_req->status); 503 pending_req->operation, pending_req->status);
440 xen_blkif_put(pending_req->blkif); 504 xen_blkif_put(pending_req->blkif);
505 if (atomic_read(&pending_req->blkif->refcnt) <= 2) {
506 if (atomic_read(&pending_req->blkif->drain))
507 complete(&pending_req->blkif->drain_complete);
508 }
441 free_req(pending_req); 509 free_req(pending_req);
442 } 510 }
443} 511}
@@ -532,7 +600,6 @@ do_block_io_op(struct xen_blkif *blkif)
532 600
533 return more_to_do; 601 return more_to_do;
534} 602}
535
536/* 603/*
537 * Transmutation of the 'struct blkif_request' to a proper 'struct bio' 604 * Transmutation of the 'struct blkif_request' to a proper 'struct bio'
538 * and call the 'submit_bio' to pass it to the underlying storage. 605 * and call the 'submit_bio' to pass it to the underlying storage.
@@ -549,6 +616,7 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif,
549 int i, nbio = 0; 616 int i, nbio = 0;
550 int operation; 617 int operation;
551 struct blk_plug plug; 618 struct blk_plug plug;
619 bool drain = false;
552 620
553 switch (req->operation) { 621 switch (req->operation) {
554 case BLKIF_OP_READ: 622 case BLKIF_OP_READ:
@@ -559,11 +627,16 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif,
559 blkif->st_wr_req++; 627 blkif->st_wr_req++;
560 operation = WRITE_ODIRECT; 628 operation = WRITE_ODIRECT;
561 break; 629 break;
630 case BLKIF_OP_WRITE_BARRIER:
631 drain = true;
562 case BLKIF_OP_FLUSH_DISKCACHE: 632 case BLKIF_OP_FLUSH_DISKCACHE:
563 blkif->st_f_req++; 633 blkif->st_f_req++;
564 operation = WRITE_FLUSH; 634 operation = WRITE_FLUSH;
565 break; 635 break;
566 case BLKIF_OP_WRITE_BARRIER: 636 case BLKIF_OP_DISCARD:
637 blkif->st_ds_req++;
638 operation = REQ_DISCARD;
639 break;
567 default: 640 default:
568 operation = 0; /* make gcc happy */ 641 operation = 0; /* make gcc happy */
569 goto fail_response; 642 goto fail_response;
@@ -572,7 +645,8 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif,
572 645
573 /* Check that the number of segments is sane. */ 646 /* Check that the number of segments is sane. */
574 nseg = req->nr_segments; 647 nseg = req->nr_segments;
575 if (unlikely(nseg == 0 && operation != WRITE_FLUSH) || 648 if (unlikely(nseg == 0 && operation != WRITE_FLUSH &&
649 operation != REQ_DISCARD) ||
576 unlikely(nseg > BLKIF_MAX_SEGMENTS_PER_REQUEST)) { 650 unlikely(nseg > BLKIF_MAX_SEGMENTS_PER_REQUEST)) {
577 pr_debug(DRV_PFX "Bad number of segments in request (%d)\n", 651 pr_debug(DRV_PFX "Bad number of segments in request (%d)\n",
578 nseg); 652 nseg);
@@ -621,16 +695,25 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif,
621 } 695 }
622 } 696 }
623 697
698 /* Wait on all outstanding I/O's and once that has been completed
699 * issue the WRITE_FLUSH.
700 */
701 if (drain)
702 xen_blk_drain_io(pending_req->blkif);
703
624 /* 704 /*
625 * If we have failed at this point, we need to undo the M2P override, 705 * If we have failed at this point, we need to undo the M2P override,
626 * set gnttab_set_unmap_op on all of the grant references and perform 706 * set gnttab_set_unmap_op on all of the grant references and perform
627 * the hypercall to unmap the grants - that is all done in 707 * the hypercall to unmap the grants - that is all done in
628 * xen_blkbk_unmap. 708 * xen_blkbk_unmap.
629 */ 709 */
630 if (xen_blkbk_map(req, pending_req, seg)) 710 if (operation != REQ_DISCARD && xen_blkbk_map(req, pending_req, seg))
631 goto fail_flush; 711 goto fail_flush;
632 712
633 /* This corresponding xen_blkif_put is done in __end_block_io_op */ 713 /*
714 * This corresponding xen_blkif_put is done in __end_block_io_op, or
715 * below (in "!bio") if we are handling a BLKIF_OP_DISCARD.
716 */
634 xen_blkif_get(blkif); 717 xen_blkif_get(blkif);
635 718
636 for (i = 0; i < nseg; i++) { 719 for (i = 0; i < nseg; i++) {
@@ -654,18 +737,25 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif,
654 preq.sector_number += seg[i].nsec; 737 preq.sector_number += seg[i].nsec;
655 } 738 }
656 739
657 /* This will be hit if the operation was a flush. */ 740 /* This will be hit if the operation was a flush or discard. */
658 if (!bio) { 741 if (!bio) {
659 BUG_ON(operation != WRITE_FLUSH); 742 BUG_ON(operation != WRITE_FLUSH && operation != REQ_DISCARD);
660 743
661 bio = bio_alloc(GFP_KERNEL, 0); 744 if (operation == WRITE_FLUSH) {
662 if (unlikely(bio == NULL)) 745 bio = bio_alloc(GFP_KERNEL, 0);
663 goto fail_put_bio; 746 if (unlikely(bio == NULL))
747 goto fail_put_bio;
664 748
665 biolist[nbio++] = bio; 749 biolist[nbio++] = bio;
666 bio->bi_bdev = preq.bdev; 750 bio->bi_bdev = preq.bdev;
667 bio->bi_private = pending_req; 751 bio->bi_private = pending_req;
668 bio->bi_end_io = end_block_io_op; 752 bio->bi_end_io = end_block_io_op;
753 } else if (operation == REQ_DISCARD) {
754 xen_blk_discard(blkif, req);
755 xen_blkif_put(blkif);
756 free_req(pending_req);
757 return 0;
758 }
669 } 759 }
670 760
671 /* 761 /*
@@ -685,7 +775,7 @@ static int dispatch_rw_block_io(struct xen_blkif *blkif,
685 775
686 if (operation == READ) 776 if (operation == READ)
687 blkif->st_rd_sect += preq.nr_sects; 777 blkif->st_rd_sect += preq.nr_sects;
688 else if (operation == WRITE || operation == WRITE_FLUSH) 778 else if (operation & WRITE)
689 blkif->st_wr_sect += preq.nr_sects; 779 blkif->st_wr_sect += preq.nr_sects;
690 780
691 return 0; 781 return 0;
@@ -765,9 +855,9 @@ static int __init xen_blkif_init(void)
765 855
766 mmap_pages = xen_blkif_reqs * BLKIF_MAX_SEGMENTS_PER_REQUEST; 856 mmap_pages = xen_blkif_reqs * BLKIF_MAX_SEGMENTS_PER_REQUEST;
767 857
768 blkbk->pending_reqs = kmalloc(sizeof(blkbk->pending_reqs[0]) * 858 blkbk->pending_reqs = kzalloc(sizeof(blkbk->pending_reqs[0]) *
769 xen_blkif_reqs, GFP_KERNEL); 859 xen_blkif_reqs, GFP_KERNEL);
770 blkbk->pending_grant_handles = kzalloc(sizeof(blkbk->pending_grant_handles[0]) * 860 blkbk->pending_grant_handles = kmalloc(sizeof(blkbk->pending_grant_handles[0]) *
771 mmap_pages, GFP_KERNEL); 861 mmap_pages, GFP_KERNEL);
772 blkbk->pending_pages = kzalloc(sizeof(blkbk->pending_pages[0]) * 862 blkbk->pending_pages = kzalloc(sizeof(blkbk->pending_pages[0]) *
773 mmap_pages, GFP_KERNEL); 863 mmap_pages, GFP_KERNEL);
@@ -790,8 +880,6 @@ static int __init xen_blkif_init(void)
790 if (rc) 880 if (rc)
791 goto failed_init; 881 goto failed_init;
792 882
793 memset(blkbk->pending_reqs, 0, sizeof(blkbk->pending_reqs));
794
795 INIT_LIST_HEAD(&blkbk->pending_free); 883 INIT_LIST_HEAD(&blkbk->pending_free);
796 spin_lock_init(&blkbk->pending_free_lock); 884 spin_lock_init(&blkbk->pending_free_lock);
797 init_waitqueue_head(&blkbk->pending_free_wq); 885 init_waitqueue_head(&blkbk->pending_free_wq);
diff --git a/drivers/block/xen-blkback/common.h b/drivers/block/xen-blkback/common.h
index c4bd34063ecc..dfb1b3a43a5d 100644
--- a/drivers/block/xen-blkback/common.h
+++ b/drivers/block/xen-blkback/common.h
@@ -62,13 +62,26 @@ struct blkif_common_response {
62 62
63/* i386 protocol version */ 63/* i386 protocol version */
64#pragma pack(push, 4) 64#pragma pack(push, 4)
65
66struct blkif_x86_32_request_rw {
67 blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */
68 struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
69};
70
71struct blkif_x86_32_request_discard {
72 blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */
73 uint64_t nr_sectors;
74};
75
65struct blkif_x86_32_request { 76struct blkif_x86_32_request {
66 uint8_t operation; /* BLKIF_OP_??? */ 77 uint8_t operation; /* BLKIF_OP_??? */
67 uint8_t nr_segments; /* number of segments */ 78 uint8_t nr_segments; /* number of segments */
68 blkif_vdev_t handle; /* only for read/write requests */ 79 blkif_vdev_t handle; /* only for read/write requests */
69 uint64_t id; /* private guest value, echoed in resp */ 80 uint64_t id; /* private guest value, echoed in resp */
70 blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */ 81 union {
71 struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST]; 82 struct blkif_x86_32_request_rw rw;
83 struct blkif_x86_32_request_discard discard;
84 } u;
72}; 85};
73struct blkif_x86_32_response { 86struct blkif_x86_32_response {
74 uint64_t id; /* copied from request */ 87 uint64_t id; /* copied from request */
@@ -78,13 +91,26 @@ struct blkif_x86_32_response {
78#pragma pack(pop) 91#pragma pack(pop)
79 92
80/* x86_64 protocol version */ 93/* x86_64 protocol version */
94
95struct blkif_x86_64_request_rw {
96 blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */
97 struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST];
98};
99
100struct blkif_x86_64_request_discard {
101 blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */
102 uint64_t nr_sectors;
103};
104
81struct blkif_x86_64_request { 105struct blkif_x86_64_request {
82 uint8_t operation; /* BLKIF_OP_??? */ 106 uint8_t operation; /* BLKIF_OP_??? */
83 uint8_t nr_segments; /* number of segments */ 107 uint8_t nr_segments; /* number of segments */
84 blkif_vdev_t handle; /* only for read/write requests */ 108 blkif_vdev_t handle; /* only for read/write requests */
85 uint64_t __attribute__((__aligned__(8))) id; 109 uint64_t __attribute__((__aligned__(8))) id;
86 blkif_sector_t sector_number;/* start sector idx on disk (r/w only) */ 110 union {
87 struct blkif_request_segment seg[BLKIF_MAX_SEGMENTS_PER_REQUEST]; 111 struct blkif_x86_64_request_rw rw;
112 struct blkif_x86_64_request_discard discard;
113 } u;
88}; 114};
89struct blkif_x86_64_response { 115struct blkif_x86_64_response {
90 uint64_t __attribute__((__aligned__(8))) id; 116 uint64_t __attribute__((__aligned__(8))) id;
@@ -112,6 +138,11 @@ enum blkif_protocol {
112 BLKIF_PROTOCOL_X86_64 = 3, 138 BLKIF_PROTOCOL_X86_64 = 3,
113}; 139};
114 140
141enum blkif_backend_type {
142 BLKIF_BACKEND_PHY = 1,
143 BLKIF_BACKEND_FILE = 2,
144};
145
115struct xen_vbd { 146struct xen_vbd {
116 /* What the domain refers to this vbd as. */ 147 /* What the domain refers to this vbd as. */
117 blkif_vdev_t handle; 148 blkif_vdev_t handle;
@@ -137,8 +168,9 @@ struct xen_blkif {
137 unsigned int irq; 168 unsigned int irq;
138 /* Comms information. */ 169 /* Comms information. */
139 enum blkif_protocol blk_protocol; 170 enum blkif_protocol blk_protocol;
171 enum blkif_backend_type blk_backend_type;
140 union blkif_back_rings blk_rings; 172 union blkif_back_rings blk_rings;
141 struct vm_struct *blk_ring_area; 173 void *blk_ring;
142 /* The VBD attached to this interface. */ 174 /* The VBD attached to this interface. */
143 struct xen_vbd vbd; 175 struct xen_vbd vbd;
144 /* Back pointer to the backend_info. */ 176 /* Back pointer to the backend_info. */
@@ -148,6 +180,9 @@ struct xen_blkif {
148 atomic_t refcnt; 180 atomic_t refcnt;
149 181
150 wait_queue_head_t wq; 182 wait_queue_head_t wq;
183 /* for barrier (drain) requests */
184 struct completion drain_complete;
185 atomic_t drain;
151 /* One thread per one blkif. */ 186 /* One thread per one blkif. */
152 struct task_struct *xenblkd; 187 struct task_struct *xenblkd;
153 unsigned int waiting_reqs; 188 unsigned int waiting_reqs;
@@ -158,13 +193,11 @@ struct xen_blkif {
158 int st_wr_req; 193 int st_wr_req;
159 int st_oo_req; 194 int st_oo_req;
160 int st_f_req; 195 int st_f_req;
196 int st_ds_req;
161 int st_rd_sect; 197 int st_rd_sect;
162 int st_wr_sect; 198 int st_wr_sect;
163 199
164 wait_queue_head_t waiting_to_free; 200 wait_queue_head_t waiting_to_free;
165
166 grant_handle_t shmem_handle;
167 grant_ref_t shmem_ref;
168}; 201};
169 202
170 203
@@ -181,7 +214,7 @@ struct xen_blkif {
181 214
182struct phys_req { 215struct phys_req {
183 unsigned short dev; 216 unsigned short dev;
184 unsigned short nr_sects; 217 blkif_sector_t nr_sects;
185 struct block_device *bdev; 218 struct block_device *bdev;
186 blkif_sector_t sector_number; 219 blkif_sector_t sector_number;
187}; 220};
@@ -195,6 +228,8 @@ int xen_blkif_schedule(void *arg);
195int xen_blkbk_flush_diskcache(struct xenbus_transaction xbt, 228int xen_blkbk_flush_diskcache(struct xenbus_transaction xbt,
196 struct backend_info *be, int state); 229 struct backend_info *be, int state);
197 230
231int xen_blkbk_barrier(struct xenbus_transaction xbt,
232 struct backend_info *be, int state);
198struct xenbus_device *xen_blkbk_xenbus(struct backend_info *be); 233struct xenbus_device *xen_blkbk_xenbus(struct backend_info *be);
199 234
200static inline void blkif_get_x86_32_req(struct blkif_request *dst, 235static inline void blkif_get_x86_32_req(struct blkif_request *dst,
@@ -205,12 +240,25 @@ static inline void blkif_get_x86_32_req(struct blkif_request *dst,
205 dst->nr_segments = src->nr_segments; 240 dst->nr_segments = src->nr_segments;
206 dst->handle = src->handle; 241 dst->handle = src->handle;
207 dst->id = src->id; 242 dst->id = src->id;
208 dst->u.rw.sector_number = src->sector_number; 243 switch (src->operation) {
209 barrier(); 244 case BLKIF_OP_READ:
210 if (n > dst->nr_segments) 245 case BLKIF_OP_WRITE:
211 n = dst->nr_segments; 246 case BLKIF_OP_WRITE_BARRIER:
212 for (i = 0; i < n; i++) 247 case BLKIF_OP_FLUSH_DISKCACHE:
213 dst->u.rw.seg[i] = src->seg[i]; 248 dst->u.rw.sector_number = src->u.rw.sector_number;
249 barrier();
250 if (n > dst->nr_segments)
251 n = dst->nr_segments;
252 for (i = 0; i < n; i++)
253 dst->u.rw.seg[i] = src->u.rw.seg[i];
254 break;
255 case BLKIF_OP_DISCARD:
256 dst->u.discard.sector_number = src->u.discard.sector_number;
257 dst->u.discard.nr_sectors = src->u.discard.nr_sectors;
258 break;
259 default:
260 break;
261 }
214} 262}
215 263
216static inline void blkif_get_x86_64_req(struct blkif_request *dst, 264static inline void blkif_get_x86_64_req(struct blkif_request *dst,
@@ -221,12 +269,25 @@ static inline void blkif_get_x86_64_req(struct blkif_request *dst,
221 dst->nr_segments = src->nr_segments; 269 dst->nr_segments = src->nr_segments;
222 dst->handle = src->handle; 270 dst->handle = src->handle;
223 dst->id = src->id; 271 dst->id = src->id;
224 dst->u.rw.sector_number = src->sector_number; 272 switch (src->operation) {
225 barrier(); 273 case BLKIF_OP_READ:
226 if (n > dst->nr_segments) 274 case BLKIF_OP_WRITE:
227 n = dst->nr_segments; 275 case BLKIF_OP_WRITE_BARRIER:
228 for (i = 0; i < n; i++) 276 case BLKIF_OP_FLUSH_DISKCACHE:
229 dst->u.rw.seg[i] = src->seg[i]; 277 dst->u.rw.sector_number = src->u.rw.sector_number;
278 barrier();
279 if (n > dst->nr_segments)
280 n = dst->nr_segments;
281 for (i = 0; i < n; i++)
282 dst->u.rw.seg[i] = src->u.rw.seg[i];
283 break;
284 case BLKIF_OP_DISCARD:
285 dst->u.discard.sector_number = src->u.discard.sector_number;
286 dst->u.discard.nr_sectors = src->u.discard.nr_sectors;
287 break;
288 default:
289 break;
290 }
230} 291}
231 292
232#endif /* __XEN_BLKIF__BACKEND__COMMON_H__ */ 293#endif /* __XEN_BLKIF__BACKEND__COMMON_H__ */
diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c
index 5fd2010f7d2b..f759ad4584c3 100644
--- a/drivers/block/xen-blkback/xenbus.c
+++ b/drivers/block/xen-blkback/xenbus.c
@@ -114,44 +114,14 @@ static struct xen_blkif *xen_blkif_alloc(domid_t domid)
114 spin_lock_init(&blkif->blk_ring_lock); 114 spin_lock_init(&blkif->blk_ring_lock);
115 atomic_set(&blkif->refcnt, 1); 115 atomic_set(&blkif->refcnt, 1);
116 init_waitqueue_head(&blkif->wq); 116 init_waitqueue_head(&blkif->wq);
117 init_completion(&blkif->drain_complete);
118 atomic_set(&blkif->drain, 0);
117 blkif->st_print = jiffies; 119 blkif->st_print = jiffies;
118 init_waitqueue_head(&blkif->waiting_to_free); 120 init_waitqueue_head(&blkif->waiting_to_free);
119 121
120 return blkif; 122 return blkif;
121} 123}
122 124
123static int map_frontend_page(struct xen_blkif *blkif, unsigned long shared_page)
124{
125 struct gnttab_map_grant_ref op;
126
127 gnttab_set_map_op(&op, (unsigned long)blkif->blk_ring_area->addr,
128 GNTMAP_host_map, shared_page, blkif->domid);
129
130 if (HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1))
131 BUG();
132
133 if (op.status) {
134 DPRINTK("Grant table operation failure !\n");
135 return op.status;
136 }
137
138 blkif->shmem_ref = shared_page;
139 blkif->shmem_handle = op.handle;
140
141 return 0;
142}
143
144static void unmap_frontend_page(struct xen_blkif *blkif)
145{
146 struct gnttab_unmap_grant_ref op;
147
148 gnttab_set_unmap_op(&op, (unsigned long)blkif->blk_ring_area->addr,
149 GNTMAP_host_map, blkif->shmem_handle);
150
151 if (HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1))
152 BUG();
153}
154
155static int xen_blkif_map(struct xen_blkif *blkif, unsigned long shared_page, 125static int xen_blkif_map(struct xen_blkif *blkif, unsigned long shared_page,
156 unsigned int evtchn) 126 unsigned int evtchn)
157{ 127{
@@ -161,35 +131,29 @@ static int xen_blkif_map(struct xen_blkif *blkif, unsigned long shared_page,
161 if (blkif->irq) 131 if (blkif->irq)
162 return 0; 132 return 0;
163 133
164 blkif->blk_ring_area = alloc_vm_area(PAGE_SIZE); 134 err = xenbus_map_ring_valloc(blkif->be->dev, shared_page, &blkif->blk_ring);
165 if (!blkif->blk_ring_area) 135 if (err < 0)
166 return -ENOMEM;
167
168 err = map_frontend_page(blkif, shared_page);
169 if (err) {
170 free_vm_area(blkif->blk_ring_area);
171 return err; 136 return err;
172 }
173 137
174 switch (blkif->blk_protocol) { 138 switch (blkif->blk_protocol) {
175 case BLKIF_PROTOCOL_NATIVE: 139 case BLKIF_PROTOCOL_NATIVE:
176 { 140 {
177 struct blkif_sring *sring; 141 struct blkif_sring *sring;
178 sring = (struct blkif_sring *)blkif->blk_ring_area->addr; 142 sring = (struct blkif_sring *)blkif->blk_ring;
179 BACK_RING_INIT(&blkif->blk_rings.native, sring, PAGE_SIZE); 143 BACK_RING_INIT(&blkif->blk_rings.native, sring, PAGE_SIZE);
180 break; 144 break;
181 } 145 }
182 case BLKIF_PROTOCOL_X86_32: 146 case BLKIF_PROTOCOL_X86_32:
183 { 147 {
184 struct blkif_x86_32_sring *sring_x86_32; 148 struct blkif_x86_32_sring *sring_x86_32;
185 sring_x86_32 = (struct blkif_x86_32_sring *)blkif->blk_ring_area->addr; 149 sring_x86_32 = (struct blkif_x86_32_sring *)blkif->blk_ring;
186 BACK_RING_INIT(&blkif->blk_rings.x86_32, sring_x86_32, PAGE_SIZE); 150 BACK_RING_INIT(&blkif->blk_rings.x86_32, sring_x86_32, PAGE_SIZE);
187 break; 151 break;
188 } 152 }
189 case BLKIF_PROTOCOL_X86_64: 153 case BLKIF_PROTOCOL_X86_64:
190 { 154 {
191 struct blkif_x86_64_sring *sring_x86_64; 155 struct blkif_x86_64_sring *sring_x86_64;
192 sring_x86_64 = (struct blkif_x86_64_sring *)blkif->blk_ring_area->addr; 156 sring_x86_64 = (struct blkif_x86_64_sring *)blkif->blk_ring;
193 BACK_RING_INIT(&blkif->blk_rings.x86_64, sring_x86_64, PAGE_SIZE); 157 BACK_RING_INIT(&blkif->blk_rings.x86_64, sring_x86_64, PAGE_SIZE);
194 break; 158 break;
195 } 159 }
@@ -201,8 +165,7 @@ static int xen_blkif_map(struct xen_blkif *blkif, unsigned long shared_page,
201 xen_blkif_be_int, 0, 165 xen_blkif_be_int, 0,
202 "blkif-backend", blkif); 166 "blkif-backend", blkif);
203 if (err < 0) { 167 if (err < 0) {
204 unmap_frontend_page(blkif); 168 xenbus_unmap_ring_vfree(blkif->be->dev, blkif->blk_ring);
205 free_vm_area(blkif->blk_ring_area);
206 blkif->blk_rings.common.sring = NULL; 169 blkif->blk_rings.common.sring = NULL;
207 return err; 170 return err;
208 } 171 }
@@ -228,8 +191,7 @@ static void xen_blkif_disconnect(struct xen_blkif *blkif)
228 } 191 }
229 192
230 if (blkif->blk_rings.common.sring) { 193 if (blkif->blk_rings.common.sring) {
231 unmap_frontend_page(blkif); 194 xenbus_unmap_ring_vfree(blkif->be->dev, blkif->blk_ring);
232 free_vm_area(blkif->blk_ring_area);
233 blkif->blk_rings.common.sring = NULL; 195 blkif->blk_rings.common.sring = NULL;
234 } 196 }
235} 197}
@@ -272,6 +234,7 @@ VBD_SHOW(oo_req, "%d\n", be->blkif->st_oo_req);
272VBD_SHOW(rd_req, "%d\n", be->blkif->st_rd_req); 234VBD_SHOW(rd_req, "%d\n", be->blkif->st_rd_req);
273VBD_SHOW(wr_req, "%d\n", be->blkif->st_wr_req); 235VBD_SHOW(wr_req, "%d\n", be->blkif->st_wr_req);
274VBD_SHOW(f_req, "%d\n", be->blkif->st_f_req); 236VBD_SHOW(f_req, "%d\n", be->blkif->st_f_req);
237VBD_SHOW(ds_req, "%d\n", be->blkif->st_ds_req);
275VBD_SHOW(rd_sect, "%d\n", be->blkif->st_rd_sect); 238VBD_SHOW(rd_sect, "%d\n", be->blkif->st_rd_sect);
276VBD_SHOW(wr_sect, "%d\n", be->blkif->st_wr_sect); 239VBD_SHOW(wr_sect, "%d\n", be->blkif->st_wr_sect);
277 240
@@ -280,6 +243,7 @@ static struct attribute *xen_vbdstat_attrs[] = {
280 &dev_attr_rd_req.attr, 243 &dev_attr_rd_req.attr,
281 &dev_attr_wr_req.attr, 244 &dev_attr_wr_req.attr,
282 &dev_attr_f_req.attr, 245 &dev_attr_f_req.attr,
246 &dev_attr_ds_req.attr,
283 &dev_attr_rd_sect.attr, 247 &dev_attr_rd_sect.attr,
284 &dev_attr_wr_sect.attr, 248 &dev_attr_wr_sect.attr,
285 NULL 249 NULL
@@ -419,6 +383,73 @@ int xen_blkbk_flush_diskcache(struct xenbus_transaction xbt,
419 return err; 383 return err;
420} 384}
421 385
386int xen_blkbk_discard(struct xenbus_transaction xbt, struct backend_info *be)
387{
388 struct xenbus_device *dev = be->dev;
389 struct xen_blkif *blkif = be->blkif;
390 char *type;
391 int err;
392 int state = 0;
393
394 type = xenbus_read(XBT_NIL, dev->nodename, "type", NULL);
395 if (!IS_ERR(type)) {
396 if (strncmp(type, "file", 4) == 0) {
397 state = 1;
398 blkif->blk_backend_type = BLKIF_BACKEND_FILE;
399 }
400 if (strncmp(type, "phy", 3) == 0) {
401 struct block_device *bdev = be->blkif->vbd.bdev;
402 struct request_queue *q = bdev_get_queue(bdev);
403 if (blk_queue_discard(q)) {
404 err = xenbus_printf(xbt, dev->nodename,
405 "discard-granularity", "%u",
406 q->limits.discard_granularity);
407 if (err) {
408 xenbus_dev_fatal(dev, err,
409 "writing discard-granularity");
410 goto kfree;
411 }
412 err = xenbus_printf(xbt, dev->nodename,
413 "discard-alignment", "%u",
414 q->limits.discard_alignment);
415 if (err) {
416 xenbus_dev_fatal(dev, err,
417 "writing discard-alignment");
418 goto kfree;
419 }
420 state = 1;
421 blkif->blk_backend_type = BLKIF_BACKEND_PHY;
422 }
423 }
424 } else {
425 err = PTR_ERR(type);
426 xenbus_dev_fatal(dev, err, "reading type");
427 goto out;
428 }
429
430 err = xenbus_printf(xbt, dev->nodename, "feature-discard",
431 "%d", state);
432 if (err)
433 xenbus_dev_fatal(dev, err, "writing feature-discard");
434kfree:
435 kfree(type);
436out:
437 return err;
438}
439int xen_blkbk_barrier(struct xenbus_transaction xbt,
440 struct backend_info *be, int state)
441{
442 struct xenbus_device *dev = be->dev;
443 int err;
444
445 err = xenbus_printf(xbt, dev->nodename, "feature-barrier",
446 "%d", state);
447 if (err)
448 xenbus_dev_fatal(dev, err, "writing feature-barrier");
449
450 return err;
451}
452
422/* 453/*
423 * Entry point to this code when a new device is created. Allocate the basic 454 * Entry point to this code when a new device is created. Allocate the basic
424 * structures, and watch the store waiting for the hotplug scripts to tell us 455 * structures, and watch the store waiting for the hotplug scripts to tell us
@@ -650,6 +681,11 @@ again:
650 if (err) 681 if (err)
651 goto abort; 682 goto abort;
652 683
684 err = xen_blkbk_discard(xbt, be);
685
686 /* If we can't advertise it is OK. */
687 err = xen_blkbk_barrier(xbt, be, be->blkif->vbd.flush_support);
688
653 err = xenbus_printf(xbt, dev->nodename, "sectors", "%llu", 689 err = xenbus_printf(xbt, dev->nodename, "sectors", "%llu",
654 (unsigned long long)vbd_sz(&be->blkif->vbd)); 690 (unsigned long long)vbd_sz(&be->blkif->vbd));
655 if (err) { 691 if (err) {
diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index 9ea8c2576c70..7b2ec5908413 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -98,6 +98,9 @@ struct blkfront_info
98 unsigned long shadow_free; 98 unsigned long shadow_free;
99 unsigned int feature_flush; 99 unsigned int feature_flush;
100 unsigned int flush_op; 100 unsigned int flush_op;
101 unsigned int feature_discard;
102 unsigned int discard_granularity;
103 unsigned int discard_alignment;
101 int is_ready; 104 int is_ready;
102}; 105};
103 106
@@ -302,29 +305,36 @@ static int blkif_queue_request(struct request *req)
302 ring_req->operation = info->flush_op; 305 ring_req->operation = info->flush_op;
303 } 306 }
304 307
305 ring_req->nr_segments = blk_rq_map_sg(req->q, req, info->sg); 308 if (unlikely(req->cmd_flags & REQ_DISCARD)) {
306 BUG_ON(ring_req->nr_segments > BLKIF_MAX_SEGMENTS_PER_REQUEST); 309 /* id, sector_number and handle are set above. */
310 ring_req->operation = BLKIF_OP_DISCARD;
311 ring_req->nr_segments = 0;
312 ring_req->u.discard.nr_sectors = blk_rq_sectors(req);
313 } else {
314 ring_req->nr_segments = blk_rq_map_sg(req->q, req, info->sg);
315 BUG_ON(ring_req->nr_segments > BLKIF_MAX_SEGMENTS_PER_REQUEST);
307 316
308 for_each_sg(info->sg, sg, ring_req->nr_segments, i) { 317 for_each_sg(info->sg, sg, ring_req->nr_segments, i) {
309 buffer_mfn = pfn_to_mfn(page_to_pfn(sg_page(sg))); 318 buffer_mfn = pfn_to_mfn(page_to_pfn(sg_page(sg)));
310 fsect = sg->offset >> 9; 319 fsect = sg->offset >> 9;
311 lsect = fsect + (sg->length >> 9) - 1; 320 lsect = fsect + (sg->length >> 9) - 1;
312 /* install a grant reference. */ 321 /* install a grant reference. */
313 ref = gnttab_claim_grant_reference(&gref_head); 322 ref = gnttab_claim_grant_reference(&gref_head);
314 BUG_ON(ref == -ENOSPC); 323 BUG_ON(ref == -ENOSPC);
315 324
316 gnttab_grant_foreign_access_ref( 325 gnttab_grant_foreign_access_ref(
317 ref, 326 ref,
318 info->xbdev->otherend_id, 327 info->xbdev->otherend_id,
319 buffer_mfn, 328 buffer_mfn,
320 rq_data_dir(req) ); 329 rq_data_dir(req));
321 330
322 info->shadow[id].frame[i] = mfn_to_pfn(buffer_mfn); 331 info->shadow[id].frame[i] = mfn_to_pfn(buffer_mfn);
323 ring_req->u.rw.seg[i] = 332 ring_req->u.rw.seg[i] =
324 (struct blkif_request_segment) { 333 (struct blkif_request_segment) {
325 .gref = ref, 334 .gref = ref,
326 .first_sect = fsect, 335 .first_sect = fsect,
327 .last_sect = lsect }; 336 .last_sect = lsect };
337 }
328 } 338 }
329 339
330 info->ring.req_prod_pvt++; 340 info->ring.req_prod_pvt++;
@@ -370,7 +380,9 @@ static void do_blkif_request(struct request_queue *rq)
370 380
371 blk_start_request(req); 381 blk_start_request(req);
372 382
373 if (req->cmd_type != REQ_TYPE_FS) { 383 if ((req->cmd_type != REQ_TYPE_FS) ||
384 ((req->cmd_flags & (REQ_FLUSH | REQ_FUA)) &&
385 !info->flush_op)) {
374 __blk_end_request_all(req, -EIO); 386 __blk_end_request_all(req, -EIO);
375 continue; 387 continue;
376 } 388 }
@@ -399,6 +411,7 @@ wait:
399static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size) 411static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size)
400{ 412{
401 struct request_queue *rq; 413 struct request_queue *rq;
414 struct blkfront_info *info = gd->private_data;
402 415
403 rq = blk_init_queue(do_blkif_request, &blkif_io_lock); 416 rq = blk_init_queue(do_blkif_request, &blkif_io_lock);
404 if (rq == NULL) 417 if (rq == NULL)
@@ -406,6 +419,13 @@ static int xlvbd_init_blk_queue(struct gendisk *gd, u16 sector_size)
406 419
407 queue_flag_set_unlocked(QUEUE_FLAG_VIRT, rq); 420 queue_flag_set_unlocked(QUEUE_FLAG_VIRT, rq);
408 421
422 if (info->feature_discard) {
423 queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, rq);
424 blk_queue_max_discard_sectors(rq, get_capacity(gd));
425 rq->limits.discard_granularity = info->discard_granularity;
426 rq->limits.discard_alignment = info->discard_alignment;
427 }
428
409 /* Hard sector size and max sectors impersonate the equiv. hardware. */ 429 /* Hard sector size and max sectors impersonate the equiv. hardware. */
410 blk_queue_logical_block_size(rq, sector_size); 430 blk_queue_logical_block_size(rq, sector_size);
411 blk_queue_max_hw_sectors(rq, 512); 431 blk_queue_max_hw_sectors(rq, 512);
@@ -722,6 +742,17 @@ static irqreturn_t blkif_interrupt(int irq, void *dev_id)
722 742
723 error = (bret->status == BLKIF_RSP_OKAY) ? 0 : -EIO; 743 error = (bret->status == BLKIF_RSP_OKAY) ? 0 : -EIO;
724 switch (bret->operation) { 744 switch (bret->operation) {
745 case BLKIF_OP_DISCARD:
746 if (unlikely(bret->status == BLKIF_RSP_EOPNOTSUPP)) {
747 struct request_queue *rq = info->rq;
748 printk(KERN_WARNING "blkfront: %s: discard op failed\n",
749 info->gd->disk_name);
750 error = -EOPNOTSUPP;
751 info->feature_discard = 0;
752 queue_flag_clear(QUEUE_FLAG_DISCARD, rq);
753 }
754 __blk_end_request_all(req, error);
755 break;
725 case BLKIF_OP_FLUSH_DISKCACHE: 756 case BLKIF_OP_FLUSH_DISKCACHE:
726 case BLKIF_OP_WRITE_BARRIER: 757 case BLKIF_OP_WRITE_BARRIER:
727 if (unlikely(bret->status == BLKIF_RSP_EOPNOTSUPP)) { 758 if (unlikely(bret->status == BLKIF_RSP_EOPNOTSUPP)) {
@@ -1098,6 +1129,33 @@ blkfront_closing(struct blkfront_info *info)
1098 bdput(bdev); 1129 bdput(bdev);
1099} 1130}
1100 1131
1132static void blkfront_setup_discard(struct blkfront_info *info)
1133{
1134 int err;
1135 char *type;
1136 unsigned int discard_granularity;
1137 unsigned int discard_alignment;
1138
1139 type = xenbus_read(XBT_NIL, info->xbdev->otherend, "type", NULL);
1140 if (IS_ERR(type))
1141 return;
1142
1143 if (strncmp(type, "phy", 3) == 0) {
1144 err = xenbus_gather(XBT_NIL, info->xbdev->otherend,
1145 "discard-granularity", "%u", &discard_granularity,
1146 "discard-alignment", "%u", &discard_alignment,
1147 NULL);
1148 if (!err) {
1149 info->feature_discard = 1;
1150 info->discard_granularity = discard_granularity;
1151 info->discard_alignment = discard_alignment;
1152 }
1153 } else if (strncmp(type, "file", 4) == 0)
1154 info->feature_discard = 1;
1155
1156 kfree(type);
1157}
1158
1101/* 1159/*
1102 * Invoked when the backend is finally 'ready' (and has told produced 1160 * Invoked when the backend is finally 'ready' (and has told produced
1103 * the details about the physical device - #sectors, size, etc). 1161 * the details about the physical device - #sectors, size, etc).
@@ -1108,7 +1166,7 @@ static void blkfront_connect(struct blkfront_info *info)
1108 unsigned long sector_size; 1166 unsigned long sector_size;
1109 unsigned int binfo; 1167 unsigned int binfo;
1110 int err; 1168 int err;
1111 int barrier, flush; 1169 int barrier, flush, discard;
1112 1170
1113 switch (info->connected) { 1171 switch (info->connected) {
1114 case BLKIF_STATE_CONNECTED: 1172 case BLKIF_STATE_CONNECTED:
@@ -1178,7 +1236,14 @@ static void blkfront_connect(struct blkfront_info *info)
1178 info->feature_flush = REQ_FLUSH; 1236 info->feature_flush = REQ_FLUSH;
1179 info->flush_op = BLKIF_OP_FLUSH_DISKCACHE; 1237 info->flush_op = BLKIF_OP_FLUSH_DISKCACHE;
1180 } 1238 }
1181 1239
1240 err = xenbus_gather(XBT_NIL, info->xbdev->otherend,
1241 "feature-discard", "%d", &discard,
1242 NULL);
1243
1244 if (!err && discard)
1245 blkfront_setup_discard(info);
1246
1182 err = xlvbd_alloc_gendisk(sectors, info, binfo, sector_size); 1247 err = xlvbd_alloc_gendisk(sectors, info, binfo, sector_size);
1183 if (err) { 1248 if (err) {
1184 xenbus_dev_fatal(info->xbdev, err, "xlvbd_add at %s", 1249 xenbus_dev_fatal(info->xbdev, err, "xlvbd_add at %s",
@@ -1385,6 +1450,8 @@ static struct xenbus_driver blkfront = {
1385 1450
1386static int __init xlblk_init(void) 1451static int __init xlblk_init(void)
1387{ 1452{
1453 int ret;
1454
1388 if (!xen_domain()) 1455 if (!xen_domain())
1389 return -ENODEV; 1456 return -ENODEV;
1390 1457
@@ -1394,7 +1461,13 @@ static int __init xlblk_init(void)
1394 return -ENODEV; 1461 return -ENODEV;
1395 } 1462 }
1396 1463
1397 return xenbus_register_frontend(&blkfront); 1464 ret = xenbus_register_frontend(&blkfront);
1465 if (ret) {
1466 unregister_blkdev(XENVBD_MAJOR, DEV_NAME);
1467 return ret;
1468 }
1469
1470 return 0;
1398} 1471}
1399module_init(xlblk_init); 1472module_init(xlblk_init);
1400 1473
diff --git a/drivers/bluetooth/btmrvl_main.c b/drivers/bluetooth/btmrvl_main.c
index 548d1d9e4dda..a88a78c86162 100644
--- a/drivers/bluetooth/btmrvl_main.c
+++ b/drivers/bluetooth/btmrvl_main.c
@@ -18,6 +18,8 @@
18 * this warranty disclaimer. 18 * this warranty disclaimer.
19 **/ 19 **/
20 20
21#include <linux/module.h>
22
21#include <net/bluetooth/bluetooth.h> 23#include <net/bluetooth/bluetooth.h>
22#include <net/bluetooth/hci_core.h> 24#include <net/bluetooth/hci_core.h>
23 25
diff --git a/drivers/bluetooth/btmrvl_sdio.c b/drivers/bluetooth/btmrvl_sdio.c
index c827d737ccee..9ef48167e2cf 100644
--- a/drivers/bluetooth/btmrvl_sdio.c
+++ b/drivers/bluetooth/btmrvl_sdio.c
@@ -23,6 +23,7 @@
23 23
24#include <linux/mmc/sdio_ids.h> 24#include <linux/mmc/sdio_ids.h>
25#include <linux/mmc/sdio_func.h> 25#include <linux/mmc/sdio_func.h>
26#include <linux/module.h>
26 27
27#include <net/bluetooth/bluetooth.h> 28#include <net/bluetooth/bluetooth.h>
28#include <net/bluetooth/hci_core.h> 29#include <net/bluetooth/hci_core.h>
diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
index 04d353f58d71..b5f83b44a0cd 100644
--- a/drivers/bluetooth/btwilink.c
+++ b/drivers/bluetooth/btwilink.c
@@ -29,6 +29,7 @@
29#include <net/bluetooth/hci.h> 29#include <net/bluetooth/hci.h>
30 30
31#include <linux/ti_wilink_st.h> 31#include <linux/ti_wilink_st.h>
32#include <linux/module.h>
32 33
33/* Bluetooth Driver Version */ 34/* Bluetooth Driver Version */
34#define VERSION "1.0" 35#define VERSION "1.0"
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 423fd56bf612..43643033a3ae 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -298,7 +298,7 @@ if RTC_LIB=n
298config RTC 298config RTC
299 tristate "Enhanced Real Time Clock Support (legacy PC RTC driver)" 299 tristate "Enhanced Real Time Clock Support (legacy PC RTC driver)"
300 depends on !PPC && !PARISC && !IA64 && !M68K && !SPARC && !FRV \ 300 depends on !PPC && !PARISC && !IA64 && !M68K && !SPARC && !FRV \
301 && !ARM && !SUPERH && !S390 && !AVR32 && !BLACKFIN 301 && !ARM && !SUPERH && !S390 && !AVR32 && !BLACKFIN && !UML
302 ---help--- 302 ---help---
303 If you say Y here and create a character special file /dev/rtc with 303 If you say Y here and create a character special file /dev/rtc with
304 major number 10 and minor number 135 using mknod ("man mknod"), you 304 major number 10 and minor number 135 using mknod ("man mknod"), you
@@ -346,7 +346,7 @@ config JS_RTC
346 346
347config GEN_RTC 347config GEN_RTC
348 tristate "Generic /dev/rtc emulation" 348 tristate "Generic /dev/rtc emulation"
349 depends on RTC!=y && !IA64 && !ARM && !M32R && !MIPS && !SPARC && !FRV && !S390 && !SUPERH && !AVR32 && !BLACKFIN 349 depends on RTC!=y && !IA64 && !ARM && !M32R && !MIPS && !SPARC && !FRV && !S390 && !SUPERH && !AVR32 && !BLACKFIN && !UML
350 ---help--- 350 ---help---
351 If you say Y here and create a character special file /dev/rtc with 351 If you say Y here and create a character special file /dev/rtc with
352 major number 10 and minor number 135 using mknod ("man mknod"), you 352 major number 10 and minor number 135 using mknod ("man mknod"), you
@@ -490,7 +490,7 @@ config SCx200_GPIO
490 490
491config PC8736x_GPIO 491config PC8736x_GPIO
492 tristate "NatSemi PC8736x GPIO Support" 492 tristate "NatSemi PC8736x GPIO Support"
493 depends on X86_32 493 depends on X86_32 && !UML
494 default SCx200_GPIO # mostly N 494 default SCx200_GPIO # mostly N
495 select NSC_GPIO # needed for support routines 495 select NSC_GPIO # needed for support routines
496 help 496 help
diff --git a/drivers/char/agp/hp-agp.c b/drivers/char/agp/hp-agp.c
index 056b289a1e89..3695773ce7c3 100644
--- a/drivers/char/agp/hp-agp.c
+++ b/drivers/char/agp/hp-agp.c
@@ -336,7 +336,8 @@ hp_zx1_insert_memory (struct agp_memory *mem, off_t pg_start, int type)
336 off_t j, io_pg_start; 336 off_t j, io_pg_start;
337 int io_pg_count; 337 int io_pg_count;
338 338
339 if (type != 0 || mem->type != 0) { 339 if (type != mem->type ||
340 agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type)) {
340 return -EINVAL; 341 return -EINVAL;
341 } 342 }
342 343
@@ -380,7 +381,8 @@ hp_zx1_remove_memory (struct agp_memory *mem, off_t pg_start, int type)
380 struct _hp_private *hp = &hp_private; 381 struct _hp_private *hp = &hp_private;
381 int i, io_pg_start, io_pg_count; 382 int i, io_pg_start, io_pg_count;
382 383
383 if (type != 0 || mem->type != 0) { 384 if (type != mem->type ||
385 agp_bridge->driver->agp_type_to_mask_type(agp_bridge, type)) {
384 return -EINVAL; 386 return -EINVAL;
385 } 387 }
386 388
diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig
index e0135873ba9d..0689bf6b0183 100644
--- a/drivers/char/hw_random/Kconfig
+++ b/drivers/char/hw_random/Kconfig
@@ -235,3 +235,18 @@ config HW_RANDOM_PPC4XX
235 module will be called ppc4xx-rng. 235 module will be called ppc4xx-rng.
236 236
237 If unsure, say N. 237 If unsure, say N.
238
239config UML_RANDOM
240 depends on UML
241 tristate "Hardware random number generator"
242 help
243 This option enables UML's "hardware" random number generator. It
244 attaches itself to the host's /dev/random, supplying as much entropy
245 as the host has, rather than the small amount the UML gets from its
246 own drivers. It registers itself as a standard hardware random number
247 generator, major 10, minor 183, and the canonical device name is
248 /dev/hwrng.
249 The way to make use of this is to install the rng-tools package
250 (check your distro, or download from
251 http://sourceforge.net/projects/gkernel/). rngd periodically reads
252 /dev/hwrng and injects the entropy into /dev/random.
diff --git a/drivers/char/hw_random/virtio-rng.c b/drivers/char/hw_random/virtio-rng.c
index 75f1cbd61c17..fd699ccecf5b 100644
--- a/drivers/char/hw_random/virtio-rng.c
+++ b/drivers/char/hw_random/virtio-rng.c
@@ -23,6 +23,7 @@
23#include <linux/spinlock.h> 23#include <linux/spinlock.h>
24#include <linux/virtio.h> 24#include <linux/virtio.h>
25#include <linux/virtio_rng.h> 25#include <linux/virtio_rng.h>
26#include <linux/module.h>
26 27
27static struct virtqueue *vq; 28static struct virtqueue *vq;
28static unsigned int data_avail; 29static unsigned int data_avail;
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 8fc04b4f311f..145179033716 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -26,6 +26,7 @@
26#include <linux/bootmem.h> 26#include <linux/bootmem.h>
27#include <linux/splice.h> 27#include <linux/splice.h>
28#include <linux/pfn.h> 28#include <linux/pfn.h>
29#include <linux/export.h>
29 30
30#include <asm/uaccess.h> 31#include <asm/uaccess.h>
31#include <asm/io.h> 32#include <asm/io.h>
diff --git a/drivers/char/ps3flash.c b/drivers/char/ps3flash.c
index d0c57c2e2909..6abdde4da2b7 100644
--- a/drivers/char/ps3flash.c
+++ b/drivers/char/ps3flash.c
@@ -22,6 +22,7 @@
22#include <linux/miscdevice.h> 22#include <linux/miscdevice.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/uaccess.h> 24#include <linux/uaccess.h>
25#include <linux/module.h>
25 26
26#include <asm/lv1call.h> 27#include <asm/lv1call.h>
27#include <asm/ps3stor.h> 28#include <asm/ps3stor.h>
diff --git a/drivers/char/ramoops.c b/drivers/char/ramoops.c
index 810aff9e750f..7c7f42a1f880 100644
--- a/drivers/char/ramoops.c
+++ b/drivers/char/ramoops.c
@@ -26,6 +26,7 @@
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/kmsg_dump.h> 27#include <linux/kmsg_dump.h>
28#include <linux/time.h> 28#include <linux/time.h>
29#include <linux/err.h>
29#include <linux/io.h> 30#include <linux/io.h>
30#include <linux/ioport.h> 31#include <linux/ioport.h>
31#include <linux/platform_device.h> 32#include <linux/platform_device.h>
diff --git a/drivers/char/ttyprintk.c b/drivers/char/ttyprintk.c
index a1f68af4ccf4..eedd5474850c 100644
--- a/drivers/char/ttyprintk.c
+++ b/drivers/char/ttyprintk.c
@@ -17,6 +17,7 @@
17#include <linux/device.h> 17#include <linux/device.h>
18#include <linux/serial.h> 18#include <linux/serial.h>
19#include <linux/tty.h> 19#include <linux/tty.h>
20#include <linux/export.h>
20 21
21struct ttyprintk_port { 22struct ttyprintk_port {
22 struct tty_port port; 23 struct tty_port port;
@@ -170,7 +171,7 @@ static const struct tty_operations ttyprintk_ops = {
170 .ioctl = tpk_ioctl, 171 .ioctl = tpk_ioctl,
171}; 172};
172 173
173struct tty_port_operations null_ops = { }; 174static struct tty_port_operations null_ops = { };
174 175
175static struct tty_driver *ttyprintk_driver; 176static struct tty_driver *ttyprintk_driver;
176 177
diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
index fb68b1295373..8e3c46d67cb3 100644
--- a/drivers/char/virtio_console.c
+++ b/drivers/char/virtio_console.c
@@ -19,8 +19,10 @@
19 */ 19 */
20#include <linux/cdev.h> 20#include <linux/cdev.h>
21#include <linux/debugfs.h> 21#include <linux/debugfs.h>
22#include <linux/completion.h>
22#include <linux/device.h> 23#include <linux/device.h>
23#include <linux/err.h> 24#include <linux/err.h>
25#include <linux/freezer.h>
24#include <linux/fs.h> 26#include <linux/fs.h>
25#include <linux/init.h> 27#include <linux/init.h>
26#include <linux/list.h> 28#include <linux/list.h>
@@ -32,6 +34,7 @@
32#include <linux/virtio_console.h> 34#include <linux/virtio_console.h>
33#include <linux/wait.h> 35#include <linux/wait.h>
34#include <linux/workqueue.h> 36#include <linux/workqueue.h>
37#include <linux/module.h>
35#include "../tty/hvc/hvc_console.h" 38#include "../tty/hvc/hvc_console.h"
36 39
37/* 40/*
@@ -73,6 +76,7 @@ struct ports_driver_data {
73static struct ports_driver_data pdrvdata; 76static struct ports_driver_data pdrvdata;
74 77
75DEFINE_SPINLOCK(pdrvdata_lock); 78DEFINE_SPINLOCK(pdrvdata_lock);
79DECLARE_COMPLETION(early_console_added);
76 80
77/* This struct holds information that's relevant only for console ports */ 81/* This struct holds information that's relevant only for console ports */
78struct console { 82struct console {
@@ -151,6 +155,10 @@ struct ports_device {
151 int chr_major; 155 int chr_major;
152}; 156};
153 157
158struct port_stats {
159 unsigned long bytes_sent, bytes_received, bytes_discarded;
160};
161
154/* This struct holds the per-port data */ 162/* This struct holds the per-port data */
155struct port { 163struct port {
156 /* Next port in the list, head is in the ports_device */ 164 /* Next port in the list, head is in the ports_device */
@@ -179,6 +187,13 @@ struct port {
179 struct dentry *debugfs_file; 187 struct dentry *debugfs_file;
180 188
181 /* 189 /*
190 * Keep count of the bytes sent, received and discarded for
191 * this port for accounting and debugging purposes. These
192 * counts are not reset across port open / close events.
193 */
194 struct port_stats stats;
195
196 /*
182 * The entries in this struct will be valid if this port is 197 * The entries in this struct will be valid if this port is
183 * hooked up to an hvc console 198 * hooked up to an hvc console
184 */ 199 */
@@ -347,17 +362,19 @@ fail:
347} 362}
348 363
349/* Callers should take appropriate locks */ 364/* Callers should take appropriate locks */
350static void *get_inbuf(struct port *port) 365static struct port_buffer *get_inbuf(struct port *port)
351{ 366{
352 struct port_buffer *buf; 367 struct port_buffer *buf;
353 struct virtqueue *vq;
354 unsigned int len; 368 unsigned int len;
355 369
356 vq = port->in_vq; 370 if (port->inbuf)
357 buf = virtqueue_get_buf(vq, &len); 371 return port->inbuf;
372
373 buf = virtqueue_get_buf(port->in_vq, &len);
358 if (buf) { 374 if (buf) {
359 buf->len = len; 375 buf->len = len;
360 buf->offset = 0; 376 buf->offset = 0;
377 port->stats.bytes_received += len;
361 } 378 }
362 return buf; 379 return buf;
363} 380}
@@ -384,32 +401,27 @@ static int add_inbuf(struct virtqueue *vq, struct port_buffer *buf)
384static void discard_port_data(struct port *port) 401static void discard_port_data(struct port *port)
385{ 402{
386 struct port_buffer *buf; 403 struct port_buffer *buf;
387 struct virtqueue *vq; 404 unsigned int err;
388 unsigned int len;
389 int ret;
390 405
391 if (!port->portdev) { 406 if (!port->portdev) {
392 /* Device has been unplugged. vqs are already gone. */ 407 /* Device has been unplugged. vqs are already gone. */
393 return; 408 return;
394 } 409 }
395 vq = port->in_vq; 410 buf = get_inbuf(port);
396 if (port->inbuf)
397 buf = port->inbuf;
398 else
399 buf = virtqueue_get_buf(vq, &len);
400 411
401 ret = 0; 412 err = 0;
402 while (buf) { 413 while (buf) {
403 if (add_inbuf(vq, buf) < 0) { 414 port->stats.bytes_discarded += buf->len - buf->offset;
404 ret++; 415 if (add_inbuf(port->in_vq, buf) < 0) {
416 err++;
405 free_buf(buf); 417 free_buf(buf);
406 } 418 }
407 buf = virtqueue_get_buf(vq, &len); 419 port->inbuf = NULL;
420 buf = get_inbuf(port);
408 } 421 }
409 port->inbuf = NULL; 422 if (err)
410 if (ret)
411 dev_warn(port->dev, "Errors adding %d buffers back to vq\n", 423 dev_warn(port->dev, "Errors adding %d buffers back to vq\n",
412 ret); 424 err);
413} 425}
414 426
415static bool port_has_data(struct port *port) 427static bool port_has_data(struct port *port)
@@ -417,18 +429,12 @@ static bool port_has_data(struct port *port)
417 unsigned long flags; 429 unsigned long flags;
418 bool ret; 430 bool ret;
419 431
432 ret = false;
420 spin_lock_irqsave(&port->inbuf_lock, flags); 433 spin_lock_irqsave(&port->inbuf_lock, flags);
421 if (port->inbuf) {
422 ret = true;
423 goto out;
424 }
425 port->inbuf = get_inbuf(port); 434 port->inbuf = get_inbuf(port);
426 if (port->inbuf) { 435 if (port->inbuf)
427 ret = true; 436 ret = true;
428 goto out; 437
429 }
430 ret = false;
431out:
432 spin_unlock_irqrestore(&port->inbuf_lock, flags); 438 spin_unlock_irqrestore(&port->inbuf_lock, flags);
433 return ret; 439 return ret;
434} 440}
@@ -529,6 +535,8 @@ static ssize_t send_buf(struct port *port, void *in_buf, size_t in_count,
529 cpu_relax(); 535 cpu_relax();
530done: 536done:
531 spin_unlock_irqrestore(&port->outvq_lock, flags); 537 spin_unlock_irqrestore(&port->outvq_lock, flags);
538
539 port->stats.bytes_sent += in_count;
532 /* 540 /*
533 * We're expected to return the amount of data we wrote -- all 541 * We're expected to return the amount of data we wrote -- all
534 * of it 542 * of it
@@ -633,8 +641,8 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
633 if (filp->f_flags & O_NONBLOCK) 641 if (filp->f_flags & O_NONBLOCK)
634 return -EAGAIN; 642 return -EAGAIN;
635 643
636 ret = wait_event_interruptible(port->waitqueue, 644 ret = wait_event_freezable(port->waitqueue,
637 !will_read_block(port)); 645 !will_read_block(port));
638 if (ret < 0) 646 if (ret < 0)
639 return ret; 647 return ret;
640 } 648 }
@@ -677,8 +685,8 @@ static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
677 if (nonblock) 685 if (nonblock)
678 return -EAGAIN; 686 return -EAGAIN;
679 687
680 ret = wait_event_interruptible(port->waitqueue, 688 ret = wait_event_freezable(port->waitqueue,
681 !will_write_block(port)); 689 !will_write_block(port));
682 if (ret < 0) 690 if (ret < 0)
683 return ret; 691 return ret;
684 } 692 }
@@ -1059,6 +1067,14 @@ static ssize_t debugfs_read(struct file *filp, char __user *ubuf,
1059 out_offset += snprintf(buf + out_offset, out_count - out_offset, 1067 out_offset += snprintf(buf + out_offset, out_count - out_offset,
1060 "outvq_full: %d\n", port->outvq_full); 1068 "outvq_full: %d\n", port->outvq_full);
1061 out_offset += snprintf(buf + out_offset, out_count - out_offset, 1069 out_offset += snprintf(buf + out_offset, out_count - out_offset,
1070 "bytes_sent: %lu\n", port->stats.bytes_sent);
1071 out_offset += snprintf(buf + out_offset, out_count - out_offset,
1072 "bytes_received: %lu\n",
1073 port->stats.bytes_received);
1074 out_offset += snprintf(buf + out_offset, out_count - out_offset,
1075 "bytes_discarded: %lu\n",
1076 port->stats.bytes_discarded);
1077 out_offset += snprintf(buf + out_offset, out_count - out_offset,
1062 "is_console: %s\n", 1078 "is_console: %s\n",
1063 is_console_port(port) ? "yes" : "no"); 1079 is_console_port(port) ? "yes" : "no");
1064 out_offset += snprintf(buf + out_offset, out_count - out_offset, 1080 out_offset += snprintf(buf + out_offset, out_count - out_offset,
@@ -1143,6 +1159,7 @@ static int add_port(struct ports_device *portdev, u32 id)
1143 port->cons.ws.ws_row = port->cons.ws.ws_col = 0; 1159 port->cons.ws.ws_row = port->cons.ws.ws_col = 0;
1144 1160
1145 port->host_connected = port->guest_connected = false; 1161 port->host_connected = port->guest_connected = false;
1162 port->stats = (struct port_stats) { 0 };
1146 1163
1147 port->outvq_full = false; 1164 port->outvq_full = false;
1148 1165
@@ -1352,6 +1369,7 @@ static void handle_control_message(struct ports_device *portdev,
1352 break; 1369 break;
1353 1370
1354 init_port_console(port); 1371 init_port_console(port);
1372 complete(&early_console_added);
1355 /* 1373 /*
1356 * Could remove the port here in case init fails - but 1374 * Could remove the port here in case init fails - but
1357 * have to notify the host first. 1375 * have to notify the host first.
@@ -1394,6 +1412,13 @@ static void handle_control_message(struct ports_device *portdev,
1394 break; 1412 break;
1395 case VIRTIO_CONSOLE_PORT_NAME: 1413 case VIRTIO_CONSOLE_PORT_NAME:
1396 /* 1414 /*
1415 * If we woke up after hibernation, we can get this
1416 * again. Skip it in that case.
1417 */
1418 if (port->name)
1419 break;
1420
1421 /*
1397 * Skip the size of the header and the cpkt to get the size 1422 * Skip the size of the header and the cpkt to get the size
1398 * of the name that was sent 1423 * of the name that was sent
1399 */ 1424 */
@@ -1481,8 +1506,7 @@ static void in_intr(struct virtqueue *vq)
1481 return; 1506 return;
1482 1507
1483 spin_lock_irqsave(&port->inbuf_lock, flags); 1508 spin_lock_irqsave(&port->inbuf_lock, flags);
1484 if (!port->inbuf) 1509 port->inbuf = get_inbuf(port);
1485 port->inbuf = get_inbuf(port);
1486 1510
1487 /* 1511 /*
1488 * Don't queue up data when port is closed. This condition 1512 * Don't queue up data when port is closed. This condition
@@ -1563,7 +1587,7 @@ static int init_vqs(struct ports_device *portdev)
1563 portdev->out_vqs = kmalloc(nr_ports * sizeof(struct virtqueue *), 1587 portdev->out_vqs = kmalloc(nr_ports * sizeof(struct virtqueue *),
1564 GFP_KERNEL); 1588 GFP_KERNEL);
1565 if (!vqs || !io_callbacks || !io_names || !portdev->in_vqs || 1589 if (!vqs || !io_callbacks || !io_names || !portdev->in_vqs ||
1566 !portdev->out_vqs) { 1590 !portdev->out_vqs) {
1567 err = -ENOMEM; 1591 err = -ENOMEM;
1568 goto free; 1592 goto free;
1569 } 1593 }
@@ -1648,6 +1672,10 @@ static int __devinit virtcons_probe(struct virtio_device *vdev)
1648 struct ports_device *portdev; 1672 struct ports_device *portdev;
1649 int err; 1673 int err;
1650 bool multiport; 1674 bool multiport;
1675 bool early = early_put_chars != NULL;
1676
1677 /* Ensure to read early_put_chars now */
1678 barrier();
1651 1679
1652 portdev = kmalloc(sizeof(*portdev), GFP_KERNEL); 1680 portdev = kmalloc(sizeof(*portdev), GFP_KERNEL);
1653 if (!portdev) { 1681 if (!portdev) {
@@ -1675,13 +1703,11 @@ static int __devinit virtcons_probe(struct virtio_device *vdev)
1675 1703
1676 multiport = false; 1704 multiport = false;
1677 portdev->config.max_nr_ports = 1; 1705 portdev->config.max_nr_ports = 1;
1678 if (virtio_has_feature(vdev, VIRTIO_CONSOLE_F_MULTIPORT)) { 1706 if (virtio_config_val(vdev, VIRTIO_CONSOLE_F_MULTIPORT,
1707 offsetof(struct virtio_console_config,
1708 max_nr_ports),
1709 &portdev->config.max_nr_ports) == 0)
1679 multiport = true; 1710 multiport = true;
1680 vdev->config->get(vdev, offsetof(struct virtio_console_config,
1681 max_nr_ports),
1682 &portdev->config.max_nr_ports,
1683 sizeof(portdev->config.max_nr_ports));
1684 }
1685 1711
1686 err = init_vqs(portdev); 1712 err = init_vqs(portdev);
1687 if (err < 0) { 1713 if (err < 0) {
@@ -1719,6 +1745,19 @@ static int __devinit virtcons_probe(struct virtio_device *vdev)
1719 1745
1720 __send_control_msg(portdev, VIRTIO_CONSOLE_BAD_ID, 1746 __send_control_msg(portdev, VIRTIO_CONSOLE_BAD_ID,
1721 VIRTIO_CONSOLE_DEVICE_READY, 1); 1747 VIRTIO_CONSOLE_DEVICE_READY, 1);
1748
1749 /*
1750 * If there was an early virtio console, assume that there are no
1751 * other consoles. We need to wait until the hvc_alloc matches the
1752 * hvc_instantiate, otherwise tty_open will complain, resulting in
1753 * a "Warning: unable to open an initial console" boot failure.
1754 * Without multiport this is done in add_port above. With multiport
1755 * this might take some host<->guest communication - thus we have to
1756 * wait.
1757 */
1758 if (multiport && early)
1759 wait_for_completion(&early_console_added);
1760
1722 return 0; 1761 return 0;
1723 1762
1724free_vqs: 1763free_vqs:
diff --git a/drivers/clocksource/sh_cmt.c b/drivers/clocksource/sh_cmt.c
index 32a77becc098..ca09bc421ddb 100644
--- a/drivers/clocksource/sh_cmt.c
+++ b/drivers/clocksource/sh_cmt.c
@@ -31,6 +31,7 @@
31#include <linux/clockchips.h> 31#include <linux/clockchips.h>
32#include <linux/sh_timer.h> 32#include <linux/sh_timer.h>
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include <linux/module.h>
34 35
35struct sh_cmt_priv { 36struct sh_cmt_priv {
36 void __iomem *mapbase; 37 void __iomem *mapbase;
diff --git a/drivers/clocksource/sh_mtu2.c b/drivers/clocksource/sh_mtu2.c
index 40630cb98237..db8d5955bad4 100644
--- a/drivers/clocksource/sh_mtu2.c
+++ b/drivers/clocksource/sh_mtu2.c
@@ -30,6 +30,7 @@
30#include <linux/clockchips.h> 30#include <linux/clockchips.h>
31#include <linux/sh_timer.h> 31#include <linux/sh_timer.h>
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/module.h>
33 34
34struct sh_mtu2_priv { 35struct sh_mtu2_priv {
35 void __iomem *mapbase; 36 void __iomem *mapbase;
diff --git a/drivers/clocksource/sh_tmu.c b/drivers/clocksource/sh_tmu.c
index 808135768617..079e96ad44e8 100644
--- a/drivers/clocksource/sh_tmu.c
+++ b/drivers/clocksource/sh_tmu.c
@@ -31,6 +31,7 @@
31#include <linux/clockchips.h> 31#include <linux/clockchips.h>
32#include <linux/sh_timer.h> 32#include <linux/sh_timer.h>
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include <linux/module.h>
34 35
35struct sh_tmu_priv { 36struct sh_tmu_priv {
36 void __iomem *mapbase; 37 void __iomem *mapbase;
diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
index faf7c5217848..c5072a91e848 100644
--- a/drivers/cpufreq/cpufreq_stats.c
+++ b/drivers/cpufreq/cpufreq_stats.c
@@ -15,6 +15,7 @@
15#include <linux/cpu.h> 15#include <linux/cpu.h>
16#include <linux/sysfs.h> 16#include <linux/sysfs.h>
17#include <linux/cpufreq.h> 17#include <linux/cpufreq.h>
18#include <linux/module.h>
18#include <linux/jiffies.h> 19#include <linux/jiffies.h>
19#include <linux/percpu.h> 20#include <linux/percpu.h>
20#include <linux/kobject.h> 21#include <linux/kobject.h>
diff --git a/drivers/cpufreq/db8500-cpufreq.c b/drivers/cpufreq/db8500-cpufreq.c
index d90456a809f9..edaa987621ea 100644
--- a/drivers/cpufreq/db8500-cpufreq.c
+++ b/drivers/cpufreq/db8500-cpufreq.c
@@ -12,30 +12,35 @@
12#include <linux/cpufreq.h> 12#include <linux/cpufreq.h>
13#include <linux/delay.h> 13#include <linux/delay.h>
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/mfd/db8500-prcmu.h> 15#include <linux/mfd/dbx500-prcmu.h>
16#include <mach/id.h> 16#include <mach/id.h>
17 17
18static struct cpufreq_frequency_table freq_table[] = { 18static struct cpufreq_frequency_table freq_table[] = {
19 [0] = { 19 [0] = {
20 .index = 0, 20 .index = 0,
21 .frequency = 300000, 21 .frequency = 200000,
22 }, 22 },
23 [1] = { 23 [1] = {
24 .index = 1, 24 .index = 1,
25 .frequency = 600000, 25 .frequency = 300000,
26 }, 26 },
27 [2] = { 27 [2] = {
28 /* Used for MAX_OPP, if available */
29 .index = 2, 28 .index = 2,
30 .frequency = CPUFREQ_TABLE_END, 29 .frequency = 600000,
31 }, 30 },
32 [3] = { 31 [3] = {
32 /* Used for MAX_OPP, if available */
33 .index = 3, 33 .index = 3,
34 .frequency = CPUFREQ_TABLE_END, 34 .frequency = CPUFREQ_TABLE_END,
35 }, 35 },
36 [4] = {
37 .index = 4,
38 .frequency = CPUFREQ_TABLE_END,
39 },
36}; 40};
37 41
38static enum arm_opp idx2opp[] = { 42static enum arm_opp idx2opp[] = {
43 ARM_EXTCLK,
39 ARM_50_OPP, 44 ARM_50_OPP,
40 ARM_100_OPP, 45 ARM_100_OPP,
41 ARM_MAX_OPP 46 ARM_MAX_OPP
@@ -72,13 +77,13 @@ static int db8500_cpufreq_target(struct cpufreq_policy *policy,
72 77
73 freqs.old = policy->cur; 78 freqs.old = policy->cur;
74 freqs.new = freq_table[idx].frequency; 79 freqs.new = freq_table[idx].frequency;
75 freqs.cpu = policy->cpu;
76 80
77 if (freqs.old == freqs.new) 81 if (freqs.old == freqs.new)
78 return 0; 82 return 0;
79 83
80 /* pre-change notification */ 84 /* pre-change notification */
81 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); 85 for_each_cpu(freqs.cpu, policy->cpus)
86 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
82 87
83 /* request the PRCM unit for opp change */ 88 /* request the PRCM unit for opp change */
84 if (prcmu_set_arm_opp(idx2opp[idx])) { 89 if (prcmu_set_arm_opp(idx2opp[idx])) {
@@ -87,7 +92,8 @@ static int db8500_cpufreq_target(struct cpufreq_policy *policy,
87 } 92 }
88 93
89 /* post change notification */ 94 /* post change notification */
90 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); 95 for_each_cpu(freqs.cpu, policy->cpus)
96 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
91 97
92 return 0; 98 return 0;
93} 99}
@@ -104,16 +110,18 @@ static unsigned int db8500_cpufreq_getspeed(unsigned int cpu)
104static int __cpuinit db8500_cpufreq_init(struct cpufreq_policy *policy) 110static int __cpuinit db8500_cpufreq_init(struct cpufreq_policy *policy)
105{ 111{
106 int res; 112 int res;
107 int i;
108 113
109 BUILD_BUG_ON(ARRAY_SIZE(idx2opp) + 1 != ARRAY_SIZE(freq_table)); 114 BUILD_BUG_ON(ARRAY_SIZE(idx2opp) + 1 != ARRAY_SIZE(freq_table));
110 115
111 if (cpu_is_u8500v2() && !prcmu_is_u8400()) { 116 if (!prcmu_is_u8400()) {
112 freq_table[0].frequency = 400000; 117 freq_table[1].frequency = 400000;
113 freq_table[1].frequency = 800000; 118 freq_table[2].frequency = 800000;
114 if (prcmu_has_arm_maxopp()) 119 if (prcmu_has_arm_maxopp())
115 freq_table[2].frequency = 1000000; 120 freq_table[3].frequency = 1000000;
116 } 121 }
122 pr_info("db8500-cpufreq : Available frequencies:\n");
123 while (freq_table[i].frequency != CPUFREQ_TABLE_END)
124 pr_info(" %d Mhz\n", freq_table[i++].frequency/1000);
117 125
118 /* get policy fields based on the table */ 126 /* get policy fields based on the table */
119 res = cpufreq_frequency_table_cpuinfo(policy, freq_table); 127 res = cpufreq_frequency_table_cpuinfo(policy, freq_table);
@@ -127,10 +135,6 @@ static int __cpuinit db8500_cpufreq_init(struct cpufreq_policy *policy)
127 policy->min = policy->cpuinfo.min_freq; 135 policy->min = policy->cpuinfo.min_freq;
128 policy->max = policy->cpuinfo.max_freq; 136 policy->max = policy->cpuinfo.max_freq;
129 policy->cur = db8500_cpufreq_getspeed(policy->cpu); 137 policy->cur = db8500_cpufreq_getspeed(policy->cpu);
130
131 for (i = 0; freq_table[i].frequency != policy->cur; i++)
132 ;
133
134 policy->governor = CPUFREQ_DEFAULT_GOVERNOR; 138 policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
135 139
136 /* 140 /*
diff --git a/drivers/cpufreq/e_powersaver.c b/drivers/cpufreq/e_powersaver.c
index 35a257dd4bb7..4bd6815d317b 100644
--- a/drivers/cpufreq/e_powersaver.c
+++ b/drivers/cpufreq/e_powersaver.c
@@ -19,6 +19,11 @@
19#include <asm/msr.h> 19#include <asm/msr.h>
20#include <asm/tsc.h> 20#include <asm/tsc.h>
21 21
22#if defined CONFIG_ACPI_PROCESSOR || defined CONFIG_ACPI_PROCESSOR_MODULE
23#include <linux/acpi.h>
24#include <acpi/processor.h>
25#endif
26
22#define EPS_BRAND_C7M 0 27#define EPS_BRAND_C7M 0
23#define EPS_BRAND_C7 1 28#define EPS_BRAND_C7 1
24#define EPS_BRAND_EDEN 2 29#define EPS_BRAND_EDEN 2
@@ -27,11 +32,59 @@
27 32
28struct eps_cpu_data { 33struct eps_cpu_data {
29 u32 fsb; 34 u32 fsb;
35#if defined CONFIG_ACPI_PROCESSOR || defined CONFIG_ACPI_PROCESSOR_MODULE
36 u32 bios_limit;
37#endif
30 struct cpufreq_frequency_table freq_table[]; 38 struct cpufreq_frequency_table freq_table[];
31}; 39};
32 40
33static struct eps_cpu_data *eps_cpu[NR_CPUS]; 41static struct eps_cpu_data *eps_cpu[NR_CPUS];
34 42
43/* Module parameters */
44static int freq_failsafe_off;
45static int voltage_failsafe_off;
46static int set_max_voltage;
47
48#if defined CONFIG_ACPI_PROCESSOR || defined CONFIG_ACPI_PROCESSOR_MODULE
49static int ignore_acpi_limit;
50
51static struct acpi_processor_performance *eps_acpi_cpu_perf;
52
53/* Minimum necessary to get acpi_processor_get_bios_limit() working */
54static int eps_acpi_init(void)
55{
56 eps_acpi_cpu_perf = kzalloc(sizeof(struct acpi_processor_performance),
57 GFP_KERNEL);
58 if (!eps_acpi_cpu_perf)
59 return -ENOMEM;
60
61 if (!zalloc_cpumask_var(&eps_acpi_cpu_perf->shared_cpu_map,
62 GFP_KERNEL)) {
63 kfree(eps_acpi_cpu_perf);
64 eps_acpi_cpu_perf = NULL;
65 return -ENOMEM;
66 }
67
68 if (acpi_processor_register_performance(eps_acpi_cpu_perf, 0)) {
69 free_cpumask_var(eps_acpi_cpu_perf->shared_cpu_map);
70 kfree(eps_acpi_cpu_perf);
71 eps_acpi_cpu_perf = NULL;
72 return -EIO;
73 }
74 return 0;
75}
76
77static int eps_acpi_exit(struct cpufreq_policy *policy)
78{
79 if (eps_acpi_cpu_perf) {
80 acpi_processor_unregister_performance(eps_acpi_cpu_perf, 0);
81 free_cpumask_var(eps_acpi_cpu_perf->shared_cpu_map);
82 kfree(eps_acpi_cpu_perf);
83 eps_acpi_cpu_perf = NULL;
84 }
85 return 0;
86}
87#endif
35 88
36static unsigned int eps_get(unsigned int cpu) 89static unsigned int eps_get(unsigned int cpu)
37{ 90{
@@ -164,6 +217,9 @@ static int eps_cpu_init(struct cpufreq_policy *policy)
164 int k, step, voltage; 217 int k, step, voltage;
165 int ret; 218 int ret;
166 int states; 219 int states;
220#if defined CONFIG_ACPI_PROCESSOR || defined CONFIG_ACPI_PROCESSOR_MODULE
221 unsigned int limit;
222#endif
167 223
168 if (policy->cpu != 0) 224 if (policy->cpu != 0)
169 return -ENODEV; 225 return -ENODEV;
@@ -244,11 +300,62 @@ static int eps_cpu_init(struct cpufreq_policy *policy)
244 return -EINVAL; 300 return -EINVAL;
245 if (current_voltage > 0x1f || max_voltage > 0x1f) 301 if (current_voltage > 0x1f || max_voltage > 0x1f)
246 return -EINVAL; 302 return -EINVAL;
247 if (max_voltage < min_voltage) 303 if (max_voltage < min_voltage
304 || current_voltage < min_voltage
305 || current_voltage > max_voltage)
248 return -EINVAL; 306 return -EINVAL;
249 307
308 /* Check for systems using underclocked CPU */
309 if (!freq_failsafe_off && max_multiplier != current_multiplier) {
310 printk(KERN_INFO "eps: Your processor is running at different "
311 "frequency then its maximum. Aborting.\n");
312 printk(KERN_INFO "eps: You can use freq_failsafe_off option "
313 "to disable this check.\n");
314 return -EINVAL;
315 }
316 if (!voltage_failsafe_off && max_voltage != current_voltage) {
317 printk(KERN_INFO "eps: Your processor is running at different "
318 "voltage then its maximum. Aborting.\n");
319 printk(KERN_INFO "eps: You can use voltage_failsafe_off "
320 "option to disable this check.\n");
321 return -EINVAL;
322 }
323
250 /* Calc FSB speed */ 324 /* Calc FSB speed */
251 fsb = cpu_khz / current_multiplier; 325 fsb = cpu_khz / current_multiplier;
326
327#if defined CONFIG_ACPI_PROCESSOR || defined CONFIG_ACPI_PROCESSOR_MODULE
328 /* Check for ACPI processor speed limit */
329 if (!ignore_acpi_limit && !eps_acpi_init()) {
330 if (!acpi_processor_get_bios_limit(policy->cpu, &limit)) {
331 printk(KERN_INFO "eps: ACPI limit %u.%uGHz\n",
332 limit/1000000,
333 (limit%1000000)/10000);
334 eps_acpi_exit(policy);
335 /* Check if max_multiplier is in BIOS limits */
336 if (limit && max_multiplier * fsb > limit) {
337 printk(KERN_INFO "eps: Aborting.\n");
338 return -EINVAL;
339 }
340 }
341 }
342#endif
343
344 /* Allow user to set lower maximum voltage then that reported
345 * by processor */
346 if (brand == EPS_BRAND_C7M && set_max_voltage) {
347 u32 v;
348
349 /* Change mV to something hardware can use */
350 v = (set_max_voltage - 700) / 16;
351 /* Check if voltage is within limits */
352 if (v >= min_voltage && v <= max_voltage) {
353 printk(KERN_INFO "eps: Setting %dmV as maximum.\n",
354 v * 16 + 700);
355 max_voltage = v;
356 }
357 }
358
252 /* Calc number of p-states supported */ 359 /* Calc number of p-states supported */
253 if (brand == EPS_BRAND_C7M) 360 if (brand == EPS_BRAND_C7M)
254 states = max_multiplier - min_multiplier + 1; 361 states = max_multiplier - min_multiplier + 1;
@@ -265,6 +372,9 @@ static int eps_cpu_init(struct cpufreq_policy *policy)
265 372
266 /* Copy basic values */ 373 /* Copy basic values */
267 centaur->fsb = fsb; 374 centaur->fsb = fsb;
375#if defined CONFIG_ACPI_PROCESSOR || defined CONFIG_ACPI_PROCESSOR_MODULE
376 centaur->bios_limit = limit;
377#endif
268 378
269 /* Fill frequency and MSR value table */ 379 /* Fill frequency and MSR value table */
270 f_table = &centaur->freq_table[0]; 380 f_table = &centaur->freq_table[0];
@@ -303,17 +413,7 @@ static int eps_cpu_init(struct cpufreq_policy *policy)
303static int eps_cpu_exit(struct cpufreq_policy *policy) 413static int eps_cpu_exit(struct cpufreq_policy *policy)
304{ 414{
305 unsigned int cpu = policy->cpu; 415 unsigned int cpu = policy->cpu;
306 struct eps_cpu_data *centaur;
307 u32 lo, hi;
308 416
309 if (eps_cpu[cpu] == NULL)
310 return -ENODEV;
311 centaur = eps_cpu[cpu];
312
313 /* Get max frequency */
314 rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
315 /* Set max frequency */
316 eps_set_state(centaur, cpu, hi & 0xffff);
317 /* Bye */ 417 /* Bye */
318 cpufreq_frequency_table_put_attr(policy->cpu); 418 cpufreq_frequency_table_put_attr(policy->cpu);
319 kfree(eps_cpu[cpu]); 419 kfree(eps_cpu[cpu]);
@@ -359,6 +459,19 @@ static void __exit eps_exit(void)
359 cpufreq_unregister_driver(&eps_driver); 459 cpufreq_unregister_driver(&eps_driver);
360} 460}
361 461
462/* Allow user to overclock his machine or to change frequency to higher after
463 * unloading module */
464module_param(freq_failsafe_off, int, 0644);
465MODULE_PARM_DESC(freq_failsafe_off, "Disable current vs max frequency check");
466module_param(voltage_failsafe_off, int, 0644);
467MODULE_PARM_DESC(voltage_failsafe_off, "Disable current vs max voltage check");
468#if defined CONFIG_ACPI_PROCESSOR || defined CONFIG_ACPI_PROCESSOR_MODULE
469module_param(ignore_acpi_limit, int, 0644);
470MODULE_PARM_DESC(ignore_acpi_limit, "Don't check ACPI's processor speed limit");
471#endif
472module_param(set_max_voltage, int, 0644);
473MODULE_PARM_DESC(set_max_voltage, "Set maximum CPU voltage (mV) C7-M only");
474
362MODULE_AUTHOR("Rafal Bilski <rafalbilski@interia.pl>"); 475MODULE_AUTHOR("Rafal Bilski <rafalbilski@interia.pl>");
363MODULE_DESCRIPTION("Enhanced PowerSaver driver for VIA C7 CPU's."); 476MODULE_DESCRIPTION("Enhanced PowerSaver driver for VIA C7 CPU's.");
364MODULE_LICENSE("GPL"); 477MODULE_LICENSE("GPL");
diff --git a/drivers/cpufreq/exynos4210-cpufreq.c b/drivers/cpufreq/exynos4210-cpufreq.c
index b7c3a84c4cfa..ab9741fab92e 100644
--- a/drivers/cpufreq/exynos4210-cpufreq.c
+++ b/drivers/cpufreq/exynos4210-cpufreq.c
@@ -17,6 +17,8 @@
17#include <linux/slab.h> 17#include <linux/slab.h>
18#include <linux/regulator/consumer.h> 18#include <linux/regulator/consumer.h>
19#include <linux/cpufreq.h> 19#include <linux/cpufreq.h>
20#include <linux/notifier.h>
21#include <linux/suspend.h>
20 22
21#include <mach/map.h> 23#include <mach/map.h>
22#include <mach/regs-clock.h> 24#include <mach/regs-clock.h>
@@ -36,6 +38,10 @@ static struct regulator *int_regulator;
36static struct cpufreq_freqs freqs; 38static struct cpufreq_freqs freqs;
37static unsigned int memtype; 39static unsigned int memtype;
38 40
41static unsigned int locking_frequency;
42static bool frequency_locked;
43static DEFINE_MUTEX(cpufreq_lock);
44
39enum exynos4_memory_type { 45enum exynos4_memory_type {
40 DDR2 = 4, 46 DDR2 = 4,
41 LPDDR2, 47 LPDDR2,
@@ -405,22 +411,32 @@ static int exynos4_target(struct cpufreq_policy *policy,
405{ 411{
406 unsigned int index, old_index; 412 unsigned int index, old_index;
407 unsigned int arm_volt, int_volt; 413 unsigned int arm_volt, int_volt;
414 int err = -EINVAL;
408 415
409 freqs.old = exynos4_getspeed(policy->cpu); 416 freqs.old = exynos4_getspeed(policy->cpu);
410 417
418 mutex_lock(&cpufreq_lock);
419
420 if (frequency_locked && target_freq != locking_frequency) {
421 err = -EAGAIN;
422 goto out;
423 }
424
411 if (cpufreq_frequency_table_target(policy, exynos4_freq_table, 425 if (cpufreq_frequency_table_target(policy, exynos4_freq_table,
412 freqs.old, relation, &old_index)) 426 freqs.old, relation, &old_index))
413 return -EINVAL; 427 goto out;
414 428
415 if (cpufreq_frequency_table_target(policy, exynos4_freq_table, 429 if (cpufreq_frequency_table_target(policy, exynos4_freq_table,
416 target_freq, relation, &index)) 430 target_freq, relation, &index))
417 return -EINVAL; 431 goto out;
432
433 err = 0;
418 434
419 freqs.new = exynos4_freq_table[index].frequency; 435 freqs.new = exynos4_freq_table[index].frequency;
420 freqs.cpu = policy->cpu; 436 freqs.cpu = policy->cpu;
421 437
422 if (freqs.new == freqs.old) 438 if (freqs.new == freqs.old)
423 return 0; 439 goto out;
424 440
425 /* get the voltage value */ 441 /* get the voltage value */
426 arm_volt = exynos4_volt_table[index].arm_volt; 442 arm_volt = exynos4_volt_table[index].arm_volt;
@@ -447,10 +463,16 @@ static int exynos4_target(struct cpufreq_policy *policy,
447 463
448 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); 464 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
449 465
450 return 0; 466out:
467 mutex_unlock(&cpufreq_lock);
468 return err;
451} 469}
452 470
453#ifdef CONFIG_PM 471#ifdef CONFIG_PM
472/*
473 * These suspend/resume are used as syscore_ops, it is already too
474 * late to set regulator voltages at this stage.
475 */
454static int exynos4_cpufreq_suspend(struct cpufreq_policy *policy) 476static int exynos4_cpufreq_suspend(struct cpufreq_policy *policy)
455{ 477{
456 return 0; 478 return 0;
@@ -462,8 +484,82 @@ static int exynos4_cpufreq_resume(struct cpufreq_policy *policy)
462} 484}
463#endif 485#endif
464 486
487/**
488 * exynos4_cpufreq_pm_notifier - block CPUFREQ's activities in suspend-resume
489 * context
490 * @notifier
491 * @pm_event
492 * @v
493 *
494 * While frequency_locked == true, target() ignores every frequency but
495 * locking_frequency. The locking_frequency value is the initial frequency,
496 * which is set by the bootloader. In order to eliminate possible
497 * inconsistency in clock values, we save and restore frequencies during
498 * suspend and resume and block CPUFREQ activities. Note that the standard
499 * suspend/resume cannot be used as they are too deep (syscore_ops) for
500 * regulator actions.
501 */
502static int exynos4_cpufreq_pm_notifier(struct notifier_block *notifier,
503 unsigned long pm_event, void *v)
504{
505 struct cpufreq_policy *policy = cpufreq_cpu_get(0); /* boot CPU */
506 static unsigned int saved_frequency;
507 unsigned int temp;
508
509 mutex_lock(&cpufreq_lock);
510 switch (pm_event) {
511 case PM_SUSPEND_PREPARE:
512 if (frequency_locked)
513 goto out;
514 frequency_locked = true;
515
516 if (locking_frequency) {
517 saved_frequency = exynos4_getspeed(0);
518
519 mutex_unlock(&cpufreq_lock);
520 exynos4_target(policy, locking_frequency,
521 CPUFREQ_RELATION_H);
522 mutex_lock(&cpufreq_lock);
523 }
524
525 break;
526 case PM_POST_SUSPEND:
527
528 if (saved_frequency) {
529 /*
530 * While frequency_locked, only locking_frequency
531 * is valid for target(). In order to use
532 * saved_frequency while keeping frequency_locked,
533 * we temporarly overwrite locking_frequency.
534 */
535 temp = locking_frequency;
536 locking_frequency = saved_frequency;
537
538 mutex_unlock(&cpufreq_lock);
539 exynos4_target(policy, locking_frequency,
540 CPUFREQ_RELATION_H);
541 mutex_lock(&cpufreq_lock);
542
543 locking_frequency = temp;
544 }
545
546 frequency_locked = false;
547 break;
548 }
549out:
550 mutex_unlock(&cpufreq_lock);
551
552 return NOTIFY_OK;
553}
554
555static struct notifier_block exynos4_cpufreq_nb = {
556 .notifier_call = exynos4_cpufreq_pm_notifier,
557};
558
465static int exynos4_cpufreq_cpu_init(struct cpufreq_policy *policy) 559static int exynos4_cpufreq_cpu_init(struct cpufreq_policy *policy)
466{ 560{
561 int ret;
562
467 policy->cur = policy->min = policy->max = exynos4_getspeed(policy->cpu); 563 policy->cur = policy->min = policy->max = exynos4_getspeed(policy->cpu);
468 564
469 cpufreq_frequency_table_get_attr(exynos4_freq_table, policy->cpu); 565 cpufreq_frequency_table_get_attr(exynos4_freq_table, policy->cpu);
@@ -479,16 +575,35 @@ static int exynos4_cpufreq_cpu_init(struct cpufreq_policy *policy)
479 */ 575 */
480 cpumask_setall(policy->cpus); 576 cpumask_setall(policy->cpus);
481 577
482 return cpufreq_frequency_table_cpuinfo(policy, exynos4_freq_table); 578 ret = cpufreq_frequency_table_cpuinfo(policy, exynos4_freq_table);
579 if (ret)
580 return ret;
581
582 cpufreq_frequency_table_get_attr(exynos4_freq_table, policy->cpu);
583
584 return 0;
585}
586
587static int exynos4_cpufreq_cpu_exit(struct cpufreq_policy *policy)
588{
589 cpufreq_frequency_table_put_attr(policy->cpu);
590 return 0;
483} 591}
484 592
593static struct freq_attr *exynos4_cpufreq_attr[] = {
594 &cpufreq_freq_attr_scaling_available_freqs,
595 NULL,
596};
597
485static struct cpufreq_driver exynos4_driver = { 598static struct cpufreq_driver exynos4_driver = {
486 .flags = CPUFREQ_STICKY, 599 .flags = CPUFREQ_STICKY,
487 .verify = exynos4_verify_speed, 600 .verify = exynos4_verify_speed,
488 .target = exynos4_target, 601 .target = exynos4_target,
489 .get = exynos4_getspeed, 602 .get = exynos4_getspeed,
490 .init = exynos4_cpufreq_cpu_init, 603 .init = exynos4_cpufreq_cpu_init,
604 .exit = exynos4_cpufreq_cpu_exit,
491 .name = "exynos4_cpufreq", 605 .name = "exynos4_cpufreq",
606 .attr = exynos4_cpufreq_attr,
492#ifdef CONFIG_PM 607#ifdef CONFIG_PM
493 .suspend = exynos4_cpufreq_suspend, 608 .suspend = exynos4_cpufreq_suspend,
494 .resume = exynos4_cpufreq_resume, 609 .resume = exynos4_cpufreq_resume,
@@ -501,6 +616,8 @@ static int __init exynos4_cpufreq_init(void)
501 if (IS_ERR(cpu_clk)) 616 if (IS_ERR(cpu_clk))
502 return PTR_ERR(cpu_clk); 617 return PTR_ERR(cpu_clk);
503 618
619 locking_frequency = exynos4_getspeed(0);
620
504 moutcore = clk_get(NULL, "moutcore"); 621 moutcore = clk_get(NULL, "moutcore");
505 if (IS_ERR(moutcore)) 622 if (IS_ERR(moutcore))
506 goto out; 623 goto out;
@@ -540,6 +657,8 @@ static int __init exynos4_cpufreq_init(void)
540 printk(KERN_DEBUG "%s: memtype= 0x%x\n", __func__, memtype); 657 printk(KERN_DEBUG "%s: memtype= 0x%x\n", __func__, memtype);
541 } 658 }
542 659
660 register_pm_notifier(&exynos4_cpufreq_nb);
661
543 return cpufreq_register_driver(&exynos4_driver); 662 return cpufreq_register_driver(&exynos4_driver);
544 663
545out: 664out:
diff --git a/drivers/cpufreq/s3c64xx-cpufreq.c b/drivers/cpufreq/s3c64xx-cpufreq.c
index b8d1d205e1ef..3475f65aeec6 100644
--- a/drivers/cpufreq/s3c64xx-cpufreq.c
+++ b/drivers/cpufreq/s3c64xx-cpufreq.c
@@ -15,6 +15,7 @@
15#include <linux/clk.h> 15#include <linux/clk.h>
16#include <linux/err.h> 16#include <linux/err.h>
17#include <linux/regulator/consumer.h> 17#include <linux/regulator/consumer.h>
18#include <linux/module.h>
18 19
19static struct clk *armclk; 20static struct clk *armclk;
20static struct regulator *vddarm; 21static struct regulator *vddarm;
diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
index 0df014110097..becd6d99203b 100644
--- a/drivers/cpuidle/cpuidle.c
+++ b/drivers/cpuidle/cpuidle.c
@@ -17,6 +17,7 @@
17#include <linux/cpuidle.h> 17#include <linux/cpuidle.h>
18#include <linux/ktime.h> 18#include <linux/ktime.h>
19#include <linux/hrtimer.h> 19#include <linux/hrtimer.h>
20#include <linux/module.h>
20#include <trace/events/power.h> 21#include <trace/events/power.h>
21 22
22#include "cpuidle.h" 23#include "cpuidle.h"
diff --git a/drivers/cpuidle/governors/ladder.c b/drivers/cpuidle/governors/ladder.c
index f62fde21e962..3b8fce20f023 100644
--- a/drivers/cpuidle/governors/ladder.c
+++ b/drivers/cpuidle/governors/ladder.c
@@ -15,7 +15,7 @@
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/cpuidle.h> 16#include <linux/cpuidle.h>
17#include <linux/pm_qos.h> 17#include <linux/pm_qos.h>
18#include <linux/moduleparam.h> 18#include <linux/module.h>
19#include <linux/jiffies.h> 19#include <linux/jiffies.h>
20 20
21#include <asm/io.h> 21#include <asm/io.h>
diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c
index 3600f1955e48..00275244ce2f 100644
--- a/drivers/cpuidle/governors/menu.c
+++ b/drivers/cpuidle/governors/menu.c
@@ -19,6 +19,7 @@
19#include <linux/tick.h> 19#include <linux/tick.h>
20#include <linux/sched.h> 20#include <linux/sched.h>
21#include <linux/math64.h> 21#include <linux/math64.h>
22#include <linux/module.h>
22 23
23#define BUCKETS 12 24#define BUCKETS 12
24#define INTERVALS 8 25#define INTERVALS 8
diff --git a/drivers/crypto/mv_cesa.c b/drivers/crypto/mv_cesa.c
index 3cf303ee3fe3..5c6f56f21443 100644
--- a/drivers/crypto/mv_cesa.c
+++ b/drivers/crypto/mv_cesa.c
@@ -15,6 +15,7 @@
15#include <linux/platform_device.h> 15#include <linux/platform_device.h>
16#include <linux/scatterlist.h> 16#include <linux/scatterlist.h>
17#include <linux/slab.h> 17#include <linux/slab.h>
18#include <linux/module.h>
18#include <crypto/internal/hash.h> 19#include <crypto/internal/hash.h>
19#include <crypto/sha.h> 20#include <crypto/sha.h>
20 21
diff --git a/drivers/dca/dca-core.c b/drivers/dca/dca-core.c
index 25ec0bb05198..bc6f5faa1e9e 100644
--- a/drivers/dca/dca-core.c
+++ b/drivers/dca/dca-core.c
@@ -28,6 +28,7 @@
28#include <linux/device.h> 28#include <linux/device.h>
29#include <linux/dca.h> 29#include <linux/dca.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/module.h>
31 32
32#define DCA_VERSION "1.12.1" 33#define DCA_VERSION "1.12.1"
33 34
diff --git a/drivers/dca/dca-sysfs.c b/drivers/dca/dca-sysfs.c
index 5e8f335e6f6e..591b6597c00a 100644
--- a/drivers/dca/dca-sysfs.c
+++ b/drivers/dca/dca-sysfs.c
@@ -27,6 +27,7 @@
27#include <linux/err.h> 27#include <linux/err.h>
28#include <linux/dca.h> 28#include <linux/dca.h>
29#include <linux/gfp.h> 29#include <linux/gfp.h>
30#include <linux/export.h>
30 31
31static struct class *dca_class; 32static struct class *dca_class;
32static struct idr dca_idr; 33static struct idr dca_idr;
diff --git a/drivers/dma/Kconfig b/drivers/dma/Kconfig
index 2e3b3d38c465..ab8f469f5cf8 100644
--- a/drivers/dma/Kconfig
+++ b/drivers/dma/Kconfig
@@ -193,7 +193,8 @@ config ARCH_HAS_ASYNC_TX_FIND_CHANNEL
193config PL330_DMA 193config PL330_DMA
194 tristate "DMA API Driver for PL330" 194 tristate "DMA API Driver for PL330"
195 select DMA_ENGINE 195 select DMA_ENGINE
196 depends on PL330 196 depends on ARM_AMBA
197 select PL330
197 help 198 help
198 Select if your platform has one or more PL330 DMACs. 199 Select if your platform has one or more PL330 DMACs.
199 You need to provide platform specific settings via 200 You need to provide platform specific settings via
diff --git a/drivers/dma/amba-pl08x.c b/drivers/dma/amba-pl08x.c
index be21e3f138a8..b7cbd1ab1db1 100644
--- a/drivers/dma/amba-pl08x.c
+++ b/drivers/dma/amba-pl08x.c
@@ -66,32 +66,29 @@
66 * after the final transfer signalled by LBREQ or LSREQ. The DMAC 66 * after the final transfer signalled by LBREQ or LSREQ. The DMAC
67 * will then move to the next LLI entry. 67 * will then move to the next LLI entry.
68 * 68 *
69 * Only the former works sanely with scatter lists, so we only implement
70 * the DMAC flow control method. However, peripherals which use the LBREQ
71 * and LSREQ signals (eg, MMCI) are unable to use this mode, which through
72 * these hardware restrictions prevents them from using scatter DMA.
73 *
74 * Global TODO: 69 * Global TODO:
75 * - Break out common code from arch/arm/mach-s3c64xx and share 70 * - Break out common code from arch/arm/mach-s3c64xx and share
76 */ 71 */
77#include <linux/device.h>
78#include <linux/init.h>
79#include <linux/module.h>
80#include <linux/interrupt.h>
81#include <linux/slab.h>
82#include <linux/delay.h>
83#include <linux/dma-mapping.h>
84#include <linux/dmapool.h>
85#include <linux/dmaengine.h>
86#include <linux/amba/bus.h> 72#include <linux/amba/bus.h>
87#include <linux/amba/pl08x.h> 73#include <linux/amba/pl08x.h>
88#include <linux/debugfs.h> 74#include <linux/debugfs.h>
75#include <linux/delay.h>
76#include <linux/device.h>
77#include <linux/dmaengine.h>
78#include <linux/dmapool.h>
79#include <linux/dma-mapping.h>
80#include <linux/init.h>
81#include <linux/interrupt.h>
82#include <linux/module.h>
83#include <linux/pm_runtime.h>
89#include <linux/seq_file.h> 84#include <linux/seq_file.h>
90 85#include <linux/slab.h>
91#include <asm/hardware/pl080.h> 86#include <asm/hardware/pl080.h>
92 87
93#define DRIVER_NAME "pl08xdmac" 88#define DRIVER_NAME "pl08xdmac"
94 89
90static struct amba_driver pl08x_amba_driver;
91
95/** 92/**
96 * struct vendor_data - vendor-specific config parameters for PL08x derivatives 93 * struct vendor_data - vendor-specific config parameters for PL08x derivatives
97 * @channels: the number of channels available in this variant 94 * @channels: the number of channels available in this variant
@@ -126,7 +123,8 @@ struct pl08x_lli {
126 * @phy_chans: array of data for the physical channels 123 * @phy_chans: array of data for the physical channels
127 * @pool: a pool for the LLI descriptors 124 * @pool: a pool for the LLI descriptors
128 * @pool_ctr: counter of LLIs in the pool 125 * @pool_ctr: counter of LLIs in the pool
129 * @lli_buses: bitmask to or in to LLI pointer selecting AHB port for LLI fetches 126 * @lli_buses: bitmask to or in to LLI pointer selecting AHB port for LLI
127 * fetches
130 * @mem_buses: set to indicate memory transfers on AHB2. 128 * @mem_buses: set to indicate memory transfers on AHB2.
131 * @lock: a spinlock for this struct 129 * @lock: a spinlock for this struct
132 */ 130 */
@@ -149,14 +147,6 @@ struct pl08x_driver_data {
149 * PL08X specific defines 147 * PL08X specific defines
150 */ 148 */
151 149
152/*
153 * Memory boundaries: the manual for PL08x says that the controller
154 * cannot read past a 1KiB boundary, so these defines are used to
155 * create transfer LLIs that do not cross such boundaries.
156 */
157#define PL08X_BOUNDARY_SHIFT (10) /* 1KB 0x400 */
158#define PL08X_BOUNDARY_SIZE (1 << PL08X_BOUNDARY_SHIFT)
159
160/* Size (bytes) of each LLI buffer allocated for one transfer */ 150/* Size (bytes) of each LLI buffer allocated for one transfer */
161# define PL08X_LLI_TSFR_SIZE 0x2000 151# define PL08X_LLI_TSFR_SIZE 0x2000
162 152
@@ -272,7 +262,6 @@ static void pl08x_resume_phy_chan(struct pl08x_phy_chan *ch)
272 writel(val, ch->base + PL080_CH_CONFIG); 262 writel(val, ch->base + PL080_CH_CONFIG);
273} 263}
274 264
275
276/* 265/*
277 * pl08x_terminate_phy_chan() stops the channel, clears the FIFO and 266 * pl08x_terminate_phy_chan() stops the channel, clears the FIFO and
278 * clears any pending interrupt status. This should not be used for 267 * clears any pending interrupt status. This should not be used for
@@ -363,7 +352,9 @@ static u32 pl08x_getbytes_chan(struct pl08x_dma_chan *plchan)
363 if (!list_empty(&plchan->pend_list)) { 352 if (!list_empty(&plchan->pend_list)) {
364 struct pl08x_txd *txdi; 353 struct pl08x_txd *txdi;
365 list_for_each_entry(txdi, &plchan->pend_list, node) { 354 list_for_each_entry(txdi, &plchan->pend_list, node) {
366 bytes += txdi->len; 355 struct pl08x_sg *dsg;
356 list_for_each_entry(dsg, &txd->dsg_list, node)
357 bytes += dsg->len;
367 } 358 }
368 } 359 }
369 360
@@ -407,6 +398,7 @@ pl08x_get_phy_channel(struct pl08x_driver_data *pl08x,
407 return NULL; 398 return NULL;
408 } 399 }
409 400
401 pm_runtime_get_sync(&pl08x->adev->dev);
410 return ch; 402 return ch;
411} 403}
412 404
@@ -420,6 +412,8 @@ static inline void pl08x_put_phy_channel(struct pl08x_driver_data *pl08x,
420 /* Stop the channel and clear its interrupts */ 412 /* Stop the channel and clear its interrupts */
421 pl08x_terminate_phy_chan(pl08x, ch); 413 pl08x_terminate_phy_chan(pl08x, ch);
422 414
415 pm_runtime_put(&pl08x->adev->dev);
416
423 /* Mark it as free */ 417 /* Mark it as free */
424 ch->serving = NULL; 418 ch->serving = NULL;
425 spin_unlock_irqrestore(&ch->lock, flags); 419 spin_unlock_irqrestore(&ch->lock, flags);
@@ -499,36 +493,30 @@ struct pl08x_lli_build_data {
499}; 493};
500 494
501/* 495/*
502 * Autoselect a master bus to use for the transfer this prefers the 496 * Autoselect a master bus to use for the transfer. Slave will be the chosen as
503 * destination bus if both available if fixed address on one bus the 497 * victim in case src & dest are not similarly aligned. i.e. If after aligning
504 * other will be chosen 498 * masters address with width requirements of transfer (by sending few byte by
499 * byte data), slave is still not aligned, then its width will be reduced to
500 * BYTE.
501 * - prefers the destination bus if both available
502 * - prefers bus with fixed address (i.e. peripheral)
505 */ 503 */
506static void pl08x_choose_master_bus(struct pl08x_lli_build_data *bd, 504static void pl08x_choose_master_bus(struct pl08x_lli_build_data *bd,
507 struct pl08x_bus_data **mbus, struct pl08x_bus_data **sbus, u32 cctl) 505 struct pl08x_bus_data **mbus, struct pl08x_bus_data **sbus, u32 cctl)
508{ 506{
509 if (!(cctl & PL080_CONTROL_DST_INCR)) { 507 if (!(cctl & PL080_CONTROL_DST_INCR)) {
510 *mbus = &bd->srcbus;
511 *sbus = &bd->dstbus;
512 } else if (!(cctl & PL080_CONTROL_SRC_INCR)) {
513 *mbus = &bd->dstbus; 508 *mbus = &bd->dstbus;
514 *sbus = &bd->srcbus; 509 *sbus = &bd->srcbus;
510 } else if (!(cctl & PL080_CONTROL_SRC_INCR)) {
511 *mbus = &bd->srcbus;
512 *sbus = &bd->dstbus;
515 } else { 513 } else {
516 if (bd->dstbus.buswidth == 4) { 514 if (bd->dstbus.buswidth >= bd->srcbus.buswidth) {
517 *mbus = &bd->dstbus; 515 *mbus = &bd->dstbus;
518 *sbus = &bd->srcbus; 516 *sbus = &bd->srcbus;
519 } else if (bd->srcbus.buswidth == 4) { 517 } else {
520 *mbus = &bd->srcbus;
521 *sbus = &bd->dstbus;
522 } else if (bd->dstbus.buswidth == 2) {
523 *mbus = &bd->dstbus;
524 *sbus = &bd->srcbus;
525 } else if (bd->srcbus.buswidth == 2) {
526 *mbus = &bd->srcbus; 518 *mbus = &bd->srcbus;
527 *sbus = &bd->dstbus; 519 *sbus = &bd->dstbus;
528 } else {
529 /* bd->srcbus.buswidth == 1 */
530 *mbus = &bd->dstbus;
531 *sbus = &bd->srcbus;
532 } 520 }
533 } 521 }
534} 522}
@@ -547,7 +535,8 @@ static void pl08x_fill_lli_for_desc(struct pl08x_lli_build_data *bd,
547 llis_va[num_llis].cctl = cctl; 535 llis_va[num_llis].cctl = cctl;
548 llis_va[num_llis].src = bd->srcbus.addr; 536 llis_va[num_llis].src = bd->srcbus.addr;
549 llis_va[num_llis].dst = bd->dstbus.addr; 537 llis_va[num_llis].dst = bd->dstbus.addr;
550 llis_va[num_llis].lli = llis_bus + (num_llis + 1) * sizeof(struct pl08x_lli); 538 llis_va[num_llis].lli = llis_bus + (num_llis + 1) *
539 sizeof(struct pl08x_lli);
551 llis_va[num_llis].lli |= bd->lli_bus; 540 llis_va[num_llis].lli |= bd->lli_bus;
552 541
553 if (cctl & PL080_CONTROL_SRC_INCR) 542 if (cctl & PL080_CONTROL_SRC_INCR)
@@ -560,16 +549,12 @@ static void pl08x_fill_lli_for_desc(struct pl08x_lli_build_data *bd,
560 bd->remainder -= len; 549 bd->remainder -= len;
561} 550}
562 551
563/* 552static inline void prep_byte_width_lli(struct pl08x_lli_build_data *bd,
564 * Return number of bytes to fill to boundary, or len. 553 u32 *cctl, u32 len, int num_llis, size_t *total_bytes)
565 * This calculation works for any value of addr.
566 */
567static inline size_t pl08x_pre_boundary(u32 addr, size_t len)
568{ 554{
569 size_t boundary_len = PL08X_BOUNDARY_SIZE - 555 *cctl = pl08x_cctl_bits(*cctl, 1, 1, len);
570 (addr & (PL08X_BOUNDARY_SIZE - 1)); 556 pl08x_fill_lli_for_desc(bd, num_llis, len, *cctl);
571 557 (*total_bytes) += len;
572 return min(boundary_len, len);
573} 558}
574 559
575/* 560/*
@@ -583,13 +568,12 @@ static int pl08x_fill_llis_for_desc(struct pl08x_driver_data *pl08x,
583 struct pl08x_bus_data *mbus, *sbus; 568 struct pl08x_bus_data *mbus, *sbus;
584 struct pl08x_lli_build_data bd; 569 struct pl08x_lli_build_data bd;
585 int num_llis = 0; 570 int num_llis = 0;
586 u32 cctl; 571 u32 cctl, early_bytes = 0;
587 size_t max_bytes_per_lli; 572 size_t max_bytes_per_lli, total_bytes;
588 size_t total_bytes = 0;
589 struct pl08x_lli *llis_va; 573 struct pl08x_lli *llis_va;
574 struct pl08x_sg *dsg;
590 575
591 txd->llis_va = dma_pool_alloc(pl08x->pool, GFP_NOWAIT, 576 txd->llis_va = dma_pool_alloc(pl08x->pool, GFP_NOWAIT, &txd->llis_bus);
592 &txd->llis_bus);
593 if (!txd->llis_va) { 577 if (!txd->llis_va) {
594 dev_err(&pl08x->adev->dev, "%s no memory for llis\n", __func__); 578 dev_err(&pl08x->adev->dev, "%s no memory for llis\n", __func__);
595 return 0; 579 return 0;
@@ -597,13 +581,9 @@ static int pl08x_fill_llis_for_desc(struct pl08x_driver_data *pl08x,
597 581
598 pl08x->pool_ctr++; 582 pl08x->pool_ctr++;
599 583
600 /* Get the default CCTL */
601 cctl = txd->cctl;
602
603 bd.txd = txd; 584 bd.txd = txd;
604 bd.srcbus.addr = txd->src_addr;
605 bd.dstbus.addr = txd->dst_addr;
606 bd.lli_bus = (pl08x->lli_buses & PL08X_AHB2) ? PL080_LLI_LM_AHB2 : 0; 585 bd.lli_bus = (pl08x->lli_buses & PL08X_AHB2) ? PL080_LLI_LM_AHB2 : 0;
586 cctl = txd->cctl;
607 587
608 /* Find maximum width of the source bus */ 588 /* Find maximum width of the source bus */
609 bd.srcbus.maxwidth = 589 bd.srcbus.maxwidth =
@@ -615,215 +595,179 @@ static int pl08x_fill_llis_for_desc(struct pl08x_driver_data *pl08x,
615 pl08x_get_bytes_for_cctl((cctl & PL080_CONTROL_DWIDTH_MASK) >> 595 pl08x_get_bytes_for_cctl((cctl & PL080_CONTROL_DWIDTH_MASK) >>
616 PL080_CONTROL_DWIDTH_SHIFT); 596 PL080_CONTROL_DWIDTH_SHIFT);
617 597
618 /* Set up the bus widths to the maximum */ 598 list_for_each_entry(dsg, &txd->dsg_list, node) {
619 bd.srcbus.buswidth = bd.srcbus.maxwidth; 599 total_bytes = 0;
620 bd.dstbus.buswidth = bd.dstbus.maxwidth; 600 cctl = txd->cctl;
621 601
622 /* 602 bd.srcbus.addr = dsg->src_addr;
623 * Bytes transferred == tsize * MIN(buswidths), not max(buswidths) 603 bd.dstbus.addr = dsg->dst_addr;
624 */ 604 bd.remainder = dsg->len;
625 max_bytes_per_lli = min(bd.srcbus.buswidth, bd.dstbus.buswidth) * 605 bd.srcbus.buswidth = bd.srcbus.maxwidth;
626 PL080_CONTROL_TRANSFER_SIZE_MASK; 606 bd.dstbus.buswidth = bd.dstbus.maxwidth;
627 607
628 /* We need to count this down to zero */ 608 pl08x_choose_master_bus(&bd, &mbus, &sbus, cctl);
629 bd.remainder = txd->len;
630 609
631 /* 610 dev_vdbg(&pl08x->adev->dev, "src=0x%08x%s/%u dst=0x%08x%s/%u len=%zu\n",
632 * Choose bus to align to 611 bd.srcbus.addr, cctl & PL080_CONTROL_SRC_INCR ? "+" : "",
633 * - prefers destination bus if both available 612 bd.srcbus.buswidth,
634 * - if fixed address on one bus chooses other 613 bd.dstbus.addr, cctl & PL080_CONTROL_DST_INCR ? "+" : "",
635 */ 614 bd.dstbus.buswidth,
636 pl08x_choose_master_bus(&bd, &mbus, &sbus, cctl); 615 bd.remainder);
637 616 dev_vdbg(&pl08x->adev->dev, "mbus=%s sbus=%s\n",
638 dev_vdbg(&pl08x->adev->dev, "src=0x%08x%s/%u dst=0x%08x%s/%u len=%zu llimax=%zu\n", 617 mbus == &bd.srcbus ? "src" : "dst",
639 bd.srcbus.addr, cctl & PL080_CONTROL_SRC_INCR ? "+" : "", 618 sbus == &bd.srcbus ? "src" : "dst");
640 bd.srcbus.buswidth,
641 bd.dstbus.addr, cctl & PL080_CONTROL_DST_INCR ? "+" : "",
642 bd.dstbus.buswidth,
643 bd.remainder, max_bytes_per_lli);
644 dev_vdbg(&pl08x->adev->dev, "mbus=%s sbus=%s\n",
645 mbus == &bd.srcbus ? "src" : "dst",
646 sbus == &bd.srcbus ? "src" : "dst");
647
648 if (txd->len < mbus->buswidth) {
649 /* Less than a bus width available - send as single bytes */
650 while (bd.remainder) {
651 dev_vdbg(&pl08x->adev->dev,
652 "%s single byte LLIs for a transfer of "
653 "less than a bus width (remain 0x%08x)\n",
654 __func__, bd.remainder);
655 cctl = pl08x_cctl_bits(cctl, 1, 1, 1);
656 pl08x_fill_lli_for_desc(&bd, num_llis++, 1, cctl);
657 total_bytes++;
658 }
659 } else {
660 /* Make one byte LLIs until master bus is aligned */
661 while ((mbus->addr) % (mbus->buswidth)) {
662 dev_vdbg(&pl08x->adev->dev,
663 "%s adjustment lli for less than bus width "
664 "(remain 0x%08x)\n",
665 __func__, bd.remainder);
666 cctl = pl08x_cctl_bits(cctl, 1, 1, 1);
667 pl08x_fill_lli_for_desc(&bd, num_llis++, 1, cctl);
668 total_bytes++;
669 }
670 619
671 /* 620 /*
672 * Master now aligned 621 * Zero length is only allowed if all these requirements are
673 * - if slave is not then we must set its width down 622 * met:
623 * - flow controller is peripheral.
624 * - src.addr is aligned to src.width
625 * - dst.addr is aligned to dst.width
626 *
627 * sg_len == 1 should be true, as there can be two cases here:
628 *
629 * - Memory addresses are contiguous and are not scattered.
630 * Here, Only one sg will be passed by user driver, with
631 * memory address and zero length. We pass this to controller
632 * and after the transfer it will receive the last burst
633 * request from peripheral and so transfer finishes.
634 *
635 * - Memory addresses are scattered and are not contiguous.
636 * Here, Obviously as DMA controller doesn't know when a lli's
637 * transfer gets over, it can't load next lli. So in this
638 * case, there has to be an assumption that only one lli is
639 * supported. Thus, we can't have scattered addresses.
674 */ 640 */
675 if (sbus->addr % sbus->buswidth) { 641 if (!bd.remainder) {
676 dev_dbg(&pl08x->adev->dev, 642 u32 fc = (txd->ccfg & PL080_CONFIG_FLOW_CONTROL_MASK) >>
677 "%s set down bus width to one byte\n", 643 PL080_CONFIG_FLOW_CONTROL_SHIFT;
678 __func__); 644 if (!((fc >= PL080_FLOW_SRC2DST_DST) &&
645 (fc <= PL080_FLOW_SRC2DST_SRC))) {
646 dev_err(&pl08x->adev->dev, "%s sg len can't be zero",
647 __func__);
648 return 0;
649 }
650
651 if ((bd.srcbus.addr % bd.srcbus.buswidth) ||
652 (bd.srcbus.addr % bd.srcbus.buswidth)) {
653 dev_err(&pl08x->adev->dev,
654 "%s src & dst address must be aligned to src"
655 " & dst width if peripheral is flow controller",
656 __func__);
657 return 0;
658 }
679 659
680 sbus->buswidth = 1; 660 cctl = pl08x_cctl_bits(cctl, bd.srcbus.buswidth,
661 bd.dstbus.buswidth, 0);
662 pl08x_fill_lli_for_desc(&bd, num_llis++, 0, cctl);
663 break;
681 } 664 }
682 665
683 /* 666 /*
684 * Make largest possible LLIs until less than one bus 667 * Send byte by byte for following cases
685 * width left 668 * - Less than a bus width available
669 * - until master bus is aligned
686 */ 670 */
687 while (bd.remainder > (mbus->buswidth - 1)) { 671 if (bd.remainder < mbus->buswidth)
688 size_t lli_len, target_len, tsize, odd_bytes; 672 early_bytes = bd.remainder;
673 else if ((mbus->addr) % (mbus->buswidth)) {
674 early_bytes = mbus->buswidth - (mbus->addr) %
675 (mbus->buswidth);
676 if ((bd.remainder - early_bytes) < mbus->buswidth)
677 early_bytes = bd.remainder;
678 }
689 679
680 if (early_bytes) {
681 dev_vdbg(&pl08x->adev->dev,
682 "%s byte width LLIs (remain 0x%08x)\n",
683 __func__, bd.remainder);
684 prep_byte_width_lli(&bd, &cctl, early_bytes, num_llis++,
685 &total_bytes);
686 }
687
688 if (bd.remainder) {
690 /* 689 /*
691 * If enough left try to send max possible, 690 * Master now aligned
692 * otherwise try to send the remainder 691 * - if slave is not then we must set its width down
693 */ 692 */
694 target_len = min(bd.remainder, max_bytes_per_lli); 693 if (sbus->addr % sbus->buswidth) {
694 dev_dbg(&pl08x->adev->dev,
695 "%s set down bus width to one byte\n",
696 __func__);
697
698 sbus->buswidth = 1;
699 }
695 700
696 /* 701 /*
697 * Set bus lengths for incrementing buses to the 702 * Bytes transferred = tsize * src width, not
698 * number of bytes which fill to next memory boundary, 703 * MIN(buswidths)
699 * limiting on the target length calculated above.
700 */ 704 */
701 if (cctl & PL080_CONTROL_SRC_INCR) 705 max_bytes_per_lli = bd.srcbus.buswidth *
702 bd.srcbus.fill_bytes = 706 PL080_CONTROL_TRANSFER_SIZE_MASK;
703 pl08x_pre_boundary(bd.srcbus.addr, 707 dev_vdbg(&pl08x->adev->dev,
704 target_len); 708 "%s max bytes per lli = %zu\n",
705 else 709 __func__, max_bytes_per_lli);
706 bd.srcbus.fill_bytes = target_len; 710
707 711 /*
708 if (cctl & PL080_CONTROL_DST_INCR) 712 * Make largest possible LLIs until less than one bus
709 bd.dstbus.fill_bytes = 713 * width left
710 pl08x_pre_boundary(bd.dstbus.addr, 714 */
711 target_len); 715 while (bd.remainder > (mbus->buswidth - 1)) {
712 else 716 size_t lli_len, tsize, width;
713 bd.dstbus.fill_bytes = target_len;
714
715 /* Find the nearest */
716 lli_len = min(bd.srcbus.fill_bytes,
717 bd.dstbus.fill_bytes);
718
719 BUG_ON(lli_len > bd.remainder);
720
721 if (lli_len <= 0) {
722 dev_err(&pl08x->adev->dev,
723 "%s lli_len is %zu, <= 0\n",
724 __func__, lli_len);
725 return 0;
726 }
727 717
728 if (lli_len == target_len) {
729 /*
730 * Can send what we wanted.
731 * Maintain alignment
732 */
733 lli_len = (lli_len/mbus->buswidth) *
734 mbus->buswidth;
735 odd_bytes = 0;
736 } else {
737 /* 718 /*
738 * So now we know how many bytes to transfer 719 * If enough left try to send max possible,
739 * to get to the nearest boundary. The next 720 * otherwise try to send the remainder
740 * LLI will past the boundary. However, we
741 * may be working to a boundary on the slave
742 * bus. We need to ensure the master stays
743 * aligned, and that we are working in
744 * multiples of the bus widths.
745 */ 721 */
746 odd_bytes = lli_len % mbus->buswidth; 722 lli_len = min(bd.remainder, max_bytes_per_lli);
747 lli_len -= odd_bytes;
748
749 }
750 723
751 if (lli_len) {
752 /* 724 /*
753 * Check against minimum bus alignment: 725 * Check against maximum bus alignment:
754 * Calculate actual transfer size in relation 726 * Calculate actual transfer size in relation to
755 * to bus width an get a maximum remainder of 727 * bus width an get a maximum remainder of the
756 * the smallest bus width - 1 728 * highest bus width - 1
757 */ 729 */
758 /* FIXME: use round_down()? */ 730 width = max(mbus->buswidth, sbus->buswidth);
759 tsize = lli_len / min(mbus->buswidth, 731 lli_len = (lli_len / width) * width;
760 sbus->buswidth); 732 tsize = lli_len / bd.srcbus.buswidth;
761 lli_len = tsize * min(mbus->buswidth,
762 sbus->buswidth);
763
764 if (target_len != lli_len) {
765 dev_vdbg(&pl08x->adev->dev,
766 "%s can't send what we want. Desired 0x%08zx, lli of 0x%08zx bytes in txd of 0x%08zx\n",
767 __func__, target_len, lli_len, txd->len);
768 }
769
770 cctl = pl08x_cctl_bits(cctl,
771 bd.srcbus.buswidth,
772 bd.dstbus.buswidth,
773 tsize);
774 733
775 dev_vdbg(&pl08x->adev->dev, 734 dev_vdbg(&pl08x->adev->dev,
776 "%s fill lli with single lli chunk of size 0x%08zx (remainder 0x%08zx)\n", 735 "%s fill lli with single lli chunk of "
736 "size 0x%08zx (remainder 0x%08zx)\n",
777 __func__, lli_len, bd.remainder); 737 __func__, lli_len, bd.remainder);
738
739 cctl = pl08x_cctl_bits(cctl, bd.srcbus.buswidth,
740 bd.dstbus.buswidth, tsize);
778 pl08x_fill_lli_for_desc(&bd, num_llis++, 741 pl08x_fill_lli_for_desc(&bd, num_llis++,
779 lli_len, cctl); 742 lli_len, cctl);
780 total_bytes += lli_len; 743 total_bytes += lli_len;
781 } 744 }
782 745
783 746 /*
784 if (odd_bytes) { 747 * Send any odd bytes
785 /* 748 */
786 * Creep past the boundary, maintaining 749 if (bd.remainder) {
787 * master alignment 750 dev_vdbg(&pl08x->adev->dev,
788 */ 751 "%s align with boundary, send odd bytes (remain %zu)\n",
789 int j; 752 __func__, bd.remainder);
790 for (j = 0; (j < mbus->buswidth) 753 prep_byte_width_lli(&bd, &cctl, bd.remainder,
791 && (bd.remainder); j++) { 754 num_llis++, &total_bytes);
792 cctl = pl08x_cctl_bits(cctl, 1, 1, 1);
793 dev_vdbg(&pl08x->adev->dev,
794 "%s align with boundary, single byte (remain 0x%08zx)\n",
795 __func__, bd.remainder);
796 pl08x_fill_lli_for_desc(&bd,
797 num_llis++, 1, cctl);
798 total_bytes++;
799 }
800 } 755 }
801 } 756 }
802 757
803 /* 758 if (total_bytes != dsg->len) {
804 * Send any odd bytes 759 dev_err(&pl08x->adev->dev,
805 */ 760 "%s size of encoded lli:s don't match total txd, transferred 0x%08zx from size 0x%08zx\n",
806 while (bd.remainder) { 761 __func__, total_bytes, dsg->len);
807 cctl = pl08x_cctl_bits(cctl, 1, 1, 1); 762 return 0;
808 dev_vdbg(&pl08x->adev->dev,
809 "%s align with boundary, single odd byte (remain %zu)\n",
810 __func__, bd.remainder);
811 pl08x_fill_lli_for_desc(&bd, num_llis++, 1, cctl);
812 total_bytes++;
813 } 763 }
814 }
815 if (total_bytes != txd->len) {
816 dev_err(&pl08x->adev->dev,
817 "%s size of encoded lli:s don't match total txd, transferred 0x%08zx from size 0x%08zx\n",
818 __func__, total_bytes, txd->len);
819 return 0;
820 }
821 764
822 if (num_llis >= MAX_NUM_TSFR_LLIS) { 765 if (num_llis >= MAX_NUM_TSFR_LLIS) {
823 dev_err(&pl08x->adev->dev, 766 dev_err(&pl08x->adev->dev,
824 "%s need to increase MAX_NUM_TSFR_LLIS from 0x%08x\n", 767 "%s need to increase MAX_NUM_TSFR_LLIS from 0x%08x\n",
825 __func__, (u32) MAX_NUM_TSFR_LLIS); 768 __func__, (u32) MAX_NUM_TSFR_LLIS);
826 return 0; 769 return 0;
770 }
827 } 771 }
828 772
829 llis_va = txd->llis_va; 773 llis_va = txd->llis_va;
@@ -856,11 +800,19 @@ static int pl08x_fill_llis_for_desc(struct pl08x_driver_data *pl08x,
856static void pl08x_free_txd(struct pl08x_driver_data *pl08x, 800static void pl08x_free_txd(struct pl08x_driver_data *pl08x,
857 struct pl08x_txd *txd) 801 struct pl08x_txd *txd)
858{ 802{
803 struct pl08x_sg *dsg, *_dsg;
804
859 /* Free the LLI */ 805 /* Free the LLI */
860 dma_pool_free(pl08x->pool, txd->llis_va, txd->llis_bus); 806 if (txd->llis_va)
807 dma_pool_free(pl08x->pool, txd->llis_va, txd->llis_bus);
861 808
862 pl08x->pool_ctr--; 809 pl08x->pool_ctr--;
863 810
811 list_for_each_entry_safe(dsg, _dsg, &txd->dsg_list, node) {
812 list_del(&dsg->node);
813 kfree(dsg);
814 }
815
864 kfree(txd); 816 kfree(txd);
865} 817}
866 818
@@ -917,9 +869,7 @@ static int prep_phy_channel(struct pl08x_dma_chan *plchan,
917 * need, but for slaves the physical signals may be muxed! 869 * need, but for slaves the physical signals may be muxed!
918 * Can the platform allow us to use this channel? 870 * Can the platform allow us to use this channel?
919 */ 871 */
920 if (plchan->slave && 872 if (plchan->slave && pl08x->pd->get_signal) {
921 ch->signal < 0 &&
922 pl08x->pd->get_signal) {
923 ret = pl08x->pd->get_signal(plchan); 873 ret = pl08x->pd->get_signal(plchan);
924 if (ret < 0) { 874 if (ret < 0) {
925 dev_dbg(&pl08x->adev->dev, 875 dev_dbg(&pl08x->adev->dev,
@@ -1008,10 +958,8 @@ static struct dma_async_tx_descriptor *pl08x_prep_dma_interrupt(
1008 * If slaves are relying on interrupts to signal completion this function 958 * If slaves are relying on interrupts to signal completion this function
1009 * must not be called with interrupts disabled. 959 * must not be called with interrupts disabled.
1010 */ 960 */
1011static enum dma_status 961static enum dma_status pl08x_dma_tx_status(struct dma_chan *chan,
1012pl08x_dma_tx_status(struct dma_chan *chan, 962 dma_cookie_t cookie, struct dma_tx_state *txstate)
1013 dma_cookie_t cookie,
1014 struct dma_tx_state *txstate)
1015{ 963{
1016 struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); 964 struct pl08x_dma_chan *plchan = to_pl08x_chan(chan);
1017 dma_cookie_t last_used; 965 dma_cookie_t last_used;
@@ -1253,7 +1201,9 @@ static int pl08x_prep_channel_resources(struct pl08x_dma_chan *plchan,
1253 1201
1254 num_llis = pl08x_fill_llis_for_desc(pl08x, txd); 1202 num_llis = pl08x_fill_llis_for_desc(pl08x, txd);
1255 if (!num_llis) { 1203 if (!num_llis) {
1256 kfree(txd); 1204 spin_lock_irqsave(&plchan->lock, flags);
1205 pl08x_free_txd(pl08x, txd);
1206 spin_unlock_irqrestore(&plchan->lock, flags);
1257 return -EINVAL; 1207 return -EINVAL;
1258 } 1208 }
1259 1209
@@ -1301,13 +1251,14 @@ static int pl08x_prep_channel_resources(struct pl08x_dma_chan *plchan,
1301static struct pl08x_txd *pl08x_get_txd(struct pl08x_dma_chan *plchan, 1251static struct pl08x_txd *pl08x_get_txd(struct pl08x_dma_chan *plchan,
1302 unsigned long flags) 1252 unsigned long flags)
1303{ 1253{
1304 struct pl08x_txd *txd = kzalloc(sizeof(struct pl08x_txd), GFP_NOWAIT); 1254 struct pl08x_txd *txd = kzalloc(sizeof(*txd), GFP_NOWAIT);
1305 1255
1306 if (txd) { 1256 if (txd) {
1307 dma_async_tx_descriptor_init(&txd->tx, &plchan->chan); 1257 dma_async_tx_descriptor_init(&txd->tx, &plchan->chan);
1308 txd->tx.flags = flags; 1258 txd->tx.flags = flags;
1309 txd->tx.tx_submit = pl08x_tx_submit; 1259 txd->tx.tx_submit = pl08x_tx_submit;
1310 INIT_LIST_HEAD(&txd->node); 1260 INIT_LIST_HEAD(&txd->node);
1261 INIT_LIST_HEAD(&txd->dsg_list);
1311 1262
1312 /* Always enable error and terminal interrupts */ 1263 /* Always enable error and terminal interrupts */
1313 txd->ccfg = PL080_CONFIG_ERR_IRQ_MASK | 1264 txd->ccfg = PL080_CONFIG_ERR_IRQ_MASK |
@@ -1326,6 +1277,7 @@ static struct dma_async_tx_descriptor *pl08x_prep_dma_memcpy(
1326 struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); 1277 struct pl08x_dma_chan *plchan = to_pl08x_chan(chan);
1327 struct pl08x_driver_data *pl08x = plchan->host; 1278 struct pl08x_driver_data *pl08x = plchan->host;
1328 struct pl08x_txd *txd; 1279 struct pl08x_txd *txd;
1280 struct pl08x_sg *dsg;
1329 int ret; 1281 int ret;
1330 1282
1331 txd = pl08x_get_txd(plchan, flags); 1283 txd = pl08x_get_txd(plchan, flags);
@@ -1335,10 +1287,19 @@ static struct dma_async_tx_descriptor *pl08x_prep_dma_memcpy(
1335 return NULL; 1287 return NULL;
1336 } 1288 }
1337 1289
1290 dsg = kzalloc(sizeof(struct pl08x_sg), GFP_NOWAIT);
1291 if (!dsg) {
1292 pl08x_free_txd(pl08x, txd);
1293 dev_err(&pl08x->adev->dev, "%s no memory for pl080 sg\n",
1294 __func__);
1295 return NULL;
1296 }
1297 list_add_tail(&dsg->node, &txd->dsg_list);
1298
1338 txd->direction = DMA_NONE; 1299 txd->direction = DMA_NONE;
1339 txd->src_addr = src; 1300 dsg->src_addr = src;
1340 txd->dst_addr = dest; 1301 dsg->dst_addr = dest;
1341 txd->len = len; 1302 dsg->len = len;
1342 1303
1343 /* Set platform data for m2m */ 1304 /* Set platform data for m2m */
1344 txd->ccfg |= PL080_FLOW_MEM2MEM << PL080_CONFIG_FLOW_CONTROL_SHIFT; 1305 txd->ccfg |= PL080_FLOW_MEM2MEM << PL080_CONFIG_FLOW_CONTROL_SHIFT;
@@ -1367,19 +1328,13 @@ static struct dma_async_tx_descriptor *pl08x_prep_slave_sg(
1367 struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); 1328 struct pl08x_dma_chan *plchan = to_pl08x_chan(chan);
1368 struct pl08x_driver_data *pl08x = plchan->host; 1329 struct pl08x_driver_data *pl08x = plchan->host;
1369 struct pl08x_txd *txd; 1330 struct pl08x_txd *txd;
1370 int ret; 1331 struct pl08x_sg *dsg;
1371 1332 struct scatterlist *sg;
1372 /* 1333 dma_addr_t slave_addr;
1373 * Current implementation ASSUMES only one sg 1334 int ret, tmp;
1374 */
1375 if (sg_len != 1) {
1376 dev_err(&pl08x->adev->dev, "%s prepared too long sglist\n",
1377 __func__);
1378 BUG();
1379 }
1380 1335
1381 dev_dbg(&pl08x->adev->dev, "%s prepare transaction of %d bytes from %s\n", 1336 dev_dbg(&pl08x->adev->dev, "%s prepare transaction of %d bytes from %s\n",
1382 __func__, sgl->length, plchan->name); 1337 __func__, sgl->length, plchan->name);
1383 1338
1384 txd = pl08x_get_txd(plchan, flags); 1339 txd = pl08x_get_txd(plchan, flags);
1385 if (!txd) { 1340 if (!txd) {
@@ -1398,24 +1353,49 @@ static struct dma_async_tx_descriptor *pl08x_prep_slave_sg(
1398 * channel target address dynamically at runtime. 1353 * channel target address dynamically at runtime.
1399 */ 1354 */
1400 txd->direction = direction; 1355 txd->direction = direction;
1401 txd->len = sgl->length;
1402 1356
1403 if (direction == DMA_TO_DEVICE) { 1357 if (direction == DMA_TO_DEVICE) {
1404 txd->ccfg |= PL080_FLOW_MEM2PER << PL080_CONFIG_FLOW_CONTROL_SHIFT;
1405 txd->cctl = plchan->dst_cctl; 1358 txd->cctl = plchan->dst_cctl;
1406 txd->src_addr = sgl->dma_address; 1359 slave_addr = plchan->dst_addr;
1407 txd->dst_addr = plchan->dst_addr;
1408 } else if (direction == DMA_FROM_DEVICE) { 1360 } else if (direction == DMA_FROM_DEVICE) {
1409 txd->ccfg |= PL080_FLOW_PER2MEM << PL080_CONFIG_FLOW_CONTROL_SHIFT;
1410 txd->cctl = plchan->src_cctl; 1361 txd->cctl = plchan->src_cctl;
1411 txd->src_addr = plchan->src_addr; 1362 slave_addr = plchan->src_addr;
1412 txd->dst_addr = sgl->dma_address;
1413 } else { 1363 } else {
1364 pl08x_free_txd(pl08x, txd);
1414 dev_err(&pl08x->adev->dev, 1365 dev_err(&pl08x->adev->dev,
1415 "%s direction unsupported\n", __func__); 1366 "%s direction unsupported\n", __func__);
1416 return NULL; 1367 return NULL;
1417 } 1368 }
1418 1369
1370 if (plchan->cd->device_fc)
1371 tmp = (direction == DMA_TO_DEVICE) ? PL080_FLOW_MEM2PER_PER :
1372 PL080_FLOW_PER2MEM_PER;
1373 else
1374 tmp = (direction == DMA_TO_DEVICE) ? PL080_FLOW_MEM2PER :
1375 PL080_FLOW_PER2MEM;
1376
1377 txd->ccfg |= tmp << PL080_CONFIG_FLOW_CONTROL_SHIFT;
1378
1379 for_each_sg(sgl, sg, sg_len, tmp) {
1380 dsg = kzalloc(sizeof(struct pl08x_sg), GFP_NOWAIT);
1381 if (!dsg) {
1382 pl08x_free_txd(pl08x, txd);
1383 dev_err(&pl08x->adev->dev, "%s no mem for pl080 sg\n",
1384 __func__);
1385 return NULL;
1386 }
1387 list_add_tail(&dsg->node, &txd->dsg_list);
1388
1389 dsg->len = sg_dma_len(sg);
1390 if (direction == DMA_TO_DEVICE) {
1391 dsg->src_addr = sg_phys(sg);
1392 dsg->dst_addr = slave_addr;
1393 } else {
1394 dsg->src_addr = slave_addr;
1395 dsg->dst_addr = sg_phys(sg);
1396 }
1397 }
1398
1419 ret = pl08x_prep_channel_resources(plchan, txd); 1399 ret = pl08x_prep_channel_resources(plchan, txd);
1420 if (ret) 1400 if (ret)
1421 return NULL; 1401 return NULL;
@@ -1489,9 +1469,15 @@ static int pl08x_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
1489 1469
1490bool pl08x_filter_id(struct dma_chan *chan, void *chan_id) 1470bool pl08x_filter_id(struct dma_chan *chan, void *chan_id)
1491{ 1471{
1492 struct pl08x_dma_chan *plchan = to_pl08x_chan(chan); 1472 struct pl08x_dma_chan *plchan;
1493 char *name = chan_id; 1473 char *name = chan_id;
1494 1474
1475 /* Reject channels for devices not bound to this driver */
1476 if (chan->device->dev->driver != &pl08x_amba_driver.drv)
1477 return false;
1478
1479 plchan = to_pl08x_chan(chan);
1480
1495 /* Check that the channel is not taken! */ 1481 /* Check that the channel is not taken! */
1496 if (!strcmp(plchan->name, name)) 1482 if (!strcmp(plchan->name, name))
1497 return true; 1483 return true;
@@ -1507,34 +1493,34 @@ bool pl08x_filter_id(struct dma_chan *chan, void *chan_id)
1507 */ 1493 */
1508static void pl08x_ensure_on(struct pl08x_driver_data *pl08x) 1494static void pl08x_ensure_on(struct pl08x_driver_data *pl08x)
1509{ 1495{
1510 u32 val; 1496 writel(PL080_CONFIG_ENABLE, pl08x->base + PL080_CONFIG);
1511
1512 val = readl(pl08x->base + PL080_CONFIG);
1513 val &= ~(PL080_CONFIG_M2_BE | PL080_CONFIG_M1_BE | PL080_CONFIG_ENABLE);
1514 /* We implicitly clear bit 1 and that means little-endian mode */
1515 val |= PL080_CONFIG_ENABLE;
1516 writel(val, pl08x->base + PL080_CONFIG);
1517} 1497}
1518 1498
1519static void pl08x_unmap_buffers(struct pl08x_txd *txd) 1499static void pl08x_unmap_buffers(struct pl08x_txd *txd)
1520{ 1500{
1521 struct device *dev = txd->tx.chan->device->dev; 1501 struct device *dev = txd->tx.chan->device->dev;
1502 struct pl08x_sg *dsg;
1522 1503
1523 if (!(txd->tx.flags & DMA_COMPL_SKIP_SRC_UNMAP)) { 1504 if (!(txd->tx.flags & DMA_COMPL_SKIP_SRC_UNMAP)) {
1524 if (txd->tx.flags & DMA_COMPL_SRC_UNMAP_SINGLE) 1505 if (txd->tx.flags & DMA_COMPL_SRC_UNMAP_SINGLE)
1525 dma_unmap_single(dev, txd->src_addr, txd->len, 1506 list_for_each_entry(dsg, &txd->dsg_list, node)
1526 DMA_TO_DEVICE); 1507 dma_unmap_single(dev, dsg->src_addr, dsg->len,
1527 else 1508 DMA_TO_DEVICE);
1528 dma_unmap_page(dev, txd->src_addr, txd->len, 1509 else {
1529 DMA_TO_DEVICE); 1510 list_for_each_entry(dsg, &txd->dsg_list, node)
1511 dma_unmap_page(dev, dsg->src_addr, dsg->len,
1512 DMA_TO_DEVICE);
1513 }
1530 } 1514 }
1531 if (!(txd->tx.flags & DMA_COMPL_SKIP_DEST_UNMAP)) { 1515 if (!(txd->tx.flags & DMA_COMPL_SKIP_DEST_UNMAP)) {
1532 if (txd->tx.flags & DMA_COMPL_DEST_UNMAP_SINGLE) 1516 if (txd->tx.flags & DMA_COMPL_DEST_UNMAP_SINGLE)
1533 dma_unmap_single(dev, txd->dst_addr, txd->len, 1517 list_for_each_entry(dsg, &txd->dsg_list, node)
1534 DMA_FROM_DEVICE); 1518 dma_unmap_single(dev, dsg->dst_addr, dsg->len,
1519 DMA_FROM_DEVICE);
1535 else 1520 else
1536 dma_unmap_page(dev, txd->dst_addr, txd->len, 1521 list_for_each_entry(dsg, &txd->dsg_list, node)
1537 DMA_FROM_DEVICE); 1522 dma_unmap_page(dev, dsg->dst_addr, dsg->len,
1523 DMA_FROM_DEVICE);
1538 } 1524 }
1539} 1525}
1540 1526
@@ -1589,8 +1575,8 @@ static void pl08x_tasklet(unsigned long data)
1589 */ 1575 */
1590 list_for_each_entry(waiting, &pl08x->memcpy.channels, 1576 list_for_each_entry(waiting, &pl08x->memcpy.channels,
1591 chan.device_node) { 1577 chan.device_node) {
1592 if (waiting->state == PL08X_CHAN_WAITING && 1578 if (waiting->state == PL08X_CHAN_WAITING &&
1593 waiting->waiting != NULL) { 1579 waiting->waiting != NULL) {
1594 int ret; 1580 int ret;
1595 1581
1596 /* This should REALLY not fail now */ 1582 /* This should REALLY not fail now */
@@ -1630,38 +1616,40 @@ static void pl08x_tasklet(unsigned long data)
1630static irqreturn_t pl08x_irq(int irq, void *dev) 1616static irqreturn_t pl08x_irq(int irq, void *dev)
1631{ 1617{
1632 struct pl08x_driver_data *pl08x = dev; 1618 struct pl08x_driver_data *pl08x = dev;
1633 u32 mask = 0; 1619 u32 mask = 0, err, tc, i;
1634 u32 val; 1620
1635 int i; 1621 /* check & clear - ERR & TC interrupts */
1636 1622 err = readl(pl08x->base + PL080_ERR_STATUS);
1637 val = readl(pl08x->base + PL080_ERR_STATUS); 1623 if (err) {
1638 if (val) { 1624 dev_err(&pl08x->adev->dev, "%s error interrupt, register value 0x%08x\n",
1639 /* An error interrupt (on one or more channels) */ 1625 __func__, err);
1640 dev_err(&pl08x->adev->dev, 1626 writel(err, pl08x->base + PL080_ERR_CLEAR);
1641 "%s error interrupt, register value 0x%08x\n",
1642 __func__, val);
1643 /*
1644 * Simply clear ALL PL08X error interrupts,
1645 * regardless of channel and cause
1646 * FIXME: should be 0x00000003 on PL081 really.
1647 */
1648 writel(0x000000FF, pl08x->base + PL080_ERR_CLEAR);
1649 } 1627 }
1650 val = readl(pl08x->base + PL080_INT_STATUS); 1628 tc = readl(pl08x->base + PL080_INT_STATUS);
1629 if (tc)
1630 writel(tc, pl08x->base + PL080_TC_CLEAR);
1631
1632 if (!err && !tc)
1633 return IRQ_NONE;
1634
1651 for (i = 0; i < pl08x->vd->channels; i++) { 1635 for (i = 0; i < pl08x->vd->channels; i++) {
1652 if ((1 << i) & val) { 1636 if (((1 << i) & err) || ((1 << i) & tc)) {
1653 /* Locate physical channel */ 1637 /* Locate physical channel */
1654 struct pl08x_phy_chan *phychan = &pl08x->phy_chans[i]; 1638 struct pl08x_phy_chan *phychan = &pl08x->phy_chans[i];
1655 struct pl08x_dma_chan *plchan = phychan->serving; 1639 struct pl08x_dma_chan *plchan = phychan->serving;
1656 1640
1641 if (!plchan) {
1642 dev_err(&pl08x->adev->dev,
1643 "%s Error TC interrupt on unused channel: 0x%08x\n",
1644 __func__, i);
1645 continue;
1646 }
1647
1657 /* Schedule tasklet on this channel */ 1648 /* Schedule tasklet on this channel */
1658 tasklet_schedule(&plchan->tasklet); 1649 tasklet_schedule(&plchan->tasklet);
1659
1660 mask |= (1 << i); 1650 mask |= (1 << i);
1661 } 1651 }
1662 } 1652 }
1663 /* Clear only the terminal interrupts on channels we processed */
1664 writel(mask, pl08x->base + PL080_TC_CLEAR);
1665 1653
1666 return mask ? IRQ_HANDLED : IRQ_NONE; 1654 return mask ? IRQ_HANDLED : IRQ_NONE;
1667} 1655}
@@ -1685,9 +1673,7 @@ static void pl08x_dma_slave_init(struct pl08x_dma_chan *chan)
1685 * Make a local wrapper to hold required data 1673 * Make a local wrapper to hold required data
1686 */ 1674 */
1687static int pl08x_dma_init_virtual_channels(struct pl08x_driver_data *pl08x, 1675static int pl08x_dma_init_virtual_channels(struct pl08x_driver_data *pl08x,
1688 struct dma_device *dmadev, 1676 struct dma_device *dmadev, unsigned int channels, bool slave)
1689 unsigned int channels,
1690 bool slave)
1691{ 1677{
1692 struct pl08x_dma_chan *chan; 1678 struct pl08x_dma_chan *chan;
1693 int i; 1679 int i;
@@ -1700,7 +1686,7 @@ static int pl08x_dma_init_virtual_channels(struct pl08x_driver_data *pl08x,
1700 * to cope with that situation. 1686 * to cope with that situation.
1701 */ 1687 */
1702 for (i = 0; i < channels; i++) { 1688 for (i = 0; i < channels; i++) {
1703 chan = kzalloc(sizeof(struct pl08x_dma_chan), GFP_KERNEL); 1689 chan = kzalloc(sizeof(*chan), GFP_KERNEL);
1704 if (!chan) { 1690 if (!chan) {
1705 dev_err(&pl08x->adev->dev, 1691 dev_err(&pl08x->adev->dev,
1706 "%s no memory for channel\n", __func__); 1692 "%s no memory for channel\n", __func__);
@@ -1728,7 +1714,7 @@ static int pl08x_dma_init_virtual_channels(struct pl08x_driver_data *pl08x,
1728 kfree(chan); 1714 kfree(chan);
1729 continue; 1715 continue;
1730 } 1716 }
1731 dev_info(&pl08x->adev->dev, 1717 dev_dbg(&pl08x->adev->dev,
1732 "initialize virtual channel \"%s\"\n", 1718 "initialize virtual channel \"%s\"\n",
1733 chan->name); 1719 chan->name);
1734 1720
@@ -1837,9 +1823,9 @@ static const struct file_operations pl08x_debugfs_operations = {
1837static void init_pl08x_debugfs(struct pl08x_driver_data *pl08x) 1823static void init_pl08x_debugfs(struct pl08x_driver_data *pl08x)
1838{ 1824{
1839 /* Expose a simple debugfs interface to view all clocks */ 1825 /* Expose a simple debugfs interface to view all clocks */
1840 (void) debugfs_create_file(dev_name(&pl08x->adev->dev), S_IFREG | S_IRUGO, 1826 (void) debugfs_create_file(dev_name(&pl08x->adev->dev),
1841 NULL, pl08x, 1827 S_IFREG | S_IRUGO, NULL, pl08x,
1842 &pl08x_debugfs_operations); 1828 &pl08x_debugfs_operations);
1843} 1829}
1844 1830
1845#else 1831#else
@@ -1860,12 +1846,15 @@ static int pl08x_probe(struct amba_device *adev, const struct amba_id *id)
1860 return ret; 1846 return ret;
1861 1847
1862 /* Create the driver state holder */ 1848 /* Create the driver state holder */
1863 pl08x = kzalloc(sizeof(struct pl08x_driver_data), GFP_KERNEL); 1849 pl08x = kzalloc(sizeof(*pl08x), GFP_KERNEL);
1864 if (!pl08x) { 1850 if (!pl08x) {
1865 ret = -ENOMEM; 1851 ret = -ENOMEM;
1866 goto out_no_pl08x; 1852 goto out_no_pl08x;
1867 } 1853 }
1868 1854
1855 pm_runtime_set_active(&adev->dev);
1856 pm_runtime_enable(&adev->dev);
1857
1869 /* Initialize memcpy engine */ 1858 /* Initialize memcpy engine */
1870 dma_cap_set(DMA_MEMCPY, pl08x->memcpy.cap_mask); 1859 dma_cap_set(DMA_MEMCPY, pl08x->memcpy.cap_mask);
1871 pl08x->memcpy.dev = &adev->dev; 1860 pl08x->memcpy.dev = &adev->dev;
@@ -1939,7 +1928,7 @@ static int pl08x_probe(struct amba_device *adev, const struct amba_id *id)
1939 } 1928 }
1940 1929
1941 /* Initialize physical channels */ 1930 /* Initialize physical channels */
1942 pl08x->phy_chans = kmalloc((vd->channels * sizeof(struct pl08x_phy_chan)), 1931 pl08x->phy_chans = kmalloc((vd->channels * sizeof(*pl08x->phy_chans)),
1943 GFP_KERNEL); 1932 GFP_KERNEL);
1944 if (!pl08x->phy_chans) { 1933 if (!pl08x->phy_chans) {
1945 dev_err(&adev->dev, "%s failed to allocate " 1934 dev_err(&adev->dev, "%s failed to allocate "
@@ -1956,9 +1945,8 @@ static int pl08x_probe(struct amba_device *adev, const struct amba_id *id)
1956 spin_lock_init(&ch->lock); 1945 spin_lock_init(&ch->lock);
1957 ch->serving = NULL; 1946 ch->serving = NULL;
1958 ch->signal = -1; 1947 ch->signal = -1;
1959 dev_info(&adev->dev, 1948 dev_dbg(&adev->dev, "physical channel %d is %s\n",
1960 "physical channel %d is %s\n", i, 1949 i, pl08x_phy_channel_busy(ch) ? "BUSY" : "FREE");
1961 pl08x_phy_channel_busy(ch) ? "BUSY" : "FREE");
1962 } 1950 }
1963 1951
1964 /* Register as many memcpy channels as there are physical channels */ 1952 /* Register as many memcpy channels as there are physical channels */
@@ -1974,8 +1962,7 @@ static int pl08x_probe(struct amba_device *adev, const struct amba_id *id)
1974 1962
1975 /* Register slave channels */ 1963 /* Register slave channels */
1976 ret = pl08x_dma_init_virtual_channels(pl08x, &pl08x->slave, 1964 ret = pl08x_dma_init_virtual_channels(pl08x, &pl08x->slave,
1977 pl08x->pd->num_slave_channels, 1965 pl08x->pd->num_slave_channels, true);
1978 true);
1979 if (ret <= 0) { 1966 if (ret <= 0) {
1980 dev_warn(&pl08x->adev->dev, 1967 dev_warn(&pl08x->adev->dev,
1981 "%s failed to enumerate slave channels - %d\n", 1968 "%s failed to enumerate slave channels - %d\n",
@@ -2005,6 +1992,8 @@ static int pl08x_probe(struct amba_device *adev, const struct amba_id *id)
2005 dev_info(&pl08x->adev->dev, "DMA: PL%03x rev%u at 0x%08llx irq %d\n", 1992 dev_info(&pl08x->adev->dev, "DMA: PL%03x rev%u at 0x%08llx irq %d\n",
2006 amba_part(adev), amba_rev(adev), 1993 amba_part(adev), amba_rev(adev),
2007 (unsigned long long)adev->res.start, adev->irq[0]); 1994 (unsigned long long)adev->res.start, adev->irq[0]);
1995
1996 pm_runtime_put(&adev->dev);
2008 return 0; 1997 return 0;
2009 1998
2010out_no_slave_reg: 1999out_no_slave_reg:
@@ -2023,6 +2012,9 @@ out_no_ioremap:
2023 dma_pool_destroy(pl08x->pool); 2012 dma_pool_destroy(pl08x->pool);
2024out_no_lli_pool: 2013out_no_lli_pool:
2025out_no_platdata: 2014out_no_platdata:
2015 pm_runtime_put(&adev->dev);
2016 pm_runtime_disable(&adev->dev);
2017
2026 kfree(pl08x); 2018 kfree(pl08x);
2027out_no_pl08x: 2019out_no_pl08x:
2028 amba_release_regions(adev); 2020 amba_release_regions(adev);
diff --git a/drivers/dma/at_hdmac.c b/drivers/dma/at_hdmac.c
index 6a483eac7b3f..fcfa0a8b5c59 100644
--- a/drivers/dma/at_hdmac.c
+++ b/drivers/dma/at_hdmac.c
@@ -107,10 +107,11 @@ static struct at_desc *atc_desc_get(struct at_dma_chan *atchan)
107{ 107{
108 struct at_desc *desc, *_desc; 108 struct at_desc *desc, *_desc;
109 struct at_desc *ret = NULL; 109 struct at_desc *ret = NULL;
110 unsigned long flags;
110 unsigned int i = 0; 111 unsigned int i = 0;
111 LIST_HEAD(tmp_list); 112 LIST_HEAD(tmp_list);
112 113
113 spin_lock_bh(&atchan->lock); 114 spin_lock_irqsave(&atchan->lock, flags);
114 list_for_each_entry_safe(desc, _desc, &atchan->free_list, desc_node) { 115 list_for_each_entry_safe(desc, _desc, &atchan->free_list, desc_node) {
115 i++; 116 i++;
116 if (async_tx_test_ack(&desc->txd)) { 117 if (async_tx_test_ack(&desc->txd)) {
@@ -121,7 +122,7 @@ static struct at_desc *atc_desc_get(struct at_dma_chan *atchan)
121 dev_dbg(chan2dev(&atchan->chan_common), 122 dev_dbg(chan2dev(&atchan->chan_common),
122 "desc %p not ACKed\n", desc); 123 "desc %p not ACKed\n", desc);
123 } 124 }
124 spin_unlock_bh(&atchan->lock); 125 spin_unlock_irqrestore(&atchan->lock, flags);
125 dev_vdbg(chan2dev(&atchan->chan_common), 126 dev_vdbg(chan2dev(&atchan->chan_common),
126 "scanned %u descriptors on freelist\n", i); 127 "scanned %u descriptors on freelist\n", i);
127 128
@@ -129,9 +130,9 @@ static struct at_desc *atc_desc_get(struct at_dma_chan *atchan)
129 if (!ret) { 130 if (!ret) {
130 ret = atc_alloc_descriptor(&atchan->chan_common, GFP_ATOMIC); 131 ret = atc_alloc_descriptor(&atchan->chan_common, GFP_ATOMIC);
131 if (ret) { 132 if (ret) {
132 spin_lock_bh(&atchan->lock); 133 spin_lock_irqsave(&atchan->lock, flags);
133 atchan->descs_allocated++; 134 atchan->descs_allocated++;
134 spin_unlock_bh(&atchan->lock); 135 spin_unlock_irqrestore(&atchan->lock, flags);
135 } else { 136 } else {
136 dev_err(chan2dev(&atchan->chan_common), 137 dev_err(chan2dev(&atchan->chan_common),
137 "not enough descriptors available\n"); 138 "not enough descriptors available\n");
@@ -150,8 +151,9 @@ static void atc_desc_put(struct at_dma_chan *atchan, struct at_desc *desc)
150{ 151{
151 if (desc) { 152 if (desc) {
152 struct at_desc *child; 153 struct at_desc *child;
154 unsigned long flags;
153 155
154 spin_lock_bh(&atchan->lock); 156 spin_lock_irqsave(&atchan->lock, flags);
155 list_for_each_entry(child, &desc->tx_list, desc_node) 157 list_for_each_entry(child, &desc->tx_list, desc_node)
156 dev_vdbg(chan2dev(&atchan->chan_common), 158 dev_vdbg(chan2dev(&atchan->chan_common),
157 "moving child desc %p to freelist\n", 159 "moving child desc %p to freelist\n",
@@ -160,7 +162,7 @@ static void atc_desc_put(struct at_dma_chan *atchan, struct at_desc *desc)
160 dev_vdbg(chan2dev(&atchan->chan_common), 162 dev_vdbg(chan2dev(&atchan->chan_common),
161 "moving desc %p to freelist\n", desc); 163 "moving desc %p to freelist\n", desc);
162 list_add(&desc->desc_node, &atchan->free_list); 164 list_add(&desc->desc_node, &atchan->free_list);
163 spin_unlock_bh(&atchan->lock); 165 spin_unlock_irqrestore(&atchan->lock, flags);
164 } 166 }
165} 167}
166 168
@@ -299,7 +301,7 @@ atc_chain_complete(struct at_dma_chan *atchan, struct at_desc *desc)
299 301
300 /* for cyclic transfers, 302 /* for cyclic transfers,
301 * no need to replay callback function while stopping */ 303 * no need to replay callback function while stopping */
302 if (!test_bit(ATC_IS_CYCLIC, &atchan->status)) { 304 if (!atc_chan_is_cyclic(atchan)) {
303 dma_async_tx_callback callback = txd->callback; 305 dma_async_tx_callback callback = txd->callback;
304 void *param = txd->callback_param; 306 void *param = txd->callback_param;
305 307
@@ -471,16 +473,17 @@ static void atc_handle_cyclic(struct at_dma_chan *atchan)
471static void atc_tasklet(unsigned long data) 473static void atc_tasklet(unsigned long data)
472{ 474{
473 struct at_dma_chan *atchan = (struct at_dma_chan *)data; 475 struct at_dma_chan *atchan = (struct at_dma_chan *)data;
476 unsigned long flags;
474 477
475 spin_lock(&atchan->lock); 478 spin_lock_irqsave(&atchan->lock, flags);
476 if (test_and_clear_bit(ATC_IS_ERROR, &atchan->status)) 479 if (test_and_clear_bit(ATC_IS_ERROR, &atchan->status))
477 atc_handle_error(atchan); 480 atc_handle_error(atchan);
478 else if (test_bit(ATC_IS_CYCLIC, &atchan->status)) 481 else if (atc_chan_is_cyclic(atchan))
479 atc_handle_cyclic(atchan); 482 atc_handle_cyclic(atchan);
480 else 483 else
481 atc_advance_work(atchan); 484 atc_advance_work(atchan);
482 485
483 spin_unlock(&atchan->lock); 486 spin_unlock_irqrestore(&atchan->lock, flags);
484} 487}
485 488
486static irqreturn_t at_dma_interrupt(int irq, void *dev_id) 489static irqreturn_t at_dma_interrupt(int irq, void *dev_id)
@@ -539,8 +542,9 @@ static dma_cookie_t atc_tx_submit(struct dma_async_tx_descriptor *tx)
539 struct at_desc *desc = txd_to_at_desc(tx); 542 struct at_desc *desc = txd_to_at_desc(tx);
540 struct at_dma_chan *atchan = to_at_dma_chan(tx->chan); 543 struct at_dma_chan *atchan = to_at_dma_chan(tx->chan);
541 dma_cookie_t cookie; 544 dma_cookie_t cookie;
545 unsigned long flags;
542 546
543 spin_lock_bh(&atchan->lock); 547 spin_lock_irqsave(&atchan->lock, flags);
544 cookie = atc_assign_cookie(atchan, desc); 548 cookie = atc_assign_cookie(atchan, desc);
545 549
546 if (list_empty(&atchan->active_list)) { 550 if (list_empty(&atchan->active_list)) {
@@ -554,7 +558,7 @@ static dma_cookie_t atc_tx_submit(struct dma_async_tx_descriptor *tx)
554 list_add_tail(&desc->desc_node, &atchan->queue); 558 list_add_tail(&desc->desc_node, &atchan->queue);
555 } 559 }
556 560
557 spin_unlock_bh(&atchan->lock); 561 spin_unlock_irqrestore(&atchan->lock, flags);
558 562
559 return cookie; 563 return cookie;
560} 564}
@@ -927,28 +931,29 @@ static int atc_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
927 struct at_dma_chan *atchan = to_at_dma_chan(chan); 931 struct at_dma_chan *atchan = to_at_dma_chan(chan);
928 struct at_dma *atdma = to_at_dma(chan->device); 932 struct at_dma *atdma = to_at_dma(chan->device);
929 int chan_id = atchan->chan_common.chan_id; 933 int chan_id = atchan->chan_common.chan_id;
934 unsigned long flags;
930 935
931 LIST_HEAD(list); 936 LIST_HEAD(list);
932 937
933 dev_vdbg(chan2dev(chan), "atc_control (%d)\n", cmd); 938 dev_vdbg(chan2dev(chan), "atc_control (%d)\n", cmd);
934 939
935 if (cmd == DMA_PAUSE) { 940 if (cmd == DMA_PAUSE) {
936 spin_lock_bh(&atchan->lock); 941 spin_lock_irqsave(&atchan->lock, flags);
937 942
938 dma_writel(atdma, CHER, AT_DMA_SUSP(chan_id)); 943 dma_writel(atdma, CHER, AT_DMA_SUSP(chan_id));
939 set_bit(ATC_IS_PAUSED, &atchan->status); 944 set_bit(ATC_IS_PAUSED, &atchan->status);
940 945
941 spin_unlock_bh(&atchan->lock); 946 spin_unlock_irqrestore(&atchan->lock, flags);
942 } else if (cmd == DMA_RESUME) { 947 } else if (cmd == DMA_RESUME) {
943 if (!test_bit(ATC_IS_PAUSED, &atchan->status)) 948 if (!atc_chan_is_paused(atchan))
944 return 0; 949 return 0;
945 950
946 spin_lock_bh(&atchan->lock); 951 spin_lock_irqsave(&atchan->lock, flags);
947 952
948 dma_writel(atdma, CHDR, AT_DMA_RES(chan_id)); 953 dma_writel(atdma, CHDR, AT_DMA_RES(chan_id));
949 clear_bit(ATC_IS_PAUSED, &atchan->status); 954 clear_bit(ATC_IS_PAUSED, &atchan->status);
950 955
951 spin_unlock_bh(&atchan->lock); 956 spin_unlock_irqrestore(&atchan->lock, flags);
952 } else if (cmd == DMA_TERMINATE_ALL) { 957 } else if (cmd == DMA_TERMINATE_ALL) {
953 struct at_desc *desc, *_desc; 958 struct at_desc *desc, *_desc;
954 /* 959 /*
@@ -957,7 +962,7 @@ static int atc_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
957 * channel. We still have to poll the channel enable bit due 962 * channel. We still have to poll the channel enable bit due
958 * to AHB/HSB limitations. 963 * to AHB/HSB limitations.
959 */ 964 */
960 spin_lock_bh(&atchan->lock); 965 spin_lock_irqsave(&atchan->lock, flags);
961 966
962 /* disabling channel: must also remove suspend state */ 967 /* disabling channel: must also remove suspend state */
963 dma_writel(atdma, CHDR, AT_DMA_RES(chan_id) | atchan->mask); 968 dma_writel(atdma, CHDR, AT_DMA_RES(chan_id) | atchan->mask);
@@ -978,7 +983,7 @@ static int atc_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
978 /* if channel dedicated to cyclic operations, free it */ 983 /* if channel dedicated to cyclic operations, free it */
979 clear_bit(ATC_IS_CYCLIC, &atchan->status); 984 clear_bit(ATC_IS_CYCLIC, &atchan->status);
980 985
981 spin_unlock_bh(&atchan->lock); 986 spin_unlock_irqrestore(&atchan->lock, flags);
982 } else { 987 } else {
983 return -ENXIO; 988 return -ENXIO;
984 } 989 }
@@ -1004,9 +1009,10 @@ atc_tx_status(struct dma_chan *chan,
1004 struct at_dma_chan *atchan = to_at_dma_chan(chan); 1009 struct at_dma_chan *atchan = to_at_dma_chan(chan);
1005 dma_cookie_t last_used; 1010 dma_cookie_t last_used;
1006 dma_cookie_t last_complete; 1011 dma_cookie_t last_complete;
1012 unsigned long flags;
1007 enum dma_status ret; 1013 enum dma_status ret;
1008 1014
1009 spin_lock_bh(&atchan->lock); 1015 spin_lock_irqsave(&atchan->lock, flags);
1010 1016
1011 last_complete = atchan->completed_cookie; 1017 last_complete = atchan->completed_cookie;
1012 last_used = chan->cookie; 1018 last_used = chan->cookie;
@@ -1021,7 +1027,7 @@ atc_tx_status(struct dma_chan *chan,
1021 ret = dma_async_is_complete(cookie, last_complete, last_used); 1027 ret = dma_async_is_complete(cookie, last_complete, last_used);
1022 } 1028 }
1023 1029
1024 spin_unlock_bh(&atchan->lock); 1030 spin_unlock_irqrestore(&atchan->lock, flags);
1025 1031
1026 if (ret != DMA_SUCCESS) 1032 if (ret != DMA_SUCCESS)
1027 dma_set_tx_state(txstate, last_complete, last_used, 1033 dma_set_tx_state(txstate, last_complete, last_used,
@@ -1029,7 +1035,7 @@ atc_tx_status(struct dma_chan *chan,
1029 else 1035 else
1030 dma_set_tx_state(txstate, last_complete, last_used, 0); 1036 dma_set_tx_state(txstate, last_complete, last_used, 0);
1031 1037
1032 if (test_bit(ATC_IS_PAUSED, &atchan->status)) 1038 if (atc_chan_is_paused(atchan))
1033 ret = DMA_PAUSED; 1039 ret = DMA_PAUSED;
1034 1040
1035 dev_vdbg(chan2dev(chan), "tx_status %d: cookie = %d (d%d, u%d)\n", 1041 dev_vdbg(chan2dev(chan), "tx_status %d: cookie = %d (d%d, u%d)\n",
@@ -1046,18 +1052,19 @@ atc_tx_status(struct dma_chan *chan,
1046static void atc_issue_pending(struct dma_chan *chan) 1052static void atc_issue_pending(struct dma_chan *chan)
1047{ 1053{
1048 struct at_dma_chan *atchan = to_at_dma_chan(chan); 1054 struct at_dma_chan *atchan = to_at_dma_chan(chan);
1055 unsigned long flags;
1049 1056
1050 dev_vdbg(chan2dev(chan), "issue_pending\n"); 1057 dev_vdbg(chan2dev(chan), "issue_pending\n");
1051 1058
1052 /* Not needed for cyclic transfers */ 1059 /* Not needed for cyclic transfers */
1053 if (test_bit(ATC_IS_CYCLIC, &atchan->status)) 1060 if (atc_chan_is_cyclic(atchan))
1054 return; 1061 return;
1055 1062
1056 spin_lock_bh(&atchan->lock); 1063 spin_lock_irqsave(&atchan->lock, flags);
1057 if (!atc_chan_is_enabled(atchan)) { 1064 if (!atc_chan_is_enabled(atchan)) {
1058 atc_advance_work(atchan); 1065 atc_advance_work(atchan);
1059 } 1066 }
1060 spin_unlock_bh(&atchan->lock); 1067 spin_unlock_irqrestore(&atchan->lock, flags);
1061} 1068}
1062 1069
1063/** 1070/**
@@ -1073,6 +1080,7 @@ static int atc_alloc_chan_resources(struct dma_chan *chan)
1073 struct at_dma *atdma = to_at_dma(chan->device); 1080 struct at_dma *atdma = to_at_dma(chan->device);
1074 struct at_desc *desc; 1081 struct at_desc *desc;
1075 struct at_dma_slave *atslave; 1082 struct at_dma_slave *atslave;
1083 unsigned long flags;
1076 int i; 1084 int i;
1077 u32 cfg; 1085 u32 cfg;
1078 LIST_HEAD(tmp_list); 1086 LIST_HEAD(tmp_list);
@@ -1116,11 +1124,11 @@ static int atc_alloc_chan_resources(struct dma_chan *chan)
1116 list_add_tail(&desc->desc_node, &tmp_list); 1124 list_add_tail(&desc->desc_node, &tmp_list);
1117 } 1125 }
1118 1126
1119 spin_lock_bh(&atchan->lock); 1127 spin_lock_irqsave(&atchan->lock, flags);
1120 atchan->descs_allocated = i; 1128 atchan->descs_allocated = i;
1121 list_splice(&tmp_list, &atchan->free_list); 1129 list_splice(&tmp_list, &atchan->free_list);
1122 atchan->completed_cookie = chan->cookie = 1; 1130 atchan->completed_cookie = chan->cookie = 1;
1123 spin_unlock_bh(&atchan->lock); 1131 spin_unlock_irqrestore(&atchan->lock, flags);
1124 1132
1125 /* channel parameters */ 1133 /* channel parameters */
1126 channel_writel(atchan, CFG, cfg); 1134 channel_writel(atchan, CFG, cfg);
@@ -1260,12 +1268,11 @@ static int __init at_dma_probe(struct platform_device *pdev)
1260 1268
1261 /* initialize channels related values */ 1269 /* initialize channels related values */
1262 INIT_LIST_HEAD(&atdma->dma_common.channels); 1270 INIT_LIST_HEAD(&atdma->dma_common.channels);
1263 for (i = 0; i < pdata->nr_channels; i++, atdma->dma_common.chancnt++) { 1271 for (i = 0; i < pdata->nr_channels; i++) {
1264 struct at_dma_chan *atchan = &atdma->chan[i]; 1272 struct at_dma_chan *atchan = &atdma->chan[i];
1265 1273
1266 atchan->chan_common.device = &atdma->dma_common; 1274 atchan->chan_common.device = &atdma->dma_common;
1267 atchan->chan_common.cookie = atchan->completed_cookie = 1; 1275 atchan->chan_common.cookie = atchan->completed_cookie = 1;
1268 atchan->chan_common.chan_id = i;
1269 list_add_tail(&atchan->chan_common.device_node, 1276 list_add_tail(&atchan->chan_common.device_node,
1270 &atdma->dma_common.channels); 1277 &atdma->dma_common.channels);
1271 1278
@@ -1293,22 +1300,20 @@ static int __init at_dma_probe(struct platform_device *pdev)
1293 if (dma_has_cap(DMA_MEMCPY, atdma->dma_common.cap_mask)) 1300 if (dma_has_cap(DMA_MEMCPY, atdma->dma_common.cap_mask))
1294 atdma->dma_common.device_prep_dma_memcpy = atc_prep_dma_memcpy; 1301 atdma->dma_common.device_prep_dma_memcpy = atc_prep_dma_memcpy;
1295 1302
1296 if (dma_has_cap(DMA_SLAVE, atdma->dma_common.cap_mask)) 1303 if (dma_has_cap(DMA_SLAVE, atdma->dma_common.cap_mask)) {
1297 atdma->dma_common.device_prep_slave_sg = atc_prep_slave_sg; 1304 atdma->dma_common.device_prep_slave_sg = atc_prep_slave_sg;
1298 1305 /* controller can do slave DMA: can trigger cyclic transfers */
1299 if (dma_has_cap(DMA_CYCLIC, atdma->dma_common.cap_mask)) 1306 dma_cap_set(DMA_CYCLIC, atdma->dma_common.cap_mask);
1300 atdma->dma_common.device_prep_dma_cyclic = atc_prep_dma_cyclic; 1307 atdma->dma_common.device_prep_dma_cyclic = atc_prep_dma_cyclic;
1301
1302 if (dma_has_cap(DMA_SLAVE, atdma->dma_common.cap_mask) ||
1303 dma_has_cap(DMA_CYCLIC, atdma->dma_common.cap_mask))
1304 atdma->dma_common.device_control = atc_control; 1308 atdma->dma_common.device_control = atc_control;
1309 }
1305 1310
1306 dma_writel(atdma, EN, AT_DMA_ENABLE); 1311 dma_writel(atdma, EN, AT_DMA_ENABLE);
1307 1312
1308 dev_info(&pdev->dev, "Atmel AHB DMA Controller ( %s%s), %d channels\n", 1313 dev_info(&pdev->dev, "Atmel AHB DMA Controller ( %s%s), %d channels\n",
1309 dma_has_cap(DMA_MEMCPY, atdma->dma_common.cap_mask) ? "cpy " : "", 1314 dma_has_cap(DMA_MEMCPY, atdma->dma_common.cap_mask) ? "cpy " : "",
1310 dma_has_cap(DMA_SLAVE, atdma->dma_common.cap_mask) ? "slave " : "", 1315 dma_has_cap(DMA_SLAVE, atdma->dma_common.cap_mask) ? "slave " : "",
1311 atdma->dma_common.chancnt); 1316 pdata->nr_channels);
1312 1317
1313 dma_async_device_register(&atdma->dma_common); 1318 dma_async_device_register(&atdma->dma_common);
1314 1319
@@ -1377,27 +1382,112 @@ static void at_dma_shutdown(struct platform_device *pdev)
1377 clk_disable(atdma->clk); 1382 clk_disable(atdma->clk);
1378} 1383}
1379 1384
1385static int at_dma_prepare(struct device *dev)
1386{
1387 struct platform_device *pdev = to_platform_device(dev);
1388 struct at_dma *atdma = platform_get_drvdata(pdev);
1389 struct dma_chan *chan, *_chan;
1390
1391 list_for_each_entry_safe(chan, _chan, &atdma->dma_common.channels,
1392 device_node) {
1393 struct at_dma_chan *atchan = to_at_dma_chan(chan);
1394 /* wait for transaction completion (except in cyclic case) */
1395 if (atc_chan_is_enabled(atchan) && !atc_chan_is_cyclic(atchan))
1396 return -EAGAIN;
1397 }
1398 return 0;
1399}
1400
1401static void atc_suspend_cyclic(struct at_dma_chan *atchan)
1402{
1403 struct dma_chan *chan = &atchan->chan_common;
1404
1405 /* Channel should be paused by user
1406 * do it anyway even if it is not done already */
1407 if (!atc_chan_is_paused(atchan)) {
1408 dev_warn(chan2dev(chan),
1409 "cyclic channel not paused, should be done by channel user\n");
1410 atc_control(chan, DMA_PAUSE, 0);
1411 }
1412
1413 /* now preserve additional data for cyclic operations */
1414 /* next descriptor address in the cyclic list */
1415 atchan->save_dscr = channel_readl(atchan, DSCR);
1416
1417 vdbg_dump_regs(atchan);
1418}
1419
1380static int at_dma_suspend_noirq(struct device *dev) 1420static int at_dma_suspend_noirq(struct device *dev)
1381{ 1421{
1382 struct platform_device *pdev = to_platform_device(dev); 1422 struct platform_device *pdev = to_platform_device(dev);
1383 struct at_dma *atdma = platform_get_drvdata(pdev); 1423 struct at_dma *atdma = platform_get_drvdata(pdev);
1424 struct dma_chan *chan, *_chan;
1384 1425
1385 at_dma_off(platform_get_drvdata(pdev)); 1426 /* preserve data */
1427 list_for_each_entry_safe(chan, _chan, &atdma->dma_common.channels,
1428 device_node) {
1429 struct at_dma_chan *atchan = to_at_dma_chan(chan);
1430
1431 if (atc_chan_is_cyclic(atchan))
1432 atc_suspend_cyclic(atchan);
1433 atchan->save_cfg = channel_readl(atchan, CFG);
1434 }
1435 atdma->save_imr = dma_readl(atdma, EBCIMR);
1436
1437 /* disable DMA controller */
1438 at_dma_off(atdma);
1386 clk_disable(atdma->clk); 1439 clk_disable(atdma->clk);
1387 return 0; 1440 return 0;
1388} 1441}
1389 1442
1443static void atc_resume_cyclic(struct at_dma_chan *atchan)
1444{
1445 struct at_dma *atdma = to_at_dma(atchan->chan_common.device);
1446
1447 /* restore channel status for cyclic descriptors list:
1448 * next descriptor in the cyclic list at the time of suspend */
1449 channel_writel(atchan, SADDR, 0);
1450 channel_writel(atchan, DADDR, 0);
1451 channel_writel(atchan, CTRLA, 0);
1452 channel_writel(atchan, CTRLB, 0);
1453 channel_writel(atchan, DSCR, atchan->save_dscr);
1454 dma_writel(atdma, CHER, atchan->mask);
1455
1456 /* channel pause status should be removed by channel user
1457 * We cannot take the initiative to do it here */
1458
1459 vdbg_dump_regs(atchan);
1460}
1461
1390static int at_dma_resume_noirq(struct device *dev) 1462static int at_dma_resume_noirq(struct device *dev)
1391{ 1463{
1392 struct platform_device *pdev = to_platform_device(dev); 1464 struct platform_device *pdev = to_platform_device(dev);
1393 struct at_dma *atdma = platform_get_drvdata(pdev); 1465 struct at_dma *atdma = platform_get_drvdata(pdev);
1466 struct dma_chan *chan, *_chan;
1394 1467
1468 /* bring back DMA controller */
1395 clk_enable(atdma->clk); 1469 clk_enable(atdma->clk);
1396 dma_writel(atdma, EN, AT_DMA_ENABLE); 1470 dma_writel(atdma, EN, AT_DMA_ENABLE);
1471
1472 /* clear any pending interrupt */
1473 while (dma_readl(atdma, EBCISR))
1474 cpu_relax();
1475
1476 /* restore saved data */
1477 dma_writel(atdma, EBCIER, atdma->save_imr);
1478 list_for_each_entry_safe(chan, _chan, &atdma->dma_common.channels,
1479 device_node) {
1480 struct at_dma_chan *atchan = to_at_dma_chan(chan);
1481
1482 channel_writel(atchan, CFG, atchan->save_cfg);
1483 if (atc_chan_is_cyclic(atchan))
1484 atc_resume_cyclic(atchan);
1485 }
1397 return 0; 1486 return 0;
1398} 1487}
1399 1488
1400static const struct dev_pm_ops at_dma_dev_pm_ops = { 1489static const struct dev_pm_ops at_dma_dev_pm_ops = {
1490 .prepare = at_dma_prepare,
1401 .suspend_noirq = at_dma_suspend_noirq, 1491 .suspend_noirq = at_dma_suspend_noirq,
1402 .resume_noirq = at_dma_resume_noirq, 1492 .resume_noirq = at_dma_resume_noirq,
1403}; 1493};
diff --git a/drivers/dma/at_hdmac_regs.h b/drivers/dma/at_hdmac_regs.h
index 087dbf1dd39c..aa4c9aebab7c 100644
--- a/drivers/dma/at_hdmac_regs.h
+++ b/drivers/dma/at_hdmac_regs.h
@@ -204,6 +204,9 @@ enum atc_status {
204 * @status: transmit status information from irq/prep* functions 204 * @status: transmit status information from irq/prep* functions
205 * to tasklet (use atomic operations) 205 * to tasklet (use atomic operations)
206 * @tasklet: bottom half to finish transaction work 206 * @tasklet: bottom half to finish transaction work
207 * @save_cfg: configuration register that is saved on suspend/resume cycle
208 * @save_dscr: for cyclic operations, preserve next descriptor address in
209 * the cyclic list on suspend/resume cycle
207 * @lock: serializes enqueue/dequeue operations to descriptors lists 210 * @lock: serializes enqueue/dequeue operations to descriptors lists
208 * @completed_cookie: identifier for the most recently completed operation 211 * @completed_cookie: identifier for the most recently completed operation
209 * @active_list: list of descriptors dmaengine is being running on 212 * @active_list: list of descriptors dmaengine is being running on
@@ -218,6 +221,8 @@ struct at_dma_chan {
218 u8 mask; 221 u8 mask;
219 unsigned long status; 222 unsigned long status;
220 struct tasklet_struct tasklet; 223 struct tasklet_struct tasklet;
224 u32 save_cfg;
225 u32 save_dscr;
221 226
222 spinlock_t lock; 227 spinlock_t lock;
223 228
@@ -248,6 +253,7 @@ static inline struct at_dma_chan *to_at_dma_chan(struct dma_chan *dchan)
248 * @chan_common: common dmaengine dma_device object members 253 * @chan_common: common dmaengine dma_device object members
249 * @ch_regs: memory mapped register base 254 * @ch_regs: memory mapped register base
250 * @clk: dma controller clock 255 * @clk: dma controller clock
256 * @save_imr: interrupt mask register that is saved on suspend/resume cycle
251 * @all_chan_mask: all channels availlable in a mask 257 * @all_chan_mask: all channels availlable in a mask
252 * @dma_desc_pool: base of DMA descriptor region (DMA address) 258 * @dma_desc_pool: base of DMA descriptor region (DMA address)
253 * @chan: channels table to store at_dma_chan structures 259 * @chan: channels table to store at_dma_chan structures
@@ -256,6 +262,7 @@ struct at_dma {
256 struct dma_device dma_common; 262 struct dma_device dma_common;
257 void __iomem *regs; 263 void __iomem *regs;
258 struct clk *clk; 264 struct clk *clk;
265 u32 save_imr;
259 266
260 u8 all_chan_mask; 267 u8 all_chan_mask;
261 268
@@ -355,6 +362,23 @@ static inline int atc_chan_is_enabled(struct at_dma_chan *atchan)
355 return !!(dma_readl(atdma, CHSR) & atchan->mask); 362 return !!(dma_readl(atdma, CHSR) & atchan->mask);
356} 363}
357 364
365/**
366 * atc_chan_is_paused - test channel pause/resume status
367 * @atchan: channel we want to test status
368 */
369static inline int atc_chan_is_paused(struct at_dma_chan *atchan)
370{
371 return test_bit(ATC_IS_PAUSED, &atchan->status);
372}
373
374/**
375 * atc_chan_is_cyclic - test if given channel has cyclic property set
376 * @atchan: channel we want to test status
377 */
378static inline int atc_chan_is_cyclic(struct at_dma_chan *atchan)
379{
380 return test_bit(ATC_IS_CYCLIC, &atchan->status);
381}
358 382
359/** 383/**
360 * set_desc_eol - set end-of-link to descriptor so it will end transfer 384 * set_desc_eol - set end-of-link to descriptor so it will end transfer
diff --git a/drivers/dma/dmatest.c b/drivers/dma/dmatest.c
index 765f5ff22304..eb1d8641cf5c 100644
--- a/drivers/dma/dmatest.c
+++ b/drivers/dma/dmatest.c
@@ -10,6 +10,7 @@
10#include <linux/delay.h> 10#include <linux/delay.h>
11#include <linux/dma-mapping.h> 11#include <linux/dma-mapping.h>
12#include <linux/dmaengine.h> 12#include <linux/dmaengine.h>
13#include <linux/freezer.h>
13#include <linux/init.h> 14#include <linux/init.h>
14#include <linux/kthread.h> 15#include <linux/kthread.h>
15#include <linux/module.h> 16#include <linux/module.h>
@@ -251,6 +252,7 @@ static int dmatest_func(void *data)
251 int i; 252 int i;
252 253
253 thread_name = current->comm; 254 thread_name = current->comm;
255 set_freezable_with_signal();
254 256
255 ret = -ENOMEM; 257 ret = -ENOMEM;
256 258
@@ -305,7 +307,8 @@ static int dmatest_func(void *data)
305 dma_addr_t dma_srcs[src_cnt]; 307 dma_addr_t dma_srcs[src_cnt];
306 dma_addr_t dma_dsts[dst_cnt]; 308 dma_addr_t dma_dsts[dst_cnt];
307 struct completion cmp; 309 struct completion cmp;
308 unsigned long tmo = msecs_to_jiffies(timeout); 310 unsigned long start, tmo, end = 0 /* compiler... */;
311 bool reload = true;
309 u8 align = 0; 312 u8 align = 0;
310 313
311 total_tests++; 314 total_tests++;
@@ -404,7 +407,17 @@ static int dmatest_func(void *data)
404 } 407 }
405 dma_async_issue_pending(chan); 408 dma_async_issue_pending(chan);
406 409
407 tmo = wait_for_completion_timeout(&cmp, tmo); 410 do {
411 start = jiffies;
412 if (reload)
413 end = start + msecs_to_jiffies(timeout);
414 else if (end <= start)
415 end = start + 1;
416 tmo = wait_for_completion_interruptible_timeout(&cmp,
417 end - start);
418 reload = try_to_freeze();
419 } while (tmo == -ERESTARTSYS);
420
408 status = dma_async_is_tx_complete(chan, cookie, NULL, NULL); 421 status = dma_async_is_tx_complete(chan, cookie, NULL, NULL);
409 422
410 if (tmo == 0) { 423 if (tmo == 0) {
@@ -477,6 +490,8 @@ err_srcs:
477 pr_notice("%s: terminating after %u tests, %u failures (status %d)\n", 490 pr_notice("%s: terminating after %u tests, %u failures (status %d)\n",
478 thread_name, total_tests, failed_tests, ret); 491 thread_name, total_tests, failed_tests, ret);
479 492
493 /* terminate all transfers on specified channels */
494 chan->device->device_control(chan, DMA_TERMINATE_ALL, 0);
480 if (iterations > 0) 495 if (iterations > 0)
481 while (!kthread_should_stop()) { 496 while (!kthread_should_stop()) {
482 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wait_dmatest_exit); 497 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wait_dmatest_exit);
@@ -499,6 +514,10 @@ static void dmatest_cleanup_channel(struct dmatest_chan *dtc)
499 list_del(&thread->node); 514 list_del(&thread->node);
500 kfree(thread); 515 kfree(thread);
501 } 516 }
517
518 /* terminate all transfers on specified channels */
519 dtc->chan->device->device_control(dtc->chan, DMA_TERMINATE_ALL, 0);
520
502 kfree(dtc); 521 kfree(dtc);
503} 522}
504 523
diff --git a/drivers/dma/dw_dmac.c b/drivers/dma/dw_dmac.c
index 4d180ca9a1d8..9bfd6d360718 100644
--- a/drivers/dma/dw_dmac.c
+++ b/drivers/dma/dw_dmac.c
@@ -1407,12 +1407,11 @@ static int __init dw_probe(struct platform_device *pdev)
1407 dw->all_chan_mask = (1 << pdata->nr_channels) - 1; 1407 dw->all_chan_mask = (1 << pdata->nr_channels) - 1;
1408 1408
1409 INIT_LIST_HEAD(&dw->dma.channels); 1409 INIT_LIST_HEAD(&dw->dma.channels);
1410 for (i = 0; i < pdata->nr_channels; i++, dw->dma.chancnt++) { 1410 for (i = 0; i < pdata->nr_channels; i++) {
1411 struct dw_dma_chan *dwc = &dw->chan[i]; 1411 struct dw_dma_chan *dwc = &dw->chan[i];
1412 1412
1413 dwc->chan.device = &dw->dma; 1413 dwc->chan.device = &dw->dma;
1414 dwc->chan.cookie = dwc->completed = 1; 1414 dwc->chan.cookie = dwc->completed = 1;
1415 dwc->chan.chan_id = i;
1416 if (pdata->chan_allocation_order == CHAN_ALLOCATION_ASCENDING) 1415 if (pdata->chan_allocation_order == CHAN_ALLOCATION_ASCENDING)
1417 list_add_tail(&dwc->chan.device_node, 1416 list_add_tail(&dwc->chan.device_node,
1418 &dw->dma.channels); 1417 &dw->dma.channels);
@@ -1468,7 +1467,7 @@ static int __init dw_probe(struct platform_device *pdev)
1468 dma_writel(dw, CFG, DW_CFG_DMA_EN); 1467 dma_writel(dw, CFG, DW_CFG_DMA_EN);
1469 1468
1470 printk(KERN_INFO "%s: DesignWare DMA Controller, %d channels\n", 1469 printk(KERN_INFO "%s: DesignWare DMA Controller, %d channels\n",
1471 dev_name(&pdev->dev), dw->dma.chancnt); 1470 dev_name(&pdev->dev), pdata->nr_channels);
1472 1471
1473 dma_async_device_register(&dw->dma); 1472 dma_async_device_register(&dw->dma);
1474 1473
diff --git a/drivers/dma/ep93xx_dma.c b/drivers/dma/ep93xx_dma.c
index 5d7a49bd7c26..b47e2b803faf 100644
--- a/drivers/dma/ep93xx_dma.c
+++ b/drivers/dma/ep93xx_dma.c
@@ -22,6 +22,7 @@
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/interrupt.h> 23#include <linux/interrupt.h>
24#include <linux/dmaengine.h> 24#include <linux/dmaengine.h>
25#include <linux/module.h>
25#include <linux/platform_device.h> 26#include <linux/platform_device.h>
26#include <linux/slab.h> 27#include <linux/slab.h>
27 28
diff --git a/drivers/dma/imx-dma.c b/drivers/dma/imx-dma.c
index d99f71c356b5..4be55f9bb6c1 100644
--- a/drivers/dma/imx-dma.c
+++ b/drivers/dma/imx-dma.c
@@ -14,6 +14,7 @@
14 * http://www.gnu.org/copyleft/gpl.html 14 * http://www.gnu.org/copyleft/gpl.html
15 */ 15 */
16#include <linux/init.h> 16#include <linux/init.h>
17#include <linux/module.h>
17#include <linux/types.h> 18#include <linux/types.h>
18#include <linux/mm.h> 19#include <linux/mm.h>
19#include <linux/interrupt.h> 20#include <linux/interrupt.h>
@@ -23,6 +24,7 @@
23#include <linux/slab.h> 24#include <linux/slab.h>
24#include <linux/platform_device.h> 25#include <linux/platform_device.h>
25#include <linux/dmaengine.h> 26#include <linux/dmaengine.h>
27#include <linux/module.h>
26 28
27#include <asm/irq.h> 29#include <asm/irq.h>
28#include <mach/dma-v1.h> 30#include <mach/dma-v1.h>
diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index 7bd7e98548cd..f993955a640c 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -18,6 +18,7 @@
18 */ 18 */
19 19
20#include <linux/init.h> 20#include <linux/init.h>
21#include <linux/module.h>
21#include <linux/types.h> 22#include <linux/types.h>
22#include <linux/mm.h> 23#include <linux/mm.h>
23#include <linux/interrupt.h> 24#include <linux/interrupt.h>
@@ -34,6 +35,7 @@
34#include <linux/dmaengine.h> 35#include <linux/dmaengine.h>
35#include <linux/of.h> 36#include <linux/of.h>
36#include <linux/of_device.h> 37#include <linux/of_device.h>
38#include <linux/module.h>
37 39
38#include <asm/irq.h> 40#include <asm/irq.h>
39#include <mach/sdma.h> 41#include <mach/sdma.h>
@@ -318,6 +320,7 @@ struct sdma_engine {
318 dma_addr_t context_phys; 320 dma_addr_t context_phys;
319 struct dma_device dma_device; 321 struct dma_device dma_device;
320 struct clk *clk; 322 struct clk *clk;
323 struct mutex channel_0_lock;
321 struct sdma_script_start_addrs *script_addrs; 324 struct sdma_script_start_addrs *script_addrs;
322}; 325};
323 326
@@ -415,11 +418,15 @@ static int sdma_load_script(struct sdma_engine *sdma, void *buf, int size,
415 dma_addr_t buf_phys; 418 dma_addr_t buf_phys;
416 int ret; 419 int ret;
417 420
421 mutex_lock(&sdma->channel_0_lock);
422
418 buf_virt = dma_alloc_coherent(NULL, 423 buf_virt = dma_alloc_coherent(NULL,
419 size, 424 size,
420 &buf_phys, GFP_KERNEL); 425 &buf_phys, GFP_KERNEL);
421 if (!buf_virt) 426 if (!buf_virt) {
422 return -ENOMEM; 427 ret = -ENOMEM;
428 goto err_out;
429 }
423 430
424 bd0->mode.command = C0_SETPM; 431 bd0->mode.command = C0_SETPM;
425 bd0->mode.status = BD_DONE | BD_INTR | BD_WRAP | BD_EXTD; 432 bd0->mode.status = BD_DONE | BD_INTR | BD_WRAP | BD_EXTD;
@@ -433,6 +440,9 @@ static int sdma_load_script(struct sdma_engine *sdma, void *buf, int size,
433 440
434 dma_free_coherent(NULL, size, buf_virt, buf_phys); 441 dma_free_coherent(NULL, size, buf_virt, buf_phys);
435 442
443err_out:
444 mutex_unlock(&sdma->channel_0_lock);
445
436 return ret; 446 return ret;
437} 447}
438 448
@@ -656,6 +666,8 @@ static int sdma_load_context(struct sdma_channel *sdmac)
656 dev_dbg(sdma->dev, "event_mask0 = 0x%08x\n", sdmac->event_mask0); 666 dev_dbg(sdma->dev, "event_mask0 = 0x%08x\n", sdmac->event_mask0);
657 dev_dbg(sdma->dev, "event_mask1 = 0x%08x\n", sdmac->event_mask1); 667 dev_dbg(sdma->dev, "event_mask1 = 0x%08x\n", sdmac->event_mask1);
658 668
669 mutex_lock(&sdma->channel_0_lock);
670
659 memset(context, 0, sizeof(*context)); 671 memset(context, 0, sizeof(*context));
660 context->channel_state.pc = load_address; 672 context->channel_state.pc = load_address;
661 673
@@ -676,6 +688,8 @@ static int sdma_load_context(struct sdma_channel *sdmac)
676 688
677 ret = sdma_run_channel(&sdma->channel[0]); 689 ret = sdma_run_channel(&sdma->channel[0]);
678 690
691 mutex_unlock(&sdma->channel_0_lock);
692
679 return ret; 693 return ret;
680} 694}
681 695
@@ -1131,18 +1145,17 @@ static void sdma_add_scripts(struct sdma_engine *sdma,
1131 saddr_arr[i] = addr_arr[i]; 1145 saddr_arr[i] = addr_arr[i];
1132} 1146}
1133 1147
1134static int __init sdma_get_firmware(struct sdma_engine *sdma, 1148static void sdma_load_firmware(const struct firmware *fw, void *context)
1135 const char *fw_name)
1136{ 1149{
1137 const struct firmware *fw; 1150 struct sdma_engine *sdma = context;
1138 const struct sdma_firmware_header *header; 1151 const struct sdma_firmware_header *header;
1139 int ret;
1140 const struct sdma_script_start_addrs *addr; 1152 const struct sdma_script_start_addrs *addr;
1141 unsigned short *ram_code; 1153 unsigned short *ram_code;
1142 1154
1143 ret = request_firmware(&fw, fw_name, sdma->dev); 1155 if (!fw) {
1144 if (ret) 1156 dev_err(sdma->dev, "firmware not found\n");
1145 return ret; 1157 return;
1158 }
1146 1159
1147 if (fw->size < sizeof(*header)) 1160 if (fw->size < sizeof(*header))
1148 goto err_firmware; 1161 goto err_firmware;
@@ -1172,6 +1185,16 @@ static int __init sdma_get_firmware(struct sdma_engine *sdma,
1172 1185
1173err_firmware: 1186err_firmware:
1174 release_firmware(fw); 1187 release_firmware(fw);
1188}
1189
1190static int __init sdma_get_firmware(struct sdma_engine *sdma,
1191 const char *fw_name)
1192{
1193 int ret;
1194
1195 ret = request_firmware_nowait(THIS_MODULE,
1196 FW_ACTION_HOTPLUG, fw_name, sdma->dev,
1197 GFP_KERNEL, sdma, sdma_load_firmware);
1175 1198
1176 return ret; 1199 return ret;
1177} 1200}
@@ -1269,11 +1292,14 @@ static int __init sdma_probe(struct platform_device *pdev)
1269 struct sdma_platform_data *pdata = pdev->dev.platform_data; 1292 struct sdma_platform_data *pdata = pdev->dev.platform_data;
1270 int i; 1293 int i;
1271 struct sdma_engine *sdma; 1294 struct sdma_engine *sdma;
1295 s32 *saddr_arr;
1272 1296
1273 sdma = kzalloc(sizeof(*sdma), GFP_KERNEL); 1297 sdma = kzalloc(sizeof(*sdma), GFP_KERNEL);
1274 if (!sdma) 1298 if (!sdma)
1275 return -ENOMEM; 1299 return -ENOMEM;
1276 1300
1301 mutex_init(&sdma->channel_0_lock);
1302
1277 sdma->dev = &pdev->dev; 1303 sdma->dev = &pdev->dev;
1278 1304
1279 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1305 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -1310,6 +1336,11 @@ static int __init sdma_probe(struct platform_device *pdev)
1310 goto err_alloc; 1336 goto err_alloc;
1311 } 1337 }
1312 1338
1339 /* initially no scripts available */
1340 saddr_arr = (s32 *)sdma->script_addrs;
1341 for (i = 0; i < SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V1; i++)
1342 saddr_arr[i] = -EINVAL;
1343
1313 if (of_id) 1344 if (of_id)
1314 pdev->id_entry = of_id->data; 1345 pdev->id_entry = of_id->data;
1315 sdma->devtype = pdev->id_entry->driver_data; 1346 sdma->devtype = pdev->id_entry->driver_data;
diff --git a/drivers/dma/intel_mid_dma.c b/drivers/dma/intel_mid_dma.c
index 8a3fdd87db97..19a0c64d45d3 100644
--- a/drivers/dma/intel_mid_dma.c
+++ b/drivers/dma/intel_mid_dma.c
@@ -27,6 +27,7 @@
27#include <linux/interrupt.h> 27#include <linux/interrupt.h>
28#include <linux/pm_runtime.h> 28#include <linux/pm_runtime.h>
29#include <linux/intel_mid_dma.h> 29#include <linux/intel_mid_dma.h>
30#include <linux/module.h>
30 31
31#define MAX_CHAN 4 /*max ch across controllers*/ 32#define MAX_CHAN 4 /*max ch across controllers*/
32#include "intel_mid_dma_regs.h" 33#include "intel_mid_dma_regs.h"
@@ -115,16 +116,15 @@ DMAC1 interrupt Functions*/
115 116
116/** 117/**
117 * dmac1_mask_periphral_intr - mask the periphral interrupt 118 * dmac1_mask_periphral_intr - mask the periphral interrupt
118 * @midc: dma channel for which masking is required 119 * @mid: dma device for which masking is required
119 * 120 *
120 * Masks the DMA periphral interrupt 121 * Masks the DMA periphral interrupt
121 * this is valid for DMAC1 family controllers only 122 * this is valid for DMAC1 family controllers only
122 * This controller should have periphral mask registers already mapped 123 * This controller should have periphral mask registers already mapped
123 */ 124 */
124static void dmac1_mask_periphral_intr(struct intel_mid_dma_chan *midc) 125static void dmac1_mask_periphral_intr(struct middma_device *mid)
125{ 126{
126 u32 pimr; 127 u32 pimr;
127 struct middma_device *mid = to_middma_device(midc->chan.device);
128 128
129 if (mid->pimr_mask) { 129 if (mid->pimr_mask) {
130 pimr = readl(mid->mask_reg + LNW_PERIPHRAL_MASK); 130 pimr = readl(mid->mask_reg + LNW_PERIPHRAL_MASK);
@@ -184,7 +184,6 @@ static void enable_dma_interrupt(struct intel_mid_dma_chan *midc)
184static void disable_dma_interrupt(struct intel_mid_dma_chan *midc) 184static void disable_dma_interrupt(struct intel_mid_dma_chan *midc)
185{ 185{
186 /*Check LPE PISR, make sure fwd is disabled*/ 186 /*Check LPE PISR, make sure fwd is disabled*/
187 dmac1_mask_periphral_intr(midc);
188 iowrite32(MASK_INTR_REG(midc->ch_id), midc->dma_base + MASK_BLOCK); 187 iowrite32(MASK_INTR_REG(midc->ch_id), midc->dma_base + MASK_BLOCK);
189 iowrite32(MASK_INTR_REG(midc->ch_id), midc->dma_base + MASK_TFR); 188 iowrite32(MASK_INTR_REG(midc->ch_id), midc->dma_base + MASK_TFR);
190 iowrite32(MASK_INTR_REG(midc->ch_id), midc->dma_base + MASK_ERR); 189 iowrite32(MASK_INTR_REG(midc->ch_id), midc->dma_base + MASK_ERR);
@@ -1114,7 +1113,6 @@ static int mid_setup_dma(struct pci_dev *pdev)
1114 1113
1115 midch->chan.device = &dma->common; 1114 midch->chan.device = &dma->common;
1116 midch->chan.cookie = 1; 1115 midch->chan.cookie = 1;
1117 midch->chan.chan_id = i;
1118 midch->ch_id = dma->chan_base + i; 1116 midch->ch_id = dma->chan_base + i;
1119 pr_debug("MDMA:Init CH %d, ID %d\n", i, midch->ch_id); 1117 pr_debug("MDMA:Init CH %d, ID %d\n", i, midch->ch_id);
1120 1118
@@ -1150,7 +1148,6 @@ static int mid_setup_dma(struct pci_dev *pdev)
1150 dma_cap_set(DMA_SLAVE, dma->common.cap_mask); 1148 dma_cap_set(DMA_SLAVE, dma->common.cap_mask);
1151 dma_cap_set(DMA_PRIVATE, dma->common.cap_mask); 1149 dma_cap_set(DMA_PRIVATE, dma->common.cap_mask);
1152 dma->common.dev = &pdev->dev; 1150 dma->common.dev = &pdev->dev;
1153 dma->common.chancnt = dma->max_chan;
1154 1151
1155 dma->common.device_alloc_chan_resources = 1152 dma->common.device_alloc_chan_resources =
1156 intel_mid_dma_alloc_chan_resources; 1153 intel_mid_dma_alloc_chan_resources;
@@ -1350,6 +1347,7 @@ int dma_suspend(struct pci_dev *pci, pm_message_t state)
1350 if (device->ch[i].in_use) 1347 if (device->ch[i].in_use)
1351 return -EAGAIN; 1348 return -EAGAIN;
1352 } 1349 }
1350 dmac1_mask_periphral_intr(device);
1353 device->state = SUSPENDED; 1351 device->state = SUSPENDED;
1354 pci_save_state(pci); 1352 pci_save_state(pci);
1355 pci_disable_device(pci); 1353 pci_disable_device(pci);
diff --git a/drivers/dma/ipu/ipu_idmac.c b/drivers/dma/ipu/ipu_idmac.c
index 6815905a772f..0e5ef33f90a1 100644
--- a/drivers/dma/ipu/ipu_idmac.c
+++ b/drivers/dma/ipu/ipu_idmac.c
@@ -21,6 +21,7 @@
21#include <linux/string.h> 21#include <linux/string.h>
22#include <linux/interrupt.h> 22#include <linux/interrupt.h>
23#include <linux/io.h> 23#include <linux/io.h>
24#include <linux/module.h>
24 25
25#include <mach/ipu.h> 26#include <mach/ipu.h>
26 27
@@ -1307,6 +1308,7 @@ static irqreturn_t idmac_interrupt(int irq, void *dev_id)
1307 ipu_submit_buffer(ichan, descnew, sgnew, ichan->active_buffer) < 0) { 1308 ipu_submit_buffer(ichan, descnew, sgnew, ichan->active_buffer) < 0) {
1308 callback = descnew->txd.callback; 1309 callback = descnew->txd.callback;
1309 callback_param = descnew->txd.callback_param; 1310 callback_param = descnew->txd.callback_param;
1311 list_del_init(&descnew->list);
1310 spin_unlock(&ichan->lock); 1312 spin_unlock(&ichan->lock);
1311 if (callback) 1313 if (callback)
1312 callback(callback_param); 1314 callback(callback_param);
@@ -1428,39 +1430,58 @@ static int __idmac_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
1428{ 1430{
1429 struct idmac_channel *ichan = to_idmac_chan(chan); 1431 struct idmac_channel *ichan = to_idmac_chan(chan);
1430 struct idmac *idmac = to_idmac(chan->device); 1432 struct idmac *idmac = to_idmac(chan->device);
1433 struct ipu *ipu = to_ipu(idmac);
1434 struct list_head *list, *tmp;
1431 unsigned long flags; 1435 unsigned long flags;
1432 int i; 1436 int i;
1433 1437
1434 /* Only supports DMA_TERMINATE_ALL */ 1438 switch (cmd) {
1435 if (cmd != DMA_TERMINATE_ALL) 1439 case DMA_PAUSE:
1436 return -ENXIO; 1440 spin_lock_irqsave(&ipu->lock, flags);
1441 ipu_ic_disable_task(ipu, chan->chan_id);
1437 1442
1438 ipu_disable_channel(idmac, ichan, 1443 /* Return all descriptors into "prepared" state */
1439 ichan->status >= IPU_CHANNEL_ENABLED); 1444 list_for_each_safe(list, tmp, &ichan->queue)
1445 list_del_init(list);
1440 1446
1441 tasklet_disable(&to_ipu(idmac)->tasklet); 1447 ichan->sg[0] = NULL;
1448 ichan->sg[1] = NULL;
1442 1449
1443 /* ichan->queue is modified in ISR, have to spinlock */ 1450 spin_unlock_irqrestore(&ipu->lock, flags);
1444 spin_lock_irqsave(&ichan->lock, flags);
1445 list_splice_init(&ichan->queue, &ichan->free_list);
1446 1451
1447 if (ichan->desc) 1452 ichan->status = IPU_CHANNEL_INITIALIZED;
1448 for (i = 0; i < ichan->n_tx_desc; i++) { 1453 break;
1449 struct idmac_tx_desc *desc = ichan->desc + i; 1454 case DMA_TERMINATE_ALL:
1450 if (list_empty(&desc->list)) 1455 ipu_disable_channel(idmac, ichan,
1451 /* Descriptor was prepared, but not submitted */ 1456 ichan->status >= IPU_CHANNEL_ENABLED);
1452 list_add(&desc->list, &ichan->free_list);
1453 1457
1454 async_tx_clear_ack(&desc->txd); 1458 tasklet_disable(&ipu->tasklet);
1455 }
1456 1459
1457 ichan->sg[0] = NULL; 1460 /* ichan->queue is modified in ISR, have to spinlock */
1458 ichan->sg[1] = NULL; 1461 spin_lock_irqsave(&ichan->lock, flags);
1459 spin_unlock_irqrestore(&ichan->lock, flags); 1462 list_splice_init(&ichan->queue, &ichan->free_list);
1460 1463
1461 tasklet_enable(&to_ipu(idmac)->tasklet); 1464 if (ichan->desc)
1465 for (i = 0; i < ichan->n_tx_desc; i++) {
1466 struct idmac_tx_desc *desc = ichan->desc + i;
1467 if (list_empty(&desc->list))
1468 /* Descriptor was prepared, but not submitted */
1469 list_add(&desc->list, &ichan->free_list);
1462 1470
1463 ichan->status = IPU_CHANNEL_INITIALIZED; 1471 async_tx_clear_ack(&desc->txd);
1472 }
1473
1474 ichan->sg[0] = NULL;
1475 ichan->sg[1] = NULL;
1476 spin_unlock_irqrestore(&ichan->lock, flags);
1477
1478 tasklet_enable(&ipu->tasklet);
1479
1480 ichan->status = IPU_CHANNEL_INITIALIZED;
1481 break;
1482 default:
1483 return -ENOSYS;
1484 }
1464 1485
1465 return 0; 1486 return 0;
1466} 1487}
@@ -1663,7 +1684,6 @@ static void __exit ipu_idmac_exit(struct ipu *ipu)
1663 struct idmac_channel *ichan = ipu->channel + i; 1684 struct idmac_channel *ichan = ipu->channel + i;
1664 1685
1665 idmac_control(&ichan->dma_chan, DMA_TERMINATE_ALL, 0); 1686 idmac_control(&ichan->dma_chan, DMA_TERMINATE_ALL, 0);
1666 idmac_prep_slave_sg(&ichan->dma_chan, NULL, 0, DMA_NONE, 0);
1667 } 1687 }
1668 1688
1669 dma_async_device_unregister(&idmac->dma); 1689 dma_async_device_unregister(&idmac->dma);
diff --git a/drivers/dma/mpc512x_dma.c b/drivers/dma/mpc512x_dma.c
index b9bae94f2015..8ba4edc6185e 100644
--- a/drivers/dma/mpc512x_dma.c
+++ b/drivers/dma/mpc512x_dma.c
@@ -741,7 +741,6 @@ static int __devinit mpc_dma_probe(struct platform_device *op)
741 mchan = &mdma->channels[i]; 741 mchan = &mdma->channels[i];
742 742
743 mchan->chan.device = dma; 743 mchan->chan.device = dma;
744 mchan->chan.chan_id = i;
745 mchan->chan.cookie = 1; 744 mchan->chan.cookie = 1;
746 mchan->completed_cookie = mchan->chan.cookie; 745 mchan->completed_cookie = mchan->chan.cookie;
747 746
diff --git a/drivers/dma/mxs-dma.c b/drivers/dma/mxs-dma.c
index be641cbd36fc..b4588bdd98bb 100644
--- a/drivers/dma/mxs-dma.c
+++ b/drivers/dma/mxs-dma.c
@@ -130,6 +130,23 @@ struct mxs_dma_engine {
130 struct mxs_dma_chan mxs_chans[MXS_DMA_CHANNELS]; 130 struct mxs_dma_chan mxs_chans[MXS_DMA_CHANNELS];
131}; 131};
132 132
133static inline void mxs_dma_clkgate(struct mxs_dma_chan *mxs_chan, int enable)
134{
135 struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma;
136 int chan_id = mxs_chan->chan.chan_id;
137 int set_clr = enable ? MXS_CLR_ADDR : MXS_SET_ADDR;
138
139 /* enable apbh channel clock */
140 if (dma_is_apbh()) {
141 if (apbh_is_old())
142 writel(1 << (chan_id + BP_APBH_CTRL0_CLKGATE_CHANNEL),
143 mxs_dma->base + HW_APBHX_CTRL0 + set_clr);
144 else
145 writel(1 << chan_id,
146 mxs_dma->base + HW_APBHX_CTRL0 + set_clr);
147 }
148}
149
133static void mxs_dma_reset_chan(struct mxs_dma_chan *mxs_chan) 150static void mxs_dma_reset_chan(struct mxs_dma_chan *mxs_chan)
134{ 151{
135 struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma; 152 struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma;
@@ -148,38 +165,21 @@ static void mxs_dma_enable_chan(struct mxs_dma_chan *mxs_chan)
148 struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma; 165 struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma;
149 int chan_id = mxs_chan->chan.chan_id; 166 int chan_id = mxs_chan->chan.chan_id;
150 167
168 /* clkgate needs to be enabled before writing other registers */
169 mxs_dma_clkgate(mxs_chan, 1);
170
151 /* set cmd_addr up */ 171 /* set cmd_addr up */
152 writel(mxs_chan->ccw_phys, 172 writel(mxs_chan->ccw_phys,
153 mxs_dma->base + HW_APBHX_CHn_NXTCMDAR(chan_id)); 173 mxs_dma->base + HW_APBHX_CHn_NXTCMDAR(chan_id));
154 174
155 /* enable apbh channel clock */
156 if (dma_is_apbh()) {
157 if (apbh_is_old())
158 writel(1 << (chan_id + BP_APBH_CTRL0_CLKGATE_CHANNEL),
159 mxs_dma->base + HW_APBHX_CTRL0 + MXS_CLR_ADDR);
160 else
161 writel(1 << chan_id,
162 mxs_dma->base + HW_APBHX_CTRL0 + MXS_CLR_ADDR);
163 }
164
165 /* write 1 to SEMA to kick off the channel */ 175 /* write 1 to SEMA to kick off the channel */
166 writel(1, mxs_dma->base + HW_APBHX_CHn_SEMA(chan_id)); 176 writel(1, mxs_dma->base + HW_APBHX_CHn_SEMA(chan_id));
167} 177}
168 178
169static void mxs_dma_disable_chan(struct mxs_dma_chan *mxs_chan) 179static void mxs_dma_disable_chan(struct mxs_dma_chan *mxs_chan)
170{ 180{
171 struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma;
172 int chan_id = mxs_chan->chan.chan_id;
173
174 /* disable apbh channel clock */ 181 /* disable apbh channel clock */
175 if (dma_is_apbh()) { 182 mxs_dma_clkgate(mxs_chan, 0);
176 if (apbh_is_old())
177 writel(1 << (chan_id + BP_APBH_CTRL0_CLKGATE_CHANNEL),
178 mxs_dma->base + HW_APBHX_CTRL0 + MXS_SET_ADDR);
179 else
180 writel(1 << chan_id,
181 mxs_dma->base + HW_APBHX_CTRL0 + MXS_SET_ADDR);
182 }
183 183
184 mxs_chan->status = DMA_SUCCESS; 184 mxs_chan->status = DMA_SUCCESS;
185} 185}
@@ -338,7 +338,10 @@ static int mxs_dma_alloc_chan_resources(struct dma_chan *chan)
338 if (ret) 338 if (ret)
339 goto err_clk; 339 goto err_clk;
340 340
341 /* clkgate needs to be enabled for reset to finish */
342 mxs_dma_clkgate(mxs_chan, 1);
341 mxs_dma_reset_chan(mxs_chan); 343 mxs_dma_reset_chan(mxs_chan);
344 mxs_dma_clkgate(mxs_chan, 0);
342 345
343 dma_async_tx_descriptor_init(&mxs_chan->desc, chan); 346 dma_async_tx_descriptor_init(&mxs_chan->desc, chan);
344 mxs_chan->desc.tx_submit = mxs_dma_tx_submit; 347 mxs_chan->desc.tx_submit = mxs_dma_tx_submit;
diff --git a/drivers/dma/pch_dma.c b/drivers/dma/pch_dma.c
index 1ac8d4b580b7..a6d0e3dbed07 100644
--- a/drivers/dma/pch_dma.c
+++ b/drivers/dma/pch_dma.c
@@ -60,7 +60,7 @@
60#define DMA_DESC_FOLLOW_WITHOUT_IRQ 0x2 60#define DMA_DESC_FOLLOW_WITHOUT_IRQ 0x2
61#define DMA_DESC_FOLLOW_WITH_IRQ 0x3 61#define DMA_DESC_FOLLOW_WITH_IRQ 0x3
62 62
63#define MAX_CHAN_NR 8 63#define MAX_CHAN_NR 12
64 64
65#define DMA_MASK_CTL0_MODE 0x33333333 65#define DMA_MASK_CTL0_MODE 0x33333333
66#define DMA_MASK_CTL2_MODE 0x00003333 66#define DMA_MASK_CTL2_MODE 0x00003333
@@ -872,8 +872,7 @@ static int __devinit pch_dma_probe(struct pci_dev *pdev,
872 int i; 872 int i;
873 873
874 nr_channels = id->driver_data; 874 nr_channels = id->driver_data;
875 pd = kzalloc(sizeof(struct pch_dma)+ 875 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
876 sizeof(struct pch_dma_chan) * nr_channels, GFP_KERNEL);
877 if (!pd) 876 if (!pd)
878 return -ENOMEM; 877 return -ENOMEM;
879 878
@@ -926,7 +925,6 @@ static int __devinit pch_dma_probe(struct pci_dev *pdev,
926 } 925 }
927 926
928 pd->dma.dev = &pdev->dev; 927 pd->dma.dev = &pdev->dev;
929 pd->dma.chancnt = nr_channels;
930 928
931 INIT_LIST_HEAD(&pd->dma.channels); 929 INIT_LIST_HEAD(&pd->dma.channels);
932 930
@@ -935,7 +933,6 @@ static int __devinit pch_dma_probe(struct pci_dev *pdev,
935 933
936 pd_chan->chan.device = &pd->dma; 934 pd_chan->chan.device = &pd->dma;
937 pd_chan->chan.cookie = 1; 935 pd_chan->chan.cookie = 1;
938 pd_chan->chan.chan_id = i;
939 936
940 pd_chan->membase = &regs->desc[i]; 937 pd_chan->membase = &regs->desc[i];
941 938
diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c
index 00eee59e8b33..571041477ab2 100644
--- a/drivers/dma/pl330.c
+++ b/drivers/dma/pl330.c
@@ -17,6 +17,8 @@
17#include <linux/interrupt.h> 17#include <linux/interrupt.h>
18#include <linux/amba/bus.h> 18#include <linux/amba/bus.h>
19#include <linux/amba/pl330.h> 19#include <linux/amba/pl330.h>
20#include <linux/pm_runtime.h>
21#include <linux/scatterlist.h>
20 22
21#define NR_DEFAULT_DESC 16 23#define NR_DEFAULT_DESC 16
22 24
@@ -68,6 +70,14 @@ struct dma_pl330_chan {
68 * NULL if the channel is available to be acquired. 70 * NULL if the channel is available to be acquired.
69 */ 71 */
70 void *pl330_chid; 72 void *pl330_chid;
73
74 /* For D-to-M and M-to-D channels */
75 int burst_sz; /* the peripheral fifo width */
76 int burst_len; /* the number of burst */
77 dma_addr_t fifo_addr;
78
79 /* for cyclic capability */
80 bool cyclic;
71}; 81};
72 82
73struct dma_pl330_dmac { 83struct dma_pl330_dmac {
@@ -83,6 +93,8 @@ struct dma_pl330_dmac {
83 93
84 /* Peripheral channels connected to this DMAC */ 94 /* Peripheral channels connected to this DMAC */
85 struct dma_pl330_chan *peripherals; /* keep at end */ 95 struct dma_pl330_chan *peripherals; /* keep at end */
96
97 struct clk *clk;
86}; 98};
87 99
88struct dma_pl330_desc { 100struct dma_pl330_desc {
@@ -152,6 +164,31 @@ static inline void free_desc_list(struct list_head *list)
152 spin_unlock_irqrestore(&pdmac->pool_lock, flags); 164 spin_unlock_irqrestore(&pdmac->pool_lock, flags);
153} 165}
154 166
167static inline void handle_cyclic_desc_list(struct list_head *list)
168{
169 struct dma_pl330_desc *desc;
170 struct dma_pl330_chan *pch;
171 unsigned long flags;
172
173 if (list_empty(list))
174 return;
175
176 list_for_each_entry(desc, list, node) {
177 dma_async_tx_callback callback;
178
179 /* Change status to reload it */
180 desc->status = PREP;
181 pch = desc->pchan;
182 callback = desc->txd.callback;
183 if (callback)
184 callback(desc->txd.callback_param);
185 }
186
187 spin_lock_irqsave(&pch->lock, flags);
188 list_splice_tail_init(list, &pch->work_list);
189 spin_unlock_irqrestore(&pch->lock, flags);
190}
191
155static inline void fill_queue(struct dma_pl330_chan *pch) 192static inline void fill_queue(struct dma_pl330_chan *pch)
156{ 193{
157 struct dma_pl330_desc *desc; 194 struct dma_pl330_desc *desc;
@@ -205,7 +242,10 @@ static void pl330_tasklet(unsigned long data)
205 242
206 spin_unlock_irqrestore(&pch->lock, flags); 243 spin_unlock_irqrestore(&pch->lock, flags);
207 244
208 free_desc_list(&list); 245 if (pch->cyclic)
246 handle_cyclic_desc_list(&list);
247 else
248 free_desc_list(&list);
209} 249}
210 250
211static void dma_pl330_rqcb(void *token, enum pl330_op_err err) 251static void dma_pl330_rqcb(void *token, enum pl330_op_err err)
@@ -236,6 +276,7 @@ static int pl330_alloc_chan_resources(struct dma_chan *chan)
236 spin_lock_irqsave(&pch->lock, flags); 276 spin_lock_irqsave(&pch->lock, flags);
237 277
238 pch->completed = chan->cookie = 1; 278 pch->completed = chan->cookie = 1;
279 pch->cyclic = false;
239 280
240 pch->pl330_chid = pl330_request_channel(&pdmac->pif); 281 pch->pl330_chid = pl330_request_channel(&pdmac->pif);
241 if (!pch->pl330_chid) { 282 if (!pch->pl330_chid) {
@@ -253,25 +294,52 @@ static int pl330_alloc_chan_resources(struct dma_chan *chan)
253static int pl330_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd, unsigned long arg) 294static int pl330_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd, unsigned long arg)
254{ 295{
255 struct dma_pl330_chan *pch = to_pchan(chan); 296 struct dma_pl330_chan *pch = to_pchan(chan);
256 struct dma_pl330_desc *desc; 297 struct dma_pl330_desc *desc, *_dt;
257 unsigned long flags; 298 unsigned long flags;
299 struct dma_pl330_dmac *pdmac = pch->dmac;
300 struct dma_slave_config *slave_config;
301 LIST_HEAD(list);
258 302
259 /* Only supports DMA_TERMINATE_ALL */ 303 switch (cmd) {
260 if (cmd != DMA_TERMINATE_ALL) 304 case DMA_TERMINATE_ALL:
261 return -ENXIO; 305 spin_lock_irqsave(&pch->lock, flags);
262
263 spin_lock_irqsave(&pch->lock, flags);
264
265 /* FLUSH the PL330 Channel thread */
266 pl330_chan_ctrl(pch->pl330_chid, PL330_OP_FLUSH);
267 306
268 /* Mark all desc done */ 307 /* FLUSH the PL330 Channel thread */
269 list_for_each_entry(desc, &pch->work_list, node) 308 pl330_chan_ctrl(pch->pl330_chid, PL330_OP_FLUSH);
270 desc->status = DONE;
271 309
272 spin_unlock_irqrestore(&pch->lock, flags); 310 /* Mark all desc done */
311 list_for_each_entry_safe(desc, _dt, &pch->work_list , node) {
312 desc->status = DONE;
313 pch->completed = desc->txd.cookie;
314 list_move_tail(&desc->node, &list);
315 }
273 316
274 pl330_tasklet((unsigned long) pch); 317 list_splice_tail_init(&list, &pdmac->desc_pool);
318 spin_unlock_irqrestore(&pch->lock, flags);
319 break;
320 case DMA_SLAVE_CONFIG:
321 slave_config = (struct dma_slave_config *)arg;
322
323 if (slave_config->direction == DMA_TO_DEVICE) {
324 if (slave_config->dst_addr)
325 pch->fifo_addr = slave_config->dst_addr;
326 if (slave_config->dst_addr_width)
327 pch->burst_sz = __ffs(slave_config->dst_addr_width);
328 if (slave_config->dst_maxburst)
329 pch->burst_len = slave_config->dst_maxburst;
330 } else if (slave_config->direction == DMA_FROM_DEVICE) {
331 if (slave_config->src_addr)
332 pch->fifo_addr = slave_config->src_addr;
333 if (slave_config->src_addr_width)
334 pch->burst_sz = __ffs(slave_config->src_addr_width);
335 if (slave_config->src_maxburst)
336 pch->burst_len = slave_config->src_maxburst;
337 }
338 break;
339 default:
340 dev_err(pch->dmac->pif.dev, "Not supported command.\n");
341 return -ENXIO;
342 }
275 343
276 return 0; 344 return 0;
277} 345}
@@ -288,6 +356,9 @@ static void pl330_free_chan_resources(struct dma_chan *chan)
288 pl330_release_channel(pch->pl330_chid); 356 pl330_release_channel(pch->pl330_chid);
289 pch->pl330_chid = NULL; 357 pch->pl330_chid = NULL;
290 358
359 if (pch->cyclic)
360 list_splice_tail_init(&pch->work_list, &pch->dmac->desc_pool);
361
291 spin_unlock_irqrestore(&pch->lock, flags); 362 spin_unlock_irqrestore(&pch->lock, flags);
292} 363}
293 364
@@ -453,7 +524,7 @@ static struct dma_pl330_desc *pl330_get_desc(struct dma_pl330_chan *pch)
453 524
454 if (peri) { 525 if (peri) {
455 desc->req.rqtype = peri->rqtype; 526 desc->req.rqtype = peri->rqtype;
456 desc->req.peri = peri->peri_id; 527 desc->req.peri = pch->chan.chan_id;
457 } else { 528 } else {
458 desc->req.rqtype = MEMTOMEM; 529 desc->req.rqtype = MEMTOMEM;
459 desc->req.peri = 0; 530 desc->req.peri = 0;
@@ -524,6 +595,51 @@ static inline int get_burst_len(struct dma_pl330_desc *desc, size_t len)
524 return burst_len; 595 return burst_len;
525} 596}
526 597
598static struct dma_async_tx_descriptor *pl330_prep_dma_cyclic(
599 struct dma_chan *chan, dma_addr_t dma_addr, size_t len,
600 size_t period_len, enum dma_data_direction direction)
601{
602 struct dma_pl330_desc *desc;
603 struct dma_pl330_chan *pch = to_pchan(chan);
604 dma_addr_t dst;
605 dma_addr_t src;
606
607 desc = pl330_get_desc(pch);
608 if (!desc) {
609 dev_err(pch->dmac->pif.dev, "%s:%d Unable to fetch desc\n",
610 __func__, __LINE__);
611 return NULL;
612 }
613
614 switch (direction) {
615 case DMA_TO_DEVICE:
616 desc->rqcfg.src_inc = 1;
617 desc->rqcfg.dst_inc = 0;
618 src = dma_addr;
619 dst = pch->fifo_addr;
620 break;
621 case DMA_FROM_DEVICE:
622 desc->rqcfg.src_inc = 0;
623 desc->rqcfg.dst_inc = 1;
624 src = pch->fifo_addr;
625 dst = dma_addr;
626 break;
627 default:
628 dev_err(pch->dmac->pif.dev, "%s:%d Invalid dma direction\n",
629 __func__, __LINE__);
630 return NULL;
631 }
632
633 desc->rqcfg.brst_size = pch->burst_sz;
634 desc->rqcfg.brst_len = 1;
635
636 pch->cyclic = true;
637
638 fill_px(&desc->px, dst, src, period_len);
639
640 return &desc->txd;
641}
642
527static struct dma_async_tx_descriptor * 643static struct dma_async_tx_descriptor *
528pl330_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dst, 644pl330_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dst,
529 dma_addr_t src, size_t len, unsigned long flags) 645 dma_addr_t src, size_t len, unsigned long flags)
@@ -579,7 +695,7 @@ pl330_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
579 struct dma_pl330_peri *peri = chan->private; 695 struct dma_pl330_peri *peri = chan->private;
580 struct scatterlist *sg; 696 struct scatterlist *sg;
581 unsigned long flags; 697 unsigned long flags;
582 int i, burst_size; 698 int i;
583 dma_addr_t addr; 699 dma_addr_t addr;
584 700
585 if (unlikely(!pch || !sgl || !sg_len || !peri)) 701 if (unlikely(!pch || !sgl || !sg_len || !peri))
@@ -595,8 +711,7 @@ pl330_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
595 return NULL; 711 return NULL;
596 } 712 }
597 713
598 addr = peri->fifo_addr; 714 addr = pch->fifo_addr;
599 burst_size = peri->burst_sz;
600 715
601 first = NULL; 716 first = NULL;
602 717
@@ -644,7 +759,7 @@ pl330_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
644 sg_dma_address(sg), addr, sg_dma_len(sg)); 759 sg_dma_address(sg), addr, sg_dma_len(sg));
645 } 760 }
646 761
647 desc->rqcfg.brst_size = burst_size; 762 desc->rqcfg.brst_size = pch->burst_sz;
648 desc->rqcfg.brst_len = 1; 763 desc->rqcfg.brst_len = 1;
649 } 764 }
650 765
@@ -696,6 +811,30 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
696 goto probe_err1; 811 goto probe_err1;
697 } 812 }
698 813
814 pdmac->clk = clk_get(&adev->dev, "dma");
815 if (IS_ERR(pdmac->clk)) {
816 dev_err(&adev->dev, "Cannot get operation clock.\n");
817 ret = -EINVAL;
818 goto probe_err1;
819 }
820
821 amba_set_drvdata(adev, pdmac);
822
823#ifdef CONFIG_PM_RUNTIME
824 /* to use the runtime PM helper functions */
825 pm_runtime_enable(&adev->dev);
826
827 /* enable the power domain */
828 if (pm_runtime_get_sync(&adev->dev)) {
829 dev_err(&adev->dev, "failed to get runtime pm\n");
830 ret = -ENODEV;
831 goto probe_err1;
832 }
833#else
834 /* enable dma clk */
835 clk_enable(pdmac->clk);
836#endif
837
699 irq = adev->irq[0]; 838 irq = adev->irq[0];
700 ret = request_irq(irq, pl330_irq_handler, 0, 839 ret = request_irq(irq, pl330_irq_handler, 0,
701 dev_name(&adev->dev), pi); 840 dev_name(&adev->dev), pi);
@@ -732,6 +871,7 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
732 case MEMTODEV: 871 case MEMTODEV:
733 case DEVTOMEM: 872 case DEVTOMEM:
734 dma_cap_set(DMA_SLAVE, pd->cap_mask); 873 dma_cap_set(DMA_SLAVE, pd->cap_mask);
874 dma_cap_set(DMA_CYCLIC, pd->cap_mask);
735 break; 875 break;
736 default: 876 default:
737 dev_err(&adev->dev, "DEVTODEV Not Supported\n"); 877 dev_err(&adev->dev, "DEVTODEV Not Supported\n");
@@ -747,11 +887,9 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
747 spin_lock_init(&pch->lock); 887 spin_lock_init(&pch->lock);
748 pch->pl330_chid = NULL; 888 pch->pl330_chid = NULL;
749 pch->chan.device = pd; 889 pch->chan.device = pd;
750 pch->chan.chan_id = i;
751 pch->dmac = pdmac; 890 pch->dmac = pdmac;
752 891
753 /* Add the channel to the DMAC list */ 892 /* Add the channel to the DMAC list */
754 pd->chancnt++;
755 list_add_tail(&pch->chan.device_node, &pd->channels); 893 list_add_tail(&pch->chan.device_node, &pd->channels);
756 } 894 }
757 895
@@ -760,6 +898,7 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
760 pd->device_alloc_chan_resources = pl330_alloc_chan_resources; 898 pd->device_alloc_chan_resources = pl330_alloc_chan_resources;
761 pd->device_free_chan_resources = pl330_free_chan_resources; 899 pd->device_free_chan_resources = pl330_free_chan_resources;
762 pd->device_prep_dma_memcpy = pl330_prep_dma_memcpy; 900 pd->device_prep_dma_memcpy = pl330_prep_dma_memcpy;
901 pd->device_prep_dma_cyclic = pl330_prep_dma_cyclic;
763 pd->device_tx_status = pl330_tx_status; 902 pd->device_tx_status = pl330_tx_status;
764 pd->device_prep_slave_sg = pl330_prep_slave_sg; 903 pd->device_prep_slave_sg = pl330_prep_slave_sg;
765 pd->device_control = pl330_control; 904 pd->device_control = pl330_control;
@@ -771,8 +910,6 @@ pl330_probe(struct amba_device *adev, const struct amba_id *id)
771 goto probe_err4; 910 goto probe_err4;
772 } 911 }
773 912
774 amba_set_drvdata(adev, pdmac);
775
776 dev_info(&adev->dev, 913 dev_info(&adev->dev,
777 "Loaded driver for PL330 DMAC-%d\n", adev->periphid); 914 "Loaded driver for PL330 DMAC-%d\n", adev->periphid);
778 dev_info(&adev->dev, 915 dev_info(&adev->dev,
@@ -833,6 +970,13 @@ static int __devexit pl330_remove(struct amba_device *adev)
833 res = &adev->res; 970 res = &adev->res;
834 release_mem_region(res->start, resource_size(res)); 971 release_mem_region(res->start, resource_size(res));
835 972
973#ifdef CONFIG_PM_RUNTIME
974 pm_runtime_put(&adev->dev);
975 pm_runtime_disable(&adev->dev);
976#else
977 clk_disable(pdmac->clk);
978#endif
979
836 kfree(pdmac); 980 kfree(pdmac);
837 981
838 return 0; 982 return 0;
@@ -846,10 +990,49 @@ static struct amba_id pl330_ids[] = {
846 { 0, 0 }, 990 { 0, 0 },
847}; 991};
848 992
993#ifdef CONFIG_PM_RUNTIME
994static int pl330_runtime_suspend(struct device *dev)
995{
996 struct dma_pl330_dmac *pdmac = dev_get_drvdata(dev);
997
998 if (!pdmac) {
999 dev_err(dev, "failed to get dmac\n");
1000 return -ENODEV;
1001 }
1002
1003 clk_disable(pdmac->clk);
1004
1005 return 0;
1006}
1007
1008static int pl330_runtime_resume(struct device *dev)
1009{
1010 struct dma_pl330_dmac *pdmac = dev_get_drvdata(dev);
1011
1012 if (!pdmac) {
1013 dev_err(dev, "failed to get dmac\n");
1014 return -ENODEV;
1015 }
1016
1017 clk_enable(pdmac->clk);
1018
1019 return 0;
1020}
1021#else
1022#define pl330_runtime_suspend NULL
1023#define pl330_runtime_resume NULL
1024#endif /* CONFIG_PM_RUNTIME */
1025
1026static const struct dev_pm_ops pl330_pm_ops = {
1027 .runtime_suspend = pl330_runtime_suspend,
1028 .runtime_resume = pl330_runtime_resume,
1029};
1030
849static struct amba_driver pl330_driver = { 1031static struct amba_driver pl330_driver = {
850 .drv = { 1032 .drv = {
851 .owner = THIS_MODULE, 1033 .owner = THIS_MODULE,
852 .name = "dma-pl330", 1034 .name = "dma-pl330",
1035 .pm = &pl330_pm_ops,
853 }, 1036 },
854 .id_table = pl330_ids, 1037 .id_table = pl330_ids,
855 .probe = pl330_probe, 1038 .probe = pl330_probe,
diff --git a/drivers/dma/shdma.c b/drivers/dma/shdma.c
index 7f49235d14b9..81809c2b46ab 100644
--- a/drivers/dma/shdma.c
+++ b/drivers/dma/shdma.c
@@ -259,14 +259,23 @@ static int dmae_set_dmars(struct sh_dmae_chan *sh_chan, u16 val)
259 return 0; 259 return 0;
260} 260}
261 261
262static void sh_chan_xfer_ld_queue(struct sh_dmae_chan *sh_chan);
263
262static dma_cookie_t sh_dmae_tx_submit(struct dma_async_tx_descriptor *tx) 264static dma_cookie_t sh_dmae_tx_submit(struct dma_async_tx_descriptor *tx)
263{ 265{
264 struct sh_desc *desc = tx_to_sh_desc(tx), *chunk, *last = desc, *c; 266 struct sh_desc *desc = tx_to_sh_desc(tx), *chunk, *last = desc, *c;
265 struct sh_dmae_chan *sh_chan = to_sh_chan(tx->chan); 267 struct sh_dmae_chan *sh_chan = to_sh_chan(tx->chan);
268 struct sh_dmae_slave *param = tx->chan->private;
266 dma_async_tx_callback callback = tx->callback; 269 dma_async_tx_callback callback = tx->callback;
267 dma_cookie_t cookie; 270 dma_cookie_t cookie;
271 bool power_up;
272
273 spin_lock_irq(&sh_chan->desc_lock);
268 274
269 spin_lock_bh(&sh_chan->desc_lock); 275 if (list_empty(&sh_chan->ld_queue))
276 power_up = true;
277 else
278 power_up = false;
270 279
271 cookie = sh_chan->common.cookie; 280 cookie = sh_chan->common.cookie;
272 cookie++; 281 cookie++;
@@ -302,7 +311,38 @@ static dma_cookie_t sh_dmae_tx_submit(struct dma_async_tx_descriptor *tx)
302 tx->cookie, &last->async_tx, sh_chan->id, 311 tx->cookie, &last->async_tx, sh_chan->id,
303 desc->hw.sar, desc->hw.tcr, desc->hw.dar); 312 desc->hw.sar, desc->hw.tcr, desc->hw.dar);
304 313
305 spin_unlock_bh(&sh_chan->desc_lock); 314 if (power_up) {
315 sh_chan->pm_state = DMAE_PM_BUSY;
316
317 pm_runtime_get(sh_chan->dev);
318
319 spin_unlock_irq(&sh_chan->desc_lock);
320
321 pm_runtime_barrier(sh_chan->dev);
322
323 spin_lock_irq(&sh_chan->desc_lock);
324
325 /* Have we been reset, while waiting? */
326 if (sh_chan->pm_state != DMAE_PM_ESTABLISHED) {
327 dev_dbg(sh_chan->dev, "Bring up channel %d\n",
328 sh_chan->id);
329 if (param) {
330 const struct sh_dmae_slave_config *cfg =
331 param->config;
332
333 dmae_set_dmars(sh_chan, cfg->mid_rid);
334 dmae_set_chcr(sh_chan, cfg->chcr);
335 } else {
336 dmae_init(sh_chan);
337 }
338
339 if (sh_chan->pm_state == DMAE_PM_PENDING)
340 sh_chan_xfer_ld_queue(sh_chan);
341 sh_chan->pm_state = DMAE_PM_ESTABLISHED;
342 }
343 }
344
345 spin_unlock_irq(&sh_chan->desc_lock);
306 346
307 return cookie; 347 return cookie;
308} 348}
@@ -346,8 +386,6 @@ static int sh_dmae_alloc_chan_resources(struct dma_chan *chan)
346 struct sh_dmae_slave *param = chan->private; 386 struct sh_dmae_slave *param = chan->private;
347 int ret; 387 int ret;
348 388
349 pm_runtime_get_sync(sh_chan->dev);
350
351 /* 389 /*
352 * This relies on the guarantee from dmaengine that alloc_chan_resources 390 * This relies on the guarantee from dmaengine that alloc_chan_resources
353 * never runs concurrently with itself or free_chan_resources. 391 * never runs concurrently with itself or free_chan_resources.
@@ -367,31 +405,20 @@ static int sh_dmae_alloc_chan_resources(struct dma_chan *chan)
367 } 405 }
368 406
369 param->config = cfg; 407 param->config = cfg;
370
371 dmae_set_dmars(sh_chan, cfg->mid_rid);
372 dmae_set_chcr(sh_chan, cfg->chcr);
373 } else {
374 dmae_init(sh_chan);
375 } 408 }
376 409
377 spin_lock_bh(&sh_chan->desc_lock);
378 while (sh_chan->descs_allocated < NR_DESCS_PER_CHANNEL) { 410 while (sh_chan->descs_allocated < NR_DESCS_PER_CHANNEL) {
379 spin_unlock_bh(&sh_chan->desc_lock);
380 desc = kzalloc(sizeof(struct sh_desc), GFP_KERNEL); 411 desc = kzalloc(sizeof(struct sh_desc), GFP_KERNEL);
381 if (!desc) { 412 if (!desc)
382 spin_lock_bh(&sh_chan->desc_lock);
383 break; 413 break;
384 }
385 dma_async_tx_descriptor_init(&desc->async_tx, 414 dma_async_tx_descriptor_init(&desc->async_tx,
386 &sh_chan->common); 415 &sh_chan->common);
387 desc->async_tx.tx_submit = sh_dmae_tx_submit; 416 desc->async_tx.tx_submit = sh_dmae_tx_submit;
388 desc->mark = DESC_IDLE; 417 desc->mark = DESC_IDLE;
389 418
390 spin_lock_bh(&sh_chan->desc_lock);
391 list_add(&desc->node, &sh_chan->ld_free); 419 list_add(&desc->node, &sh_chan->ld_free);
392 sh_chan->descs_allocated++; 420 sh_chan->descs_allocated++;
393 } 421 }
394 spin_unlock_bh(&sh_chan->desc_lock);
395 422
396 if (!sh_chan->descs_allocated) { 423 if (!sh_chan->descs_allocated) {
397 ret = -ENOMEM; 424 ret = -ENOMEM;
@@ -405,7 +432,7 @@ edescalloc:
405 clear_bit(param->slave_id, sh_dmae_slave_used); 432 clear_bit(param->slave_id, sh_dmae_slave_used);
406etestused: 433etestused:
407efindslave: 434efindslave:
408 pm_runtime_put(sh_chan->dev); 435 chan->private = NULL;
409 return ret; 436 return ret;
410} 437}
411 438
@@ -417,7 +444,6 @@ static void sh_dmae_free_chan_resources(struct dma_chan *chan)
417 struct sh_dmae_chan *sh_chan = to_sh_chan(chan); 444 struct sh_dmae_chan *sh_chan = to_sh_chan(chan);
418 struct sh_desc *desc, *_desc; 445 struct sh_desc *desc, *_desc;
419 LIST_HEAD(list); 446 LIST_HEAD(list);
420 int descs = sh_chan->descs_allocated;
421 447
422 /* Protect against ISR */ 448 /* Protect against ISR */
423 spin_lock_irq(&sh_chan->desc_lock); 449 spin_lock_irq(&sh_chan->desc_lock);
@@ -437,15 +463,12 @@ static void sh_dmae_free_chan_resources(struct dma_chan *chan)
437 chan->private = NULL; 463 chan->private = NULL;
438 } 464 }
439 465
440 spin_lock_bh(&sh_chan->desc_lock); 466 spin_lock_irq(&sh_chan->desc_lock);
441 467
442 list_splice_init(&sh_chan->ld_free, &list); 468 list_splice_init(&sh_chan->ld_free, &list);
443 sh_chan->descs_allocated = 0; 469 sh_chan->descs_allocated = 0;
444 470
445 spin_unlock_bh(&sh_chan->desc_lock); 471 spin_unlock_irq(&sh_chan->desc_lock);
446
447 if (descs > 0)
448 pm_runtime_put(sh_chan->dev);
449 472
450 list_for_each_entry_safe(desc, _desc, &list, node) 473 list_for_each_entry_safe(desc, _desc, &list, node)
451 kfree(desc); 474 kfree(desc);
@@ -534,6 +557,7 @@ static struct dma_async_tx_descriptor *sh_dmae_prep_sg(struct sh_dmae_chan *sh_c
534 struct sh_desc *first = NULL, *new = NULL /* compiler... */; 557 struct sh_desc *first = NULL, *new = NULL /* compiler... */;
535 LIST_HEAD(tx_list); 558 LIST_HEAD(tx_list);
536 int chunks = 0; 559 int chunks = 0;
560 unsigned long irq_flags;
537 int i; 561 int i;
538 562
539 if (!sg_len) 563 if (!sg_len)
@@ -544,7 +568,7 @@ static struct dma_async_tx_descriptor *sh_dmae_prep_sg(struct sh_dmae_chan *sh_c
544 (SH_DMA_TCR_MAX + 1); 568 (SH_DMA_TCR_MAX + 1);
545 569
546 /* Have to lock the whole loop to protect against concurrent release */ 570 /* Have to lock the whole loop to protect against concurrent release */
547 spin_lock_bh(&sh_chan->desc_lock); 571 spin_lock_irqsave(&sh_chan->desc_lock, irq_flags);
548 572
549 /* 573 /*
550 * Chaining: 574 * Chaining:
@@ -590,7 +614,7 @@ static struct dma_async_tx_descriptor *sh_dmae_prep_sg(struct sh_dmae_chan *sh_c
590 /* Put them back on the free list, so, they don't get lost */ 614 /* Put them back on the free list, so, they don't get lost */
591 list_splice_tail(&tx_list, &sh_chan->ld_free); 615 list_splice_tail(&tx_list, &sh_chan->ld_free);
592 616
593 spin_unlock_bh(&sh_chan->desc_lock); 617 spin_unlock_irqrestore(&sh_chan->desc_lock, irq_flags);
594 618
595 return &first->async_tx; 619 return &first->async_tx;
596 620
@@ -599,7 +623,7 @@ err_get_desc:
599 new->mark = DESC_IDLE; 623 new->mark = DESC_IDLE;
600 list_splice(&tx_list, &sh_chan->ld_free); 624 list_splice(&tx_list, &sh_chan->ld_free);
601 625
602 spin_unlock_bh(&sh_chan->desc_lock); 626 spin_unlock_irqrestore(&sh_chan->desc_lock, irq_flags);
603 627
604 return NULL; 628 return NULL;
605} 629}
@@ -661,6 +685,7 @@ static int sh_dmae_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
661 unsigned long arg) 685 unsigned long arg)
662{ 686{
663 struct sh_dmae_chan *sh_chan = to_sh_chan(chan); 687 struct sh_dmae_chan *sh_chan = to_sh_chan(chan);
688 unsigned long flags;
664 689
665 /* Only supports DMA_TERMINATE_ALL */ 690 /* Only supports DMA_TERMINATE_ALL */
666 if (cmd != DMA_TERMINATE_ALL) 691 if (cmd != DMA_TERMINATE_ALL)
@@ -669,7 +694,7 @@ static int sh_dmae_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
669 if (!chan) 694 if (!chan)
670 return -EINVAL; 695 return -EINVAL;
671 696
672 spin_lock_bh(&sh_chan->desc_lock); 697 spin_lock_irqsave(&sh_chan->desc_lock, flags);
673 dmae_halt(sh_chan); 698 dmae_halt(sh_chan);
674 699
675 if (!list_empty(&sh_chan->ld_queue)) { 700 if (!list_empty(&sh_chan->ld_queue)) {
@@ -678,9 +703,8 @@ static int sh_dmae_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
678 struct sh_desc, node); 703 struct sh_desc, node);
679 desc->partial = (desc->hw.tcr - sh_dmae_readl(sh_chan, TCR)) << 704 desc->partial = (desc->hw.tcr - sh_dmae_readl(sh_chan, TCR)) <<
680 sh_chan->xmit_shift; 705 sh_chan->xmit_shift;
681
682 } 706 }
683 spin_unlock_bh(&sh_chan->desc_lock); 707 spin_unlock_irqrestore(&sh_chan->desc_lock, flags);
684 708
685 sh_dmae_chan_ld_cleanup(sh_chan, true); 709 sh_dmae_chan_ld_cleanup(sh_chan, true);
686 710
@@ -695,8 +719,9 @@ static dma_async_tx_callback __ld_cleanup(struct sh_dmae_chan *sh_chan, bool all
695 dma_cookie_t cookie = 0; 719 dma_cookie_t cookie = 0;
696 dma_async_tx_callback callback = NULL; 720 dma_async_tx_callback callback = NULL;
697 void *param = NULL; 721 void *param = NULL;
722 unsigned long flags;
698 723
699 spin_lock_bh(&sh_chan->desc_lock); 724 spin_lock_irqsave(&sh_chan->desc_lock, flags);
700 list_for_each_entry_safe(desc, _desc, &sh_chan->ld_queue, node) { 725 list_for_each_entry_safe(desc, _desc, &sh_chan->ld_queue, node) {
701 struct dma_async_tx_descriptor *tx = &desc->async_tx; 726 struct dma_async_tx_descriptor *tx = &desc->async_tx;
702 727
@@ -762,7 +787,13 @@ static dma_async_tx_callback __ld_cleanup(struct sh_dmae_chan *sh_chan, bool all
762 async_tx_test_ack(&desc->async_tx)) || all) { 787 async_tx_test_ack(&desc->async_tx)) || all) {
763 /* Remove from ld_queue list */ 788 /* Remove from ld_queue list */
764 desc->mark = DESC_IDLE; 789 desc->mark = DESC_IDLE;
790
765 list_move(&desc->node, &sh_chan->ld_free); 791 list_move(&desc->node, &sh_chan->ld_free);
792
793 if (list_empty(&sh_chan->ld_queue)) {
794 dev_dbg(sh_chan->dev, "Bring down channel %d\n", sh_chan->id);
795 pm_runtime_put(sh_chan->dev);
796 }
766 } 797 }
767 } 798 }
768 799
@@ -773,7 +804,7 @@ static dma_async_tx_callback __ld_cleanup(struct sh_dmae_chan *sh_chan, bool all
773 */ 804 */
774 sh_chan->completed_cookie = sh_chan->common.cookie; 805 sh_chan->completed_cookie = sh_chan->common.cookie;
775 806
776 spin_unlock_bh(&sh_chan->desc_lock); 807 spin_unlock_irqrestore(&sh_chan->desc_lock, flags);
777 808
778 if (callback) 809 if (callback)
779 callback(param); 810 callback(param);
@@ -792,14 +823,14 @@ static void sh_dmae_chan_ld_cleanup(struct sh_dmae_chan *sh_chan, bool all)
792 ; 823 ;
793} 824}
794 825
826/* Called under spin_lock_irq(&sh_chan->desc_lock) */
795static void sh_chan_xfer_ld_queue(struct sh_dmae_chan *sh_chan) 827static void sh_chan_xfer_ld_queue(struct sh_dmae_chan *sh_chan)
796{ 828{
797 struct sh_desc *desc; 829 struct sh_desc *desc;
798 830
799 spin_lock_bh(&sh_chan->desc_lock);
800 /* DMA work check */ 831 /* DMA work check */
801 if (dmae_is_busy(sh_chan)) 832 if (dmae_is_busy(sh_chan))
802 goto sh_chan_xfer_ld_queue_end; 833 return;
803 834
804 /* Find the first not transferred descriptor */ 835 /* Find the first not transferred descriptor */
805 list_for_each_entry(desc, &sh_chan->ld_queue, node) 836 list_for_each_entry(desc, &sh_chan->ld_queue, node)
@@ -812,15 +843,18 @@ static void sh_chan_xfer_ld_queue(struct sh_dmae_chan *sh_chan)
812 dmae_start(sh_chan); 843 dmae_start(sh_chan);
813 break; 844 break;
814 } 845 }
815
816sh_chan_xfer_ld_queue_end:
817 spin_unlock_bh(&sh_chan->desc_lock);
818} 846}
819 847
820static void sh_dmae_memcpy_issue_pending(struct dma_chan *chan) 848static void sh_dmae_memcpy_issue_pending(struct dma_chan *chan)
821{ 849{
822 struct sh_dmae_chan *sh_chan = to_sh_chan(chan); 850 struct sh_dmae_chan *sh_chan = to_sh_chan(chan);
823 sh_chan_xfer_ld_queue(sh_chan); 851
852 spin_lock_irq(&sh_chan->desc_lock);
853 if (sh_chan->pm_state == DMAE_PM_ESTABLISHED)
854 sh_chan_xfer_ld_queue(sh_chan);
855 else
856 sh_chan->pm_state = DMAE_PM_PENDING;
857 spin_unlock_irq(&sh_chan->desc_lock);
824} 858}
825 859
826static enum dma_status sh_dmae_tx_status(struct dma_chan *chan, 860static enum dma_status sh_dmae_tx_status(struct dma_chan *chan,
@@ -831,6 +865,7 @@ static enum dma_status sh_dmae_tx_status(struct dma_chan *chan,
831 dma_cookie_t last_used; 865 dma_cookie_t last_used;
832 dma_cookie_t last_complete; 866 dma_cookie_t last_complete;
833 enum dma_status status; 867 enum dma_status status;
868 unsigned long flags;
834 869
835 sh_dmae_chan_ld_cleanup(sh_chan, false); 870 sh_dmae_chan_ld_cleanup(sh_chan, false);
836 871
@@ -841,7 +876,7 @@ static enum dma_status sh_dmae_tx_status(struct dma_chan *chan,
841 BUG_ON(last_complete < 0); 876 BUG_ON(last_complete < 0);
842 dma_set_tx_state(txstate, last_complete, last_used, 0); 877 dma_set_tx_state(txstate, last_complete, last_used, 0);
843 878
844 spin_lock_bh(&sh_chan->desc_lock); 879 spin_lock_irqsave(&sh_chan->desc_lock, flags);
845 880
846 status = dma_async_is_complete(cookie, last_complete, last_used); 881 status = dma_async_is_complete(cookie, last_complete, last_used);
847 882
@@ -859,7 +894,7 @@ static enum dma_status sh_dmae_tx_status(struct dma_chan *chan,
859 } 894 }
860 } 895 }
861 896
862 spin_unlock_bh(&sh_chan->desc_lock); 897 spin_unlock_irqrestore(&sh_chan->desc_lock, flags);
863 898
864 return status; 899 return status;
865} 900}
@@ -912,6 +947,12 @@ static bool sh_dmae_reset(struct sh_dmae_device *shdev)
912 947
913 list_splice_init(&sh_chan->ld_queue, &dl); 948 list_splice_init(&sh_chan->ld_queue, &dl);
914 949
950 if (!list_empty(&dl)) {
951 dev_dbg(sh_chan->dev, "Bring down channel %d\n", sh_chan->id);
952 pm_runtime_put(sh_chan->dev);
953 }
954 sh_chan->pm_state = DMAE_PM_ESTABLISHED;
955
915 spin_unlock(&sh_chan->desc_lock); 956 spin_unlock(&sh_chan->desc_lock);
916 957
917 /* Complete all */ 958 /* Complete all */
@@ -952,7 +993,7 @@ static void dmae_do_tasklet(unsigned long data)
952 u32 sar_buf = sh_dmae_readl(sh_chan, SAR); 993 u32 sar_buf = sh_dmae_readl(sh_chan, SAR);
953 u32 dar_buf = sh_dmae_readl(sh_chan, DAR); 994 u32 dar_buf = sh_dmae_readl(sh_chan, DAR);
954 995
955 spin_lock(&sh_chan->desc_lock); 996 spin_lock_irq(&sh_chan->desc_lock);
956 list_for_each_entry(desc, &sh_chan->ld_queue, node) { 997 list_for_each_entry(desc, &sh_chan->ld_queue, node) {
957 if (desc->mark == DESC_SUBMITTED && 998 if (desc->mark == DESC_SUBMITTED &&
958 ((desc->direction == DMA_FROM_DEVICE && 999 ((desc->direction == DMA_FROM_DEVICE &&
@@ -965,10 +1006,10 @@ static void dmae_do_tasklet(unsigned long data)
965 break; 1006 break;
966 } 1007 }
967 } 1008 }
968 spin_unlock(&sh_chan->desc_lock);
969
970 /* Next desc */ 1009 /* Next desc */
971 sh_chan_xfer_ld_queue(sh_chan); 1010 sh_chan_xfer_ld_queue(sh_chan);
1011 spin_unlock_irq(&sh_chan->desc_lock);
1012
972 sh_dmae_chan_ld_cleanup(sh_chan, false); 1013 sh_dmae_chan_ld_cleanup(sh_chan, false);
973} 1014}
974 1015
@@ -1036,7 +1077,9 @@ static int __devinit sh_dmae_chan_probe(struct sh_dmae_device *shdev, int id,
1036 return -ENOMEM; 1077 return -ENOMEM;
1037 } 1078 }
1038 1079
1039 /* copy struct dma_device */ 1080 new_sh_chan->pm_state = DMAE_PM_ESTABLISHED;
1081
1082 /* reference struct dma_device */
1040 new_sh_chan->common.device = &shdev->common; 1083 new_sh_chan->common.device = &shdev->common;
1041 1084
1042 new_sh_chan->dev = shdev->common.dev; 1085 new_sh_chan->dev = shdev->common.dev;
diff --git a/drivers/dma/shdma.h b/drivers/dma/shdma.h
index dc56576f9fdb..2b55a276dc5b 100644
--- a/drivers/dma/shdma.h
+++ b/drivers/dma/shdma.h
@@ -23,6 +23,12 @@
23 23
24struct device; 24struct device;
25 25
26enum dmae_pm_state {
27 DMAE_PM_ESTABLISHED,
28 DMAE_PM_BUSY,
29 DMAE_PM_PENDING,
30};
31
26struct sh_dmae_chan { 32struct sh_dmae_chan {
27 dma_cookie_t completed_cookie; /* The maximum cookie completed */ 33 dma_cookie_t completed_cookie; /* The maximum cookie completed */
28 spinlock_t desc_lock; /* Descriptor operation lock */ 34 spinlock_t desc_lock; /* Descriptor operation lock */
@@ -38,6 +44,7 @@ struct sh_dmae_chan {
38 u32 __iomem *base; 44 u32 __iomem *base;
39 char dev_id[16]; /* unique name per DMAC of channel */ 45 char dev_id[16]; /* unique name per DMAC of channel */
40 int pm_error; 46 int pm_error;
47 enum dmae_pm_state pm_state;
41}; 48};
42 49
43struct sh_dmae_device { 50struct sh_dmae_device {
diff --git a/drivers/dma/ste_dma40.c b/drivers/dma/ste_dma40.c
index 467e4dcb20a0..13259cad0ceb 100644
--- a/drivers/dma/ste_dma40.c
+++ b/drivers/dma/ste_dma40.c
@@ -9,6 +9,7 @@
9#include <linux/dma-mapping.h> 9#include <linux/dma-mapping.h>
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <linux/slab.h> 11#include <linux/slab.h>
12#include <linux/export.h>
12#include <linux/dmaengine.h> 13#include <linux/dmaengine.h>
13#include <linux/platform_device.h> 14#include <linux/platform_device.h>
14#include <linux/clk.h> 15#include <linux/clk.h>
diff --git a/drivers/dma/timb_dma.c b/drivers/dma/timb_dma.c
index f69f90a61873..a4a398f2ef61 100644
--- a/drivers/dma/timb_dma.c
+++ b/drivers/dma/timb_dma.c
@@ -753,7 +753,7 @@ static int __devinit td_probe(struct platform_device *pdev)
753 753
754 INIT_LIST_HEAD(&td->dma.channels); 754 INIT_LIST_HEAD(&td->dma.channels);
755 755
756 for (i = 0; i < pdata->nr_channels; i++, td->dma.chancnt++) { 756 for (i = 0; i < pdata->nr_channels; i++) {
757 struct timb_dma_chan *td_chan = &td->channels[i]; 757 struct timb_dma_chan *td_chan = &td->channels[i];
758 struct timb_dma_platform_data_channel *pchan = 758 struct timb_dma_platform_data_channel *pchan =
759 pdata->channels + i; 759 pdata->channels + i;
@@ -762,12 +762,11 @@ static int __devinit td_probe(struct platform_device *pdev)
762 if ((i % 2) == pchan->rx) { 762 if ((i % 2) == pchan->rx) {
763 dev_err(&pdev->dev, "Wrong channel configuration\n"); 763 dev_err(&pdev->dev, "Wrong channel configuration\n");
764 err = -EINVAL; 764 err = -EINVAL;
765 goto err_tasklet_kill; 765 goto err_free_irq;
766 } 766 }
767 767
768 td_chan->chan.device = &td->dma; 768 td_chan->chan.device = &td->dma;
769 td_chan->chan.cookie = 1; 769 td_chan->chan.cookie = 1;
770 td_chan->chan.chan_id = i;
771 spin_lock_init(&td_chan->lock); 770 spin_lock_init(&td_chan->lock);
772 INIT_LIST_HEAD(&td_chan->active_list); 771 INIT_LIST_HEAD(&td_chan->active_list);
773 INIT_LIST_HEAD(&td_chan->queue); 772 INIT_LIST_HEAD(&td_chan->queue);
diff --git a/drivers/edac/Kconfig b/drivers/edac/Kconfig
index af1a17d42bd7..5948a2194f50 100644
--- a/drivers/edac/Kconfig
+++ b/drivers/edac/Kconfig
@@ -41,7 +41,7 @@ config EDAC_DEBUG
41 41
42config EDAC_DECODE_MCE 42config EDAC_DECODE_MCE
43 tristate "Decode MCEs in human-readable form (only on AMD for now)" 43 tristate "Decode MCEs in human-readable form (only on AMD for now)"
44 depends on CPU_SUP_AMD && X86_MCE 44 depends on CPU_SUP_AMD && X86_MCE_AMD
45 default y 45 default y
46 ---help--- 46 ---help---
47 Enable this option if you want to decode Machine Check Exceptions 47 Enable this option if you want to decode Machine Check Exceptions
@@ -71,9 +71,6 @@ config EDAC_MM_EDAC
71 occurred so that a particular failing memory module can be 71 occurred so that a particular failing memory module can be
72 replaced. If unsure, select 'Y'. 72 replaced. If unsure, select 'Y'.
73 73
74config EDAC_MCE
75 bool
76
77config EDAC_AMD64 74config EDAC_AMD64
78 tristate "AMD64 (Opteron, Athlon64) K8, F10h" 75 tristate "AMD64 (Opteron, Athlon64) K8, F10h"
79 depends on EDAC_MM_EDAC && AMD_NB && X86_64 && EDAC_DECODE_MCE 76 depends on EDAC_MM_EDAC && AMD_NB && X86_64 && EDAC_DECODE_MCE
@@ -173,8 +170,7 @@ config EDAC_I5400
173 170
174config EDAC_I7CORE 171config EDAC_I7CORE
175 tristate "Intel i7 Core (Nehalem) processors" 172 tristate "Intel i7 Core (Nehalem) processors"
176 depends on EDAC_MM_EDAC && PCI && X86 173 depends on EDAC_MM_EDAC && PCI && X86 && X86_MCE_INTEL
177 select EDAC_MCE
178 help 174 help
179 Support for error detection and correction the Intel 175 Support for error detection and correction the Intel
180 i7 Core (Nehalem) Integrated Memory Controller that exists on 176 i7 Core (Nehalem) Integrated Memory Controller that exists on
@@ -216,6 +212,14 @@ config EDAC_I7300
216 Support for error detection and correction the Intel 212 Support for error detection and correction the Intel
217 Clarksboro MCH (Intel 7300 chipset). 213 Clarksboro MCH (Intel 7300 chipset).
218 214
215config EDAC_SBRIDGE
216 tristate "Intel Sandy-Bridge Integrated MC"
217 depends on EDAC_MM_EDAC && PCI && X86_64 && X86_MCE_INTEL
218 depends on EXPERIMENTAL
219 help
220 Support for error detection and correction the Intel
221 Sandy Bridge Integrated Memory Controller.
222
219config EDAC_MPC85XX 223config EDAC_MPC85XX
220 tristate "Freescale MPC83xx / MPC85xx" 224 tristate "Freescale MPC83xx / MPC85xx"
221 depends on EDAC_MM_EDAC && FSL_SOC && (PPC_83xx || PPC_85xx) 225 depends on EDAC_MM_EDAC && FSL_SOC && (PPC_83xx || PPC_85xx)
diff --git a/drivers/edac/Makefile b/drivers/edac/Makefile
index 3e239133e29e..196a63dd37c5 100644
--- a/drivers/edac/Makefile
+++ b/drivers/edac/Makefile
@@ -8,7 +8,6 @@
8 8
9obj-$(CONFIG_EDAC) := edac_stub.o 9obj-$(CONFIG_EDAC) := edac_stub.o
10obj-$(CONFIG_EDAC_MM_EDAC) += edac_core.o 10obj-$(CONFIG_EDAC_MM_EDAC) += edac_core.o
11obj-$(CONFIG_EDAC_MCE) += edac_mce.o
12 11
13edac_core-y := edac_mc.o edac_device.o edac_mc_sysfs.o edac_pci_sysfs.o 12edac_core-y := edac_mc.o edac_device.o edac_mc_sysfs.o edac_pci_sysfs.o
14edac_core-y += edac_module.o edac_device_sysfs.o 13edac_core-y += edac_module.o edac_device_sysfs.o
@@ -29,6 +28,7 @@ obj-$(CONFIG_EDAC_I5100) += i5100_edac.o
29obj-$(CONFIG_EDAC_I5400) += i5400_edac.o 28obj-$(CONFIG_EDAC_I5400) += i5400_edac.o
30obj-$(CONFIG_EDAC_I7300) += i7300_edac.o 29obj-$(CONFIG_EDAC_I7300) += i7300_edac.o
31obj-$(CONFIG_EDAC_I7CORE) += i7core_edac.o 30obj-$(CONFIG_EDAC_I7CORE) += i7core_edac.o
31obj-$(CONFIG_EDAC_SBRIDGE) += sb_edac.o
32obj-$(CONFIG_EDAC_E7XXX) += e7xxx_edac.o 32obj-$(CONFIG_EDAC_E7XXX) += e7xxx_edac.o
33obj-$(CONFIG_EDAC_E752X) += e752x_edac.o 33obj-$(CONFIG_EDAC_E752X) += e752x_edac.o
34obj-$(CONFIG_EDAC_I82443BXGX) += i82443bxgx_edac.o 34obj-$(CONFIG_EDAC_I82443BXGX) += i82443bxgx_edac.o
diff --git a/drivers/edac/cpc925_edac.c b/drivers/edac/cpc925_edac.c
index a687a0d16962..a774c0ddaf5b 100644
--- a/drivers/edac/cpc925_edac.c
+++ b/drivers/edac/cpc925_edac.c
@@ -90,6 +90,7 @@ enum apimask_bits {
90 ECC_MASK_ENABLE = (APIMASK_ECC_UE_H | APIMASK_ECC_CE_H | 90 ECC_MASK_ENABLE = (APIMASK_ECC_UE_H | APIMASK_ECC_CE_H |
91 APIMASK_ECC_UE_L | APIMASK_ECC_CE_L), 91 APIMASK_ECC_UE_L | APIMASK_ECC_CE_L),
92}; 92};
93#define APIMASK_ADI(n) CPC925_BIT(((n)+1))
93 94
94/************************************************************ 95/************************************************************
95 * Processor Interface Exception Register (APIEXCP) 96 * Processor Interface Exception Register (APIEXCP)
@@ -581,16 +582,73 @@ static void cpc925_mc_check(struct mem_ctl_info *mci)
581} 582}
582 583
583/******************** CPU err device********************************/ 584/******************** CPU err device********************************/
585static u32 cpc925_cpu_mask_disabled(void)
586{
587 struct device_node *cpus;
588 struct device_node *cpunode = NULL;
589 static u32 mask = 0;
590
591 /* use cached value if available */
592 if (mask != 0)
593 return mask;
594
595 mask = APIMASK_ADI0 | APIMASK_ADI1;
596
597 cpus = of_find_node_by_path("/cpus");
598 if (cpus == NULL) {
599 cpc925_printk(KERN_DEBUG, "No /cpus node !\n");
600 return 0;
601 }
602
603 while ((cpunode = of_get_next_child(cpus, cpunode)) != NULL) {
604 const u32 *reg = of_get_property(cpunode, "reg", NULL);
605
606 if (strcmp(cpunode->type, "cpu")) {
607 cpc925_printk(KERN_ERR, "Not a cpu node in /cpus: %s\n", cpunode->name);
608 continue;
609 }
610
611 if (reg == NULL || *reg > 2) {
612 cpc925_printk(KERN_ERR, "Bad reg value at %s\n", cpunode->full_name);
613 continue;
614 }
615
616 mask &= ~APIMASK_ADI(*reg);
617 }
618
619 if (mask != (APIMASK_ADI0 | APIMASK_ADI1)) {
620 /* We assume that each CPU sits on it's own PI and that
621 * for present CPUs the reg property equals to the PI
622 * interface id */
623 cpc925_printk(KERN_WARNING,
624 "Assuming PI id is equal to CPU MPIC id!\n");
625 }
626
627 of_node_put(cpunode);
628 of_node_put(cpus);
629
630 return mask;
631}
632
584/* Enable CPU Errors detection */ 633/* Enable CPU Errors detection */
585static void cpc925_cpu_init(struct cpc925_dev_info *dev_info) 634static void cpc925_cpu_init(struct cpc925_dev_info *dev_info)
586{ 635{
587 u32 apimask; 636 u32 apimask;
637 u32 cpumask;
588 638
589 apimask = __raw_readl(dev_info->vbase + REG_APIMASK_OFFSET); 639 apimask = __raw_readl(dev_info->vbase + REG_APIMASK_OFFSET);
590 if ((apimask & CPU_MASK_ENABLE) == 0) { 640
591 apimask |= CPU_MASK_ENABLE; 641 cpumask = cpc925_cpu_mask_disabled();
592 __raw_writel(apimask, dev_info->vbase + REG_APIMASK_OFFSET); 642 if (apimask & cpumask) {
643 cpc925_printk(KERN_WARNING, "CPU(s) not present, "
644 "but enabled in APIMASK, disabling\n");
645 apimask &= ~cpumask;
593 } 646 }
647
648 if ((apimask & CPU_MASK_ENABLE) == 0)
649 apimask |= CPU_MASK_ENABLE;
650
651 __raw_writel(apimask, dev_info->vbase + REG_APIMASK_OFFSET);
594} 652}
595 653
596/* Disable CPU Errors detection */ 654/* Disable CPU Errors detection */
@@ -622,6 +680,9 @@ static void cpc925_cpu_check(struct edac_device_ctl_info *edac_dev)
622 if ((apiexcp & CPU_EXCP_DETECTED) == 0) 680 if ((apiexcp & CPU_EXCP_DETECTED) == 0)
623 return; 681 return;
624 682
683 if ((apiexcp & ~cpc925_cpu_mask_disabled()) == 0)
684 return;
685
625 apimask = __raw_readl(dev_info->vbase + REG_APIMASK_OFFSET); 686 apimask = __raw_readl(dev_info->vbase + REG_APIMASK_OFFSET);
626 cpc925_printk(KERN_INFO, "Processor Interface Fault\n" 687 cpc925_printk(KERN_INFO, "Processor Interface Fault\n"
627 "Processor Interface register dump:\n"); 688 "Processor Interface register dump:\n");
diff --git a/drivers/edac/edac_core.h b/drivers/edac/edac_core.h
index 55b8278bb172..fe90cd4a7ebc 100644
--- a/drivers/edac/edac_core.h
+++ b/drivers/edac/edac_core.h
@@ -34,11 +34,10 @@
34#include <linux/platform_device.h> 34#include <linux/platform_device.h>
35#include <linux/sysdev.h> 35#include <linux/sysdev.h>
36#include <linux/workqueue.h> 36#include <linux/workqueue.h>
37#include <linux/edac.h>
37 38
38#define EDAC_MC_LABEL_LEN 31
39#define EDAC_DEVICE_NAME_LEN 31 39#define EDAC_DEVICE_NAME_LEN 31
40#define EDAC_ATTRIB_VALUE_LEN 15 40#define EDAC_ATTRIB_VALUE_LEN 15
41#define MC_PROC_NAME_MAX_LEN 7
42 41
43#if PAGE_SHIFT < 20 42#if PAGE_SHIFT < 20
44#define PAGES_TO_MiB(pages) ((pages) >> (20 - PAGE_SHIFT)) 43#define PAGES_TO_MiB(pages) ((pages) >> (20 - PAGE_SHIFT))
@@ -101,353 +100,6 @@ extern int edac_debug_level;
101 100
102#define edac_dev_name(dev) (dev)->dev_name 101#define edac_dev_name(dev) (dev)->dev_name
103 102
104/* memory devices */
105enum dev_type {
106 DEV_UNKNOWN = 0,
107 DEV_X1,
108 DEV_X2,
109 DEV_X4,
110 DEV_X8,
111 DEV_X16,
112 DEV_X32, /* Do these parts exist? */
113 DEV_X64 /* Do these parts exist? */
114};
115
116#define DEV_FLAG_UNKNOWN BIT(DEV_UNKNOWN)
117#define DEV_FLAG_X1 BIT(DEV_X1)
118#define DEV_FLAG_X2 BIT(DEV_X2)
119#define DEV_FLAG_X4 BIT(DEV_X4)
120#define DEV_FLAG_X8 BIT(DEV_X8)
121#define DEV_FLAG_X16 BIT(DEV_X16)
122#define DEV_FLAG_X32 BIT(DEV_X32)
123#define DEV_FLAG_X64 BIT(DEV_X64)
124
125/* memory types */
126enum mem_type {
127 MEM_EMPTY = 0, /* Empty csrow */
128 MEM_RESERVED, /* Reserved csrow type */
129 MEM_UNKNOWN, /* Unknown csrow type */
130 MEM_FPM, /* Fast page mode */
131 MEM_EDO, /* Extended data out */
132 MEM_BEDO, /* Burst Extended data out */
133 MEM_SDR, /* Single data rate SDRAM */
134 MEM_RDR, /* Registered single data rate SDRAM */
135 MEM_DDR, /* Double data rate SDRAM */
136 MEM_RDDR, /* Registered Double data rate SDRAM */
137 MEM_RMBS, /* Rambus DRAM */
138 MEM_DDR2, /* DDR2 RAM */
139 MEM_FB_DDR2, /* fully buffered DDR2 */
140 MEM_RDDR2, /* Registered DDR2 RAM */
141 MEM_XDR, /* Rambus XDR */
142 MEM_DDR3, /* DDR3 RAM */
143 MEM_RDDR3, /* Registered DDR3 RAM */
144};
145
146#define MEM_FLAG_EMPTY BIT(MEM_EMPTY)
147#define MEM_FLAG_RESERVED BIT(MEM_RESERVED)
148#define MEM_FLAG_UNKNOWN BIT(MEM_UNKNOWN)
149#define MEM_FLAG_FPM BIT(MEM_FPM)
150#define MEM_FLAG_EDO BIT(MEM_EDO)
151#define MEM_FLAG_BEDO BIT(MEM_BEDO)
152#define MEM_FLAG_SDR BIT(MEM_SDR)
153#define MEM_FLAG_RDR BIT(MEM_RDR)
154#define MEM_FLAG_DDR BIT(MEM_DDR)
155#define MEM_FLAG_RDDR BIT(MEM_RDDR)
156#define MEM_FLAG_RMBS BIT(MEM_RMBS)
157#define MEM_FLAG_DDR2 BIT(MEM_DDR2)
158#define MEM_FLAG_FB_DDR2 BIT(MEM_FB_DDR2)
159#define MEM_FLAG_RDDR2 BIT(MEM_RDDR2)
160#define MEM_FLAG_XDR BIT(MEM_XDR)
161#define MEM_FLAG_DDR3 BIT(MEM_DDR3)
162#define MEM_FLAG_RDDR3 BIT(MEM_RDDR3)
163
164/* chipset Error Detection and Correction capabilities and mode */
165enum edac_type {
166 EDAC_UNKNOWN = 0, /* Unknown if ECC is available */
167 EDAC_NONE, /* Doesn't support ECC */
168 EDAC_RESERVED, /* Reserved ECC type */
169 EDAC_PARITY, /* Detects parity errors */
170 EDAC_EC, /* Error Checking - no correction */
171 EDAC_SECDED, /* Single bit error correction, Double detection */
172 EDAC_S2ECD2ED, /* Chipkill x2 devices - do these exist? */
173 EDAC_S4ECD4ED, /* Chipkill x4 devices */
174 EDAC_S8ECD8ED, /* Chipkill x8 devices */
175 EDAC_S16ECD16ED, /* Chipkill x16 devices */
176};
177
178#define EDAC_FLAG_UNKNOWN BIT(EDAC_UNKNOWN)
179#define EDAC_FLAG_NONE BIT(EDAC_NONE)
180#define EDAC_FLAG_PARITY BIT(EDAC_PARITY)
181#define EDAC_FLAG_EC BIT(EDAC_EC)
182#define EDAC_FLAG_SECDED BIT(EDAC_SECDED)
183#define EDAC_FLAG_S2ECD2ED BIT(EDAC_S2ECD2ED)
184#define EDAC_FLAG_S4ECD4ED BIT(EDAC_S4ECD4ED)
185#define EDAC_FLAG_S8ECD8ED BIT(EDAC_S8ECD8ED)
186#define EDAC_FLAG_S16ECD16ED BIT(EDAC_S16ECD16ED)
187
188/* scrubbing capabilities */
189enum scrub_type {
190 SCRUB_UNKNOWN = 0, /* Unknown if scrubber is available */
191 SCRUB_NONE, /* No scrubber */
192 SCRUB_SW_PROG, /* SW progressive (sequential) scrubbing */
193 SCRUB_SW_SRC, /* Software scrub only errors */
194 SCRUB_SW_PROG_SRC, /* Progressive software scrub from an error */
195 SCRUB_SW_TUNABLE, /* Software scrub frequency is tunable */
196 SCRUB_HW_PROG, /* HW progressive (sequential) scrubbing */
197 SCRUB_HW_SRC, /* Hardware scrub only errors */
198 SCRUB_HW_PROG_SRC, /* Progressive hardware scrub from an error */
199 SCRUB_HW_TUNABLE /* Hardware scrub frequency is tunable */
200};
201
202#define SCRUB_FLAG_SW_PROG BIT(SCRUB_SW_PROG)
203#define SCRUB_FLAG_SW_SRC BIT(SCRUB_SW_SRC)
204#define SCRUB_FLAG_SW_PROG_SRC BIT(SCRUB_SW_PROG_SRC)
205#define SCRUB_FLAG_SW_TUN BIT(SCRUB_SW_SCRUB_TUNABLE)
206#define SCRUB_FLAG_HW_PROG BIT(SCRUB_HW_PROG)
207#define SCRUB_FLAG_HW_SRC BIT(SCRUB_HW_SRC)
208#define SCRUB_FLAG_HW_PROG_SRC BIT(SCRUB_HW_PROG_SRC)
209#define SCRUB_FLAG_HW_TUN BIT(SCRUB_HW_TUNABLE)
210
211/* FIXME - should have notify capabilities: NMI, LOG, PROC, etc */
212
213/* EDAC internal operation states */
214#define OP_ALLOC 0x100
215#define OP_RUNNING_POLL 0x201
216#define OP_RUNNING_INTERRUPT 0x202
217#define OP_RUNNING_POLL_INTR 0x203
218#define OP_OFFLINE 0x300
219
220/*
221 * There are several things to be aware of that aren't at all obvious:
222 *
223 *
224 * SOCKETS, SOCKET SETS, BANKS, ROWS, CHIP-SELECT ROWS, CHANNELS, etc..
225 *
226 * These are some of the many terms that are thrown about that don't always
227 * mean what people think they mean (Inconceivable!). In the interest of
228 * creating a common ground for discussion, terms and their definitions
229 * will be established.
230 *
231 * Memory devices: The individual chip on a memory stick. These devices
232 * commonly output 4 and 8 bits each. Grouping several
233 * of these in parallel provides 64 bits which is common
234 * for a memory stick.
235 *
236 * Memory Stick: A printed circuit board that aggregates multiple
237 * memory devices in parallel. This is the atomic
238 * memory component that is purchaseable by Joe consumer
239 * and loaded into a memory socket.
240 *
241 * Socket: A physical connector on the motherboard that accepts
242 * a single memory stick.
243 *
244 * Channel: Set of memory devices on a memory stick that must be
245 * grouped in parallel with one or more additional
246 * channels from other memory sticks. This parallel
247 * grouping of the output from multiple channels are
248 * necessary for the smallest granularity of memory access.
249 * Some memory controllers are capable of single channel -
250 * which means that memory sticks can be loaded
251 * individually. Other memory controllers are only
252 * capable of dual channel - which means that memory
253 * sticks must be loaded as pairs (see "socket set").
254 *
255 * Chip-select row: All of the memory devices that are selected together.
256 * for a single, minimum grain of memory access.
257 * This selects all of the parallel memory devices across
258 * all of the parallel channels. Common chip-select rows
259 * for single channel are 64 bits, for dual channel 128
260 * bits.
261 *
262 * Single-Ranked stick: A Single-ranked stick has 1 chip-select row of memory.
263 * Motherboards commonly drive two chip-select pins to
264 * a memory stick. A single-ranked stick, will occupy
265 * only one of those rows. The other will be unused.
266 *
267 * Double-Ranked stick: A double-ranked stick has two chip-select rows which
268 * access different sets of memory devices. The two
269 * rows cannot be accessed concurrently.
270 *
271 * Double-sided stick: DEPRECATED TERM, see Double-Ranked stick.
272 * A double-sided stick has two chip-select rows which
273 * access different sets of memory devices. The two
274 * rows cannot be accessed concurrently. "Double-sided"
275 * is irrespective of the memory devices being mounted
276 * on both sides of the memory stick.
277 *
278 * Socket set: All of the memory sticks that are required for
279 * a single memory access or all of the memory sticks
280 * spanned by a chip-select row. A single socket set
281 * has two chip-select rows and if double-sided sticks
282 * are used these will occupy those chip-select rows.
283 *
284 * Bank: This term is avoided because it is unclear when
285 * needing to distinguish between chip-select rows and
286 * socket sets.
287 *
288 * Controller pages:
289 *
290 * Physical pages:
291 *
292 * Virtual pages:
293 *
294 *
295 * STRUCTURE ORGANIZATION AND CHOICES
296 *
297 *
298 *
299 * PS - I enjoyed writing all that about as much as you enjoyed reading it.
300 */
301
302struct channel_info {
303 int chan_idx; /* channel index */
304 u32 ce_count; /* Correctable Errors for this CHANNEL */
305 char label[EDAC_MC_LABEL_LEN + 1]; /* DIMM label on motherboard */
306 struct csrow_info *csrow; /* the parent */
307};
308
309struct csrow_info {
310 unsigned long first_page; /* first page number in dimm */
311 unsigned long last_page; /* last page number in dimm */
312 unsigned long page_mask; /* used for interleaving -
313 * 0UL for non intlv
314 */
315 u32 nr_pages; /* number of pages in csrow */
316 u32 grain; /* granularity of reported error in bytes */
317 int csrow_idx; /* the chip-select row */
318 enum dev_type dtype; /* memory device type */
319 u32 ue_count; /* Uncorrectable Errors for this csrow */
320 u32 ce_count; /* Correctable Errors for this csrow */
321 enum mem_type mtype; /* memory csrow type */
322 enum edac_type edac_mode; /* EDAC mode for this csrow */
323 struct mem_ctl_info *mci; /* the parent */
324
325 struct kobject kobj; /* sysfs kobject for this csrow */
326
327 /* channel information for this csrow */
328 u32 nr_channels;
329 struct channel_info *channels;
330};
331
332struct mcidev_sysfs_group {
333 const char *name; /* group name */
334 const struct mcidev_sysfs_attribute *mcidev_attr; /* group attributes */
335};
336
337struct mcidev_sysfs_group_kobj {
338 struct list_head list; /* list for all instances within a mc */
339
340 struct kobject kobj; /* kobj for the group */
341
342 const struct mcidev_sysfs_group *grp; /* group description table */
343 struct mem_ctl_info *mci; /* the parent */
344};
345
346/* mcidev_sysfs_attribute structure
347 * used for driver sysfs attributes and in mem_ctl_info
348 * sysfs top level entries
349 */
350struct mcidev_sysfs_attribute {
351 /* It should use either attr or grp */
352 struct attribute attr;
353 const struct mcidev_sysfs_group *grp; /* Points to a group of attributes */
354
355 /* Ops for show/store values at the attribute - not used on group */
356 ssize_t (*show)(struct mem_ctl_info *,char *);
357 ssize_t (*store)(struct mem_ctl_info *, const char *,size_t);
358};
359
360/* MEMORY controller information structure
361 */
362struct mem_ctl_info {
363 struct list_head link; /* for global list of mem_ctl_info structs */
364
365 struct module *owner; /* Module owner of this control struct */
366
367 unsigned long mtype_cap; /* memory types supported by mc */
368 unsigned long edac_ctl_cap; /* Mem controller EDAC capabilities */
369 unsigned long edac_cap; /* configuration capabilities - this is
370 * closely related to edac_ctl_cap. The
371 * difference is that the controller may be
372 * capable of s4ecd4ed which would be listed
373 * in edac_ctl_cap, but if channels aren't
374 * capable of s4ecd4ed then the edac_cap would
375 * not have that capability.
376 */
377 unsigned long scrub_cap; /* chipset scrub capabilities */
378 enum scrub_type scrub_mode; /* current scrub mode */
379
380 /* Translates sdram memory scrub rate given in bytes/sec to the
381 internal representation and configures whatever else needs
382 to be configured.
383 */
384 int (*set_sdram_scrub_rate) (struct mem_ctl_info * mci, u32 bw);
385
386 /* Get the current sdram memory scrub rate from the internal
387 representation and converts it to the closest matching
388 bandwidth in bytes/sec.
389 */
390 int (*get_sdram_scrub_rate) (struct mem_ctl_info * mci);
391
392
393 /* pointer to edac checking routine */
394 void (*edac_check) (struct mem_ctl_info * mci);
395
396 /*
397 * Remaps memory pages: controller pages to physical pages.
398 * For most MC's, this will be NULL.
399 */
400 /* FIXME - why not send the phys page to begin with? */
401 unsigned long (*ctl_page_to_phys) (struct mem_ctl_info * mci,
402 unsigned long page);
403 int mc_idx;
404 int nr_csrows;
405 struct csrow_info *csrows;
406 /*
407 * FIXME - what about controllers on other busses? - IDs must be
408 * unique. dev pointer should be sufficiently unique, but
409 * BUS:SLOT.FUNC numbers may not be unique.
410 */
411 struct device *dev;
412 const char *mod_name;
413 const char *mod_ver;
414 const char *ctl_name;
415 const char *dev_name;
416 char proc_name[MC_PROC_NAME_MAX_LEN + 1];
417 void *pvt_info;
418 u32 ue_noinfo_count; /* Uncorrectable Errors w/o info */
419 u32 ce_noinfo_count; /* Correctable Errors w/o info */
420 u32 ue_count; /* Total Uncorrectable Errors for this MC */
421 u32 ce_count; /* Total Correctable Errors for this MC */
422 unsigned long start_time; /* mci load start time (in jiffies) */
423
424 struct completion complete;
425
426 /* edac sysfs device control */
427 struct kobject edac_mci_kobj;
428
429 /* list for all grp instances within a mc */
430 struct list_head grp_kobj_list;
431
432 /* Additional top controller level attributes, but specified
433 * by the low level driver.
434 *
435 * Set by the low level driver to provide attributes at the
436 * controller level, same level as 'ue_count' and 'ce_count' above.
437 * An array of structures, NULL terminated
438 *
439 * If attributes are desired, then set to array of attributes
440 * If no attributes are desired, leave NULL
441 */
442 const struct mcidev_sysfs_attribute *mc_driver_sysfs_attributes;
443
444 /* work struct for this MC */
445 struct delayed_work work;
446
447 /* the internal state of this controller instance */
448 int op_state;
449};
450
451/* 103/*
452 * The following are the structures to provide for a generic 104 * The following are the structures to provide for a generic
453 * or abstract 'edac_device'. This set of structures and the 105 * or abstract 'edac_device'. This set of structures and the
diff --git a/drivers/edac/edac_mce.c b/drivers/edac/edac_mce.c
deleted file mode 100644
index 9ccdc5b140e7..000000000000
--- a/drivers/edac/edac_mce.c
+++ /dev/null
@@ -1,61 +0,0 @@
1/* Provides edac interface to mcelog events
2 *
3 * This file may be distributed under the terms of the
4 * GNU General Public License version 2.
5 *
6 * Copyright (c) 2009 by:
7 * Mauro Carvalho Chehab <mchehab@redhat.com>
8 *
9 * Red Hat Inc. http://www.redhat.com
10 */
11
12#include <linux/module.h>
13#include <linux/edac_mce.h>
14#include <asm/mce.h>
15
16int edac_mce_enabled;
17EXPORT_SYMBOL_GPL(edac_mce_enabled);
18
19
20/*
21 * Extension interface
22 */
23
24static LIST_HEAD(edac_mce_list);
25static DEFINE_MUTEX(edac_mce_lock);
26
27int edac_mce_register(struct edac_mce *edac_mce)
28{
29 mutex_lock(&edac_mce_lock);
30 list_add_tail(&edac_mce->list, &edac_mce_list);
31 mutex_unlock(&edac_mce_lock);
32 return 0;
33}
34EXPORT_SYMBOL(edac_mce_register);
35
36void edac_mce_unregister(struct edac_mce *edac_mce)
37{
38 mutex_lock(&edac_mce_lock);
39 list_del(&edac_mce->list);
40 mutex_unlock(&edac_mce_lock);
41}
42EXPORT_SYMBOL(edac_mce_unregister);
43
44int edac_mce_parse(struct mce *mce)
45{
46 struct edac_mce *edac_mce;
47
48 list_for_each_entry(edac_mce, &edac_mce_list, list) {
49 if (edac_mce->check_error(edac_mce->priv, mce))
50 return 1;
51 }
52
53 /* Nobody queued the error */
54 return 0;
55}
56EXPORT_SYMBOL_GPL(edac_mce_parse);
57
58MODULE_LICENSE("GPL");
59MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
60MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
61MODULE_DESCRIPTION("EDAC Driver for mcelog captured errors");
diff --git a/drivers/edac/i7300_edac.c b/drivers/edac/i7300_edac.c
index a76fe8366b68..6104dba380b6 100644
--- a/drivers/edac/i7300_edac.c
+++ b/drivers/edac/i7300_edac.c
@@ -372,7 +372,7 @@ static const char *get_err_from_table(const char *table[], int size, int pos)
372static void i7300_process_error_global(struct mem_ctl_info *mci) 372static void i7300_process_error_global(struct mem_ctl_info *mci)
373{ 373{
374 struct i7300_pvt *pvt; 374 struct i7300_pvt *pvt;
375 u32 errnum, value; 375 u32 errnum, error_reg;
376 unsigned long errors; 376 unsigned long errors;
377 const char *specific; 377 const char *specific;
378 bool is_fatal; 378 bool is_fatal;
@@ -381,9 +381,9 @@ static void i7300_process_error_global(struct mem_ctl_info *mci)
381 381
382 /* read in the 1st FATAL error register */ 382 /* read in the 1st FATAL error register */
383 pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs, 383 pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
384 FERR_GLOBAL_HI, &value); 384 FERR_GLOBAL_HI, &error_reg);
385 if (unlikely(value)) { 385 if (unlikely(error_reg)) {
386 errors = value; 386 errors = error_reg;
387 errnum = find_first_bit(&errors, 387 errnum = find_first_bit(&errors,
388 ARRAY_SIZE(ferr_global_hi_name)); 388 ARRAY_SIZE(ferr_global_hi_name));
389 specific = GET_ERR_FROM_TABLE(ferr_global_hi_name, errnum); 389 specific = GET_ERR_FROM_TABLE(ferr_global_hi_name, errnum);
@@ -391,15 +391,15 @@ static void i7300_process_error_global(struct mem_ctl_info *mci)
391 391
392 /* Clear the error bit */ 392 /* Clear the error bit */
393 pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs, 393 pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
394 FERR_GLOBAL_HI, value); 394 FERR_GLOBAL_HI, error_reg);
395 395
396 goto error_global; 396 goto error_global;
397 } 397 }
398 398
399 pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs, 399 pci_read_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
400 FERR_GLOBAL_LO, &value); 400 FERR_GLOBAL_LO, &error_reg);
401 if (unlikely(value)) { 401 if (unlikely(error_reg)) {
402 errors = value; 402 errors = error_reg;
403 errnum = find_first_bit(&errors, 403 errnum = find_first_bit(&errors,
404 ARRAY_SIZE(ferr_global_lo_name)); 404 ARRAY_SIZE(ferr_global_lo_name));
405 specific = GET_ERR_FROM_TABLE(ferr_global_lo_name, errnum); 405 specific = GET_ERR_FROM_TABLE(ferr_global_lo_name, errnum);
@@ -407,7 +407,7 @@ static void i7300_process_error_global(struct mem_ctl_info *mci)
407 407
408 /* Clear the error bit */ 408 /* Clear the error bit */
409 pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs, 409 pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
410 FERR_GLOBAL_LO, value); 410 FERR_GLOBAL_LO, error_reg);
411 411
412 goto error_global; 412 goto error_global;
413 } 413 }
@@ -427,7 +427,7 @@ error_global:
427static void i7300_process_fbd_error(struct mem_ctl_info *mci) 427static void i7300_process_fbd_error(struct mem_ctl_info *mci)
428{ 428{
429 struct i7300_pvt *pvt; 429 struct i7300_pvt *pvt;
430 u32 errnum, value; 430 u32 errnum, value, error_reg;
431 u16 val16; 431 u16 val16;
432 unsigned branch, channel, bank, rank, cas, ras; 432 unsigned branch, channel, bank, rank, cas, ras;
433 u32 syndrome; 433 u32 syndrome;
@@ -440,14 +440,14 @@ static void i7300_process_fbd_error(struct mem_ctl_info *mci)
440 440
441 /* read in the 1st FATAL error register */ 441 /* read in the 1st FATAL error register */
442 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map, 442 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
443 FERR_FAT_FBD, &value); 443 FERR_FAT_FBD, &error_reg);
444 if (unlikely(value & FERR_FAT_FBD_ERR_MASK)) { 444 if (unlikely(error_reg & FERR_FAT_FBD_ERR_MASK)) {
445 errors = value & FERR_FAT_FBD_ERR_MASK ; 445 errors = error_reg & FERR_FAT_FBD_ERR_MASK ;
446 errnum = find_first_bit(&errors, 446 errnum = find_first_bit(&errors,
447 ARRAY_SIZE(ferr_fat_fbd_name)); 447 ARRAY_SIZE(ferr_fat_fbd_name));
448 specific = GET_ERR_FROM_TABLE(ferr_fat_fbd_name, errnum); 448 specific = GET_ERR_FROM_TABLE(ferr_fat_fbd_name, errnum);
449 branch = (GET_FBD_FAT_IDX(error_reg) == 2) ? 1 : 0;
449 450
450 branch = (GET_FBD_FAT_IDX(value) == 2) ? 1 : 0;
451 pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, 451 pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map,
452 NRECMEMA, &val16); 452 NRECMEMA, &val16);
453 bank = NRECMEMA_BANK(val16); 453 bank = NRECMEMA_BANK(val16);
@@ -455,11 +455,14 @@ static void i7300_process_fbd_error(struct mem_ctl_info *mci)
455 455
456 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map, 456 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
457 NRECMEMB, &value); 457 NRECMEMB, &value);
458
459 is_wr = NRECMEMB_IS_WR(value); 458 is_wr = NRECMEMB_IS_WR(value);
460 cas = NRECMEMB_CAS(value); 459 cas = NRECMEMB_CAS(value);
461 ras = NRECMEMB_RAS(value); 460 ras = NRECMEMB_RAS(value);
462 461
462 /* Clean the error register */
463 pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
464 FERR_FAT_FBD, error_reg);
465
463 snprintf(pvt->tmp_prt_buffer, PAGE_SIZE, 466 snprintf(pvt->tmp_prt_buffer, PAGE_SIZE,
464 "FATAL (Branch=%d DRAM-Bank=%d %s " 467 "FATAL (Branch=%d DRAM-Bank=%d %s "
465 "RAS=%d CAS=%d Err=0x%lx (%s))", 468 "RAS=%d CAS=%d Err=0x%lx (%s))",
@@ -476,21 +479,17 @@ static void i7300_process_fbd_error(struct mem_ctl_info *mci)
476 479
477 /* read in the 1st NON-FATAL error register */ 480 /* read in the 1st NON-FATAL error register */
478 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map, 481 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
479 FERR_NF_FBD, &value); 482 FERR_NF_FBD, &error_reg);
480 if (unlikely(value & FERR_NF_FBD_ERR_MASK)) { 483 if (unlikely(error_reg & FERR_NF_FBD_ERR_MASK)) {
481 errors = value & FERR_NF_FBD_ERR_MASK; 484 errors = error_reg & FERR_NF_FBD_ERR_MASK;
482 errnum = find_first_bit(&errors, 485 errnum = find_first_bit(&errors,
483 ARRAY_SIZE(ferr_nf_fbd_name)); 486 ARRAY_SIZE(ferr_nf_fbd_name));
484 specific = GET_ERR_FROM_TABLE(ferr_nf_fbd_name, errnum); 487 specific = GET_ERR_FROM_TABLE(ferr_nf_fbd_name, errnum);
485 488 branch = (GET_FBD_FAT_IDX(error_reg) == 2) ? 1 : 0;
486 /* Clear the error bit */
487 pci_write_config_dword(pvt->pci_dev_16_2_fsb_err_regs,
488 FERR_GLOBAL_LO, value);
489 489
490 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map, 490 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
491 REDMEMA, &syndrome); 491 REDMEMA, &syndrome);
492 492
493 branch = (GET_FBD_FAT_IDX(value) == 2) ? 1 : 0;
494 pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map, 493 pci_read_config_word(pvt->pci_dev_16_1_fsb_addr_map,
495 RECMEMA, &val16); 494 RECMEMA, &val16);
496 bank = RECMEMA_BANK(val16); 495 bank = RECMEMA_BANK(val16);
@@ -498,18 +497,20 @@ static void i7300_process_fbd_error(struct mem_ctl_info *mci)
498 497
499 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map, 498 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
500 RECMEMB, &value); 499 RECMEMB, &value);
501
502 is_wr = RECMEMB_IS_WR(value); 500 is_wr = RECMEMB_IS_WR(value);
503 cas = RECMEMB_CAS(value); 501 cas = RECMEMB_CAS(value);
504 ras = RECMEMB_RAS(value); 502 ras = RECMEMB_RAS(value);
505 503
506 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map, 504 pci_read_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
507 REDMEMB, &value); 505 REDMEMB, &value);
508
509 channel = (branch << 1); 506 channel = (branch << 1);
510 if (IS_SECOND_CH(value)) 507 if (IS_SECOND_CH(value))
511 channel++; 508 channel++;
512 509
510 /* Clear the error bit */
511 pci_write_config_dword(pvt->pci_dev_16_1_fsb_addr_map,
512 FERR_NF_FBD, error_reg);
513
513 /* Form out message */ 514 /* Form out message */
514 snprintf(pvt->tmp_prt_buffer, PAGE_SIZE, 515 snprintf(pvt->tmp_prt_buffer, PAGE_SIZE,
515 "Corrected error (Branch=%d, Channel %d), " 516 "Corrected error (Branch=%d, Channel %d), "
diff --git a/drivers/edac/i7core_edac.c b/drivers/edac/i7core_edac.c
index f6cf448d69b4..70ad8923f1d7 100644
--- a/drivers/edac/i7core_edac.c
+++ b/drivers/edac/i7core_edac.c
@@ -31,11 +31,13 @@
31#include <linux/pci_ids.h> 31#include <linux/pci_ids.h>
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/delay.h> 33#include <linux/delay.h>
34#include <linux/dmi.h>
34#include <linux/edac.h> 35#include <linux/edac.h>
35#include <linux/mmzone.h> 36#include <linux/mmzone.h>
36#include <linux/edac_mce.h>
37#include <linux/smp.h> 37#include <linux/smp.h>
38#include <asm/mce.h>
38#include <asm/processor.h> 39#include <asm/processor.h>
40#include <asm/div64.h>
39 41
40#include "edac_core.h" 42#include "edac_core.h"
41 43
@@ -78,6 +80,8 @@ MODULE_PARM_DESC(use_pci_fixup, "Enable PCI fixup to seek for hidden devices");
78 /* OFFSETS for Device 0 Function 0 */ 80 /* OFFSETS for Device 0 Function 0 */
79 81
80#define MC_CFG_CONTROL 0x90 82#define MC_CFG_CONTROL 0x90
83 #define MC_CFG_UNLOCK 0x02
84 #define MC_CFG_LOCK 0x00
81 85
82 /* OFFSETS for Device 3 Function 0 */ 86 /* OFFSETS for Device 3 Function 0 */
83 87
@@ -98,6 +102,15 @@ MODULE_PARM_DESC(use_pci_fixup, "Enable PCI fixup to seek for hidden devices");
98 #define DIMM0_COR_ERR(r) ((r) & 0x7fff) 102 #define DIMM0_COR_ERR(r) ((r) & 0x7fff)
99 103
100/* OFFSETS for Device 3 Function 2, as inicated on Xeon 5500 datasheet */ 104/* OFFSETS for Device 3 Function 2, as inicated on Xeon 5500 datasheet */
105#define MC_SSRCONTROL 0x48
106 #define SSR_MODE_DISABLE 0x00
107 #define SSR_MODE_ENABLE 0x01
108 #define SSR_MODE_MASK 0x03
109
110#define MC_SCRUB_CONTROL 0x4c
111 #define STARTSCRUB (1 << 24)
112 #define SCRUBINTERVAL_MASK 0xffffff
113
101#define MC_COR_ECC_CNT_0 0x80 114#define MC_COR_ECC_CNT_0 0x80
102#define MC_COR_ECC_CNT_1 0x84 115#define MC_COR_ECC_CNT_1 0x84
103#define MC_COR_ECC_CNT_2 0x88 116#define MC_COR_ECC_CNT_2 0x88
@@ -253,10 +266,7 @@ struct i7core_pvt {
253 unsigned long rdimm_ce_count[NUM_CHANS][MAX_DIMMS]; 266 unsigned long rdimm_ce_count[NUM_CHANS][MAX_DIMMS];
254 int rdimm_last_ce_count[NUM_CHANS][MAX_DIMMS]; 267 int rdimm_last_ce_count[NUM_CHANS][MAX_DIMMS];
255 268
256 unsigned int is_registered; 269 bool is_registered, enable_scrub;
257
258 /* mcelog glue */
259 struct edac_mce edac_mce;
260 270
261 /* Fifo double buffers */ 271 /* Fifo double buffers */
262 struct mce mce_entry[MCE_LOG_LEN]; 272 struct mce mce_entry[MCE_LOG_LEN];
@@ -268,6 +278,9 @@ struct i7core_pvt {
268 /* Count indicator to show errors not got */ 278 /* Count indicator to show errors not got */
269 unsigned mce_overrun; 279 unsigned mce_overrun;
270 280
281 /* DCLK Frequency used for computing scrub rate */
282 int dclk_freq;
283
271 /* Struct to control EDAC polling */ 284 /* Struct to control EDAC polling */
272 struct edac_pci_ctl_info *i7core_pci; 285 struct edac_pci_ctl_info *i7core_pci;
273}; 286};
@@ -281,8 +294,7 @@ static const struct pci_id_descr pci_dev_descr_i7core_nehalem[] = {
281 /* Memory controller */ 294 /* Memory controller */
282 { PCI_DESCR(3, 0, PCI_DEVICE_ID_INTEL_I7_MCR) }, 295 { PCI_DESCR(3, 0, PCI_DEVICE_ID_INTEL_I7_MCR) },
283 { PCI_DESCR(3, 1, PCI_DEVICE_ID_INTEL_I7_MC_TAD) }, 296 { PCI_DESCR(3, 1, PCI_DEVICE_ID_INTEL_I7_MC_TAD) },
284 297 /* Exists only for RDIMM */
285 /* Exists only for RDIMM */
286 { PCI_DESCR(3, 2, PCI_DEVICE_ID_INTEL_I7_MC_RAS), .optional = 1 }, 298 { PCI_DESCR(3, 2, PCI_DEVICE_ID_INTEL_I7_MC_RAS), .optional = 1 },
287 { PCI_DESCR(3, 4, PCI_DEVICE_ID_INTEL_I7_MC_TEST) }, 299 { PCI_DESCR(3, 4, PCI_DEVICE_ID_INTEL_I7_MC_TEST) },
288 300
@@ -303,6 +315,16 @@ static const struct pci_id_descr pci_dev_descr_i7core_nehalem[] = {
303 { PCI_DESCR(6, 1, PCI_DEVICE_ID_INTEL_I7_MC_CH2_ADDR) }, 315 { PCI_DESCR(6, 1, PCI_DEVICE_ID_INTEL_I7_MC_CH2_ADDR) },
304 { PCI_DESCR(6, 2, PCI_DEVICE_ID_INTEL_I7_MC_CH2_RANK) }, 316 { PCI_DESCR(6, 2, PCI_DEVICE_ID_INTEL_I7_MC_CH2_RANK) },
305 { PCI_DESCR(6, 3, PCI_DEVICE_ID_INTEL_I7_MC_CH2_TC) }, 317 { PCI_DESCR(6, 3, PCI_DEVICE_ID_INTEL_I7_MC_CH2_TC) },
318
319 /* Generic Non-core registers */
320 /*
321 * This is the PCI device on i7core and on Xeon 35xx (8086:2c41)
322 * On Xeon 55xx, however, it has a different id (8086:2c40). So,
323 * the probing code needs to test for the other address in case of
324 * failure of this one
325 */
326 { PCI_DESCR(0, 0, PCI_DEVICE_ID_INTEL_I7_NONCORE) },
327
306}; 328};
307 329
308static const struct pci_id_descr pci_dev_descr_lynnfield[] = { 330static const struct pci_id_descr pci_dev_descr_lynnfield[] = {
@@ -319,6 +341,12 @@ static const struct pci_id_descr pci_dev_descr_lynnfield[] = {
319 { PCI_DESCR( 5, 1, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_ADDR) }, 341 { PCI_DESCR( 5, 1, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_ADDR) },
320 { PCI_DESCR( 5, 2, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_RANK) }, 342 { PCI_DESCR( 5, 2, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_RANK) },
321 { PCI_DESCR( 5, 3, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_TC) }, 343 { PCI_DESCR( 5, 3, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH1_TC) },
344
345 /*
346 * This is the PCI device has an alternate address on some
347 * processors like Core i7 860
348 */
349 { PCI_DESCR( 0, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE) },
322}; 350};
323 351
324static const struct pci_id_descr pci_dev_descr_i7core_westmere[] = { 352static const struct pci_id_descr pci_dev_descr_i7core_westmere[] = {
@@ -346,6 +374,10 @@ static const struct pci_id_descr pci_dev_descr_i7core_westmere[] = {
346 { PCI_DESCR(6, 1, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH2_ADDR_REV2) }, 374 { PCI_DESCR(6, 1, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH2_ADDR_REV2) },
347 { PCI_DESCR(6, 2, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH2_RANK_REV2) }, 375 { PCI_DESCR(6, 2, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH2_RANK_REV2) },
348 { PCI_DESCR(6, 3, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH2_TC_REV2) }, 376 { PCI_DESCR(6, 3, PCI_DEVICE_ID_INTEL_LYNNFIELD_MC_CH2_TC_REV2) },
377
378 /* Generic Non-core registers */
379 { PCI_DESCR(0, 0, PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE_REV2) },
380
349}; 381};
350 382
351#define PCI_ID_TABLE_ENTRY(A) { .descr=A, .n_devs = ARRAY_SIZE(A) } 383#define PCI_ID_TABLE_ENTRY(A) { .descr=A, .n_devs = ARRAY_SIZE(A) }
@@ -714,6 +746,10 @@ static int get_dimm_config(const struct mem_ctl_info *mci)
714 746
715 csr->edac_mode = mode; 747 csr->edac_mode = mode;
716 csr->mtype = mtype; 748 csr->mtype = mtype;
749 snprintf(csr->channels[0].label,
750 sizeof(csr->channels[0].label),
751 "CPU#%uChannel#%u_DIMM#%u",
752 pvt->i7core_dev->socket, i, j);
717 753
718 csrow++; 754 csrow++;
719 } 755 }
@@ -731,7 +767,7 @@ static int get_dimm_config(const struct mem_ctl_info *mci)
731 debugf1("\t\t%#x\t%#x\t%#x\n", 767 debugf1("\t\t%#x\t%#x\t%#x\n",
732 (value[j] >> 27) & 0x1, 768 (value[j] >> 27) & 0x1,
733 (value[j] >> 24) & 0x7, 769 (value[j] >> 24) & 0x7,
734 (value[j] && ((1 << 24) - 1))); 770 (value[j] & ((1 << 24) - 1)));
735 } 771 }
736 772
737 return 0; 773 return 0;
@@ -1324,6 +1360,20 @@ static int i7core_get_onedevice(struct pci_dev **prev,
1324 pdev = pci_get_device(PCI_VENDOR_ID_INTEL, 1360 pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
1325 dev_descr->dev_id, *prev); 1361 dev_descr->dev_id, *prev);
1326 1362
1363 /*
1364 * On Xeon 55xx, the Intel Quckpath Arch Generic Non-core regs
1365 * is at addr 8086:2c40, instead of 8086:2c41. So, we need
1366 * to probe for the alternate address in case of failure
1367 */
1368 if (dev_descr->dev_id == PCI_DEVICE_ID_INTEL_I7_NONCORE && !pdev)
1369 pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
1370 PCI_DEVICE_ID_INTEL_I7_NONCORE_ALT, *prev);
1371
1372 if (dev_descr->dev_id == PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE && !pdev)
1373 pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
1374 PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE_ALT,
1375 *prev);
1376
1327 if (!pdev) { 1377 if (!pdev) {
1328 if (*prev) { 1378 if (*prev) {
1329 *prev = pdev; 1379 *prev = pdev;
@@ -1444,8 +1494,10 @@ static int mci_bind_devs(struct mem_ctl_info *mci,
1444 struct i7core_pvt *pvt = mci->pvt_info; 1494 struct i7core_pvt *pvt = mci->pvt_info;
1445 struct pci_dev *pdev; 1495 struct pci_dev *pdev;
1446 int i, func, slot; 1496 int i, func, slot;
1497 char *family;
1447 1498
1448 pvt->is_registered = 0; 1499 pvt->is_registered = false;
1500 pvt->enable_scrub = false;
1449 for (i = 0; i < i7core_dev->n_devs; i++) { 1501 for (i = 0; i < i7core_dev->n_devs; i++) {
1450 pdev = i7core_dev->pdev[i]; 1502 pdev = i7core_dev->pdev[i];
1451 if (!pdev) 1503 if (!pdev)
@@ -1461,9 +1513,37 @@ static int mci_bind_devs(struct mem_ctl_info *mci,
1461 if (unlikely(func > MAX_CHAN_FUNC)) 1513 if (unlikely(func > MAX_CHAN_FUNC))
1462 goto error; 1514 goto error;
1463 pvt->pci_ch[slot - 4][func] = pdev; 1515 pvt->pci_ch[slot - 4][func] = pdev;
1464 } else if (!slot && !func) 1516 } else if (!slot && !func) {
1465 pvt->pci_noncore = pdev; 1517 pvt->pci_noncore = pdev;
1466 else 1518
1519 /* Detect the processor family */
1520 switch (pdev->device) {
1521 case PCI_DEVICE_ID_INTEL_I7_NONCORE:
1522 family = "Xeon 35xx/ i7core";
1523 pvt->enable_scrub = false;
1524 break;
1525 case PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE_ALT:
1526 family = "i7-800/i5-700";
1527 pvt->enable_scrub = false;
1528 break;
1529 case PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE:
1530 family = "Xeon 34xx";
1531 pvt->enable_scrub = false;
1532 break;
1533 case PCI_DEVICE_ID_INTEL_I7_NONCORE_ALT:
1534 family = "Xeon 55xx";
1535 pvt->enable_scrub = true;
1536 break;
1537 case PCI_DEVICE_ID_INTEL_LYNNFIELD_NONCORE_REV2:
1538 family = "Xeon 56xx / i7-900";
1539 pvt->enable_scrub = true;
1540 break;
1541 default:
1542 family = "unknown";
1543 pvt->enable_scrub = false;
1544 }
1545 debugf0("Detected a processor type %s\n", family);
1546 } else
1467 goto error; 1547 goto error;
1468 1548
1469 debugf0("Associated fn %d.%d, dev = %p, socket %d\n", 1549 debugf0("Associated fn %d.%d, dev = %p, socket %d\n",
@@ -1472,7 +1552,7 @@ static int mci_bind_devs(struct mem_ctl_info *mci,
1472 1552
1473 if (PCI_SLOT(pdev->devfn) == 3 && 1553 if (PCI_SLOT(pdev->devfn) == 3 &&
1474 PCI_FUNC(pdev->devfn) == 2) 1554 PCI_FUNC(pdev->devfn) == 2)
1475 pvt->is_registered = 1; 1555 pvt->is_registered = true;
1476 } 1556 }
1477 1557
1478 return 0; 1558 return 0;
@@ -1826,33 +1906,43 @@ check_ce_error:
1826 * WARNING: As this routine should be called at NMI time, extra care should 1906 * WARNING: As this routine should be called at NMI time, extra care should
1827 * be taken to avoid deadlocks, and to be as fast as possible. 1907 * be taken to avoid deadlocks, and to be as fast as possible.
1828 */ 1908 */
1829static int i7core_mce_check_error(void *priv, struct mce *mce) 1909static int i7core_mce_check_error(struct notifier_block *nb, unsigned long val,
1910 void *data)
1830{ 1911{
1831 struct mem_ctl_info *mci = priv; 1912 struct mce *mce = (struct mce *)data;
1832 struct i7core_pvt *pvt = mci->pvt_info; 1913 struct i7core_dev *i7_dev;
1914 struct mem_ctl_info *mci;
1915 struct i7core_pvt *pvt;
1916
1917 i7_dev = get_i7core_dev(mce->socketid);
1918 if (!i7_dev)
1919 return NOTIFY_BAD;
1920
1921 mci = i7_dev->mci;
1922 pvt = mci->pvt_info;
1833 1923
1834 /* 1924 /*
1835 * Just let mcelog handle it if the error is 1925 * Just let mcelog handle it if the error is
1836 * outside the memory controller 1926 * outside the memory controller
1837 */ 1927 */
1838 if (((mce->status & 0xffff) >> 7) != 1) 1928 if (((mce->status & 0xffff) >> 7) != 1)
1839 return 0; 1929 return NOTIFY_DONE;
1840 1930
1841 /* Bank 8 registers are the only ones that we know how to handle */ 1931 /* Bank 8 registers are the only ones that we know how to handle */
1842 if (mce->bank != 8) 1932 if (mce->bank != 8)
1843 return 0; 1933 return NOTIFY_DONE;
1844 1934
1845#ifdef CONFIG_SMP 1935#ifdef CONFIG_SMP
1846 /* Only handle if it is the right mc controller */ 1936 /* Only handle if it is the right mc controller */
1847 if (cpu_data(mce->cpu).phys_proc_id != pvt->i7core_dev->socket) 1937 if (mce->socketid != pvt->i7core_dev->socket)
1848 return 0; 1938 return NOTIFY_DONE;
1849#endif 1939#endif
1850 1940
1851 smp_rmb(); 1941 smp_rmb();
1852 if ((pvt->mce_out + 1) % MCE_LOG_LEN == pvt->mce_in) { 1942 if ((pvt->mce_out + 1) % MCE_LOG_LEN == pvt->mce_in) {
1853 smp_wmb(); 1943 smp_wmb();
1854 pvt->mce_overrun++; 1944 pvt->mce_overrun++;
1855 return 0; 1945 return NOTIFY_DONE;
1856 } 1946 }
1857 1947
1858 /* Copy memory error at the ringbuffer */ 1948 /* Copy memory error at the ringbuffer */
@@ -1865,7 +1955,240 @@ static int i7core_mce_check_error(void *priv, struct mce *mce)
1865 i7core_check_error(mci); 1955 i7core_check_error(mci);
1866 1956
1867 /* Advise mcelog that the errors were handled */ 1957 /* Advise mcelog that the errors were handled */
1868 return 1; 1958 return NOTIFY_STOP;
1959}
1960
1961static struct notifier_block i7_mce_dec = {
1962 .notifier_call = i7core_mce_check_error,
1963};
1964
1965struct memdev_dmi_entry {
1966 u8 type;
1967 u8 length;
1968 u16 handle;
1969 u16 phys_mem_array_handle;
1970 u16 mem_err_info_handle;
1971 u16 total_width;
1972 u16 data_width;
1973 u16 size;
1974 u8 form;
1975 u8 device_set;
1976 u8 device_locator;
1977 u8 bank_locator;
1978 u8 memory_type;
1979 u16 type_detail;
1980 u16 speed;
1981 u8 manufacturer;
1982 u8 serial_number;
1983 u8 asset_tag;
1984 u8 part_number;
1985 u8 attributes;
1986 u32 extended_size;
1987 u16 conf_mem_clk_speed;
1988} __attribute__((__packed__));
1989
1990
1991/*
1992 * Decode the DRAM Clock Frequency, be paranoid, make sure that all
1993 * memory devices show the same speed, and if they don't then consider
1994 * all speeds to be invalid.
1995 */
1996static void decode_dclk(const struct dmi_header *dh, void *_dclk_freq)
1997{
1998 int *dclk_freq = _dclk_freq;
1999 u16 dmi_mem_clk_speed;
2000
2001 if (*dclk_freq == -1)
2002 return;
2003
2004 if (dh->type == DMI_ENTRY_MEM_DEVICE) {
2005 struct memdev_dmi_entry *memdev_dmi_entry =
2006 (struct memdev_dmi_entry *)dh;
2007 unsigned long conf_mem_clk_speed_offset =
2008 (unsigned long)&memdev_dmi_entry->conf_mem_clk_speed -
2009 (unsigned long)&memdev_dmi_entry->type;
2010 unsigned long speed_offset =
2011 (unsigned long)&memdev_dmi_entry->speed -
2012 (unsigned long)&memdev_dmi_entry->type;
2013
2014 /* Check that a DIMM is present */
2015 if (memdev_dmi_entry->size == 0)
2016 return;
2017
2018 /*
2019 * Pick the configured speed if it's available, otherwise
2020 * pick the DIMM speed, or we don't have a speed.
2021 */
2022 if (memdev_dmi_entry->length > conf_mem_clk_speed_offset) {
2023 dmi_mem_clk_speed =
2024 memdev_dmi_entry->conf_mem_clk_speed;
2025 } else if (memdev_dmi_entry->length > speed_offset) {
2026 dmi_mem_clk_speed = memdev_dmi_entry->speed;
2027 } else {
2028 *dclk_freq = -1;
2029 return;
2030 }
2031
2032 if (*dclk_freq == 0) {
2033 /* First pass, speed was 0 */
2034 if (dmi_mem_clk_speed > 0) {
2035 /* Set speed if a valid speed is read */
2036 *dclk_freq = dmi_mem_clk_speed;
2037 } else {
2038 /* Otherwise we don't have a valid speed */
2039 *dclk_freq = -1;
2040 }
2041 } else if (*dclk_freq > 0 &&
2042 *dclk_freq != dmi_mem_clk_speed) {
2043 /*
2044 * If we have a speed, check that all DIMMS are the same
2045 * speed, otherwise set the speed as invalid.
2046 */
2047 *dclk_freq = -1;
2048 }
2049 }
2050}
2051
2052/*
2053 * The default DCLK frequency is used as a fallback if we
2054 * fail to find anything reliable in the DMI. The value
2055 * is taken straight from the datasheet.
2056 */
2057#define DEFAULT_DCLK_FREQ 800
2058
2059static int get_dclk_freq(void)
2060{
2061 int dclk_freq = 0;
2062
2063 dmi_walk(decode_dclk, (void *)&dclk_freq);
2064
2065 if (dclk_freq < 1)
2066 return DEFAULT_DCLK_FREQ;
2067
2068 return dclk_freq;
2069}
2070
2071/*
2072 * set_sdram_scrub_rate This routine sets byte/sec bandwidth scrub rate
2073 * to hardware according to SCRUBINTERVAL formula
2074 * found in datasheet.
2075 */
2076static int set_sdram_scrub_rate(struct mem_ctl_info *mci, u32 new_bw)
2077{
2078 struct i7core_pvt *pvt = mci->pvt_info;
2079 struct pci_dev *pdev;
2080 u32 dw_scrub;
2081 u32 dw_ssr;
2082
2083 /* Get data from the MC register, function 2 */
2084 pdev = pvt->pci_mcr[2];
2085 if (!pdev)
2086 return -ENODEV;
2087
2088 pci_read_config_dword(pdev, MC_SCRUB_CONTROL, &dw_scrub);
2089
2090 if (new_bw == 0) {
2091 /* Prepare to disable petrol scrub */
2092 dw_scrub &= ~STARTSCRUB;
2093 /* Stop the patrol scrub engine */
2094 write_and_test(pdev, MC_SCRUB_CONTROL,
2095 dw_scrub & ~SCRUBINTERVAL_MASK);
2096
2097 /* Get current status of scrub rate and set bit to disable */
2098 pci_read_config_dword(pdev, MC_SSRCONTROL, &dw_ssr);
2099 dw_ssr &= ~SSR_MODE_MASK;
2100 dw_ssr |= SSR_MODE_DISABLE;
2101 } else {
2102 const int cache_line_size = 64;
2103 const u32 freq_dclk_mhz = pvt->dclk_freq;
2104 unsigned long long scrub_interval;
2105 /*
2106 * Translate the desired scrub rate to a register value and
2107 * program the corresponding register value.
2108 */
2109 scrub_interval = (unsigned long long)freq_dclk_mhz *
2110 cache_line_size * 1000000;
2111 do_div(scrub_interval, new_bw);
2112
2113 if (!scrub_interval || scrub_interval > SCRUBINTERVAL_MASK)
2114 return -EINVAL;
2115
2116 dw_scrub = SCRUBINTERVAL_MASK & scrub_interval;
2117
2118 /* Start the patrol scrub engine */
2119 pci_write_config_dword(pdev, MC_SCRUB_CONTROL,
2120 STARTSCRUB | dw_scrub);
2121
2122 /* Get current status of scrub rate and set bit to enable */
2123 pci_read_config_dword(pdev, MC_SSRCONTROL, &dw_ssr);
2124 dw_ssr &= ~SSR_MODE_MASK;
2125 dw_ssr |= SSR_MODE_ENABLE;
2126 }
2127 /* Disable or enable scrubbing */
2128 pci_write_config_dword(pdev, MC_SSRCONTROL, dw_ssr);
2129
2130 return new_bw;
2131}
2132
2133/*
2134 * get_sdram_scrub_rate This routine convert current scrub rate value
2135 * into byte/sec bandwidth accourding to
2136 * SCRUBINTERVAL formula found in datasheet.
2137 */
2138static int get_sdram_scrub_rate(struct mem_ctl_info *mci)
2139{
2140 struct i7core_pvt *pvt = mci->pvt_info;
2141 struct pci_dev *pdev;
2142 const u32 cache_line_size = 64;
2143 const u32 freq_dclk_mhz = pvt->dclk_freq;
2144 unsigned long long scrub_rate;
2145 u32 scrubval;
2146
2147 /* Get data from the MC register, function 2 */
2148 pdev = pvt->pci_mcr[2];
2149 if (!pdev)
2150 return -ENODEV;
2151
2152 /* Get current scrub control data */
2153 pci_read_config_dword(pdev, MC_SCRUB_CONTROL, &scrubval);
2154
2155 /* Mask highest 8-bits to 0 */
2156 scrubval &= SCRUBINTERVAL_MASK;
2157 if (!scrubval)
2158 return 0;
2159
2160 /* Calculate scrub rate value into byte/sec bandwidth */
2161 scrub_rate = (unsigned long long)freq_dclk_mhz *
2162 1000000 * cache_line_size;
2163 do_div(scrub_rate, scrubval);
2164 return (int)scrub_rate;
2165}
2166
2167static void enable_sdram_scrub_setting(struct mem_ctl_info *mci)
2168{
2169 struct i7core_pvt *pvt = mci->pvt_info;
2170 u32 pci_lock;
2171
2172 /* Unlock writes to pci registers */
2173 pci_read_config_dword(pvt->pci_noncore, MC_CFG_CONTROL, &pci_lock);
2174 pci_lock &= ~0x3;
2175 pci_write_config_dword(pvt->pci_noncore, MC_CFG_CONTROL,
2176 pci_lock | MC_CFG_UNLOCK);
2177
2178 mci->set_sdram_scrub_rate = set_sdram_scrub_rate;
2179 mci->get_sdram_scrub_rate = get_sdram_scrub_rate;
2180}
2181
2182static void disable_sdram_scrub_setting(struct mem_ctl_info *mci)
2183{
2184 struct i7core_pvt *pvt = mci->pvt_info;
2185 u32 pci_lock;
2186
2187 /* Lock writes to pci registers */
2188 pci_read_config_dword(pvt->pci_noncore, MC_CFG_CONTROL, &pci_lock);
2189 pci_lock &= ~0x3;
2190 pci_write_config_dword(pvt->pci_noncore, MC_CFG_CONTROL,
2191 pci_lock | MC_CFG_LOCK);
1869} 2192}
1870 2193
1871static void i7core_pci_ctl_create(struct i7core_pvt *pvt) 2194static void i7core_pci_ctl_create(struct i7core_pvt *pvt)
@@ -1874,7 +2197,8 @@ static void i7core_pci_ctl_create(struct i7core_pvt *pvt)
1874 &pvt->i7core_dev->pdev[0]->dev, 2197 &pvt->i7core_dev->pdev[0]->dev,
1875 EDAC_MOD_STR); 2198 EDAC_MOD_STR);
1876 if (unlikely(!pvt->i7core_pci)) 2199 if (unlikely(!pvt->i7core_pci))
1877 pr_warn("Unable to setup PCI error report via EDAC\n"); 2200 i7core_printk(KERN_WARNING,
2201 "Unable to setup PCI error report via EDAC\n");
1878} 2202}
1879 2203
1880static void i7core_pci_ctl_release(struct i7core_pvt *pvt) 2204static void i7core_pci_ctl_release(struct i7core_pvt *pvt)
@@ -1906,8 +2230,11 @@ static void i7core_unregister_mci(struct i7core_dev *i7core_dev)
1906 debugf0("MC: " __FILE__ ": %s(): mci = %p, dev = %p\n", 2230 debugf0("MC: " __FILE__ ": %s(): mci = %p, dev = %p\n",
1907 __func__, mci, &i7core_dev->pdev[0]->dev); 2231 __func__, mci, &i7core_dev->pdev[0]->dev);
1908 2232
1909 /* Disable MCE NMI handler */ 2233 /* Disable scrubrate setting */
1910 edac_mce_unregister(&pvt->edac_mce); 2234 if (pvt->enable_scrub)
2235 disable_sdram_scrub_setting(mci);
2236
2237 atomic_notifier_chain_unregister(&x86_mce_decoder_chain, &i7_mce_dec);
1911 2238
1912 /* Disable EDAC polling */ 2239 /* Disable EDAC polling */
1913 i7core_pci_ctl_release(pvt); 2240 i7core_pci_ctl_release(pvt);
@@ -1979,6 +2306,10 @@ static int i7core_register_mci(struct i7core_dev *i7core_dev)
1979 /* Set the function pointer to an actual operation function */ 2306 /* Set the function pointer to an actual operation function */
1980 mci->edac_check = i7core_check_error; 2307 mci->edac_check = i7core_check_error;
1981 2308
2309 /* Enable scrubrate setting */
2310 if (pvt->enable_scrub)
2311 enable_sdram_scrub_setting(mci);
2312
1982 /* add this new MC control structure to EDAC's list of MCs */ 2313 /* add this new MC control structure to EDAC's list of MCs */
1983 if (unlikely(edac_mc_add_mc(mci))) { 2314 if (unlikely(edac_mc_add_mc(mci))) {
1984 debugf0("MC: " __FILE__ 2315 debugf0("MC: " __FILE__
@@ -2002,21 +2333,13 @@ static int i7core_register_mci(struct i7core_dev *i7core_dev)
2002 /* allocating generic PCI control info */ 2333 /* allocating generic PCI control info */
2003 i7core_pci_ctl_create(pvt); 2334 i7core_pci_ctl_create(pvt);
2004 2335
2005 /* Registers on edac_mce in order to receive memory errors */ 2336 /* DCLK for scrub rate setting */
2006 pvt->edac_mce.priv = mci; 2337 pvt->dclk_freq = get_dclk_freq();
2007 pvt->edac_mce.check_error = i7core_mce_check_error; 2338
2008 rc = edac_mce_register(&pvt->edac_mce); 2339 atomic_notifier_chain_register(&x86_mce_decoder_chain, &i7_mce_dec);
2009 if (unlikely(rc < 0)) {
2010 debugf0("MC: " __FILE__
2011 ": %s(): failed edac_mce_register()\n", __func__);
2012 goto fail1;
2013 }
2014 2340
2015 return 0; 2341 return 0;
2016 2342
2017fail1:
2018 i7core_pci_ctl_release(pvt);
2019 edac_mc_del_mc(mci->dev);
2020fail0: 2343fail0:
2021 kfree(mci->ctl_name); 2344 kfree(mci->ctl_name);
2022 edac_mc_free(mci); 2345 edac_mc_free(mci);
@@ -2035,7 +2358,7 @@ fail0:
2035static int __devinit i7core_probe(struct pci_dev *pdev, 2358static int __devinit i7core_probe(struct pci_dev *pdev,
2036 const struct pci_device_id *id) 2359 const struct pci_device_id *id)
2037{ 2360{
2038 int rc; 2361 int rc, count = 0;
2039 struct i7core_dev *i7core_dev; 2362 struct i7core_dev *i7core_dev;
2040 2363
2041 /* get the pci devices we want to reserve for our use */ 2364 /* get the pci devices we want to reserve for our use */
@@ -2055,12 +2378,28 @@ static int __devinit i7core_probe(struct pci_dev *pdev,
2055 goto fail0; 2378 goto fail0;
2056 2379
2057 list_for_each_entry(i7core_dev, &i7core_edac_list, list) { 2380 list_for_each_entry(i7core_dev, &i7core_edac_list, list) {
2381 count++;
2058 rc = i7core_register_mci(i7core_dev); 2382 rc = i7core_register_mci(i7core_dev);
2059 if (unlikely(rc < 0)) 2383 if (unlikely(rc < 0))
2060 goto fail1; 2384 goto fail1;
2061 } 2385 }
2062 2386
2063 i7core_printk(KERN_INFO, "Driver loaded.\n"); 2387 /*
2388 * Nehalem-EX uses a different memory controller. However, as the
2389 * memory controller is not visible on some Nehalem/Nehalem-EP, we
2390 * need to indirectly probe via a X58 PCI device. The same devices
2391 * are found on (some) Nehalem-EX. So, on those machines, the
2392 * probe routine needs to return -ENODEV, as the actual Memory
2393 * Controller registers won't be detected.
2394 */
2395 if (!count) {
2396 rc = -ENODEV;
2397 goto fail1;
2398 }
2399
2400 i7core_printk(KERN_INFO,
2401 "Driver loaded, %d memory controller(s) found.\n",
2402 count);
2064 2403
2065 mutex_unlock(&i7core_edac_lock); 2404 mutex_unlock(&i7core_edac_lock);
2066 return 0; 2405 return 0;
diff --git a/drivers/edac/mce_amd_inj.c b/drivers/edac/mce_amd_inj.c
index a4987e03f59e..73c3e26a0bce 100644
--- a/drivers/edac/mce_amd_inj.c
+++ b/drivers/edac/mce_amd_inj.c
@@ -13,6 +13,7 @@
13#include <linux/kobject.h> 13#include <linux/kobject.h>
14#include <linux/sysdev.h> 14#include <linux/sysdev.h>
15#include <linux/edac.h> 15#include <linux/edac.h>
16#include <linux/module.h>
16#include <asm/mce.h> 17#include <asm/mce.h>
17 18
18#include "mce_amd.h" 19#include "mce_amd.h"
diff --git a/drivers/edac/ppc4xx_edac.c b/drivers/edac/ppc4xx_edac.c
index 0de7d8770891..38400963e245 100644
--- a/drivers/edac/ppc4xx_edac.c
+++ b/drivers/edac/ppc4xx_edac.c
@@ -205,7 +205,7 @@ static struct platform_driver ppc4xx_edac_driver = {
205 .remove = ppc4xx_edac_remove, 205 .remove = ppc4xx_edac_remove,
206 .driver = { 206 .driver = {
207 .owner = THIS_MODULE, 207 .owner = THIS_MODULE,
208 .name = PPC4XX_EDAC_MODULE_NAME 208 .name = PPC4XX_EDAC_MODULE_NAME,
209 .of_match_table = ppc4xx_edac_match, 209 .of_match_table = ppc4xx_edac_match,
210 }, 210 },
211}; 211};
diff --git a/drivers/edac/sb_edac.c b/drivers/edac/sb_edac.c
new file mode 100644
index 000000000000..7a402bfbee7d
--- /dev/null
+++ b/drivers/edac/sb_edac.c
@@ -0,0 +1,1893 @@
1/* Intel Sandy Bridge -EN/-EP/-EX Memory Controller kernel module
2 *
3 * This driver supports the memory controllers found on the Intel
4 * processor family Sandy Bridge.
5 *
6 * This file may be distributed under the terms of the
7 * GNU General Public License version 2 only.
8 *
9 * Copyright (c) 2011 by:
10 * Mauro Carvalho Chehab <mchehab@redhat.com>
11 */
12
13#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/pci.h>
16#include <linux/pci_ids.h>
17#include <linux/slab.h>
18#include <linux/delay.h>
19#include <linux/edac.h>
20#include <linux/mmzone.h>
21#include <linux/smp.h>
22#include <linux/bitmap.h>
23#include <asm/processor.h>
24#include <asm/mce.h>
25
26#include "edac_core.h"
27
28/* Static vars */
29static LIST_HEAD(sbridge_edac_list);
30static DEFINE_MUTEX(sbridge_edac_lock);
31static int probed;
32
33/*
34 * Alter this version for the module when modifications are made
35 */
36#define SBRIDGE_REVISION " Ver: 1.0.0 "
37#define EDAC_MOD_STR "sbridge_edac"
38
39/*
40 * Debug macros
41 */
42#define sbridge_printk(level, fmt, arg...) \
43 edac_printk(level, "sbridge", fmt, ##arg)
44
45#define sbridge_mc_printk(mci, level, fmt, arg...) \
46 edac_mc_chipset_printk(mci, level, "sbridge", fmt, ##arg)
47
48/*
49 * Get a bit field at register value <v>, from bit <lo> to bit <hi>
50 */
51#define GET_BITFIELD(v, lo, hi) \
52 (((v) & ((1ULL << ((hi) - (lo) + 1)) - 1) << (lo)) >> (lo))
53
54/*
55 * sbridge Memory Controller Registers
56 */
57
58/*
59 * FIXME: For now, let's order by device function, as it makes
60 * easier for driver's development proccess. This table should be
61 * moved to pci_id.h when submitted upstream
62 */
63#define PCI_DEVICE_ID_INTEL_SBRIDGE_SAD0 0x3cf4 /* 12.6 */
64#define PCI_DEVICE_ID_INTEL_SBRIDGE_SAD1 0x3cf6 /* 12.7 */
65#define PCI_DEVICE_ID_INTEL_SBRIDGE_BR 0x3cf5 /* 13.6 */
66#define PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_HA0 0x3ca0 /* 14.0 */
67#define PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA 0x3ca8 /* 15.0 */
68#define PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_RAS 0x3c71 /* 15.1 */
69#define PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD0 0x3caa /* 15.2 */
70#define PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD1 0x3cab /* 15.3 */
71#define PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD2 0x3cac /* 15.4 */
72#define PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD3 0x3cad /* 15.5 */
73#define PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_DDRIO 0x3cb8 /* 17.0 */
74
75 /*
76 * Currently, unused, but will be needed in the future
77 * implementations, as they hold the error counters
78 */
79#define PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_ERR0 0x3c72 /* 16.2 */
80#define PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_ERR1 0x3c73 /* 16.3 */
81#define PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_ERR2 0x3c76 /* 16.6 */
82#define PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_ERR3 0x3c77 /* 16.7 */
83
84/* Devices 12 Function 6, Offsets 0x80 to 0xcc */
85static const u32 dram_rule[] = {
86 0x80, 0x88, 0x90, 0x98, 0xa0,
87 0xa8, 0xb0, 0xb8, 0xc0, 0xc8,
88};
89#define MAX_SAD ARRAY_SIZE(dram_rule)
90
91#define SAD_LIMIT(reg) ((GET_BITFIELD(reg, 6, 25) << 26) | 0x3ffffff)
92#define DRAM_ATTR(reg) GET_BITFIELD(reg, 2, 3)
93#define INTERLEAVE_MODE(reg) GET_BITFIELD(reg, 1, 1)
94#define DRAM_RULE_ENABLE(reg) GET_BITFIELD(reg, 0, 0)
95
96static char *get_dram_attr(u32 reg)
97{
98 switch(DRAM_ATTR(reg)) {
99 case 0:
100 return "DRAM";
101 case 1:
102 return "MMCFG";
103 case 2:
104 return "NXM";
105 default:
106 return "unknown";
107 }
108}
109
110static const u32 interleave_list[] = {
111 0x84, 0x8c, 0x94, 0x9c, 0xa4,
112 0xac, 0xb4, 0xbc, 0xc4, 0xcc,
113};
114#define MAX_INTERLEAVE ARRAY_SIZE(interleave_list)
115
116#define SAD_PKG0(reg) GET_BITFIELD(reg, 0, 2)
117#define SAD_PKG1(reg) GET_BITFIELD(reg, 3, 5)
118#define SAD_PKG2(reg) GET_BITFIELD(reg, 8, 10)
119#define SAD_PKG3(reg) GET_BITFIELD(reg, 11, 13)
120#define SAD_PKG4(reg) GET_BITFIELD(reg, 16, 18)
121#define SAD_PKG5(reg) GET_BITFIELD(reg, 19, 21)
122#define SAD_PKG6(reg) GET_BITFIELD(reg, 24, 26)
123#define SAD_PKG7(reg) GET_BITFIELD(reg, 27, 29)
124
125static inline int sad_pkg(u32 reg, int interleave)
126{
127 switch (interleave) {
128 case 0:
129 return SAD_PKG0(reg);
130 case 1:
131 return SAD_PKG1(reg);
132 case 2:
133 return SAD_PKG2(reg);
134 case 3:
135 return SAD_PKG3(reg);
136 case 4:
137 return SAD_PKG4(reg);
138 case 5:
139 return SAD_PKG5(reg);
140 case 6:
141 return SAD_PKG6(reg);
142 case 7:
143 return SAD_PKG7(reg);
144 default:
145 return -EINVAL;
146 }
147}
148
149/* Devices 12 Function 7 */
150
151#define TOLM 0x80
152#define TOHM 0x84
153
154#define GET_TOLM(reg) ((GET_BITFIELD(reg, 0, 3) << 28) | 0x3ffffff)
155#define GET_TOHM(reg) ((GET_BITFIELD(reg, 0, 20) << 25) | 0x3ffffff)
156
157/* Device 13 Function 6 */
158
159#define SAD_TARGET 0xf0
160
161#define SOURCE_ID(reg) GET_BITFIELD(reg, 9, 11)
162
163#define SAD_CONTROL 0xf4
164
165#define NODE_ID(reg) GET_BITFIELD(reg, 0, 2)
166
167/* Device 14 function 0 */
168
169static const u32 tad_dram_rule[] = {
170 0x40, 0x44, 0x48, 0x4c,
171 0x50, 0x54, 0x58, 0x5c,
172 0x60, 0x64, 0x68, 0x6c,
173};
174#define MAX_TAD ARRAY_SIZE(tad_dram_rule)
175
176#define TAD_LIMIT(reg) ((GET_BITFIELD(reg, 12, 31) << 26) | 0x3ffffff)
177#define TAD_SOCK(reg) GET_BITFIELD(reg, 10, 11)
178#define TAD_CH(reg) GET_BITFIELD(reg, 8, 9)
179#define TAD_TGT3(reg) GET_BITFIELD(reg, 6, 7)
180#define TAD_TGT2(reg) GET_BITFIELD(reg, 4, 5)
181#define TAD_TGT1(reg) GET_BITFIELD(reg, 2, 3)
182#define TAD_TGT0(reg) GET_BITFIELD(reg, 0, 1)
183
184/* Device 15, function 0 */
185
186#define MCMTR 0x7c
187
188#define IS_ECC_ENABLED(mcmtr) GET_BITFIELD(mcmtr, 2, 2)
189#define IS_LOCKSTEP_ENABLED(mcmtr) GET_BITFIELD(mcmtr, 1, 1)
190#define IS_CLOSE_PG(mcmtr) GET_BITFIELD(mcmtr, 0, 0)
191
192/* Device 15, function 1 */
193
194#define RASENABLES 0xac
195#define IS_MIRROR_ENABLED(reg) GET_BITFIELD(reg, 0, 0)
196
197/* Device 15, functions 2-5 */
198
199static const int mtr_regs[] = {
200 0x80, 0x84, 0x88,
201};
202
203#define RANK_DISABLE(mtr) GET_BITFIELD(mtr, 16, 19)
204#define IS_DIMM_PRESENT(mtr) GET_BITFIELD(mtr, 14, 14)
205#define RANK_CNT_BITS(mtr) GET_BITFIELD(mtr, 12, 13)
206#define RANK_WIDTH_BITS(mtr) GET_BITFIELD(mtr, 2, 4)
207#define COL_WIDTH_BITS(mtr) GET_BITFIELD(mtr, 0, 1)
208
209static const u32 tad_ch_nilv_offset[] = {
210 0x90, 0x94, 0x98, 0x9c,
211 0xa0, 0xa4, 0xa8, 0xac,
212 0xb0, 0xb4, 0xb8, 0xbc,
213};
214#define CHN_IDX_OFFSET(reg) GET_BITFIELD(reg, 28, 29)
215#define TAD_OFFSET(reg) (GET_BITFIELD(reg, 6, 25) << 26)
216
217static const u32 rir_way_limit[] = {
218 0x108, 0x10c, 0x110, 0x114, 0x118,
219};
220#define MAX_RIR_RANGES ARRAY_SIZE(rir_way_limit)
221
222#define IS_RIR_VALID(reg) GET_BITFIELD(reg, 31, 31)
223#define RIR_WAY(reg) GET_BITFIELD(reg, 28, 29)
224#define RIR_LIMIT(reg) ((GET_BITFIELD(reg, 1, 10) << 29)| 0x1fffffff)
225
226#define MAX_RIR_WAY 8
227
228static const u32 rir_offset[MAX_RIR_RANGES][MAX_RIR_WAY] = {
229 { 0x120, 0x124, 0x128, 0x12c, 0x130, 0x134, 0x138, 0x13c },
230 { 0x140, 0x144, 0x148, 0x14c, 0x150, 0x154, 0x158, 0x15c },
231 { 0x160, 0x164, 0x168, 0x16c, 0x170, 0x174, 0x178, 0x17c },
232 { 0x180, 0x184, 0x188, 0x18c, 0x190, 0x194, 0x198, 0x19c },
233 { 0x1a0, 0x1a4, 0x1a8, 0x1ac, 0x1b0, 0x1b4, 0x1b8, 0x1bc },
234};
235
236#define RIR_RNK_TGT(reg) GET_BITFIELD(reg, 16, 19)
237#define RIR_OFFSET(reg) GET_BITFIELD(reg, 2, 14)
238
239/* Device 16, functions 2-7 */
240
241/*
242 * FIXME: Implement the error count reads directly
243 */
244
245static const u32 correrrcnt[] = {
246 0x104, 0x108, 0x10c, 0x110,
247};
248
249#define RANK_ODD_OV(reg) GET_BITFIELD(reg, 31, 31)
250#define RANK_ODD_ERR_CNT(reg) GET_BITFIELD(reg, 16, 30)
251#define RANK_EVEN_OV(reg) GET_BITFIELD(reg, 15, 15)
252#define RANK_EVEN_ERR_CNT(reg) GET_BITFIELD(reg, 0, 14)
253
254static const u32 correrrthrsld[] = {
255 0x11c, 0x120, 0x124, 0x128,
256};
257
258#define RANK_ODD_ERR_THRSLD(reg) GET_BITFIELD(reg, 16, 30)
259#define RANK_EVEN_ERR_THRSLD(reg) GET_BITFIELD(reg, 0, 14)
260
261
262/* Device 17, function 0 */
263
264#define RANK_CFG_A 0x0328
265
266#define IS_RDIMM_ENABLED(reg) GET_BITFIELD(reg, 11, 11)
267
268/*
269 * sbridge structs
270 */
271
272#define NUM_CHANNELS 4
273#define MAX_DIMMS 3 /* Max DIMMS per channel */
274
275struct sbridge_info {
276 u32 mcmtr;
277};
278
279struct sbridge_channel {
280 u32 ranks;
281 u32 dimms;
282};
283
284struct pci_id_descr {
285 int dev;
286 int func;
287 int dev_id;
288 int optional;
289};
290
291struct pci_id_table {
292 const struct pci_id_descr *descr;
293 int n_devs;
294};
295
296struct sbridge_dev {
297 struct list_head list;
298 u8 bus, mc;
299 u8 node_id, source_id;
300 struct pci_dev **pdev;
301 int n_devs;
302 struct mem_ctl_info *mci;
303};
304
305struct sbridge_pvt {
306 struct pci_dev *pci_ta, *pci_ddrio, *pci_ras;
307 struct pci_dev *pci_sad0, *pci_sad1, *pci_ha0;
308 struct pci_dev *pci_br;
309 struct pci_dev *pci_tad[NUM_CHANNELS];
310
311 struct sbridge_dev *sbridge_dev;
312
313 struct sbridge_info info;
314 struct sbridge_channel channel[NUM_CHANNELS];
315
316 int csrow_map[NUM_CHANNELS][MAX_DIMMS];
317
318 /* Memory type detection */
319 bool is_mirrored, is_lockstep, is_close_pg;
320
321 /* Fifo double buffers */
322 struct mce mce_entry[MCE_LOG_LEN];
323 struct mce mce_outentry[MCE_LOG_LEN];
324
325 /* Fifo in/out counters */
326 unsigned mce_in, mce_out;
327
328 /* Count indicator to show errors not got */
329 unsigned mce_overrun;
330
331 /* Memory description */
332 u64 tolm, tohm;
333};
334
335#define PCI_DESCR(device, function, device_id) \
336 .dev = (device), \
337 .func = (function), \
338 .dev_id = (device_id)
339
340static const struct pci_id_descr pci_dev_descr_sbridge[] = {
341 /* Processor Home Agent */
342 { PCI_DESCR(14, 0, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_HA0) },
343
344 /* Memory controller */
345 { PCI_DESCR(15, 0, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA) },
346 { PCI_DESCR(15, 1, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_RAS) },
347 { PCI_DESCR(15, 2, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD0) },
348 { PCI_DESCR(15, 3, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD1) },
349 { PCI_DESCR(15, 4, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD2) },
350 { PCI_DESCR(15, 5, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TAD3) },
351 { PCI_DESCR(17, 0, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_DDRIO) },
352
353 /* System Address Decoder */
354 { PCI_DESCR(12, 6, PCI_DEVICE_ID_INTEL_SBRIDGE_SAD0) },
355 { PCI_DESCR(12, 7, PCI_DEVICE_ID_INTEL_SBRIDGE_SAD1) },
356
357 /* Broadcast Registers */
358 { PCI_DESCR(13, 6, PCI_DEVICE_ID_INTEL_SBRIDGE_BR) },
359};
360
361#define PCI_ID_TABLE_ENTRY(A) { .descr=A, .n_devs = ARRAY_SIZE(A) }
362static const struct pci_id_table pci_dev_descr_sbridge_table[] = {
363 PCI_ID_TABLE_ENTRY(pci_dev_descr_sbridge),
364 {0,} /* 0 terminated list. */
365};
366
367/*
368 * pci_device_id table for which devices we are looking for
369 */
370static const struct pci_device_id sbridge_pci_tbl[] __devinitdata = {
371 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SBRIDGE_IMC_TA)},
372 {0,} /* 0 terminated list. */
373};
374
375
376/****************************************************************************
377 Anciliary status routines
378 ****************************************************************************/
379
380static inline int numrank(u32 mtr)
381{
382 int ranks = (1 << RANK_CNT_BITS(mtr));
383
384 if (ranks > 4) {
385 debugf0("Invalid number of ranks: %d (max = 4) raw value = %x (%04x)",
386 ranks, (unsigned int)RANK_CNT_BITS(mtr), mtr);
387 return -EINVAL;
388 }
389
390 return ranks;
391}
392
393static inline int numrow(u32 mtr)
394{
395 int rows = (RANK_WIDTH_BITS(mtr) + 12);
396
397 if (rows < 13 || rows > 18) {
398 debugf0("Invalid number of rows: %d (should be between 14 and 17) raw value = %x (%04x)",
399 rows, (unsigned int)RANK_WIDTH_BITS(mtr), mtr);
400 return -EINVAL;
401 }
402
403 return 1 << rows;
404}
405
406static inline int numcol(u32 mtr)
407{
408 int cols = (COL_WIDTH_BITS(mtr) + 10);
409
410 if (cols > 12) {
411 debugf0("Invalid number of cols: %d (max = 4) raw value = %x (%04x)",
412 cols, (unsigned int)COL_WIDTH_BITS(mtr), mtr);
413 return -EINVAL;
414 }
415
416 return 1 << cols;
417}
418
419static struct sbridge_dev *get_sbridge_dev(u8 bus)
420{
421 struct sbridge_dev *sbridge_dev;
422
423 list_for_each_entry(sbridge_dev, &sbridge_edac_list, list) {
424 if (sbridge_dev->bus == bus)
425 return sbridge_dev;
426 }
427
428 return NULL;
429}
430
431static struct sbridge_dev *alloc_sbridge_dev(u8 bus,
432 const struct pci_id_table *table)
433{
434 struct sbridge_dev *sbridge_dev;
435
436 sbridge_dev = kzalloc(sizeof(*sbridge_dev), GFP_KERNEL);
437 if (!sbridge_dev)
438 return NULL;
439
440 sbridge_dev->pdev = kzalloc(sizeof(*sbridge_dev->pdev) * table->n_devs,
441 GFP_KERNEL);
442 if (!sbridge_dev->pdev) {
443 kfree(sbridge_dev);
444 return NULL;
445 }
446
447 sbridge_dev->bus = bus;
448 sbridge_dev->n_devs = table->n_devs;
449 list_add_tail(&sbridge_dev->list, &sbridge_edac_list);
450
451 return sbridge_dev;
452}
453
454static void free_sbridge_dev(struct sbridge_dev *sbridge_dev)
455{
456 list_del(&sbridge_dev->list);
457 kfree(sbridge_dev->pdev);
458 kfree(sbridge_dev);
459}
460
461/****************************************************************************
462 Memory check routines
463 ****************************************************************************/
464static struct pci_dev *get_pdev_slot_func(u8 bus, unsigned slot,
465 unsigned func)
466{
467 struct sbridge_dev *sbridge_dev = get_sbridge_dev(bus);
468 int i;
469
470 if (!sbridge_dev)
471 return NULL;
472
473 for (i = 0; i < sbridge_dev->n_devs; i++) {
474 if (!sbridge_dev->pdev[i])
475 continue;
476
477 if (PCI_SLOT(sbridge_dev->pdev[i]->devfn) == slot &&
478 PCI_FUNC(sbridge_dev->pdev[i]->devfn) == func) {
479 debugf1("Associated %02x.%02x.%d with %p\n",
480 bus, slot, func, sbridge_dev->pdev[i]);
481 return sbridge_dev->pdev[i];
482 }
483 }
484
485 return NULL;
486}
487
488/**
489 * sbridge_get_active_channels() - gets the number of channels and csrows
490 * bus: Device bus
491 * @channels: Number of channels that will be returned
492 * @csrows: Number of csrows found
493 *
494 * Since EDAC core needs to know in advance the number of available channels
495 * and csrows, in order to allocate memory for csrows/channels, it is needed
496 * to run two similar steps. At the first step, implemented on this function,
497 * it checks the number of csrows/channels present at one socket, identified
498 * by the associated PCI bus.
499 * this is used in order to properly allocate the size of mci components.
500 * Note: one csrow is one dimm.
501 */
502static int sbridge_get_active_channels(const u8 bus, unsigned *channels,
503 unsigned *csrows)
504{
505 struct pci_dev *pdev = NULL;
506 int i, j;
507 u32 mcmtr;
508
509 *channels = 0;
510 *csrows = 0;
511
512 pdev = get_pdev_slot_func(bus, 15, 0);
513 if (!pdev) {
514 sbridge_printk(KERN_ERR, "Couldn't find PCI device "
515 "%2x.%02d.%d!!!\n",
516 bus, 15, 0);
517 return -ENODEV;
518 }
519
520 pci_read_config_dword(pdev, MCMTR, &mcmtr);
521 if (!IS_ECC_ENABLED(mcmtr)) {
522 sbridge_printk(KERN_ERR, "ECC is disabled. Aborting\n");
523 return -ENODEV;
524 }
525
526 for (i = 0; i < NUM_CHANNELS; i++) {
527 u32 mtr;
528
529 /* Device 15 functions 2 - 5 */
530 pdev = get_pdev_slot_func(bus, 15, 2 + i);
531 if (!pdev) {
532 sbridge_printk(KERN_ERR, "Couldn't find PCI device "
533 "%2x.%02d.%d!!!\n",
534 bus, 15, 2 + i);
535 return -ENODEV;
536 }
537 (*channels)++;
538
539 for (j = 0; j < ARRAY_SIZE(mtr_regs); j++) {
540 pci_read_config_dword(pdev, mtr_regs[j], &mtr);
541 debugf1("Bus#%02x channel #%d MTR%d = %x\n", bus, i, j, mtr);
542 if (IS_DIMM_PRESENT(mtr))
543 (*csrows)++;
544 }
545 }
546
547 debugf0("Number of active channels: %d, number of active dimms: %d\n",
548 *channels, *csrows);
549
550 return 0;
551}
552
553static int get_dimm_config(const struct mem_ctl_info *mci)
554{
555 struct sbridge_pvt *pvt = mci->pvt_info;
556 struct csrow_info *csr;
557 int i, j, banks, ranks, rows, cols, size, npages;
558 int csrow = 0;
559 unsigned long last_page = 0;
560 u32 reg;
561 enum edac_type mode;
562 enum mem_type mtype;
563
564 pci_read_config_dword(pvt->pci_br, SAD_TARGET, &reg);
565 pvt->sbridge_dev->source_id = SOURCE_ID(reg);
566
567 pci_read_config_dword(pvt->pci_br, SAD_CONTROL, &reg);
568 pvt->sbridge_dev->node_id = NODE_ID(reg);
569 debugf0("mc#%d: Node ID: %d, source ID: %d\n",
570 pvt->sbridge_dev->mc,
571 pvt->sbridge_dev->node_id,
572 pvt->sbridge_dev->source_id);
573
574 pci_read_config_dword(pvt->pci_ras, RASENABLES, &reg);
575 if (IS_MIRROR_ENABLED(reg)) {
576 debugf0("Memory mirror is enabled\n");
577 pvt->is_mirrored = true;
578 } else {
579 debugf0("Memory mirror is disabled\n");
580 pvt->is_mirrored = false;
581 }
582
583 pci_read_config_dword(pvt->pci_ta, MCMTR, &pvt->info.mcmtr);
584 if (IS_LOCKSTEP_ENABLED(pvt->info.mcmtr)) {
585 debugf0("Lockstep is enabled\n");
586 mode = EDAC_S8ECD8ED;
587 pvt->is_lockstep = true;
588 } else {
589 debugf0("Lockstep is disabled\n");
590 mode = EDAC_S4ECD4ED;
591 pvt->is_lockstep = false;
592 }
593 if (IS_CLOSE_PG(pvt->info.mcmtr)) {
594 debugf0("address map is on closed page mode\n");
595 pvt->is_close_pg = true;
596 } else {
597 debugf0("address map is on open page mode\n");
598 pvt->is_close_pg = false;
599 }
600
601 pci_read_config_dword(pvt->pci_ta, RANK_CFG_A, &reg);
602 if (IS_RDIMM_ENABLED(reg)) {
603 /* FIXME: Can also be LRDIMM */
604 debugf0("Memory is registered\n");
605 mtype = MEM_RDDR3;
606 } else {
607 debugf0("Memory is unregistered\n");
608 mtype = MEM_DDR3;
609 }
610
611 /* On all supported DDR3 DIMM types, there are 8 banks available */
612 banks = 8;
613
614 for (i = 0; i < NUM_CHANNELS; i++) {
615 u32 mtr;
616
617 for (j = 0; j < ARRAY_SIZE(mtr_regs); j++) {
618 pci_read_config_dword(pvt->pci_tad[i],
619 mtr_regs[j], &mtr);
620 debugf4("Channel #%d MTR%d = %x\n", i, j, mtr);
621 if (IS_DIMM_PRESENT(mtr)) {
622 pvt->channel[i].dimms++;
623
624 ranks = numrank(mtr);
625 rows = numrow(mtr);
626 cols = numcol(mtr);
627
628 /* DDR3 has 8 I/O banks */
629 size = (rows * cols * banks * ranks) >> (20 - 3);
630 npages = MiB_TO_PAGES(size);
631
632 debugf0("mc#%d: channel %d, dimm %d, %d Mb (%d pages) bank: %d, rank: %d, row: %#x, col: %#x\n",
633 pvt->sbridge_dev->mc, i, j,
634 size, npages,
635 banks, ranks, rows, cols);
636 csr = &mci->csrows[csrow];
637
638 csr->first_page = last_page;
639 csr->last_page = last_page + npages - 1;
640 csr->page_mask = 0UL; /* Unused */
641 csr->nr_pages = npages;
642 csr->grain = 32;
643 csr->csrow_idx = csrow;
644 csr->dtype = (banks == 8) ? DEV_X8 : DEV_X4;
645 csr->ce_count = 0;
646 csr->ue_count = 0;
647 csr->mtype = mtype;
648 csr->edac_mode = mode;
649 csr->nr_channels = 1;
650 csr->channels[0].chan_idx = i;
651 csr->channels[0].ce_count = 0;
652 pvt->csrow_map[i][j] = csrow;
653 snprintf(csr->channels[0].label,
654 sizeof(csr->channels[0].label),
655 "CPU_SrcID#%u_Channel#%u_DIMM#%u",
656 pvt->sbridge_dev->source_id, i, j);
657 last_page += npages;
658 csrow++;
659 }
660 }
661 }
662
663 return 0;
664}
665
666static void get_memory_layout(const struct mem_ctl_info *mci)
667{
668 struct sbridge_pvt *pvt = mci->pvt_info;
669 int i, j, k, n_sads, n_tads, sad_interl;
670 u32 reg;
671 u64 limit, prv = 0;
672 u64 tmp_mb;
673 u32 rir_way;
674
675 /*
676 * Step 1) Get TOLM/TOHM ranges
677 */
678
679 /* Address range is 32:28 */
680 pci_read_config_dword(pvt->pci_sad1, TOLM,
681 &reg);
682 pvt->tolm = GET_TOLM(reg);
683 tmp_mb = (1 + pvt->tolm) >> 20;
684
685 debugf0("TOLM: %Lu.%03Lu GB (0x%016Lx)\n",
686 tmp_mb / 1000, tmp_mb % 1000, (u64)pvt->tolm);
687
688 /* Address range is already 45:25 */
689 pci_read_config_dword(pvt->pci_sad1, TOHM,
690 &reg);
691 pvt->tohm = GET_TOHM(reg);
692 tmp_mb = (1 + pvt->tohm) >> 20;
693
694 debugf0("TOHM: %Lu.%03Lu GB (0x%016Lx)",
695 tmp_mb / 1000, tmp_mb % 1000, (u64)pvt->tohm);
696
697 /*
698 * Step 2) Get SAD range and SAD Interleave list
699 * TAD registers contain the interleave wayness. However, it
700 * seems simpler to just discover it indirectly, with the
701 * algorithm bellow.
702 */
703 prv = 0;
704 for (n_sads = 0; n_sads < MAX_SAD; n_sads++) {
705 /* SAD_LIMIT Address range is 45:26 */
706 pci_read_config_dword(pvt->pci_sad0, dram_rule[n_sads],
707 &reg);
708 limit = SAD_LIMIT(reg);
709
710 if (!DRAM_RULE_ENABLE(reg))
711 continue;
712
713 if (limit <= prv)
714 break;
715
716 tmp_mb = (limit + 1) >> 20;
717 debugf0("SAD#%d %s up to %Lu.%03Lu GB (0x%016Lx) %s reg=0x%08x\n",
718 n_sads,
719 get_dram_attr(reg),
720 tmp_mb / 1000, tmp_mb % 1000,
721 ((u64)tmp_mb) << 20L,
722 INTERLEAVE_MODE(reg) ? "Interleave: 8:6" : "Interleave: [8:6]XOR[18:16]",
723 reg);
724 prv = limit;
725
726 pci_read_config_dword(pvt->pci_sad0, interleave_list[n_sads],
727 &reg);
728 sad_interl = sad_pkg(reg, 0);
729 for (j = 0; j < 8; j++) {
730 if (j > 0 && sad_interl == sad_pkg(reg, j))
731 break;
732
733 debugf0("SAD#%d, interleave #%d: %d\n",
734 n_sads, j, sad_pkg(reg, j));
735 }
736 }
737
738 /*
739 * Step 3) Get TAD range
740 */
741 prv = 0;
742 for (n_tads = 0; n_tads < MAX_TAD; n_tads++) {
743 pci_read_config_dword(pvt->pci_ha0, tad_dram_rule[n_tads],
744 &reg);
745 limit = TAD_LIMIT(reg);
746 if (limit <= prv)
747 break;
748 tmp_mb = (limit + 1) >> 20;
749
750 debugf0("TAD#%d: up to %Lu.%03Lu GB (0x%016Lx), socket interleave %d, memory interleave %d, TGT: %d, %d, %d, %d, reg=0x%08x\n",
751 n_tads, tmp_mb / 1000, tmp_mb % 1000,
752 ((u64)tmp_mb) << 20L,
753 (u32)TAD_SOCK(reg),
754 (u32)TAD_CH(reg),
755 (u32)TAD_TGT0(reg),
756 (u32)TAD_TGT1(reg),
757 (u32)TAD_TGT2(reg),
758 (u32)TAD_TGT3(reg),
759 reg);
760 prv = tmp_mb;
761 }
762
763 /*
764 * Step 4) Get TAD offsets, per each channel
765 */
766 for (i = 0; i < NUM_CHANNELS; i++) {
767 if (!pvt->channel[i].dimms)
768 continue;
769 for (j = 0; j < n_tads; j++) {
770 pci_read_config_dword(pvt->pci_tad[i],
771 tad_ch_nilv_offset[j],
772 &reg);
773 tmp_mb = TAD_OFFSET(reg) >> 20;
774 debugf0("TAD CH#%d, offset #%d: %Lu.%03Lu GB (0x%016Lx), reg=0x%08x\n",
775 i, j,
776 tmp_mb / 1000, tmp_mb % 1000,
777 ((u64)tmp_mb) << 20L,
778 reg);
779 }
780 }
781
782 /*
783 * Step 6) Get RIR Wayness/Limit, per each channel
784 */
785 for (i = 0; i < NUM_CHANNELS; i++) {
786 if (!pvt->channel[i].dimms)
787 continue;
788 for (j = 0; j < MAX_RIR_RANGES; j++) {
789 pci_read_config_dword(pvt->pci_tad[i],
790 rir_way_limit[j],
791 &reg);
792
793 if (!IS_RIR_VALID(reg))
794 continue;
795
796 tmp_mb = RIR_LIMIT(reg) >> 20;
797 rir_way = 1 << RIR_WAY(reg);
798 debugf0("CH#%d RIR#%d, limit: %Lu.%03Lu GB (0x%016Lx), way: %d, reg=0x%08x\n",
799 i, j,
800 tmp_mb / 1000, tmp_mb % 1000,
801 ((u64)tmp_mb) << 20L,
802 rir_way,
803 reg);
804
805 for (k = 0; k < rir_way; k++) {
806 pci_read_config_dword(pvt->pci_tad[i],
807 rir_offset[j][k],
808 &reg);
809 tmp_mb = RIR_OFFSET(reg) << 6;
810
811 debugf0("CH#%d RIR#%d INTL#%d, offset %Lu.%03Lu GB (0x%016Lx), tgt: %d, reg=0x%08x\n",
812 i, j, k,
813 tmp_mb / 1000, tmp_mb % 1000,
814 ((u64)tmp_mb) << 20L,
815 (u32)RIR_RNK_TGT(reg),
816 reg);
817 }
818 }
819 }
820}
821
822struct mem_ctl_info *get_mci_for_node_id(u8 node_id)
823{
824 struct sbridge_dev *sbridge_dev;
825
826 list_for_each_entry(sbridge_dev, &sbridge_edac_list, list) {
827 if (sbridge_dev->node_id == node_id)
828 return sbridge_dev->mci;
829 }
830 return NULL;
831}
832
833static int get_memory_error_data(struct mem_ctl_info *mci,
834 u64 addr,
835 u8 *socket,
836 long *channel_mask,
837 u8 *rank,
838 char *area_type)
839{
840 struct mem_ctl_info *new_mci;
841 struct sbridge_pvt *pvt = mci->pvt_info;
842 char msg[256];
843 int n_rir, n_sads, n_tads, sad_way, sck_xch;
844 int sad_interl, idx, base_ch;
845 int interleave_mode;
846 unsigned sad_interleave[MAX_INTERLEAVE];
847 u32 reg;
848 u8 ch_way,sck_way;
849 u32 tad_offset;
850 u32 rir_way;
851 u64 ch_addr, offset, limit, prv = 0;
852
853
854 /*
855 * Step 0) Check if the address is at special memory ranges
856 * The check bellow is probably enough to fill all cases where
857 * the error is not inside a memory, except for the legacy
858 * range (e. g. VGA addresses). It is unlikely, however, that the
859 * memory controller would generate an error on that range.
860 */
861 if ((addr > (u64) pvt->tolm) && (addr < (1L << 32))) {
862 sprintf(msg, "Error at TOLM area, on addr 0x%08Lx", addr);
863 edac_mc_handle_ce_no_info(mci, msg);
864 return -EINVAL;
865 }
866 if (addr >= (u64)pvt->tohm) {
867 sprintf(msg, "Error at MMIOH area, on addr 0x%016Lx", addr);
868 edac_mc_handle_ce_no_info(mci, msg);
869 return -EINVAL;
870 }
871
872 /*
873 * Step 1) Get socket
874 */
875 for (n_sads = 0; n_sads < MAX_SAD; n_sads++) {
876 pci_read_config_dword(pvt->pci_sad0, dram_rule[n_sads],
877 &reg);
878
879 if (!DRAM_RULE_ENABLE(reg))
880 continue;
881
882 limit = SAD_LIMIT(reg);
883 if (limit <= prv) {
884 sprintf(msg, "Can't discover the memory socket");
885 edac_mc_handle_ce_no_info(mci, msg);
886 return -EINVAL;
887 }
888 if (addr <= limit)
889 break;
890 prv = limit;
891 }
892 if (n_sads == MAX_SAD) {
893 sprintf(msg, "Can't discover the memory socket");
894 edac_mc_handle_ce_no_info(mci, msg);
895 return -EINVAL;
896 }
897 area_type = get_dram_attr(reg);
898 interleave_mode = INTERLEAVE_MODE(reg);
899
900 pci_read_config_dword(pvt->pci_sad0, interleave_list[n_sads],
901 &reg);
902 sad_interl = sad_pkg(reg, 0);
903 for (sad_way = 0; sad_way < 8; sad_way++) {
904 if (sad_way > 0 && sad_interl == sad_pkg(reg, sad_way))
905 break;
906 sad_interleave[sad_way] = sad_pkg(reg, sad_way);
907 debugf0("SAD interleave #%d: %d\n",
908 sad_way, sad_interleave[sad_way]);
909 }
910 debugf0("mc#%d: Error detected on SAD#%d: address 0x%016Lx < 0x%016Lx, Interleave [%d:6]%s\n",
911 pvt->sbridge_dev->mc,
912 n_sads,
913 addr,
914 limit,
915 sad_way + 7,
916 INTERLEAVE_MODE(reg) ? "" : "XOR[18:16]");
917 if (interleave_mode)
918 idx = ((addr >> 6) ^ (addr >> 16)) & 7;
919 else
920 idx = (addr >> 6) & 7;
921 switch (sad_way) {
922 case 1:
923 idx = 0;
924 break;
925 case 2:
926 idx = idx & 1;
927 break;
928 case 4:
929 idx = idx & 3;
930 break;
931 case 8:
932 break;
933 default:
934 sprintf(msg, "Can't discover socket interleave");
935 edac_mc_handle_ce_no_info(mci, msg);
936 return -EINVAL;
937 }
938 *socket = sad_interleave[idx];
939 debugf0("SAD interleave index: %d (wayness %d) = CPU socket %d\n",
940 idx, sad_way, *socket);
941
942 /*
943 * Move to the proper node structure, in order to access the
944 * right PCI registers
945 */
946 new_mci = get_mci_for_node_id(*socket);
947 if (!new_mci) {
948 sprintf(msg, "Struct for socket #%u wasn't initialized",
949 *socket);
950 edac_mc_handle_ce_no_info(mci, msg);
951 return -EINVAL;
952 }
953 mci = new_mci;
954 pvt = mci->pvt_info;
955
956 /*
957 * Step 2) Get memory channel
958 */
959 prv = 0;
960 for (n_tads = 0; n_tads < MAX_TAD; n_tads++) {
961 pci_read_config_dword(pvt->pci_ha0, tad_dram_rule[n_tads],
962 &reg);
963 limit = TAD_LIMIT(reg);
964 if (limit <= prv) {
965 sprintf(msg, "Can't discover the memory channel");
966 edac_mc_handle_ce_no_info(mci, msg);
967 return -EINVAL;
968 }
969 if (addr <= limit)
970 break;
971 prv = limit;
972 }
973 ch_way = TAD_CH(reg) + 1;
974 sck_way = TAD_SOCK(reg) + 1;
975 /*
976 * FIXME: Is it right to always use channel 0 for offsets?
977 */
978 pci_read_config_dword(pvt->pci_tad[0],
979 tad_ch_nilv_offset[n_tads],
980 &tad_offset);
981
982 if (ch_way == 3)
983 idx = addr >> 6;
984 else
985 idx = addr >> (6 + sck_way);
986 idx = idx % ch_way;
987
988 /*
989 * FIXME: Shouldn't we use CHN_IDX_OFFSET() here, when ch_way == 3 ???
990 */
991 switch (idx) {
992 case 0:
993 base_ch = TAD_TGT0(reg);
994 break;
995 case 1:
996 base_ch = TAD_TGT1(reg);
997 break;
998 case 2:
999 base_ch = TAD_TGT2(reg);
1000 break;
1001 case 3:
1002 base_ch = TAD_TGT3(reg);
1003 break;
1004 default:
1005 sprintf(msg, "Can't discover the TAD target");
1006 edac_mc_handle_ce_no_info(mci, msg);
1007 return -EINVAL;
1008 }
1009 *channel_mask = 1 << base_ch;
1010
1011 if (pvt->is_mirrored) {
1012 *channel_mask |= 1 << ((base_ch + 2) % 4);
1013 switch(ch_way) {
1014 case 2:
1015 case 4:
1016 sck_xch = 1 << sck_way * (ch_way >> 1);
1017 break;
1018 default:
1019 sprintf(msg, "Invalid mirror set. Can't decode addr");
1020 edac_mc_handle_ce_no_info(mci, msg);
1021 return -EINVAL;
1022 }
1023 } else
1024 sck_xch = (1 << sck_way) * ch_way;
1025
1026 if (pvt->is_lockstep)
1027 *channel_mask |= 1 << ((base_ch + 1) % 4);
1028
1029 offset = TAD_OFFSET(tad_offset);
1030
1031 debugf0("TAD#%d: address 0x%016Lx < 0x%016Lx, socket interleave %d, channel interleave %d (offset 0x%08Lx), index %d, base ch: %d, ch mask: 0x%02lx\n",
1032 n_tads,
1033 addr,
1034 limit,
1035 (u32)TAD_SOCK(reg),
1036 ch_way,
1037 offset,
1038 idx,
1039 base_ch,
1040 *channel_mask);
1041
1042 /* Calculate channel address */
1043 /* Remove the TAD offset */
1044
1045 if (offset > addr) {
1046 sprintf(msg, "Can't calculate ch addr: TAD offset 0x%08Lx is too high for addr 0x%08Lx!",
1047 offset, addr);
1048 edac_mc_handle_ce_no_info(mci, msg);
1049 return -EINVAL;
1050 }
1051 addr -= offset;
1052 /* Store the low bits [0:6] of the addr */
1053 ch_addr = addr & 0x7f;
1054 /* Remove socket wayness and remove 6 bits */
1055 addr >>= 6;
1056 addr /= sck_xch;
1057#if 0
1058 /* Divide by channel way */
1059 addr = addr / ch_way;
1060#endif
1061 /* Recover the last 6 bits */
1062 ch_addr |= addr << 6;
1063
1064 /*
1065 * Step 3) Decode rank
1066 */
1067 for (n_rir = 0; n_rir < MAX_RIR_RANGES; n_rir++) {
1068 pci_read_config_dword(pvt->pci_tad[base_ch],
1069 rir_way_limit[n_rir],
1070 &reg);
1071
1072 if (!IS_RIR_VALID(reg))
1073 continue;
1074
1075 limit = RIR_LIMIT(reg);
1076
1077 debugf0("RIR#%d, limit: %Lu.%03Lu GB (0x%016Lx), way: %d\n",
1078 n_rir,
1079 (limit >> 20) / 1000, (limit >> 20) % 1000,
1080 limit,
1081 1 << RIR_WAY(reg));
1082 if (ch_addr <= limit)
1083 break;
1084 }
1085 if (n_rir == MAX_RIR_RANGES) {
1086 sprintf(msg, "Can't discover the memory rank for ch addr 0x%08Lx",
1087 ch_addr);
1088 edac_mc_handle_ce_no_info(mci, msg);
1089 return -EINVAL;
1090 }
1091 rir_way = RIR_WAY(reg);
1092 if (pvt->is_close_pg)
1093 idx = (ch_addr >> 6);
1094 else
1095 idx = (ch_addr >> 13); /* FIXME: Datasheet says to shift by 15 */
1096 idx %= 1 << rir_way;
1097
1098 pci_read_config_dword(pvt->pci_tad[base_ch],
1099 rir_offset[n_rir][idx],
1100 &reg);
1101 *rank = RIR_RNK_TGT(reg);
1102
1103 debugf0("RIR#%d: channel address 0x%08Lx < 0x%08Lx, RIR interleave %d, index %d\n",
1104 n_rir,
1105 ch_addr,
1106 limit,
1107 rir_way,
1108 idx);
1109
1110 return 0;
1111}
1112
1113/****************************************************************************
1114 Device initialization routines: put/get, init/exit
1115 ****************************************************************************/
1116
1117/*
1118 * sbridge_put_all_devices 'put' all the devices that we have
1119 * reserved via 'get'
1120 */
1121static void sbridge_put_devices(struct sbridge_dev *sbridge_dev)
1122{
1123 int i;
1124
1125 debugf0(__FILE__ ": %s()\n", __func__);
1126 for (i = 0; i < sbridge_dev->n_devs; i++) {
1127 struct pci_dev *pdev = sbridge_dev->pdev[i];
1128 if (!pdev)
1129 continue;
1130 debugf0("Removing dev %02x:%02x.%d\n",
1131 pdev->bus->number,
1132 PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
1133 pci_dev_put(pdev);
1134 }
1135}
1136
1137static void sbridge_put_all_devices(void)
1138{
1139 struct sbridge_dev *sbridge_dev, *tmp;
1140
1141 list_for_each_entry_safe(sbridge_dev, tmp, &sbridge_edac_list, list) {
1142 sbridge_put_devices(sbridge_dev);
1143 free_sbridge_dev(sbridge_dev);
1144 }
1145}
1146
1147/*
1148 * sbridge_get_all_devices Find and perform 'get' operation on the MCH's
1149 * device/functions we want to reference for this driver
1150 *
1151 * Need to 'get' device 16 func 1 and func 2
1152 */
1153static int sbridge_get_onedevice(struct pci_dev **prev,
1154 u8 *num_mc,
1155 const struct pci_id_table *table,
1156 const unsigned devno)
1157{
1158 struct sbridge_dev *sbridge_dev;
1159 const struct pci_id_descr *dev_descr = &table->descr[devno];
1160
1161 struct pci_dev *pdev = NULL;
1162 u8 bus = 0;
1163
1164 sbridge_printk(KERN_INFO,
1165 "Seeking for: dev %02x.%d PCI ID %04x:%04x\n",
1166 dev_descr->dev, dev_descr->func,
1167 PCI_VENDOR_ID_INTEL, dev_descr->dev_id);
1168
1169 pdev = pci_get_device(PCI_VENDOR_ID_INTEL,
1170 dev_descr->dev_id, *prev);
1171
1172 if (!pdev) {
1173 if (*prev) {
1174 *prev = pdev;
1175 return 0;
1176 }
1177
1178 if (dev_descr->optional)
1179 return 0;
1180
1181 if (devno == 0)
1182 return -ENODEV;
1183
1184 sbridge_printk(KERN_INFO,
1185 "Device not found: dev %02x.%d PCI ID %04x:%04x\n",
1186 dev_descr->dev, dev_descr->func,
1187 PCI_VENDOR_ID_INTEL, dev_descr->dev_id);
1188
1189 /* End of list, leave */
1190 return -ENODEV;
1191 }
1192 bus = pdev->bus->number;
1193
1194 sbridge_dev = get_sbridge_dev(bus);
1195 if (!sbridge_dev) {
1196 sbridge_dev = alloc_sbridge_dev(bus, table);
1197 if (!sbridge_dev) {
1198 pci_dev_put(pdev);
1199 return -ENOMEM;
1200 }
1201 (*num_mc)++;
1202 }
1203
1204 if (sbridge_dev->pdev[devno]) {
1205 sbridge_printk(KERN_ERR,
1206 "Duplicated device for "
1207 "dev %02x:%d.%d PCI ID %04x:%04x\n",
1208 bus, dev_descr->dev, dev_descr->func,
1209 PCI_VENDOR_ID_INTEL, dev_descr->dev_id);
1210 pci_dev_put(pdev);
1211 return -ENODEV;
1212 }
1213
1214 sbridge_dev->pdev[devno] = pdev;
1215
1216 /* Sanity check */
1217 if (unlikely(PCI_SLOT(pdev->devfn) != dev_descr->dev ||
1218 PCI_FUNC(pdev->devfn) != dev_descr->func)) {
1219 sbridge_printk(KERN_ERR,
1220 "Device PCI ID %04x:%04x "
1221 "has dev %02x:%d.%d instead of dev %02x:%02x.%d\n",
1222 PCI_VENDOR_ID_INTEL, dev_descr->dev_id,
1223 bus, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
1224 bus, dev_descr->dev, dev_descr->func);
1225 return -ENODEV;
1226 }
1227
1228 /* Be sure that the device is enabled */
1229 if (unlikely(pci_enable_device(pdev) < 0)) {
1230 sbridge_printk(KERN_ERR,
1231 "Couldn't enable "
1232 "dev %02x:%d.%d PCI ID %04x:%04x\n",
1233 bus, dev_descr->dev, dev_descr->func,
1234 PCI_VENDOR_ID_INTEL, dev_descr->dev_id);
1235 return -ENODEV;
1236 }
1237
1238 debugf0("Detected dev %02x:%d.%d PCI ID %04x:%04x\n",
1239 bus, dev_descr->dev,
1240 dev_descr->func,
1241 PCI_VENDOR_ID_INTEL, dev_descr->dev_id);
1242
1243 /*
1244 * As stated on drivers/pci/search.c, the reference count for
1245 * @from is always decremented if it is not %NULL. So, as we need
1246 * to get all devices up to null, we need to do a get for the device
1247 */
1248 pci_dev_get(pdev);
1249
1250 *prev = pdev;
1251
1252 return 0;
1253}
1254
1255static int sbridge_get_all_devices(u8 *num_mc)
1256{
1257 int i, rc;
1258 struct pci_dev *pdev = NULL;
1259 const struct pci_id_table *table = pci_dev_descr_sbridge_table;
1260
1261 while (table && table->descr) {
1262 for (i = 0; i < table->n_devs; i++) {
1263 pdev = NULL;
1264 do {
1265 rc = sbridge_get_onedevice(&pdev, num_mc,
1266 table, i);
1267 if (rc < 0) {
1268 if (i == 0) {
1269 i = table->n_devs;
1270 break;
1271 }
1272 sbridge_put_all_devices();
1273 return -ENODEV;
1274 }
1275 } while (pdev);
1276 }
1277 table++;
1278 }
1279
1280 return 0;
1281}
1282
1283static int mci_bind_devs(struct mem_ctl_info *mci,
1284 struct sbridge_dev *sbridge_dev)
1285{
1286 struct sbridge_pvt *pvt = mci->pvt_info;
1287 struct pci_dev *pdev;
1288 int i, func, slot;
1289
1290 for (i = 0; i < sbridge_dev->n_devs; i++) {
1291 pdev = sbridge_dev->pdev[i];
1292 if (!pdev)
1293 continue;
1294 slot = PCI_SLOT(pdev->devfn);
1295 func = PCI_FUNC(pdev->devfn);
1296 switch (slot) {
1297 case 12:
1298 switch (func) {
1299 case 6:
1300 pvt->pci_sad0 = pdev;
1301 break;
1302 case 7:
1303 pvt->pci_sad1 = pdev;
1304 break;
1305 default:
1306 goto error;
1307 }
1308 break;
1309 case 13:
1310 switch (func) {
1311 case 6:
1312 pvt->pci_br = pdev;
1313 break;
1314 default:
1315 goto error;
1316 }
1317 break;
1318 case 14:
1319 switch (func) {
1320 case 0:
1321 pvt->pci_ha0 = pdev;
1322 break;
1323 default:
1324 goto error;
1325 }
1326 break;
1327 case 15:
1328 switch (func) {
1329 case 0:
1330 pvt->pci_ta = pdev;
1331 break;
1332 case 1:
1333 pvt->pci_ras = pdev;
1334 break;
1335 case 2:
1336 case 3:
1337 case 4:
1338 case 5:
1339 pvt->pci_tad[func - 2] = pdev;
1340 break;
1341 default:
1342 goto error;
1343 }
1344 break;
1345 case 17:
1346 switch (func) {
1347 case 0:
1348 pvt->pci_ddrio = pdev;
1349 break;
1350 default:
1351 goto error;
1352 }
1353 break;
1354 default:
1355 goto error;
1356 }
1357
1358 debugf0("Associated PCI %02x.%02d.%d with dev = %p\n",
1359 sbridge_dev->bus,
1360 PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
1361 pdev);
1362 }
1363
1364 /* Check if everything were registered */
1365 if (!pvt->pci_sad0 || !pvt->pci_sad1 || !pvt->pci_ha0 ||
1366 !pvt-> pci_tad || !pvt->pci_ras || !pvt->pci_ta ||
1367 !pvt->pci_ddrio)
1368 goto enodev;
1369
1370 for (i = 0; i < NUM_CHANNELS; i++) {
1371 if (!pvt->pci_tad[i])
1372 goto enodev;
1373 }
1374 return 0;
1375
1376enodev:
1377 sbridge_printk(KERN_ERR, "Some needed devices are missing\n");
1378 return -ENODEV;
1379
1380error:
1381 sbridge_printk(KERN_ERR, "Device %d, function %d "
1382 "is out of the expected range\n",
1383 slot, func);
1384 return -EINVAL;
1385}
1386
1387/****************************************************************************
1388 Error check routines
1389 ****************************************************************************/
1390
1391/*
1392 * While Sandy Bridge has error count registers, SMI BIOS read values from
1393 * and resets the counters. So, they are not reliable for the OS to read
1394 * from them. So, we have no option but to just trust on whatever MCE is
1395 * telling us about the errors.
1396 */
1397static void sbridge_mce_output_error(struct mem_ctl_info *mci,
1398 const struct mce *m)
1399{
1400 struct mem_ctl_info *new_mci;
1401 struct sbridge_pvt *pvt = mci->pvt_info;
1402 char *type, *optype, *msg, *recoverable_msg;
1403 bool ripv = GET_BITFIELD(m->mcgstatus, 0, 0);
1404 bool overflow = GET_BITFIELD(m->status, 62, 62);
1405 bool uncorrected_error = GET_BITFIELD(m->status, 61, 61);
1406 bool recoverable = GET_BITFIELD(m->status, 56, 56);
1407 u32 core_err_cnt = GET_BITFIELD(m->status, 38, 52);
1408 u32 mscod = GET_BITFIELD(m->status, 16, 31);
1409 u32 errcode = GET_BITFIELD(m->status, 0, 15);
1410 u32 channel = GET_BITFIELD(m->status, 0, 3);
1411 u32 optypenum = GET_BITFIELD(m->status, 4, 6);
1412 long channel_mask, first_channel;
1413 u8 rank, socket;
1414 int csrow, rc, dimm;
1415 char *area_type = "Unknown";
1416
1417 if (ripv)
1418 type = "NON_FATAL";
1419 else
1420 type = "FATAL";
1421
1422 /*
1423 * According with Table 15-9 of the Intel Archictecture spec vol 3A,
1424 * memory errors should fit in this mask:
1425 * 000f 0000 1mmm cccc (binary)
1426 * where:
1427 * f = Correction Report Filtering Bit. If 1, subsequent errors
1428 * won't be shown
1429 * mmm = error type
1430 * cccc = channel
1431 * If the mask doesn't match, report an error to the parsing logic
1432 */
1433 if (! ((errcode & 0xef80) == 0x80)) {
1434 optype = "Can't parse: it is not a mem";
1435 } else {
1436 switch (optypenum) {
1437 case 0:
1438 optype = "generic undef request";
1439 break;
1440 case 1:
1441 optype = "memory read";
1442 break;
1443 case 2:
1444 optype = "memory write";
1445 break;
1446 case 3:
1447 optype = "addr/cmd";
1448 break;
1449 case 4:
1450 optype = "memory scrubbing";
1451 break;
1452 default:
1453 optype = "reserved";
1454 break;
1455 }
1456 }
1457
1458 rc = get_memory_error_data(mci, m->addr, &socket,
1459 &channel_mask, &rank, area_type);
1460 if (rc < 0)
1461 return;
1462 new_mci = get_mci_for_node_id(socket);
1463 if (!new_mci) {
1464 edac_mc_handle_ce_no_info(mci, "Error: socket got corrupted!");
1465 return;
1466 }
1467 mci = new_mci;
1468 pvt = mci->pvt_info;
1469
1470 first_channel = find_first_bit(&channel_mask, NUM_CHANNELS);
1471
1472 if (rank < 4)
1473 dimm = 0;
1474 else if (rank < 8)
1475 dimm = 1;
1476 else
1477 dimm = 2;
1478
1479 csrow = pvt->csrow_map[first_channel][dimm];
1480
1481 if (uncorrected_error && recoverable)
1482 recoverable_msg = " recoverable";
1483 else
1484 recoverable_msg = "";
1485
1486 /*
1487 * FIXME: What should we do with "channel" information on mcelog?
1488 * Probably, we can just discard it, as the channel information
1489 * comes from the get_memory_error_data() address decoding
1490 */
1491 msg = kasprintf(GFP_ATOMIC,
1492 "%d %s error(s): %s on %s area %s%s: cpu=%d Err=%04x:%04x (ch=%d), "
1493 "addr = 0x%08llx => socket=%d, Channel=%ld(mask=%ld), rank=%d\n",
1494 core_err_cnt,
1495 area_type,
1496 optype,
1497 type,
1498 recoverable_msg,
1499 overflow ? "OVERFLOW" : "",
1500 m->cpu,
1501 mscod, errcode,
1502 channel, /* 1111b means not specified */
1503 (long long) m->addr,
1504 socket,
1505 first_channel, /* This is the real channel on SB */
1506 channel_mask,
1507 rank);
1508
1509 debugf0("%s", msg);
1510
1511 /* Call the helper to output message */
1512 if (uncorrected_error)
1513 edac_mc_handle_fbd_ue(mci, csrow, 0, 0, msg);
1514 else
1515 edac_mc_handle_fbd_ce(mci, csrow, 0, msg);
1516
1517 kfree(msg);
1518}
1519
1520/*
1521 * sbridge_check_error Retrieve and process errors reported by the
1522 * hardware. Called by the Core module.
1523 */
1524static void sbridge_check_error(struct mem_ctl_info *mci)
1525{
1526 struct sbridge_pvt *pvt = mci->pvt_info;
1527 int i;
1528 unsigned count = 0;
1529 struct mce *m;
1530
1531 /*
1532 * MCE first step: Copy all mce errors into a temporary buffer
1533 * We use a double buffering here, to reduce the risk of
1534 * loosing an error.
1535 */
1536 smp_rmb();
1537 count = (pvt->mce_out + MCE_LOG_LEN - pvt->mce_in)
1538 % MCE_LOG_LEN;
1539 if (!count)
1540 return;
1541
1542 m = pvt->mce_outentry;
1543 if (pvt->mce_in + count > MCE_LOG_LEN) {
1544 unsigned l = MCE_LOG_LEN - pvt->mce_in;
1545
1546 memcpy(m, &pvt->mce_entry[pvt->mce_in], sizeof(*m) * l);
1547 smp_wmb();
1548 pvt->mce_in = 0;
1549 count -= l;
1550 m += l;
1551 }
1552 memcpy(m, &pvt->mce_entry[pvt->mce_in], sizeof(*m) * count);
1553 smp_wmb();
1554 pvt->mce_in += count;
1555
1556 smp_rmb();
1557 if (pvt->mce_overrun) {
1558 sbridge_printk(KERN_ERR, "Lost %d memory errors\n",
1559 pvt->mce_overrun);
1560 smp_wmb();
1561 pvt->mce_overrun = 0;
1562 }
1563
1564 /*
1565 * MCE second step: parse errors and display
1566 */
1567 for (i = 0; i < count; i++)
1568 sbridge_mce_output_error(mci, &pvt->mce_outentry[i]);
1569}
1570
1571/*
1572 * sbridge_mce_check_error Replicates mcelog routine to get errors
1573 * This routine simply queues mcelog errors, and
1574 * return. The error itself should be handled later
1575 * by sbridge_check_error.
1576 * WARNING: As this routine should be called at NMI time, extra care should
1577 * be taken to avoid deadlocks, and to be as fast as possible.
1578 */
1579static int sbridge_mce_check_error(struct notifier_block *nb, unsigned long val,
1580 void *data)
1581{
1582 struct mce *mce = (struct mce *)data;
1583 struct mem_ctl_info *mci;
1584 struct sbridge_pvt *pvt;
1585
1586 mci = get_mci_for_node_id(mce->socketid);
1587 if (!mci)
1588 return NOTIFY_BAD;
1589 pvt = mci->pvt_info;
1590
1591 /*
1592 * Just let mcelog handle it if the error is
1593 * outside the memory controller. A memory error
1594 * is indicated by bit 7 = 1 and bits = 8-11,13-15 = 0.
1595 * bit 12 has an special meaning.
1596 */
1597 if ((mce->status & 0xefff) >> 7 != 1)
1598 return NOTIFY_DONE;
1599
1600 printk("sbridge: HANDLING MCE MEMORY ERROR\n");
1601
1602 printk("CPU %d: Machine Check Exception: %Lx Bank %d: %016Lx\n",
1603 mce->extcpu, mce->mcgstatus, mce->bank, mce->status);
1604 printk("TSC %llx ", mce->tsc);
1605 printk("ADDR %llx ", mce->addr);
1606 printk("MISC %llx ", mce->misc);
1607
1608 printk("PROCESSOR %u:%x TIME %llu SOCKET %u APIC %x\n",
1609 mce->cpuvendor, mce->cpuid, mce->time,
1610 mce->socketid, mce->apicid);
1611
1612#ifdef CONFIG_SMP
1613 /* Only handle if it is the right mc controller */
1614 if (cpu_data(mce->cpu).phys_proc_id != pvt->sbridge_dev->mc)
1615 return NOTIFY_DONE;
1616#endif
1617
1618 smp_rmb();
1619 if ((pvt->mce_out + 1) % MCE_LOG_LEN == pvt->mce_in) {
1620 smp_wmb();
1621 pvt->mce_overrun++;
1622 return NOTIFY_DONE;
1623 }
1624
1625 /* Copy memory error at the ringbuffer */
1626 memcpy(&pvt->mce_entry[pvt->mce_out], mce, sizeof(*mce));
1627 smp_wmb();
1628 pvt->mce_out = (pvt->mce_out + 1) % MCE_LOG_LEN;
1629
1630 /* Handle fatal errors immediately */
1631 if (mce->mcgstatus & 1)
1632 sbridge_check_error(mci);
1633
1634 /* Advice mcelog that the error were handled */
1635 return NOTIFY_STOP;
1636}
1637
1638static struct notifier_block sbridge_mce_dec = {
1639 .notifier_call = sbridge_mce_check_error,
1640};
1641
1642/****************************************************************************
1643 EDAC register/unregister logic
1644 ****************************************************************************/
1645
1646static void sbridge_unregister_mci(struct sbridge_dev *sbridge_dev)
1647{
1648 struct mem_ctl_info *mci = sbridge_dev->mci;
1649 struct sbridge_pvt *pvt;
1650
1651 if (unlikely(!mci || !mci->pvt_info)) {
1652 debugf0("MC: " __FILE__ ": %s(): dev = %p\n",
1653 __func__, &sbridge_dev->pdev[0]->dev);
1654
1655 sbridge_printk(KERN_ERR, "Couldn't find mci handler\n");
1656 return;
1657 }
1658
1659 pvt = mci->pvt_info;
1660
1661 debugf0("MC: " __FILE__ ": %s(): mci = %p, dev = %p\n",
1662 __func__, mci, &sbridge_dev->pdev[0]->dev);
1663
1664 atomic_notifier_chain_unregister(&x86_mce_decoder_chain,
1665 &sbridge_mce_dec);
1666
1667 /* Remove MC sysfs nodes */
1668 edac_mc_del_mc(mci->dev);
1669
1670 debugf1("%s: free mci struct\n", mci->ctl_name);
1671 kfree(mci->ctl_name);
1672 edac_mc_free(mci);
1673 sbridge_dev->mci = NULL;
1674}
1675
1676static int sbridge_register_mci(struct sbridge_dev *sbridge_dev)
1677{
1678 struct mem_ctl_info *mci;
1679 struct sbridge_pvt *pvt;
1680 int rc, channels, csrows;
1681
1682 /* Check the number of active and not disabled channels */
1683 rc = sbridge_get_active_channels(sbridge_dev->bus, &channels, &csrows);
1684 if (unlikely(rc < 0))
1685 return rc;
1686
1687 /* allocate a new MC control structure */
1688 mci = edac_mc_alloc(sizeof(*pvt), csrows, channels, sbridge_dev->mc);
1689 if (unlikely(!mci))
1690 return -ENOMEM;
1691
1692 debugf0("MC: " __FILE__ ": %s(): mci = %p, dev = %p\n",
1693 __func__, mci, &sbridge_dev->pdev[0]->dev);
1694
1695 pvt = mci->pvt_info;
1696 memset(pvt, 0, sizeof(*pvt));
1697
1698 /* Associate sbridge_dev and mci for future usage */
1699 pvt->sbridge_dev = sbridge_dev;
1700 sbridge_dev->mci = mci;
1701
1702 mci->mtype_cap = MEM_FLAG_DDR3;
1703 mci->edac_ctl_cap = EDAC_FLAG_NONE;
1704 mci->edac_cap = EDAC_FLAG_NONE;
1705 mci->mod_name = "sbridge_edac.c";
1706 mci->mod_ver = SBRIDGE_REVISION;
1707 mci->ctl_name = kasprintf(GFP_KERNEL, "Sandy Bridge Socket#%d", mci->mc_idx);
1708 mci->dev_name = pci_name(sbridge_dev->pdev[0]);
1709 mci->ctl_page_to_phys = NULL;
1710
1711 /* Set the function pointer to an actual operation function */
1712 mci->edac_check = sbridge_check_error;
1713
1714 /* Store pci devices at mci for faster access */
1715 rc = mci_bind_devs(mci, sbridge_dev);
1716 if (unlikely(rc < 0))
1717 goto fail0;
1718
1719 /* Get dimm basic config and the memory layout */
1720 get_dimm_config(mci);
1721 get_memory_layout(mci);
1722
1723 /* record ptr to the generic device */
1724 mci->dev = &sbridge_dev->pdev[0]->dev;
1725
1726 /* add this new MC control structure to EDAC's list of MCs */
1727 if (unlikely(edac_mc_add_mc(mci))) {
1728 debugf0("MC: " __FILE__
1729 ": %s(): failed edac_mc_add_mc()\n", __func__);
1730 rc = -EINVAL;
1731 goto fail0;
1732 }
1733
1734 atomic_notifier_chain_register(&x86_mce_decoder_chain,
1735 &sbridge_mce_dec);
1736 return 0;
1737
1738fail0:
1739 kfree(mci->ctl_name);
1740 edac_mc_free(mci);
1741 sbridge_dev->mci = NULL;
1742 return rc;
1743}
1744
1745/*
1746 * sbridge_probe Probe for ONE instance of device to see if it is
1747 * present.
1748 * return:
1749 * 0 for FOUND a device
1750 * < 0 for error code
1751 */
1752
1753static int __devinit sbridge_probe(struct pci_dev *pdev,
1754 const struct pci_device_id *id)
1755{
1756 int rc;
1757 u8 mc, num_mc = 0;
1758 struct sbridge_dev *sbridge_dev;
1759
1760 /* get the pci devices we want to reserve for our use */
1761 mutex_lock(&sbridge_edac_lock);
1762
1763 /*
1764 * All memory controllers are allocated at the first pass.
1765 */
1766 if (unlikely(probed >= 1)) {
1767 mutex_unlock(&sbridge_edac_lock);
1768 return -ENODEV;
1769 }
1770 probed++;
1771
1772 rc = sbridge_get_all_devices(&num_mc);
1773 if (unlikely(rc < 0))
1774 goto fail0;
1775 mc = 0;
1776
1777 list_for_each_entry(sbridge_dev, &sbridge_edac_list, list) {
1778 debugf0("Registering MC#%d (%d of %d)\n", mc, mc + 1, num_mc);
1779 sbridge_dev->mc = mc++;
1780 rc = sbridge_register_mci(sbridge_dev);
1781 if (unlikely(rc < 0))
1782 goto fail1;
1783 }
1784
1785 sbridge_printk(KERN_INFO, "Driver loaded.\n");
1786
1787 mutex_unlock(&sbridge_edac_lock);
1788 return 0;
1789
1790fail1:
1791 list_for_each_entry(sbridge_dev, &sbridge_edac_list, list)
1792 sbridge_unregister_mci(sbridge_dev);
1793
1794 sbridge_put_all_devices();
1795fail0:
1796 mutex_unlock(&sbridge_edac_lock);
1797 return rc;
1798}
1799
1800/*
1801 * sbridge_remove destructor for one instance of device
1802 *
1803 */
1804static void __devexit sbridge_remove(struct pci_dev *pdev)
1805{
1806 struct sbridge_dev *sbridge_dev;
1807
1808 debugf0(__FILE__ ": %s()\n", __func__);
1809
1810 /*
1811 * we have a trouble here: pdev value for removal will be wrong, since
1812 * it will point to the X58 register used to detect that the machine
1813 * is a Nehalem or upper design. However, due to the way several PCI
1814 * devices are grouped together to provide MC functionality, we need
1815 * to use a different method for releasing the devices
1816 */
1817
1818 mutex_lock(&sbridge_edac_lock);
1819
1820 if (unlikely(!probed)) {
1821 mutex_unlock(&sbridge_edac_lock);
1822 return;
1823 }
1824
1825 list_for_each_entry(sbridge_dev, &sbridge_edac_list, list)
1826 sbridge_unregister_mci(sbridge_dev);
1827
1828 /* Release PCI resources */
1829 sbridge_put_all_devices();
1830
1831 probed--;
1832
1833 mutex_unlock(&sbridge_edac_lock);
1834}
1835
1836MODULE_DEVICE_TABLE(pci, sbridge_pci_tbl);
1837
1838/*
1839 * sbridge_driver pci_driver structure for this module
1840 *
1841 */
1842static struct pci_driver sbridge_driver = {
1843 .name = "sbridge_edac",
1844 .probe = sbridge_probe,
1845 .remove = __devexit_p(sbridge_remove),
1846 .id_table = sbridge_pci_tbl,
1847};
1848
1849/*
1850 * sbridge_init Module entry function
1851 * Try to initialize this module for its devices
1852 */
1853static int __init sbridge_init(void)
1854{
1855 int pci_rc;
1856
1857 debugf2("MC: " __FILE__ ": %s()\n", __func__);
1858
1859 /* Ensure that the OPSTATE is set correctly for POLL or NMI */
1860 opstate_init();
1861
1862 pci_rc = pci_register_driver(&sbridge_driver);
1863
1864 if (pci_rc >= 0)
1865 return 0;
1866
1867 sbridge_printk(KERN_ERR, "Failed to register device with error %d.\n",
1868 pci_rc);
1869
1870 return pci_rc;
1871}
1872
1873/*
1874 * sbridge_exit() Module exit function
1875 * Unregister the driver
1876 */
1877static void __exit sbridge_exit(void)
1878{
1879 debugf2("MC: " __FILE__ ": %s()\n", __func__);
1880 pci_unregister_driver(&sbridge_driver);
1881}
1882
1883module_init(sbridge_init);
1884module_exit(sbridge_exit);
1885
1886module_param(edac_op_state, int, 0444);
1887MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");
1888
1889MODULE_LICENSE("GPL");
1890MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>");
1891MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
1892MODULE_DESCRIPTION("MC Driver for Intel Sandy Bridge memory controllers - "
1893 SBRIDGE_REVISION);
diff --git a/drivers/firewire/core-iso.c b/drivers/firewire/core-iso.c
index 57c3973093ad..0f90e0071875 100644
--- a/drivers/firewire/core-iso.c
+++ b/drivers/firewire/core-iso.c
@@ -29,6 +29,7 @@
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/spinlock.h> 30#include <linux/spinlock.h>
31#include <linux/vmalloc.h> 31#include <linux/vmalloc.h>
32#include <linux/export.h>
32 33
33#include <asm/byteorder.h> 34#include <asm/byteorder.h>
34 35
diff --git a/drivers/firmware/edd.c b/drivers/firmware/edd.c
index f1b7f659d3c9..e22957665808 100644
--- a/drivers/firmware/edd.c
+++ b/drivers/firmware/edd.c
@@ -151,7 +151,8 @@ edd_show_host_bus(struct edd_device *edev, char *buf)
151 p += scnprintf(p, left, "\tbase_address: %x\n", 151 p += scnprintf(p, left, "\tbase_address: %x\n",
152 info->params.interface_path.isa.base_address); 152 info->params.interface_path.isa.base_address);
153 } else if (!strncmp(info->params.host_bus_type, "PCIX", 4) || 153 } else if (!strncmp(info->params.host_bus_type, "PCIX", 4) ||
154 !strncmp(info->params.host_bus_type, "PCI", 3)) { 154 !strncmp(info->params.host_bus_type, "PCI", 3) ||
155 !strncmp(info->params.host_bus_type, "XPRS", 4)) {
155 p += scnprintf(p, left, 156 p += scnprintf(p, left,
156 "\t%02x:%02x.%d channel: %u\n", 157 "\t%02x:%02x.%d channel: %u\n",
157 info->params.interface_path.pci.bus, 158 info->params.interface_path.pci.bus,
@@ -159,7 +160,6 @@ edd_show_host_bus(struct edd_device *edev, char *buf)
159 info->params.interface_path.pci.function, 160 info->params.interface_path.pci.function,
160 info->params.interface_path.pci.channel); 161 info->params.interface_path.pci.channel);
161 } else if (!strncmp(info->params.host_bus_type, "IBND", 4) || 162 } else if (!strncmp(info->params.host_bus_type, "IBND", 4) ||
162 !strncmp(info->params.host_bus_type, "XPRS", 4) ||
163 !strncmp(info->params.host_bus_type, "HTPT", 4)) { 163 !strncmp(info->params.host_bus_type, "HTPT", 4)) {
164 p += scnprintf(p, left, 164 p += scnprintf(p, left,
165 "\tTBD: %llx\n", 165 "\tTBD: %llx\n",
@@ -668,7 +668,7 @@ edd_get_pci_dev(struct edd_device *edev)
668{ 668{
669 struct edd_info *info = edd_dev_get_info(edev); 669 struct edd_info *info = edd_dev_get_info(edev);
670 670
671 if (edd_dev_is_type(edev, "PCI")) { 671 if (edd_dev_is_type(edev, "PCI") || edd_dev_is_type(edev, "XPRS")) {
672 return pci_get_bus_and_slot(info->params.interface_path.pci.bus, 672 return pci_get_bus_and_slot(info->params.interface_path.pci.bus,
673 PCI_DEVFN(info->params.interface_path.pci.slot, 673 PCI_DEVFN(info->params.interface_path.pci.slot,
674 info->params.interface_path.pci. 674 info->params.interface_path.pci.
diff --git a/drivers/firmware/google/gsmi.c b/drivers/firmware/google/gsmi.c
index aa83de9db1b9..c4e7c59d1c63 100644
--- a/drivers/firmware/google/gsmi.c
+++ b/drivers/firmware/google/gsmi.c
@@ -27,6 +27,7 @@
27#include <linux/kdebug.h> 27#include <linux/kdebug.h>
28#include <linux/reboot.h> 28#include <linux/reboot.h>
29#include <linux/efi.h> 29#include <linux/efi.h>
30#include <linux/module.h>
30 31
31#define GSMI_SHUTDOWN_CLEAN 0 /* Clean Shutdown */ 32#define GSMI_SHUTDOWN_CLEAN 0 /* Clean Shutdown */
32/* TODO(mikew@google.com): Tie in HARDLOCKUP_DETECTOR with NMIWDT */ 33/* TODO(mikew@google.com): Tie in HARDLOCKUP_DETECTOR with NMIWDT */
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index cb0bd078efc0..8482a23887dc 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -95,14 +95,18 @@ config GPIO_EP93XX
95 depends on ARCH_EP93XX 95 depends on ARCH_EP93XX
96 select GPIO_GENERIC 96 select GPIO_GENERIC
97 97
98config GPIO_EXYNOS4
99 def_bool y
100 depends on CPU_EXYNOS4210
101
102config GPIO_MPC5200 98config GPIO_MPC5200
103 def_bool y 99 def_bool y
104 depends on PPC_MPC52xx 100 depends on PPC_MPC52xx
105 101
102config GPIO_MPC8XXX
103 bool "MPC512x/MPC8xxx GPIO support"
104 depends on PPC_MPC512x || PPC_MPC831x || PPC_MPC834x || PPC_MPC837x || \
105 FSL_SOC_BOOKE || PPC_86xx
106 help
107 Say Y here if you're going to use hardware that connects to the
108 MPC512x/831x/834x/837x/8572/8610 GPIOs.
109
106config GPIO_MSM_V1 110config GPIO_MSM_V1
107 tristate "Qualcomm MSM GPIO v1" 111 tristate "Qualcomm MSM GPIO v1"
108 depends on GPIOLIB && ARCH_MSM 112 depends on GPIOLIB && ARCH_MSM
@@ -131,18 +135,6 @@ config GPIO_MXS
131 select GPIO_GENERIC 135 select GPIO_GENERIC
132 select GENERIC_IRQ_CHIP 136 select GENERIC_IRQ_CHIP
133 137
134config GPIO_PLAT_SAMSUNG
135 def_bool y
136 depends on SAMSUNG_GPIOLIB_4BIT
137
138config GPIO_S5PC100
139 def_bool y
140 depends on CPU_S5PC100
141
142config GPIO_S5PV210
143 def_bool y
144 depends on CPU_S5PV210
145
146config GPIO_PL061 138config GPIO_PL061
147 bool "PrimeCell PL061 GPIO support" 139 bool "PrimeCell PL061 GPIO support"
148 depends on ARM_AMBA 140 depends on ARM_AMBA
@@ -189,7 +181,7 @@ config GPIO_U300
189 181
190config GPIO_VX855 182config GPIO_VX855
191 tristate "VIA VX855/VX875 GPIO" 183 tristate "VIA VX855/VX875 GPIO"
192 depends on MFD_SUPPORT && PCI 184 depends on PCI
193 select MFD_CORE 185 select MFD_CORE
194 select MFD_VX855 186 select MFD_VX855
195 help 187 help
@@ -428,7 +420,6 @@ config GPIO_TIMBERDALE
428config GPIO_RDC321X 420config GPIO_RDC321X
429 tristate "RDC R-321x GPIO support" 421 tristate "RDC R-321x GPIO support"
430 depends on PCI 422 depends on PCI
431 select MFD_SUPPORT
432 select MFD_CORE 423 select MFD_CORE
433 select MFD_RDC321X 424 select MFD_RDC321X
434 help 425 help
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 19c5d27b6d2e..dbcb0bcfd8da 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -16,7 +16,6 @@ obj-$(CONFIG_GPIO_CS5535) += gpio-cs5535.o
16obj-$(CONFIG_GPIO_DA9052) += gpio-da9052.o 16obj-$(CONFIG_GPIO_DA9052) += gpio-da9052.o
17obj-$(CONFIG_ARCH_DAVINCI) += gpio-davinci.o 17obj-$(CONFIG_ARCH_DAVINCI) += gpio-davinci.o
18obj-$(CONFIG_GPIO_EP93XX) += gpio-ep93xx.o 18obj-$(CONFIG_GPIO_EP93XX) += gpio-ep93xx.o
19obj-$(CONFIG_GPIO_EXYNOS4) += gpio-exynos4.o
20obj-$(CONFIG_GPIO_IT8761E) += gpio-it8761e.o 19obj-$(CONFIG_GPIO_IT8761E) += gpio-it8761e.o
21obj-$(CONFIG_GPIO_JANZ_TTL) += gpio-janz-ttl.o 20obj-$(CONFIG_GPIO_JANZ_TTL) += gpio-janz-ttl.o
22obj-$(CONFIG_MACH_KS8695) += gpio-ks8695.o 21obj-$(CONFIG_MACH_KS8695) += gpio-ks8695.o
@@ -30,6 +29,7 @@ obj-$(CONFIG_GPIO_MC33880) += gpio-mc33880.o
30obj-$(CONFIG_GPIO_MCP23S08) += gpio-mcp23s08.o 29obj-$(CONFIG_GPIO_MCP23S08) += gpio-mcp23s08.o
31obj-$(CONFIG_GPIO_ML_IOH) += gpio-ml-ioh.o 30obj-$(CONFIG_GPIO_ML_IOH) += gpio-ml-ioh.o
32obj-$(CONFIG_GPIO_MPC5200) += gpio-mpc5200.o 31obj-$(CONFIG_GPIO_MPC5200) += gpio-mpc5200.o
32obj-$(CONFIG_GPIO_MPC8XXX) += gpio-mpc8xxx.o
33obj-$(CONFIG_GPIO_MSM_V1) += gpio-msm-v1.o 33obj-$(CONFIG_GPIO_MSM_V1) += gpio-msm-v1.o
34obj-$(CONFIG_GPIO_MSM_V2) += gpio-msm-v2.o 34obj-$(CONFIG_GPIO_MSM_V2) += gpio-msm-v2.o
35obj-$(CONFIG_GPIO_MXC) += gpio-mxc.o 35obj-$(CONFIG_GPIO_MXC) += gpio-mxc.o
@@ -42,10 +42,7 @@ obj-$(CONFIG_GPIO_PCH) += gpio-pch.o
42obj-$(CONFIG_GPIO_PL061) += gpio-pl061.o 42obj-$(CONFIG_GPIO_PL061) += gpio-pl061.o
43obj-$(CONFIG_PLAT_PXA) += gpio-pxa.o 43obj-$(CONFIG_PLAT_PXA) += gpio-pxa.o
44obj-$(CONFIG_GPIO_RDC321X) += gpio-rdc321x.o 44obj-$(CONFIG_GPIO_RDC321X) += gpio-rdc321x.o
45 45obj-$(CONFIG_PLAT_SAMSUNG) += gpio-samsung.o
46obj-$(CONFIG_GPIO_PLAT_SAMSUNG) += gpio-plat-samsung.o
47obj-$(CONFIG_GPIO_S5PC100) += gpio-s5pc100.o
48obj-$(CONFIG_GPIO_S5PV210) += gpio-s5pv210.o
49obj-$(CONFIG_ARCH_SA1100) += gpio-sa1100.o 46obj-$(CONFIG_ARCH_SA1100) += gpio-sa1100.o
50obj-$(CONFIG_GPIO_SCH) += gpio-sch.o 47obj-$(CONFIG_GPIO_SCH) += gpio-sch.o
51obj-$(CONFIG_GPIO_STMPE) += gpio-stmpe.o 48obj-$(CONFIG_GPIO_STMPE) += gpio-stmpe.o
diff --git a/drivers/gpio/gpio-74x164.c b/drivers/gpio/gpio-74x164.c
index ff525c0958dd..a31ad6f5d910 100644
--- a/drivers/gpio/gpio-74x164.c
+++ b/drivers/gpio/gpio-74x164.c
@@ -15,6 +15,7 @@
15#include <linux/spi/74x164.h> 15#include <linux/spi/74x164.h>
16#include <linux/gpio.h> 16#include <linux/gpio.h>
17#include <linux/slab.h> 17#include <linux/slab.h>
18#include <linux/module.h>
18 19
19struct gen_74x164_chip { 20struct gen_74x164_chip {
20 struct spi_device *spi; 21 struct spi_device *spi;
diff --git a/drivers/gpio/gpio-ep93xx.c b/drivers/gpio/gpio-ep93xx.c
index 7aafbb437339..1c0fc3756cb1 100644
--- a/drivers/gpio/gpio-ep93xx.c
+++ b/drivers/gpio/gpio-ep93xx.c
@@ -15,6 +15,7 @@
15#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 15#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
16 16
17#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/module.h>
18#include <linux/platform_device.h> 19#include <linux/platform_device.h>
19#include <linux/io.h> 20#include <linux/io.h>
20#include <linux/gpio.h> 21#include <linux/gpio.h>
diff --git a/drivers/gpio/gpio-exynos4.c b/drivers/gpio/gpio-exynos4.c
deleted file mode 100644
index d24b337cf1ac..000000000000
--- a/drivers/gpio/gpio-exynos4.c
+++ /dev/null
@@ -1,385 +0,0 @@
1/*
2 * EXYNOS4 - GPIOlib support
3 *
4 * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10*/
11
12#include <linux/kernel.h>
13#include <linux/irq.h>
14#include <linux/io.h>
15#include <linux/gpio.h>
16
17#include <mach/map.h>
18
19#include <plat/gpio-core.h>
20#include <plat/gpio-cfg.h>
21#include <plat/gpio-cfg-helpers.h>
22
23int s3c_gpio_setpull_exynos4(struct s3c_gpio_chip *chip,
24 unsigned int off, s3c_gpio_pull_t pull)
25{
26 if (pull == S3C_GPIO_PULL_UP)
27 pull = 3;
28
29 return s3c_gpio_setpull_updown(chip, off, pull);
30}
31
32s3c_gpio_pull_t s3c_gpio_getpull_exynos4(struct s3c_gpio_chip *chip,
33 unsigned int off)
34{
35 s3c_gpio_pull_t pull;
36
37 pull = s3c_gpio_getpull_updown(chip, off);
38 if (pull == 3)
39 pull = S3C_GPIO_PULL_UP;
40
41 return pull;
42}
43
44static struct s3c_gpio_cfg gpio_cfg = {
45 .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
46 .set_pull = s3c_gpio_setpull_exynos4,
47 .get_pull = s3c_gpio_getpull_exynos4,
48};
49
50static struct s3c_gpio_cfg gpio_cfg_noint = {
51 .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
52 .set_pull = s3c_gpio_setpull_exynos4,
53 .get_pull = s3c_gpio_getpull_exynos4,
54};
55
56/*
57 * Following are the gpio banks in v310.
58 *
59 * The 'config' member when left to NULL, is initialized to the default
60 * structure gpio_cfg in the init function below.
61 *
62 * The 'base' member is also initialized in the init function below.
63 * Note: The initialization of 'base' member of s3c_gpio_chip structure
64 * uses the above macro and depends on the banks being listed in order here.
65 */
66static struct s3c_gpio_chip exynos4_gpio_part1_4bit[] = {
67 {
68 .chip = {
69 .base = EXYNOS4_GPA0(0),
70 .ngpio = EXYNOS4_GPIO_A0_NR,
71 .label = "GPA0",
72 },
73 }, {
74 .chip = {
75 .base = EXYNOS4_GPA1(0),
76 .ngpio = EXYNOS4_GPIO_A1_NR,
77 .label = "GPA1",
78 },
79 }, {
80 .chip = {
81 .base = EXYNOS4_GPB(0),
82 .ngpio = EXYNOS4_GPIO_B_NR,
83 .label = "GPB",
84 },
85 }, {
86 .chip = {
87 .base = EXYNOS4_GPC0(0),
88 .ngpio = EXYNOS4_GPIO_C0_NR,
89 .label = "GPC0",
90 },
91 }, {
92 .chip = {
93 .base = EXYNOS4_GPC1(0),
94 .ngpio = EXYNOS4_GPIO_C1_NR,
95 .label = "GPC1",
96 },
97 }, {
98 .chip = {
99 .base = EXYNOS4_GPD0(0),
100 .ngpio = EXYNOS4_GPIO_D0_NR,
101 .label = "GPD0",
102 },
103 }, {
104 .chip = {
105 .base = EXYNOS4_GPD1(0),
106 .ngpio = EXYNOS4_GPIO_D1_NR,
107 .label = "GPD1",
108 },
109 }, {
110 .chip = {
111 .base = EXYNOS4_GPE0(0),
112 .ngpio = EXYNOS4_GPIO_E0_NR,
113 .label = "GPE0",
114 },
115 }, {
116 .chip = {
117 .base = EXYNOS4_GPE1(0),
118 .ngpio = EXYNOS4_GPIO_E1_NR,
119 .label = "GPE1",
120 },
121 }, {
122 .chip = {
123 .base = EXYNOS4_GPE2(0),
124 .ngpio = EXYNOS4_GPIO_E2_NR,
125 .label = "GPE2",
126 },
127 }, {
128 .chip = {
129 .base = EXYNOS4_GPE3(0),
130 .ngpio = EXYNOS4_GPIO_E3_NR,
131 .label = "GPE3",
132 },
133 }, {
134 .chip = {
135 .base = EXYNOS4_GPE4(0),
136 .ngpio = EXYNOS4_GPIO_E4_NR,
137 .label = "GPE4",
138 },
139 }, {
140 .chip = {
141 .base = EXYNOS4_GPF0(0),
142 .ngpio = EXYNOS4_GPIO_F0_NR,
143 .label = "GPF0",
144 },
145 }, {
146 .chip = {
147 .base = EXYNOS4_GPF1(0),
148 .ngpio = EXYNOS4_GPIO_F1_NR,
149 .label = "GPF1",
150 },
151 }, {
152 .chip = {
153 .base = EXYNOS4_GPF2(0),
154 .ngpio = EXYNOS4_GPIO_F2_NR,
155 .label = "GPF2",
156 },
157 }, {
158 .chip = {
159 .base = EXYNOS4_GPF3(0),
160 .ngpio = EXYNOS4_GPIO_F3_NR,
161 .label = "GPF3",
162 },
163 },
164};
165
166static struct s3c_gpio_chip exynos4_gpio_part2_4bit[] = {
167 {
168 .chip = {
169 .base = EXYNOS4_GPJ0(0),
170 .ngpio = EXYNOS4_GPIO_J0_NR,
171 .label = "GPJ0",
172 },
173 }, {
174 .chip = {
175 .base = EXYNOS4_GPJ1(0),
176 .ngpio = EXYNOS4_GPIO_J1_NR,
177 .label = "GPJ1",
178 },
179 }, {
180 .chip = {
181 .base = EXYNOS4_GPK0(0),
182 .ngpio = EXYNOS4_GPIO_K0_NR,
183 .label = "GPK0",
184 },
185 }, {
186 .chip = {
187 .base = EXYNOS4_GPK1(0),
188 .ngpio = EXYNOS4_GPIO_K1_NR,
189 .label = "GPK1",
190 },
191 }, {
192 .chip = {
193 .base = EXYNOS4_GPK2(0),
194 .ngpio = EXYNOS4_GPIO_K2_NR,
195 .label = "GPK2",
196 },
197 }, {
198 .chip = {
199 .base = EXYNOS4_GPK3(0),
200 .ngpio = EXYNOS4_GPIO_K3_NR,
201 .label = "GPK3",
202 },
203 }, {
204 .chip = {
205 .base = EXYNOS4_GPL0(0),
206 .ngpio = EXYNOS4_GPIO_L0_NR,
207 .label = "GPL0",
208 },
209 }, {
210 .chip = {
211 .base = EXYNOS4_GPL1(0),
212 .ngpio = EXYNOS4_GPIO_L1_NR,
213 .label = "GPL1",
214 },
215 }, {
216 .chip = {
217 .base = EXYNOS4_GPL2(0),
218 .ngpio = EXYNOS4_GPIO_L2_NR,
219 .label = "GPL2",
220 },
221 }, {
222 .config = &gpio_cfg_noint,
223 .chip = {
224 .base = EXYNOS4_GPY0(0),
225 .ngpio = EXYNOS4_GPIO_Y0_NR,
226 .label = "GPY0",
227 },
228 }, {
229 .config = &gpio_cfg_noint,
230 .chip = {
231 .base = EXYNOS4_GPY1(0),
232 .ngpio = EXYNOS4_GPIO_Y1_NR,
233 .label = "GPY1",
234 },
235 }, {
236 .config = &gpio_cfg_noint,
237 .chip = {
238 .base = EXYNOS4_GPY2(0),
239 .ngpio = EXYNOS4_GPIO_Y2_NR,
240 .label = "GPY2",
241 },
242 }, {
243 .config = &gpio_cfg_noint,
244 .chip = {
245 .base = EXYNOS4_GPY3(0),
246 .ngpio = EXYNOS4_GPIO_Y3_NR,
247 .label = "GPY3",
248 },
249 }, {
250 .config = &gpio_cfg_noint,
251 .chip = {
252 .base = EXYNOS4_GPY4(0),
253 .ngpio = EXYNOS4_GPIO_Y4_NR,
254 .label = "GPY4",
255 },
256 }, {
257 .config = &gpio_cfg_noint,
258 .chip = {
259 .base = EXYNOS4_GPY5(0),
260 .ngpio = EXYNOS4_GPIO_Y5_NR,
261 .label = "GPY5",
262 },
263 }, {
264 .config = &gpio_cfg_noint,
265 .chip = {
266 .base = EXYNOS4_GPY6(0),
267 .ngpio = EXYNOS4_GPIO_Y6_NR,
268 .label = "GPY6",
269 },
270 }, {
271 .base = (S5P_VA_GPIO2 + 0xC00),
272 .config = &gpio_cfg_noint,
273 .irq_base = IRQ_EINT(0),
274 .chip = {
275 .base = EXYNOS4_GPX0(0),
276 .ngpio = EXYNOS4_GPIO_X0_NR,
277 .label = "GPX0",
278 .to_irq = samsung_gpiolib_to_irq,
279 },
280 }, {
281 .base = (S5P_VA_GPIO2 + 0xC20),
282 .config = &gpio_cfg_noint,
283 .irq_base = IRQ_EINT(8),
284 .chip = {
285 .base = EXYNOS4_GPX1(0),
286 .ngpio = EXYNOS4_GPIO_X1_NR,
287 .label = "GPX1",
288 .to_irq = samsung_gpiolib_to_irq,
289 },
290 }, {
291 .base = (S5P_VA_GPIO2 + 0xC40),
292 .config = &gpio_cfg_noint,
293 .irq_base = IRQ_EINT(16),
294 .chip = {
295 .base = EXYNOS4_GPX2(0),
296 .ngpio = EXYNOS4_GPIO_X2_NR,
297 .label = "GPX2",
298 .to_irq = samsung_gpiolib_to_irq,
299 },
300 }, {
301 .base = (S5P_VA_GPIO2 + 0xC60),
302 .config = &gpio_cfg_noint,
303 .irq_base = IRQ_EINT(24),
304 .chip = {
305 .base = EXYNOS4_GPX3(0),
306 .ngpio = EXYNOS4_GPIO_X3_NR,
307 .label = "GPX3",
308 .to_irq = samsung_gpiolib_to_irq,
309 },
310 },
311};
312
313static struct s3c_gpio_chip exynos4_gpio_part3_4bit[] = {
314 {
315 .chip = {
316 .base = EXYNOS4_GPZ(0),
317 .ngpio = EXYNOS4_GPIO_Z_NR,
318 .label = "GPZ",
319 },
320 },
321};
322
323static __init int exynos4_gpiolib_init(void)
324{
325 struct s3c_gpio_chip *chip;
326 int i;
327 int group = 0;
328 int nr_chips;
329
330 /* GPIO part 1 */
331
332 chip = exynos4_gpio_part1_4bit;
333 nr_chips = ARRAY_SIZE(exynos4_gpio_part1_4bit);
334
335 for (i = 0; i < nr_chips; i++, chip++) {
336 if (chip->config == NULL) {
337 chip->config = &gpio_cfg;
338 /* Assign the GPIO interrupt group */
339 chip->group = group++;
340 }
341 if (chip->base == NULL)
342 chip->base = S5P_VA_GPIO1 + (i) * 0x20;
343 }
344
345 samsung_gpiolib_add_4bit_chips(exynos4_gpio_part1_4bit, nr_chips);
346
347 /* GPIO part 2 */
348
349 chip = exynos4_gpio_part2_4bit;
350 nr_chips = ARRAY_SIZE(exynos4_gpio_part2_4bit);
351
352 for (i = 0; i < nr_chips; i++, chip++) {
353 if (chip->config == NULL) {
354 chip->config = &gpio_cfg;
355 /* Assign the GPIO interrupt group */
356 chip->group = group++;
357 }
358 if (chip->base == NULL)
359 chip->base = S5P_VA_GPIO2 + (i) * 0x20;
360 }
361
362 samsung_gpiolib_add_4bit_chips(exynos4_gpio_part2_4bit, nr_chips);
363
364 /* GPIO part 3 */
365
366 chip = exynos4_gpio_part3_4bit;
367 nr_chips = ARRAY_SIZE(exynos4_gpio_part3_4bit);
368
369 for (i = 0; i < nr_chips; i++, chip++) {
370 if (chip->config == NULL) {
371 chip->config = &gpio_cfg;
372 /* Assign the GPIO interrupt group */
373 chip->group = group++;
374 }
375 if (chip->base == NULL)
376 chip->base = S5P_VA_GPIO3 + (i) * 0x20;
377 }
378
379 samsung_gpiolib_add_4bit_chips(exynos4_gpio_part3_4bit, nr_chips);
380 s5p_register_gpioint_bank(IRQ_GPIO_XA, 0, IRQ_GPIO1_NR_GROUPS);
381 s5p_register_gpioint_bank(IRQ_GPIO_XB, IRQ_GPIO1_NR_GROUPS, IRQ_GPIO2_NR_GROUPS);
382
383 return 0;
384}
385core_initcall(exynos4_gpiolib_init);
diff --git a/drivers/gpio/gpio-mc33880.c b/drivers/gpio/gpio-mc33880.c
index b3b4652e89ec..2de57ce5feb6 100644
--- a/drivers/gpio/gpio-mc33880.c
+++ b/drivers/gpio/gpio-mc33880.c
@@ -26,6 +26,7 @@
26#include <linux/spi/mc33880.h> 26#include <linux/spi/mc33880.h>
27#include <linux/gpio.h> 27#include <linux/gpio.h>
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/module.h>
29 30
30#define DRIVER_NAME "mc33880" 31#define DRIVER_NAME "mc33880"
31 32
diff --git a/drivers/gpio/gpio-mcp23s08.c b/drivers/gpio/gpio-mcp23s08.c
index 1ef46e6c2a2a..c5d83a8a91c2 100644
--- a/drivers/gpio/gpio-mcp23s08.c
+++ b/drivers/gpio/gpio-mcp23s08.c
@@ -5,6 +5,7 @@
5#include <linux/kernel.h> 5#include <linux/kernel.h>
6#include <linux/device.h> 6#include <linux/device.h>
7#include <linux/mutex.h> 7#include <linux/mutex.h>
8#include <linux/module.h>
8#include <linux/gpio.h> 9#include <linux/gpio.h>
9#include <linux/i2c.h> 10#include <linux/i2c.h>
10#include <linux/spi/spi.h> 11#include <linux/spi/spi.h>
diff --git a/drivers/gpio/gpio-ml-ioh.c b/drivers/gpio/gpio-ml-ioh.c
index 3aa6beec8c1e..ea8e73869250 100644
--- a/drivers/gpio/gpio-ml-ioh.c
+++ b/drivers/gpio/gpio-ml-ioh.c
@@ -14,6 +14,7 @@
14 * along with this program; if not, write to the Free Software 14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
16 */ 16 */
17#include <linux/module.h>
17#include <linux/kernel.h> 18#include <linux/kernel.h>
18#include <linux/slab.h> 19#include <linux/slab.h>
19#include <linux/pci.h> 20#include <linux/pci.h>
diff --git a/drivers/gpio/gpio-mpc5200.c b/drivers/gpio/gpio-mpc5200.c
index 52d3ed208105..2c7cef367fc0 100644
--- a/drivers/gpio/gpio-mpc5200.c
+++ b/drivers/gpio/gpio-mpc5200.c
@@ -23,6 +23,7 @@
23#include <linux/of_gpio.h> 23#include <linux/of_gpio.h>
24#include <linux/io.h> 24#include <linux/io.h>
25#include <linux/of_platform.h> 25#include <linux/of_platform.h>
26#include <linux/module.h>
26 27
27#include <asm/gpio.h> 28#include <asm/gpio.h>
28#include <asm/mpc52xx.h> 29#include <asm/mpc52xx.h>
diff --git a/drivers/gpio/gpio-mpc8xxx.c b/drivers/gpio/gpio-mpc8xxx.c
new file mode 100644
index 000000000000..ec3fcf0a7e12
--- /dev/null
+++ b/drivers/gpio/gpio-mpc8xxx.c
@@ -0,0 +1,398 @@
1/*
2 * GPIOs on MPC512x/8349/8572/8610 and compatible
3 *
4 * Copyright (C) 2008 Peter Korsgaard <jacmet@sunsite.dk>
5 *
6 * This file is licensed under the terms of the GNU General Public License
7 * version 2. This program is licensed "as is" without any warranty of any
8 * kind, whether express or implied.
9 */
10
11#include <linux/kernel.h>
12#include <linux/init.h>
13#include <linux/spinlock.h>
14#include <linux/io.h>
15#include <linux/of.h>
16#include <linux/of_gpio.h>
17#include <linux/gpio.h>
18#include <linux/slab.h>
19#include <linux/irq.h>
20
21#define MPC8XXX_GPIO_PINS 32
22
23#define GPIO_DIR 0x00
24#define GPIO_ODR 0x04
25#define GPIO_DAT 0x08
26#define GPIO_IER 0x0c
27#define GPIO_IMR 0x10
28#define GPIO_ICR 0x14
29#define GPIO_ICR2 0x18
30
31struct mpc8xxx_gpio_chip {
32 struct of_mm_gpio_chip mm_gc;
33 spinlock_t lock;
34
35 /*
36 * shadowed data register to be able to clear/set output pins in
37 * open drain mode safely
38 */
39 u32 data;
40 struct irq_host *irq;
41 void *of_dev_id_data;
42};
43
44static inline u32 mpc8xxx_gpio2mask(unsigned int gpio)
45{
46 return 1u << (MPC8XXX_GPIO_PINS - 1 - gpio);
47}
48
49static inline struct mpc8xxx_gpio_chip *
50to_mpc8xxx_gpio_chip(struct of_mm_gpio_chip *mm)
51{
52 return container_of(mm, struct mpc8xxx_gpio_chip, mm_gc);
53}
54
55static void mpc8xxx_gpio_save_regs(struct of_mm_gpio_chip *mm)
56{
57 struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm);
58
59 mpc8xxx_gc->data = in_be32(mm->regs + GPIO_DAT);
60}
61
62/* Workaround GPIO 1 errata on MPC8572/MPC8536. The status of GPIOs
63 * defined as output cannot be determined by reading GPDAT register,
64 * so we use shadow data register instead. The status of input pins
65 * is determined by reading GPDAT register.
66 */
67static int mpc8572_gpio_get(struct gpio_chip *gc, unsigned int gpio)
68{
69 u32 val;
70 struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc);
71 struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm);
72
73 val = in_be32(mm->regs + GPIO_DAT) & ~in_be32(mm->regs + GPIO_DIR);
74
75 return (val | mpc8xxx_gc->data) & mpc8xxx_gpio2mask(gpio);
76}
77
78static int mpc8xxx_gpio_get(struct gpio_chip *gc, unsigned int gpio)
79{
80 struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc);
81
82 return in_be32(mm->regs + GPIO_DAT) & mpc8xxx_gpio2mask(gpio);
83}
84
85static void mpc8xxx_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
86{
87 struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc);
88 struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm);
89 unsigned long flags;
90
91 spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
92
93 if (val)
94 mpc8xxx_gc->data |= mpc8xxx_gpio2mask(gpio);
95 else
96 mpc8xxx_gc->data &= ~mpc8xxx_gpio2mask(gpio);
97
98 out_be32(mm->regs + GPIO_DAT, mpc8xxx_gc->data);
99
100 spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
101}
102
103static int mpc8xxx_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
104{
105 struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc);
106 struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm);
107 unsigned long flags;
108
109 spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
110
111 clrbits32(mm->regs + GPIO_DIR, mpc8xxx_gpio2mask(gpio));
112
113 spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
114
115 return 0;
116}
117
118static int mpc8xxx_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
119{
120 struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc);
121 struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm);
122 unsigned long flags;
123
124 mpc8xxx_gpio_set(gc, gpio, val);
125
126 spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
127
128 setbits32(mm->regs + GPIO_DIR, mpc8xxx_gpio2mask(gpio));
129
130 spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
131
132 return 0;
133}
134
135static int mpc8xxx_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
136{
137 struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc);
138 struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm);
139
140 if (mpc8xxx_gc->irq && offset < MPC8XXX_GPIO_PINS)
141 return irq_create_mapping(mpc8xxx_gc->irq, offset);
142 else
143 return -ENXIO;
144}
145
146static void mpc8xxx_gpio_irq_cascade(unsigned int irq, struct irq_desc *desc)
147{
148 struct mpc8xxx_gpio_chip *mpc8xxx_gc = irq_desc_get_handler_data(desc);
149 struct irq_chip *chip = irq_desc_get_chip(desc);
150 struct of_mm_gpio_chip *mm = &mpc8xxx_gc->mm_gc;
151 unsigned int mask;
152
153 mask = in_be32(mm->regs + GPIO_IER) & in_be32(mm->regs + GPIO_IMR);
154 if (mask)
155 generic_handle_irq(irq_linear_revmap(mpc8xxx_gc->irq,
156 32 - ffs(mask)));
157 chip->irq_eoi(&desc->irq_data);
158}
159
160static void mpc8xxx_irq_unmask(struct irq_data *d)
161{
162 struct mpc8xxx_gpio_chip *mpc8xxx_gc = irq_data_get_irq_chip_data(d);
163 struct of_mm_gpio_chip *mm = &mpc8xxx_gc->mm_gc;
164 unsigned long flags;
165
166 spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
167
168 setbits32(mm->regs + GPIO_IMR, mpc8xxx_gpio2mask(irqd_to_hwirq(d)));
169
170 spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
171}
172
173static void mpc8xxx_irq_mask(struct irq_data *d)
174{
175 struct mpc8xxx_gpio_chip *mpc8xxx_gc = irq_data_get_irq_chip_data(d);
176 struct of_mm_gpio_chip *mm = &mpc8xxx_gc->mm_gc;
177 unsigned long flags;
178
179 spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
180
181 clrbits32(mm->regs + GPIO_IMR, mpc8xxx_gpio2mask(irqd_to_hwirq(d)));
182
183 spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
184}
185
186static void mpc8xxx_irq_ack(struct irq_data *d)
187{
188 struct mpc8xxx_gpio_chip *mpc8xxx_gc = irq_data_get_irq_chip_data(d);
189 struct of_mm_gpio_chip *mm = &mpc8xxx_gc->mm_gc;
190
191 out_be32(mm->regs + GPIO_IER, mpc8xxx_gpio2mask(irqd_to_hwirq(d)));
192}
193
194static int mpc8xxx_irq_set_type(struct irq_data *d, unsigned int flow_type)
195{
196 struct mpc8xxx_gpio_chip *mpc8xxx_gc = irq_data_get_irq_chip_data(d);
197 struct of_mm_gpio_chip *mm = &mpc8xxx_gc->mm_gc;
198 unsigned long flags;
199
200 switch (flow_type) {
201 case IRQ_TYPE_EDGE_FALLING:
202 spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
203 setbits32(mm->regs + GPIO_ICR,
204 mpc8xxx_gpio2mask(irqd_to_hwirq(d)));
205 spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
206 break;
207
208 case IRQ_TYPE_EDGE_BOTH:
209 spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
210 clrbits32(mm->regs + GPIO_ICR,
211 mpc8xxx_gpio2mask(irqd_to_hwirq(d)));
212 spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
213 break;
214
215 default:
216 return -EINVAL;
217 }
218
219 return 0;
220}
221
222static int mpc512x_irq_set_type(struct irq_data *d, unsigned int flow_type)
223{
224 struct mpc8xxx_gpio_chip *mpc8xxx_gc = irq_data_get_irq_chip_data(d);
225 struct of_mm_gpio_chip *mm = &mpc8xxx_gc->mm_gc;
226 unsigned long gpio = irqd_to_hwirq(d);
227 void __iomem *reg;
228 unsigned int shift;
229 unsigned long flags;
230
231 if (gpio < 16) {
232 reg = mm->regs + GPIO_ICR;
233 shift = (15 - gpio) * 2;
234 } else {
235 reg = mm->regs + GPIO_ICR2;
236 shift = (15 - (gpio % 16)) * 2;
237 }
238
239 switch (flow_type) {
240 case IRQ_TYPE_EDGE_FALLING:
241 case IRQ_TYPE_LEVEL_LOW:
242 spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
243 clrsetbits_be32(reg, 3 << shift, 2 << shift);
244 spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
245 break;
246
247 case IRQ_TYPE_EDGE_RISING:
248 case IRQ_TYPE_LEVEL_HIGH:
249 spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
250 clrsetbits_be32(reg, 3 << shift, 1 << shift);
251 spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
252 break;
253
254 case IRQ_TYPE_EDGE_BOTH:
255 spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
256 clrbits32(reg, 3 << shift);
257 spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
258 break;
259
260 default:
261 return -EINVAL;
262 }
263
264 return 0;
265}
266
267static struct irq_chip mpc8xxx_irq_chip = {
268 .name = "mpc8xxx-gpio",
269 .irq_unmask = mpc8xxx_irq_unmask,
270 .irq_mask = mpc8xxx_irq_mask,
271 .irq_ack = mpc8xxx_irq_ack,
272 .irq_set_type = mpc8xxx_irq_set_type,
273};
274
275static int mpc8xxx_gpio_irq_map(struct irq_host *h, unsigned int virq,
276 irq_hw_number_t hw)
277{
278 struct mpc8xxx_gpio_chip *mpc8xxx_gc = h->host_data;
279
280 if (mpc8xxx_gc->of_dev_id_data)
281 mpc8xxx_irq_chip.irq_set_type = mpc8xxx_gc->of_dev_id_data;
282
283 irq_set_chip_data(virq, h->host_data);
284 irq_set_chip_and_handler(virq, &mpc8xxx_irq_chip, handle_level_irq);
285 irq_set_irq_type(virq, IRQ_TYPE_NONE);
286
287 return 0;
288}
289
290static int mpc8xxx_gpio_irq_xlate(struct irq_host *h, struct device_node *ct,
291 const u32 *intspec, unsigned int intsize,
292 irq_hw_number_t *out_hwirq,
293 unsigned int *out_flags)
294
295{
296 /* interrupt sense values coming from the device tree equal either
297 * EDGE_FALLING or EDGE_BOTH
298 */
299 *out_hwirq = intspec[0];
300 *out_flags = intspec[1];
301
302 return 0;
303}
304
305static struct irq_host_ops mpc8xxx_gpio_irq_ops = {
306 .map = mpc8xxx_gpio_irq_map,
307 .xlate = mpc8xxx_gpio_irq_xlate,
308};
309
310static struct of_device_id mpc8xxx_gpio_ids[] __initdata = {
311 { .compatible = "fsl,mpc8349-gpio", },
312 { .compatible = "fsl,mpc8572-gpio", },
313 { .compatible = "fsl,mpc8610-gpio", },
314 { .compatible = "fsl,mpc5121-gpio", .data = mpc512x_irq_set_type, },
315 { .compatible = "fsl,pq3-gpio", },
316 { .compatible = "fsl,qoriq-gpio", },
317 {}
318};
319
320static void __init mpc8xxx_add_controller(struct device_node *np)
321{
322 struct mpc8xxx_gpio_chip *mpc8xxx_gc;
323 struct of_mm_gpio_chip *mm_gc;
324 struct gpio_chip *gc;
325 const struct of_device_id *id;
326 unsigned hwirq;
327 int ret;
328
329 mpc8xxx_gc = kzalloc(sizeof(*mpc8xxx_gc), GFP_KERNEL);
330 if (!mpc8xxx_gc) {
331 ret = -ENOMEM;
332 goto err;
333 }
334
335 spin_lock_init(&mpc8xxx_gc->lock);
336
337 mm_gc = &mpc8xxx_gc->mm_gc;
338 gc = &mm_gc->gc;
339
340 mm_gc->save_regs = mpc8xxx_gpio_save_regs;
341 gc->ngpio = MPC8XXX_GPIO_PINS;
342 gc->direction_input = mpc8xxx_gpio_dir_in;
343 gc->direction_output = mpc8xxx_gpio_dir_out;
344 if (of_device_is_compatible(np, "fsl,mpc8572-gpio"))
345 gc->get = mpc8572_gpio_get;
346 else
347 gc->get = mpc8xxx_gpio_get;
348 gc->set = mpc8xxx_gpio_set;
349 gc->to_irq = mpc8xxx_gpio_to_irq;
350
351 ret = of_mm_gpiochip_add(np, mm_gc);
352 if (ret)
353 goto err;
354
355 hwirq = irq_of_parse_and_map(np, 0);
356 if (hwirq == NO_IRQ)
357 goto skip_irq;
358
359 mpc8xxx_gc->irq =
360 irq_alloc_host(np, IRQ_HOST_MAP_LINEAR, MPC8XXX_GPIO_PINS,
361 &mpc8xxx_gpio_irq_ops, MPC8XXX_GPIO_PINS);
362 if (!mpc8xxx_gc->irq)
363 goto skip_irq;
364
365 id = of_match_node(mpc8xxx_gpio_ids, np);
366 if (id)
367 mpc8xxx_gc->of_dev_id_data = id->data;
368
369 mpc8xxx_gc->irq->host_data = mpc8xxx_gc;
370
371 /* ack and mask all irqs */
372 out_be32(mm_gc->regs + GPIO_IER, 0xffffffff);
373 out_be32(mm_gc->regs + GPIO_IMR, 0);
374
375 irq_set_handler_data(hwirq, mpc8xxx_gc);
376 irq_set_chained_handler(hwirq, mpc8xxx_gpio_irq_cascade);
377
378skip_irq:
379 return;
380
381err:
382 pr_err("%s: registration failed with status %d\n",
383 np->full_name, ret);
384 kfree(mpc8xxx_gc);
385
386 return;
387}
388
389static int __init mpc8xxx_add_gpiochips(void)
390{
391 struct device_node *np;
392
393 for_each_matching_node(np, mpc8xxx_gpio_ids)
394 mpc8xxx_add_controller(np);
395
396 return 0;
397}
398arch_initcall(mpc8xxx_add_gpiochips);
diff --git a/drivers/gpio/gpio-mxc.c b/drivers/gpio/gpio-mxc.c
index b81c98992114..e79147634573 100644
--- a/drivers/gpio/gpio-mxc.c
+++ b/drivers/gpio/gpio-mxc.c
@@ -29,6 +29,7 @@
29#include <linux/basic_mmio_gpio.h> 29#include <linux/basic_mmio_gpio.h>
30#include <linux/of.h> 30#include <linux/of.h>
31#include <linux/of_device.h> 31#include <linux/of_device.h>
32#include <linux/module.h>
32#include <asm-generic/bug.h> 33#include <asm-generic/bug.h>
33#include <asm/mach/irq.h> 34#include <asm/mach/irq.h>
34 35
diff --git a/drivers/gpio/gpio-mxs.c b/drivers/gpio/gpio-mxs.c
index 292b50481db9..385c58e8405b 100644
--- a/drivers/gpio/gpio-mxs.c
+++ b/drivers/gpio/gpio-mxs.c
@@ -28,6 +28,7 @@
28#include <linux/platform_device.h> 28#include <linux/platform_device.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/basic_mmio_gpio.h> 30#include <linux/basic_mmio_gpio.h>
31#include <linux/module.h>
31#include <mach/mxs.h> 32#include <mach/mxs.h>
32 33
33#define MXS_SET 0x4 34#define MXS_SET 0x4
diff --git a/drivers/gpio/gpio-pcf857x.c b/drivers/gpio/gpio-pcf857x.c
index 7369fdda92b0..3e1f1ecd07be 100644
--- a/drivers/gpio/gpio-pcf857x.c
+++ b/drivers/gpio/gpio-pcf857x.c
@@ -23,6 +23,7 @@
23#include <linux/gpio.h> 23#include <linux/gpio.h>
24#include <linux/i2c.h> 24#include <linux/i2c.h>
25#include <linux/i2c/pcf857x.h> 25#include <linux/i2c/pcf857x.h>
26#include <linux/module.h>
26 27
27 28
28static const struct i2c_device_id pcf857x_id[] = { 29static const struct i2c_device_id pcf857x_id[] = {
diff --git a/drivers/gpio/gpio-pch.c b/drivers/gpio/gpio-pch.c
index 1e8a4a538810..a6008e123d04 100644
--- a/drivers/gpio/gpio-pch.c
+++ b/drivers/gpio/gpio-pch.c
@@ -14,6 +14,7 @@
14 * along with this program; if not, write to the Free Software 14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
16 */ 16 */
17#include <linux/module.h>
17#include <linux/kernel.h> 18#include <linux/kernel.h>
18#include <linux/pci.h> 19#include <linux/pci.h>
19#include <linux/gpio.h> 20#include <linux/gpio.h>
diff --git a/drivers/gpio/gpio-plat-samsung.c b/drivers/gpio/gpio-plat-samsung.c
deleted file mode 100644
index ef67f1952a72..000000000000
--- a/drivers/gpio/gpio-plat-samsung.c
+++ /dev/null
@@ -1,205 +0,0 @@
1/*
2 * Copyright 2008 Openmoko, Inc.
3 * Copyright 2008 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk>
5 * http://armlinux.simtec.co.uk/
6 *
7 * Copyright (c) 2009 Samsung Electronics Co., Ltd.
8 * http://www.samsung.com/
9 *
10 * SAMSUNG - GPIOlib support
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 */
16
17#include <linux/kernel.h>
18#include <linux/irq.h>
19#include <linux/io.h>
20#include <linux/gpio.h>
21#include <plat/gpio-core.h>
22#include <plat/gpio-cfg.h>
23#include <plat/gpio-cfg-helpers.h>
24
25#ifndef DEBUG_GPIO
26#define gpio_dbg(x...) do { } while (0)
27#else
28#define gpio_dbg(x...) printk(KERN_DEBUG x)
29#endif
30
31/* The samsung_gpiolib_4bit routines are to control the gpio banks where
32 * the gpio configuration register (GPxCON) has 4 bits per GPIO, as the
33 * following example:
34 *
35 * base + 0x00: Control register, 4 bits per gpio
36 * gpio n: 4 bits starting at (4*n)
37 * 0000 = input, 0001 = output, others mean special-function
38 * base + 0x04: Data register, 1 bit per gpio
39 * bit n: data bit n
40 *
41 * Note, since the data register is one bit per gpio and is at base + 0x4
42 * we can use s3c_gpiolib_get and s3c_gpiolib_set to change the state of
43 * the output.
44*/
45
46static int samsung_gpiolib_4bit_input(struct gpio_chip *chip,
47 unsigned int offset)
48{
49 struct s3c_gpio_chip *ourchip = to_s3c_gpio(chip);
50 void __iomem *base = ourchip->base;
51 unsigned long con;
52
53 con = __raw_readl(base + GPIOCON_OFF);
54 con &= ~(0xf << con_4bit_shift(offset));
55 __raw_writel(con, base + GPIOCON_OFF);
56
57 gpio_dbg("%s: %p: CON now %08lx\n", __func__, base, con);
58
59 return 0;
60}
61
62static int samsung_gpiolib_4bit_output(struct gpio_chip *chip,
63 unsigned int offset, int value)
64{
65 struct s3c_gpio_chip *ourchip = to_s3c_gpio(chip);
66 void __iomem *base = ourchip->base;
67 unsigned long con;
68 unsigned long dat;
69
70 con = __raw_readl(base + GPIOCON_OFF);
71 con &= ~(0xf << con_4bit_shift(offset));
72 con |= 0x1 << con_4bit_shift(offset);
73
74 dat = __raw_readl(base + GPIODAT_OFF);
75
76 if (value)
77 dat |= 1 << offset;
78 else
79 dat &= ~(1 << offset);
80
81 __raw_writel(dat, base + GPIODAT_OFF);
82 __raw_writel(con, base + GPIOCON_OFF);
83 __raw_writel(dat, base + GPIODAT_OFF);
84
85 gpio_dbg("%s: %p: CON %08lx, DAT %08lx\n", __func__, base, con, dat);
86
87 return 0;
88}
89
90/* The next set of routines are for the case where the GPIO configuration
91 * registers are 4 bits per GPIO but there is more than one register (the
92 * bank has more than 8 GPIOs.
93 *
94 * This case is the similar to the 4 bit case, but the registers are as
95 * follows:
96 *
97 * base + 0x00: Control register, 4 bits per gpio (lower 8 GPIOs)
98 * gpio n: 4 bits starting at (4*n)
99 * 0000 = input, 0001 = output, others mean special-function
100 * base + 0x04: Control register, 4 bits per gpio (up to 8 additions GPIOs)
101 * gpio n: 4 bits starting at (4*n)
102 * 0000 = input, 0001 = output, others mean special-function
103 * base + 0x08: Data register, 1 bit per gpio
104 * bit n: data bit n
105 *
106 * To allow us to use the s3c_gpiolib_get and s3c_gpiolib_set routines we
107 * store the 'base + 0x4' address so that these routines see the data
108 * register at ourchip->base + 0x04.
109 */
110
111static int samsung_gpiolib_4bit2_input(struct gpio_chip *chip,
112 unsigned int offset)
113{
114 struct s3c_gpio_chip *ourchip = to_s3c_gpio(chip);
115 void __iomem *base = ourchip->base;
116 void __iomem *regcon = base;
117 unsigned long con;
118
119 if (offset > 7)
120 offset -= 8;
121 else
122 regcon -= 4;
123
124 con = __raw_readl(regcon);
125 con &= ~(0xf << con_4bit_shift(offset));
126 __raw_writel(con, regcon);
127
128 gpio_dbg("%s: %p: CON %08lx\n", __func__, base, con);
129
130 return 0;
131}
132
133static int samsung_gpiolib_4bit2_output(struct gpio_chip *chip,
134 unsigned int offset, int value)
135{
136 struct s3c_gpio_chip *ourchip = to_s3c_gpio(chip);
137 void __iomem *base = ourchip->base;
138 void __iomem *regcon = base;
139 unsigned long con;
140 unsigned long dat;
141 unsigned con_offset = offset;
142
143 if (con_offset > 7)
144 con_offset -= 8;
145 else
146 regcon -= 4;
147
148 con = __raw_readl(regcon);
149 con &= ~(0xf << con_4bit_shift(con_offset));
150 con |= 0x1 << con_4bit_shift(con_offset);
151
152 dat = __raw_readl(base + GPIODAT_OFF);
153
154 if (value)
155 dat |= 1 << offset;
156 else
157 dat &= ~(1 << offset);
158
159 __raw_writel(dat, base + GPIODAT_OFF);
160 __raw_writel(con, regcon);
161 __raw_writel(dat, base + GPIODAT_OFF);
162
163 gpio_dbg("%s: %p: CON %08lx, DAT %08lx\n", __func__, base, con, dat);
164
165 return 0;
166}
167
168void __init samsung_gpiolib_add_4bit(struct s3c_gpio_chip *chip)
169{
170 chip->chip.direction_input = samsung_gpiolib_4bit_input;
171 chip->chip.direction_output = samsung_gpiolib_4bit_output;
172 chip->pm = __gpio_pm(&s3c_gpio_pm_4bit);
173}
174
175void __init samsung_gpiolib_add_4bit2(struct s3c_gpio_chip *chip)
176{
177 chip->chip.direction_input = samsung_gpiolib_4bit2_input;
178 chip->chip.direction_output = samsung_gpiolib_4bit2_output;
179 chip->pm = __gpio_pm(&s3c_gpio_pm_4bit);
180}
181
182void __init samsung_gpiolib_add_4bit_chips(struct s3c_gpio_chip *chip,
183 int nr_chips)
184{
185 for (; nr_chips > 0; nr_chips--, chip++) {
186 samsung_gpiolib_add_4bit(chip);
187 s3c_gpiolib_add(chip);
188 }
189}
190
191void __init samsung_gpiolib_add_4bit2_chips(struct s3c_gpio_chip *chip,
192 int nr_chips)
193{
194 for (; nr_chips > 0; nr_chips--, chip++) {
195 samsung_gpiolib_add_4bit2(chip);
196 s3c_gpiolib_add(chip);
197 }
198}
199
200void __init samsung_gpiolib_add_2bit_chips(struct s3c_gpio_chip *chip,
201 int nr_chips)
202{
203 for (; nr_chips > 0; nr_chips--, chip++)
204 s3c_gpiolib_add(chip);
205}
diff --git a/drivers/gpio/gpio-s5pc100.c b/drivers/gpio/gpio-s5pc100.c
deleted file mode 100644
index 7f87b0c76e0b..000000000000
--- a/drivers/gpio/gpio-s5pc100.c
+++ /dev/null
@@ -1,354 +0,0 @@
1/*
2 * S5PC100 - GPIOlib support
3 *
4 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com
6 *
7 * Copyright 2009 Samsung Electronics Co
8 * Kyungmin Park <kyungmin.park@samsung.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/kernel.h>
16#include <linux/irq.h>
17#include <linux/io.h>
18#include <linux/gpio.h>
19
20#include <mach/map.h>
21#include <mach/regs-gpio.h>
22
23#include <plat/gpio-core.h>
24#include <plat/gpio-cfg.h>
25#include <plat/gpio-cfg-helpers.h>
26
27/* S5PC100 GPIO bank summary:
28 *
29 * Bank GPIOs Style INT Type
30 * A0 8 4Bit GPIO_INT0
31 * A1 5 4Bit GPIO_INT1
32 * B 8 4Bit GPIO_INT2
33 * C 5 4Bit GPIO_INT3
34 * D 7 4Bit GPIO_INT4
35 * E0 8 4Bit GPIO_INT5
36 * E1 6 4Bit GPIO_INT6
37 * F0 8 4Bit GPIO_INT7
38 * F1 8 4Bit GPIO_INT8
39 * F2 8 4Bit GPIO_INT9
40 * F3 4 4Bit GPIO_INT10
41 * G0 8 4Bit GPIO_INT11
42 * G1 3 4Bit GPIO_INT12
43 * G2 7 4Bit GPIO_INT13
44 * G3 7 4Bit GPIO_INT14
45 * H0 8 4Bit WKUP_INT
46 * H1 8 4Bit WKUP_INT
47 * H2 8 4Bit WKUP_INT
48 * H3 8 4Bit WKUP_INT
49 * I 8 4Bit GPIO_INT15
50 * J0 8 4Bit GPIO_INT16
51 * J1 5 4Bit GPIO_INT17
52 * J2 8 4Bit GPIO_INT18
53 * J3 8 4Bit GPIO_INT19
54 * J4 4 4Bit GPIO_INT20
55 * K0 8 4Bit None
56 * K1 6 4Bit None
57 * K2 8 4Bit None
58 * K3 8 4Bit None
59 * L0 8 4Bit None
60 * L1 8 4Bit None
61 * L2 8 4Bit None
62 * L3 8 4Bit None
63 */
64
65static struct s3c_gpio_cfg gpio_cfg = {
66 .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
67 .set_pull = s3c_gpio_setpull_updown,
68 .get_pull = s3c_gpio_getpull_updown,
69};
70
71static struct s3c_gpio_cfg gpio_cfg_eint = {
72 .cfg_eint = 0xf,
73 .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
74 .set_pull = s3c_gpio_setpull_updown,
75 .get_pull = s3c_gpio_getpull_updown,
76};
77
78static struct s3c_gpio_cfg gpio_cfg_noint = {
79 .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
80 .set_pull = s3c_gpio_setpull_updown,
81 .get_pull = s3c_gpio_getpull_updown,
82};
83
84/*
85 * GPIO bank's base address given the index of the bank in the
86 * list of all gpio banks.
87 */
88#define S5PC100_BANK_BASE(bank_nr) (S5P_VA_GPIO + ((bank_nr) * 0x20))
89
90/*
91 * Following are the gpio banks in S5PC100.
92 *
93 * The 'config' member when left to NULL, is initialized to the default
94 * structure gpio_cfg in the init function below.
95 *
96 * The 'base' member is also initialized in the init function below.
97 * Note: The initialization of 'base' member of s3c_gpio_chip structure
98 * uses the above macro and depends on the banks being listed in order here.
99 */
100static struct s3c_gpio_chip s5pc100_gpio_chips[] = {
101 {
102 .chip = {
103 .base = S5PC100_GPA0(0),
104 .ngpio = S5PC100_GPIO_A0_NR,
105 .label = "GPA0",
106 },
107 }, {
108 .chip = {
109 .base = S5PC100_GPA1(0),
110 .ngpio = S5PC100_GPIO_A1_NR,
111 .label = "GPA1",
112 },
113 }, {
114 .chip = {
115 .base = S5PC100_GPB(0),
116 .ngpio = S5PC100_GPIO_B_NR,
117 .label = "GPB",
118 },
119 }, {
120 .chip = {
121 .base = S5PC100_GPC(0),
122 .ngpio = S5PC100_GPIO_C_NR,
123 .label = "GPC",
124 },
125 }, {
126 .chip = {
127 .base = S5PC100_GPD(0),
128 .ngpio = S5PC100_GPIO_D_NR,
129 .label = "GPD",
130 },
131 }, {
132 .chip = {
133 .base = S5PC100_GPE0(0),
134 .ngpio = S5PC100_GPIO_E0_NR,
135 .label = "GPE0",
136 },
137 }, {
138 .chip = {
139 .base = S5PC100_GPE1(0),
140 .ngpio = S5PC100_GPIO_E1_NR,
141 .label = "GPE1",
142 },
143 }, {
144 .chip = {
145 .base = S5PC100_GPF0(0),
146 .ngpio = S5PC100_GPIO_F0_NR,
147 .label = "GPF0",
148 },
149 }, {
150 .chip = {
151 .base = S5PC100_GPF1(0),
152 .ngpio = S5PC100_GPIO_F1_NR,
153 .label = "GPF1",
154 },
155 }, {
156 .chip = {
157 .base = S5PC100_GPF2(0),
158 .ngpio = S5PC100_GPIO_F2_NR,
159 .label = "GPF2",
160 },
161 }, {
162 .chip = {
163 .base = S5PC100_GPF3(0),
164 .ngpio = S5PC100_GPIO_F3_NR,
165 .label = "GPF3",
166 },
167 }, {
168 .chip = {
169 .base = S5PC100_GPG0(0),
170 .ngpio = S5PC100_GPIO_G0_NR,
171 .label = "GPG0",
172 },
173 }, {
174 .chip = {
175 .base = S5PC100_GPG1(0),
176 .ngpio = S5PC100_GPIO_G1_NR,
177 .label = "GPG1",
178 },
179 }, {
180 .chip = {
181 .base = S5PC100_GPG2(0),
182 .ngpio = S5PC100_GPIO_G2_NR,
183 .label = "GPG2",
184 },
185 }, {
186 .chip = {
187 .base = S5PC100_GPG3(0),
188 .ngpio = S5PC100_GPIO_G3_NR,
189 .label = "GPG3",
190 },
191 }, {
192 .chip = {
193 .base = S5PC100_GPI(0),
194 .ngpio = S5PC100_GPIO_I_NR,
195 .label = "GPI",
196 },
197 }, {
198 .chip = {
199 .base = S5PC100_GPJ0(0),
200 .ngpio = S5PC100_GPIO_J0_NR,
201 .label = "GPJ0",
202 },
203 }, {
204 .chip = {
205 .base = S5PC100_GPJ1(0),
206 .ngpio = S5PC100_GPIO_J1_NR,
207 .label = "GPJ1",
208 },
209 }, {
210 .chip = {
211 .base = S5PC100_GPJ2(0),
212 .ngpio = S5PC100_GPIO_J2_NR,
213 .label = "GPJ2",
214 },
215 }, {
216 .chip = {
217 .base = S5PC100_GPJ3(0),
218 .ngpio = S5PC100_GPIO_J3_NR,
219 .label = "GPJ3",
220 },
221 }, {
222 .chip = {
223 .base = S5PC100_GPJ4(0),
224 .ngpio = S5PC100_GPIO_J4_NR,
225 .label = "GPJ4",
226 },
227 }, {
228 .config = &gpio_cfg_noint,
229 .chip = {
230 .base = S5PC100_GPK0(0),
231 .ngpio = S5PC100_GPIO_K0_NR,
232 .label = "GPK0",
233 },
234 }, {
235 .config = &gpio_cfg_noint,
236 .chip = {
237 .base = S5PC100_GPK1(0),
238 .ngpio = S5PC100_GPIO_K1_NR,
239 .label = "GPK1",
240 },
241 }, {
242 .config = &gpio_cfg_noint,
243 .chip = {
244 .base = S5PC100_GPK2(0),
245 .ngpio = S5PC100_GPIO_K2_NR,
246 .label = "GPK2",
247 },
248 }, {
249 .config = &gpio_cfg_noint,
250 .chip = {
251 .base = S5PC100_GPK3(0),
252 .ngpio = S5PC100_GPIO_K3_NR,
253 .label = "GPK3",
254 },
255 }, {
256 .config = &gpio_cfg_noint,
257 .chip = {
258 .base = S5PC100_GPL0(0),
259 .ngpio = S5PC100_GPIO_L0_NR,
260 .label = "GPL0",
261 },
262 }, {
263 .config = &gpio_cfg_noint,
264 .chip = {
265 .base = S5PC100_GPL1(0),
266 .ngpio = S5PC100_GPIO_L1_NR,
267 .label = "GPL1",
268 },
269 }, {
270 .config = &gpio_cfg_noint,
271 .chip = {
272 .base = S5PC100_GPL2(0),
273 .ngpio = S5PC100_GPIO_L2_NR,
274 .label = "GPL2",
275 },
276 }, {
277 .config = &gpio_cfg_noint,
278 .chip = {
279 .base = S5PC100_GPL3(0),
280 .ngpio = S5PC100_GPIO_L3_NR,
281 .label = "GPL3",
282 },
283 }, {
284 .config = &gpio_cfg_noint,
285 .chip = {
286 .base = S5PC100_GPL4(0),
287 .ngpio = S5PC100_GPIO_L4_NR,
288 .label = "GPL4",
289 },
290 }, {
291 .base = (S5P_VA_GPIO + 0xC00),
292 .config = &gpio_cfg_eint,
293 .irq_base = IRQ_EINT(0),
294 .chip = {
295 .base = S5PC100_GPH0(0),
296 .ngpio = S5PC100_GPIO_H0_NR,
297 .label = "GPH0",
298 .to_irq = samsung_gpiolib_to_irq,
299 },
300 }, {
301 .base = (S5P_VA_GPIO + 0xC20),
302 .config = &gpio_cfg_eint,
303 .irq_base = IRQ_EINT(8),
304 .chip = {
305 .base = S5PC100_GPH1(0),
306 .ngpio = S5PC100_GPIO_H1_NR,
307 .label = "GPH1",
308 .to_irq = samsung_gpiolib_to_irq,
309 },
310 }, {
311 .base = (S5P_VA_GPIO + 0xC40),
312 .config = &gpio_cfg_eint,
313 .irq_base = IRQ_EINT(16),
314 .chip = {
315 .base = S5PC100_GPH2(0),
316 .ngpio = S5PC100_GPIO_H2_NR,
317 .label = "GPH2",
318 .to_irq = samsung_gpiolib_to_irq,
319 },
320 }, {
321 .base = (S5P_VA_GPIO + 0xC60),
322 .config = &gpio_cfg_eint,
323 .irq_base = IRQ_EINT(24),
324 .chip = {
325 .base = S5PC100_GPH3(0),
326 .ngpio = S5PC100_GPIO_H3_NR,
327 .label = "GPH3",
328 .to_irq = samsung_gpiolib_to_irq,
329 },
330 },
331};
332
333static __init int s5pc100_gpiolib_init(void)
334{
335 struct s3c_gpio_chip *chip = s5pc100_gpio_chips;
336 int nr_chips = ARRAY_SIZE(s5pc100_gpio_chips);
337 int gpioint_group = 0;
338 int i;
339
340 for (i = 0; i < nr_chips; i++, chip++) {
341 if (chip->config == NULL) {
342 chip->config = &gpio_cfg;
343 chip->group = gpioint_group++;
344 }
345 if (chip->base == NULL)
346 chip->base = S5PC100_BANK_BASE(i);
347 }
348
349 samsung_gpiolib_add_4bit_chips(s5pc100_gpio_chips, nr_chips);
350 s5p_register_gpioint_bank(IRQ_GPIOINT, 0, S5P_GPIOINT_GROUP_MAXNR);
351
352 return 0;
353}
354core_initcall(s5pc100_gpiolib_init);
diff --git a/drivers/gpio/gpio-s5pv210.c b/drivers/gpio/gpio-s5pv210.c
deleted file mode 100644
index eb12f1602de9..000000000000
--- a/drivers/gpio/gpio-s5pv210.c
+++ /dev/null
@@ -1,287 +0,0 @@
1/*
2 * S5PV210 - GPIOlib support
3 *
4 * Copyright (c) 2010 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/kernel.h>
13#include <linux/irq.h>
14#include <linux/io.h>
15#include <linux/gpio.h>
16#include <plat/gpio-core.h>
17#include <plat/gpio-cfg.h>
18#include <plat/gpio-cfg-helpers.h>
19#include <mach/map.h>
20
21static struct s3c_gpio_cfg gpio_cfg = {
22 .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
23 .set_pull = s3c_gpio_setpull_updown,
24 .get_pull = s3c_gpio_getpull_updown,
25};
26
27static struct s3c_gpio_cfg gpio_cfg_noint = {
28 .set_config = s3c_gpio_setcfg_s3c64xx_4bit,
29 .set_pull = s3c_gpio_setpull_updown,
30 .get_pull = s3c_gpio_getpull_updown,
31};
32
33/* GPIO bank's base address given the index of the bank in the
34 * list of all gpio banks.
35 */
36#define S5PV210_BANK_BASE(bank_nr) (S5P_VA_GPIO + ((bank_nr) * 0x20))
37
38/*
39 * Following are the gpio banks in v210.
40 *
41 * The 'config' member when left to NULL, is initialized to the default
42 * structure gpio_cfg in the init function below.
43 *
44 * The 'base' member is also initialized in the init function below.
45 * Note: The initialization of 'base' member of s3c_gpio_chip structure
46 * uses the above macro and depends on the banks being listed in order here.
47 */
48static struct s3c_gpio_chip s5pv210_gpio_4bit[] = {
49 {
50 .chip = {
51 .base = S5PV210_GPA0(0),
52 .ngpio = S5PV210_GPIO_A0_NR,
53 .label = "GPA0",
54 },
55 }, {
56 .chip = {
57 .base = S5PV210_GPA1(0),
58 .ngpio = S5PV210_GPIO_A1_NR,
59 .label = "GPA1",
60 },
61 }, {
62 .chip = {
63 .base = S5PV210_GPB(0),
64 .ngpio = S5PV210_GPIO_B_NR,
65 .label = "GPB",
66 },
67 }, {
68 .chip = {
69 .base = S5PV210_GPC0(0),
70 .ngpio = S5PV210_GPIO_C0_NR,
71 .label = "GPC0",
72 },
73 }, {
74 .chip = {
75 .base = S5PV210_GPC1(0),
76 .ngpio = S5PV210_GPIO_C1_NR,
77 .label = "GPC1",
78 },
79 }, {
80 .chip = {
81 .base = S5PV210_GPD0(0),
82 .ngpio = S5PV210_GPIO_D0_NR,
83 .label = "GPD0",
84 },
85 }, {
86 .chip = {
87 .base = S5PV210_GPD1(0),
88 .ngpio = S5PV210_GPIO_D1_NR,
89 .label = "GPD1",
90 },
91 }, {
92 .chip = {
93 .base = S5PV210_GPE0(0),
94 .ngpio = S5PV210_GPIO_E0_NR,
95 .label = "GPE0",
96 },
97 }, {
98 .chip = {
99 .base = S5PV210_GPE1(0),
100 .ngpio = S5PV210_GPIO_E1_NR,
101 .label = "GPE1",
102 },
103 }, {
104 .chip = {
105 .base = S5PV210_GPF0(0),
106 .ngpio = S5PV210_GPIO_F0_NR,
107 .label = "GPF0",
108 },
109 }, {
110 .chip = {
111 .base = S5PV210_GPF1(0),
112 .ngpio = S5PV210_GPIO_F1_NR,
113 .label = "GPF1",
114 },
115 }, {
116 .chip = {
117 .base = S5PV210_GPF2(0),
118 .ngpio = S5PV210_GPIO_F2_NR,
119 .label = "GPF2",
120 },
121 }, {
122 .chip = {
123 .base = S5PV210_GPF3(0),
124 .ngpio = S5PV210_GPIO_F3_NR,
125 .label = "GPF3",
126 },
127 }, {
128 .chip = {
129 .base = S5PV210_GPG0(0),
130 .ngpio = S5PV210_GPIO_G0_NR,
131 .label = "GPG0",
132 },
133 }, {
134 .chip = {
135 .base = S5PV210_GPG1(0),
136 .ngpio = S5PV210_GPIO_G1_NR,
137 .label = "GPG1",
138 },
139 }, {
140 .chip = {
141 .base = S5PV210_GPG2(0),
142 .ngpio = S5PV210_GPIO_G2_NR,
143 .label = "GPG2",
144 },
145 }, {
146 .chip = {
147 .base = S5PV210_GPG3(0),
148 .ngpio = S5PV210_GPIO_G3_NR,
149 .label = "GPG3",
150 },
151 }, {
152 .config = &gpio_cfg_noint,
153 .chip = {
154 .base = S5PV210_GPI(0),
155 .ngpio = S5PV210_GPIO_I_NR,
156 .label = "GPI",
157 },
158 }, {
159 .chip = {
160 .base = S5PV210_GPJ0(0),
161 .ngpio = S5PV210_GPIO_J0_NR,
162 .label = "GPJ0",
163 },
164 }, {
165 .chip = {
166 .base = S5PV210_GPJ1(0),
167 .ngpio = S5PV210_GPIO_J1_NR,
168 .label = "GPJ1",
169 },
170 }, {
171 .chip = {
172 .base = S5PV210_GPJ2(0),
173 .ngpio = S5PV210_GPIO_J2_NR,
174 .label = "GPJ2",
175 },
176 }, {
177 .chip = {
178 .base = S5PV210_GPJ3(0),
179 .ngpio = S5PV210_GPIO_J3_NR,
180 .label = "GPJ3",
181 },
182 }, {
183 .chip = {
184 .base = S5PV210_GPJ4(0),
185 .ngpio = S5PV210_GPIO_J4_NR,
186 .label = "GPJ4",
187 },
188 }, {
189 .config = &gpio_cfg_noint,
190 .chip = {
191 .base = S5PV210_MP01(0),
192 .ngpio = S5PV210_GPIO_MP01_NR,
193 .label = "MP01",
194 },
195 }, {
196 .config = &gpio_cfg_noint,
197 .chip = {
198 .base = S5PV210_MP02(0),
199 .ngpio = S5PV210_GPIO_MP02_NR,
200 .label = "MP02",
201 },
202 }, {
203 .config = &gpio_cfg_noint,
204 .chip = {
205 .base = S5PV210_MP03(0),
206 .ngpio = S5PV210_GPIO_MP03_NR,
207 .label = "MP03",
208 },
209 }, {
210 .config = &gpio_cfg_noint,
211 .chip = {
212 .base = S5PV210_MP04(0),
213 .ngpio = S5PV210_GPIO_MP04_NR,
214 .label = "MP04",
215 },
216 }, {
217 .config = &gpio_cfg_noint,
218 .chip = {
219 .base = S5PV210_MP05(0),
220 .ngpio = S5PV210_GPIO_MP05_NR,
221 .label = "MP05",
222 },
223 }, {
224 .base = (S5P_VA_GPIO + 0xC00),
225 .config = &gpio_cfg_noint,
226 .irq_base = IRQ_EINT(0),
227 .chip = {
228 .base = S5PV210_GPH0(0),
229 .ngpio = S5PV210_GPIO_H0_NR,
230 .label = "GPH0",
231 .to_irq = samsung_gpiolib_to_irq,
232 },
233 }, {
234 .base = (S5P_VA_GPIO + 0xC20),
235 .config = &gpio_cfg_noint,
236 .irq_base = IRQ_EINT(8),
237 .chip = {
238 .base = S5PV210_GPH1(0),
239 .ngpio = S5PV210_GPIO_H1_NR,
240 .label = "GPH1",
241 .to_irq = samsung_gpiolib_to_irq,
242 },
243 }, {
244 .base = (S5P_VA_GPIO + 0xC40),
245 .config = &gpio_cfg_noint,
246 .irq_base = IRQ_EINT(16),
247 .chip = {
248 .base = S5PV210_GPH2(0),
249 .ngpio = S5PV210_GPIO_H2_NR,
250 .label = "GPH2",
251 .to_irq = samsung_gpiolib_to_irq,
252 },
253 }, {
254 .base = (S5P_VA_GPIO + 0xC60),
255 .config = &gpio_cfg_noint,
256 .irq_base = IRQ_EINT(24),
257 .chip = {
258 .base = S5PV210_GPH3(0),
259 .ngpio = S5PV210_GPIO_H3_NR,
260 .label = "GPH3",
261 .to_irq = samsung_gpiolib_to_irq,
262 },
263 },
264};
265
266static __init int s5pv210_gpiolib_init(void)
267{
268 struct s3c_gpio_chip *chip = s5pv210_gpio_4bit;
269 int nr_chips = ARRAY_SIZE(s5pv210_gpio_4bit);
270 int gpioint_group = 0;
271 int i = 0;
272
273 for (i = 0; i < nr_chips; i++, chip++) {
274 if (chip->config == NULL) {
275 chip->config = &gpio_cfg;
276 chip->group = gpioint_group++;
277 }
278 if (chip->base == NULL)
279 chip->base = S5PV210_BANK_BASE(i);
280 }
281
282 samsung_gpiolib_add_4bit_chips(s5pv210_gpio_4bit, nr_chips);
283 s5p_register_gpioint_bank(IRQ_GPIOINT, 0, S5P_GPIOINT_GROUP_MAXNR);
284
285 return 0;
286}
287core_initcall(s5pv210_gpiolib_init);
diff --git a/drivers/gpio/gpio-samsung.c b/drivers/gpio/gpio-samsung.c
new file mode 100644
index 000000000000..866251852719
--- /dev/null
+++ b/drivers/gpio/gpio-samsung.c
@@ -0,0 +1,2712 @@
1/*
2 * Copyright (c) 2009-2011 Samsung Electronics Co., Ltd.
3 * http://www.samsung.com/
4 *
5 * Copyright 2008 Openmoko, Inc.
6 * Copyright 2008 Simtec Electronics
7 * Ben Dooks <ben@simtec.co.uk>
8 * http://armlinux.simtec.co.uk/
9 *
10 * SAMSUNG - GPIOlib support
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation.
15 */
16
17#include <linux/kernel.h>
18#include <linux/irq.h>
19#include <linux/io.h>
20#include <linux/gpio.h>
21#include <linux/init.h>
22#include <linux/spinlock.h>
23#include <linux/module.h>
24#include <linux/interrupt.h>
25#include <linux/sysdev.h>
26#include <linux/ioport.h>
27
28#include <asm/irq.h>
29
30#include <mach/hardware.h>
31#include <mach/map.h>
32#include <mach/regs-clock.h>
33#include <mach/regs-gpio.h>
34
35#include <plat/cpu.h>
36#include <plat/gpio-core.h>
37#include <plat/gpio-cfg.h>
38#include <plat/gpio-cfg-helpers.h>
39#include <plat/gpio-fns.h>
40#include <plat/pm.h>
41
42#ifndef DEBUG_GPIO
43#define gpio_dbg(x...) do { } while (0)
44#else
45#define gpio_dbg(x...) printk(KERN_DEBUG x)
46#endif
47
48int samsung_gpio_setpull_updown(struct samsung_gpio_chip *chip,
49 unsigned int off, samsung_gpio_pull_t pull)
50{
51 void __iomem *reg = chip->base + 0x08;
52 int shift = off * 2;
53 u32 pup;
54
55 pup = __raw_readl(reg);
56 pup &= ~(3 << shift);
57 pup |= pull << shift;
58 __raw_writel(pup, reg);
59
60 return 0;
61}
62
63samsung_gpio_pull_t samsung_gpio_getpull_updown(struct samsung_gpio_chip *chip,
64 unsigned int off)
65{
66 void __iomem *reg = chip->base + 0x08;
67 int shift = off * 2;
68 u32 pup = __raw_readl(reg);
69
70 pup >>= shift;
71 pup &= 0x3;
72
73 return (__force samsung_gpio_pull_t)pup;
74}
75
76int s3c2443_gpio_setpull(struct samsung_gpio_chip *chip,
77 unsigned int off, samsung_gpio_pull_t pull)
78{
79 switch (pull) {
80 case S3C_GPIO_PULL_NONE:
81 pull = 0x01;
82 break;
83 case S3C_GPIO_PULL_UP:
84 pull = 0x00;
85 break;
86 case S3C_GPIO_PULL_DOWN:
87 pull = 0x02;
88 break;
89 }
90 return samsung_gpio_setpull_updown(chip, off, pull);
91}
92
93samsung_gpio_pull_t s3c2443_gpio_getpull(struct samsung_gpio_chip *chip,
94 unsigned int off)
95{
96 samsung_gpio_pull_t pull;
97
98 pull = samsung_gpio_getpull_updown(chip, off);
99
100 switch (pull) {
101 case 0x00:
102 pull = S3C_GPIO_PULL_UP;
103 break;
104 case 0x01:
105 case 0x03:
106 pull = S3C_GPIO_PULL_NONE;
107 break;
108 case 0x02:
109 pull = S3C_GPIO_PULL_DOWN;
110 break;
111 }
112
113 return pull;
114}
115
116static int s3c24xx_gpio_setpull_1(struct samsung_gpio_chip *chip,
117 unsigned int off, samsung_gpio_pull_t pull,
118 samsung_gpio_pull_t updown)
119{
120 void __iomem *reg = chip->base + 0x08;
121 u32 pup = __raw_readl(reg);
122
123 if (pull == updown)
124 pup &= ~(1 << off);
125 else if (pull == S3C_GPIO_PULL_NONE)
126 pup |= (1 << off);
127 else
128 return -EINVAL;
129
130 __raw_writel(pup, reg);
131 return 0;
132}
133
134static samsung_gpio_pull_t s3c24xx_gpio_getpull_1(struct samsung_gpio_chip *chip,
135 unsigned int off,
136 samsung_gpio_pull_t updown)
137{
138 void __iomem *reg = chip->base + 0x08;
139 u32 pup = __raw_readl(reg);
140
141 pup &= (1 << off);
142 return pup ? S3C_GPIO_PULL_NONE : updown;
143}
144
145samsung_gpio_pull_t s3c24xx_gpio_getpull_1up(struct samsung_gpio_chip *chip,
146 unsigned int off)
147{
148 return s3c24xx_gpio_getpull_1(chip, off, S3C_GPIO_PULL_UP);
149}
150
151int s3c24xx_gpio_setpull_1up(struct samsung_gpio_chip *chip,
152 unsigned int off, samsung_gpio_pull_t pull)
153{
154 return s3c24xx_gpio_setpull_1(chip, off, pull, S3C_GPIO_PULL_UP);
155}
156
157samsung_gpio_pull_t s3c24xx_gpio_getpull_1down(struct samsung_gpio_chip *chip,
158 unsigned int off)
159{
160 return s3c24xx_gpio_getpull_1(chip, off, S3C_GPIO_PULL_DOWN);
161}
162
163int s3c24xx_gpio_setpull_1down(struct samsung_gpio_chip *chip,
164 unsigned int off, samsung_gpio_pull_t pull)
165{
166 return s3c24xx_gpio_setpull_1(chip, off, pull, S3C_GPIO_PULL_DOWN);
167}
168
169static int exynos4_gpio_setpull(struct samsung_gpio_chip *chip,
170 unsigned int off, samsung_gpio_pull_t pull)
171{
172 if (pull == S3C_GPIO_PULL_UP)
173 pull = 3;
174
175 return samsung_gpio_setpull_updown(chip, off, pull);
176}
177
178static samsung_gpio_pull_t exynos4_gpio_getpull(struct samsung_gpio_chip *chip,
179 unsigned int off)
180{
181 samsung_gpio_pull_t pull;
182
183 pull = samsung_gpio_getpull_updown(chip, off);
184
185 if (pull == 3)
186 pull = S3C_GPIO_PULL_UP;
187
188 return pull;
189}
190
191/*
192 * samsung_gpio_setcfg_2bit - Samsung 2bit style GPIO configuration.
193 * @chip: The gpio chip that is being configured.
194 * @off: The offset for the GPIO being configured.
195 * @cfg: The configuration value to set.
196 *
197 * This helper deal with the GPIO cases where the control register
198 * has two bits of configuration per gpio, which have the following
199 * functions:
200 * 00 = input
201 * 01 = output
202 * 1x = special function
203 */
204
205static int samsung_gpio_setcfg_2bit(struct samsung_gpio_chip *chip,
206 unsigned int off, unsigned int cfg)
207{
208 void __iomem *reg = chip->base;
209 unsigned int shift = off * 2;
210 u32 con;
211
212 if (samsung_gpio_is_cfg_special(cfg)) {
213 cfg &= 0xf;
214 if (cfg > 3)
215 return -EINVAL;
216
217 cfg <<= shift;
218 }
219
220 con = __raw_readl(reg);
221 con &= ~(0x3 << shift);
222 con |= cfg;
223 __raw_writel(con, reg);
224
225 return 0;
226}
227
228/*
229 * samsung_gpio_getcfg_2bit - Samsung 2bit style GPIO configuration read.
230 * @chip: The gpio chip that is being configured.
231 * @off: The offset for the GPIO being configured.
232 *
233 * The reverse of samsung_gpio_setcfg_2bit(). Will return a value whicg
234 * could be directly passed back to samsung_gpio_setcfg_2bit(), from the
235 * S3C_GPIO_SPECIAL() macro.
236 */
237
238static unsigned int samsung_gpio_getcfg_2bit(struct samsung_gpio_chip *chip,
239 unsigned int off)
240{
241 u32 con;
242
243 con = __raw_readl(chip->base);
244 con >>= off * 2;
245 con &= 3;
246
247 /* this conversion works for IN and OUT as well as special mode */
248 return S3C_GPIO_SPECIAL(con);
249}
250
251/*
252 * samsung_gpio_setcfg_4bit - Samsung 4bit single register GPIO config.
253 * @chip: The gpio chip that is being configured.
254 * @off: The offset for the GPIO being configured.
255 * @cfg: The configuration value to set.
256 *
257 * This helper deal with the GPIO cases where the control register has 4 bits
258 * of control per GPIO, generally in the form of:
259 * 0000 = Input
260 * 0001 = Output
261 * others = Special functions (dependent on bank)
262 *
263 * Note, since the code to deal with the case where there are two control
264 * registers instead of one, we do not have a separate set of functions for
265 * each case.
266 */
267
268static int samsung_gpio_setcfg_4bit(struct samsung_gpio_chip *chip,
269 unsigned int off, unsigned int cfg)
270{
271 void __iomem *reg = chip->base;
272 unsigned int shift = (off & 7) * 4;
273 u32 con;
274
275 if (off < 8 && chip->chip.ngpio > 8)
276 reg -= 4;
277
278 if (samsung_gpio_is_cfg_special(cfg)) {
279 cfg &= 0xf;
280 cfg <<= shift;
281 }
282
283 con = __raw_readl(reg);
284 con &= ~(0xf << shift);
285 con |= cfg;
286 __raw_writel(con, reg);
287
288 return 0;
289}
290
291/*
292 * samsung_gpio_getcfg_4bit - Samsung 4bit single register GPIO config read.
293 * @chip: The gpio chip that is being configured.
294 * @off: The offset for the GPIO being configured.
295 *
296 * The reverse of samsung_gpio_setcfg_4bit(), turning a gpio configuration
297 * register setting into a value the software can use, such as could be passed
298 * to samsung_gpio_setcfg_4bit().
299 *
300 * @sa samsung_gpio_getcfg_2bit
301 */
302
303static unsigned samsung_gpio_getcfg_4bit(struct samsung_gpio_chip *chip,
304 unsigned int off)
305{
306 void __iomem *reg = chip->base;
307 unsigned int shift = (off & 7) * 4;
308 u32 con;
309
310 if (off < 8 && chip->chip.ngpio > 8)
311 reg -= 4;
312
313 con = __raw_readl(reg);
314 con >>= shift;
315 con &= 0xf;
316
317 /* this conversion works for IN and OUT as well as special mode */
318 return S3C_GPIO_SPECIAL(con);
319}
320
321#ifdef CONFIG_PLAT_S3C24XX
322/*
323 * s3c24xx_gpio_setcfg_abank - S3C24XX style GPIO configuration (Bank A)
324 * @chip: The gpio chip that is being configured.
325 * @off: The offset for the GPIO being configured.
326 * @cfg: The configuration value to set.
327 *
328 * This helper deal with the GPIO cases where the control register
329 * has one bit of configuration for the gpio, where setting the bit
330 * means the pin is in special function mode and unset means output.
331 */
332
333static int s3c24xx_gpio_setcfg_abank(struct samsung_gpio_chip *chip,
334 unsigned int off, unsigned int cfg)
335{
336 void __iomem *reg = chip->base;
337 unsigned int shift = off;
338 u32 con;
339
340 if (samsung_gpio_is_cfg_special(cfg)) {
341 cfg &= 0xf;
342
343 /* Map output to 0, and SFN2 to 1 */
344 cfg -= 1;
345 if (cfg > 1)
346 return -EINVAL;
347
348 cfg <<= shift;
349 }
350
351 con = __raw_readl(reg);
352 con &= ~(0x1 << shift);
353 con |= cfg;
354 __raw_writel(con, reg);
355
356 return 0;
357}
358
359/*
360 * s3c24xx_gpio_getcfg_abank - S3C24XX style GPIO configuration read (Bank A)
361 * @chip: The gpio chip that is being configured.
362 * @off: The offset for the GPIO being configured.
363 *
364 * The reverse of s3c24xx_gpio_setcfg_abank() turning an GPIO into a usable
365 * GPIO configuration value.
366 *
367 * @sa samsung_gpio_getcfg_2bit
368 * @sa samsung_gpio_getcfg_4bit
369 */
370
371static unsigned s3c24xx_gpio_getcfg_abank(struct samsung_gpio_chip *chip,
372 unsigned int off)
373{
374 u32 con;
375
376 con = __raw_readl(chip->base);
377 con >>= off;
378 con &= 1;
379 con++;
380
381 return S3C_GPIO_SFN(con);
382}
383#endif
384
385#if defined(CONFIG_CPU_S5P6440) || defined(CONFIG_CPU_S5P6450)
386static int s5p64x0_gpio_setcfg_rbank(struct samsung_gpio_chip *chip,
387 unsigned int off, unsigned int cfg)
388{
389 void __iomem *reg = chip->base;
390 unsigned int shift;
391 u32 con;
392
393 switch (off) {
394 case 0:
395 case 1:
396 case 2:
397 case 3:
398 case 4:
399 case 5:
400 shift = (off & 7) * 4;
401 reg -= 4;
402 break;
403 case 6:
404 shift = ((off + 1) & 7) * 4;
405 reg -= 4;
406 default:
407 shift = ((off + 1) & 7) * 4;
408 break;
409 }
410
411 if (samsung_gpio_is_cfg_special(cfg)) {
412 cfg &= 0xf;
413 cfg <<= shift;
414 }
415
416 con = __raw_readl(reg);
417 con &= ~(0xf << shift);
418 con |= cfg;
419 __raw_writel(con, reg);
420
421 return 0;
422}
423#endif
424
425static void __init samsung_gpiolib_set_cfg(struct samsung_gpio_cfg *chipcfg,
426 int nr_chips)
427{
428 for (; nr_chips > 0; nr_chips--, chipcfg++) {
429 if (!chipcfg->set_config)
430 chipcfg->set_config = samsung_gpio_setcfg_4bit;
431 if (!chipcfg->get_config)
432 chipcfg->get_config = samsung_gpio_getcfg_4bit;
433 if (!chipcfg->set_pull)
434 chipcfg->set_pull = samsung_gpio_setpull_updown;
435 if (!chipcfg->get_pull)
436 chipcfg->get_pull = samsung_gpio_getpull_updown;
437 }
438}
439
440struct samsung_gpio_cfg s3c24xx_gpiocfg_default = {
441 .set_config = samsung_gpio_setcfg_2bit,
442 .get_config = samsung_gpio_getcfg_2bit,
443};
444
445#ifdef CONFIG_PLAT_S3C24XX
446static struct samsung_gpio_cfg s3c24xx_gpiocfg_banka = {
447 .set_config = s3c24xx_gpio_setcfg_abank,
448 .get_config = s3c24xx_gpio_getcfg_abank,
449};
450#endif
451
452static struct samsung_gpio_cfg exynos4_gpio_cfg = {
453 .set_pull = exynos4_gpio_setpull,
454 .get_pull = exynos4_gpio_getpull,
455 .set_config = samsung_gpio_setcfg_4bit,
456 .get_config = samsung_gpio_getcfg_4bit,
457};
458
459#if defined(CONFIG_CPU_S5P6440) || defined(CONFIG_CPU_S5P6450)
460static struct samsung_gpio_cfg s5p64x0_gpio_cfg_rbank = {
461 .cfg_eint = 0x3,
462 .set_config = s5p64x0_gpio_setcfg_rbank,
463 .get_config = samsung_gpio_getcfg_4bit,
464 .set_pull = samsung_gpio_setpull_updown,
465 .get_pull = samsung_gpio_getpull_updown,
466};
467#endif
468
469static struct samsung_gpio_cfg samsung_gpio_cfgs[] = {
470 {
471 .cfg_eint = 0x0,
472 }, {
473 .cfg_eint = 0x3,
474 }, {
475 .cfg_eint = 0x7,
476 }, {
477 .cfg_eint = 0xF,
478 }, {
479 .cfg_eint = 0x0,
480 .set_config = samsung_gpio_setcfg_2bit,
481 .get_config = samsung_gpio_getcfg_2bit,
482 }, {
483 .cfg_eint = 0x2,
484 .set_config = samsung_gpio_setcfg_2bit,
485 .get_config = samsung_gpio_getcfg_2bit,
486 }, {
487 .cfg_eint = 0x3,
488 .set_config = samsung_gpio_setcfg_2bit,
489 .get_config = samsung_gpio_getcfg_2bit,
490 }, {
491 .set_config = samsung_gpio_setcfg_2bit,
492 .get_config = samsung_gpio_getcfg_2bit,
493 }, {
494 .set_pull = exynos4_gpio_setpull,
495 .get_pull = exynos4_gpio_getpull,
496 }, {
497 .cfg_eint = 0x3,
498 .set_pull = exynos4_gpio_setpull,
499 .get_pull = exynos4_gpio_getpull,
500 }
501};
502
503/*
504 * Default routines for controlling GPIO, based on the original S3C24XX
505 * GPIO functions which deal with the case where each gpio bank of the
506 * chip is as following:
507 *
508 * base + 0x00: Control register, 2 bits per gpio
509 * gpio n: 2 bits starting at (2*n)
510 * 00 = input, 01 = output, others mean special-function
511 * base + 0x04: Data register, 1 bit per gpio
512 * bit n: data bit n
513*/
514
515static int samsung_gpiolib_2bit_input(struct gpio_chip *chip, unsigned offset)
516{
517 struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
518 void __iomem *base = ourchip->base;
519 unsigned long flags;
520 unsigned long con;
521
522 samsung_gpio_lock(ourchip, flags);
523
524 con = __raw_readl(base + 0x00);
525 con &= ~(3 << (offset * 2));
526
527 __raw_writel(con, base + 0x00);
528
529 samsung_gpio_unlock(ourchip, flags);
530 return 0;
531}
532
533static int samsung_gpiolib_2bit_output(struct gpio_chip *chip,
534 unsigned offset, int value)
535{
536 struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
537 void __iomem *base = ourchip->base;
538 unsigned long flags;
539 unsigned long dat;
540 unsigned long con;
541
542 samsung_gpio_lock(ourchip, flags);
543
544 dat = __raw_readl(base + 0x04);
545 dat &= ~(1 << offset);
546 if (value)
547 dat |= 1 << offset;
548 __raw_writel(dat, base + 0x04);
549
550 con = __raw_readl(base + 0x00);
551 con &= ~(3 << (offset * 2));
552 con |= 1 << (offset * 2);
553
554 __raw_writel(con, base + 0x00);
555 __raw_writel(dat, base + 0x04);
556
557 samsung_gpio_unlock(ourchip, flags);
558 return 0;
559}
560
561/*
562 * The samsung_gpiolib_4bit routines are to control the gpio banks where
563 * the gpio configuration register (GPxCON) has 4 bits per GPIO, as the
564 * following example:
565 *
566 * base + 0x00: Control register, 4 bits per gpio
567 * gpio n: 4 bits starting at (4*n)
568 * 0000 = input, 0001 = output, others mean special-function
569 * base + 0x04: Data register, 1 bit per gpio
570 * bit n: data bit n
571 *
572 * Note, since the data register is one bit per gpio and is at base + 0x4
573 * we can use samsung_gpiolib_get and samsung_gpiolib_set to change the
574 * state of the output.
575 */
576
577static int samsung_gpiolib_4bit_input(struct gpio_chip *chip,
578 unsigned int offset)
579{
580 struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
581 void __iomem *base = ourchip->base;
582 unsigned long con;
583
584 con = __raw_readl(base + GPIOCON_OFF);
585 con &= ~(0xf << con_4bit_shift(offset));
586 __raw_writel(con, base + GPIOCON_OFF);
587
588 gpio_dbg("%s: %p: CON now %08lx\n", __func__, base, con);
589
590 return 0;
591}
592
593static int samsung_gpiolib_4bit_output(struct gpio_chip *chip,
594 unsigned int offset, int value)
595{
596 struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
597 void __iomem *base = ourchip->base;
598 unsigned long con;
599 unsigned long dat;
600
601 con = __raw_readl(base + GPIOCON_OFF);
602 con &= ~(0xf << con_4bit_shift(offset));
603 con |= 0x1 << con_4bit_shift(offset);
604
605 dat = __raw_readl(base + GPIODAT_OFF);
606
607 if (value)
608 dat |= 1 << offset;
609 else
610 dat &= ~(1 << offset);
611
612 __raw_writel(dat, base + GPIODAT_OFF);
613 __raw_writel(con, base + GPIOCON_OFF);
614 __raw_writel(dat, base + GPIODAT_OFF);
615
616 gpio_dbg("%s: %p: CON %08lx, DAT %08lx\n", __func__, base, con, dat);
617
618 return 0;
619}
620
621/*
622 * The next set of routines are for the case where the GPIO configuration
623 * registers are 4 bits per GPIO but there is more than one register (the
624 * bank has more than 8 GPIOs.
625 *
626 * This case is the similar to the 4 bit case, but the registers are as
627 * follows:
628 *
629 * base + 0x00: Control register, 4 bits per gpio (lower 8 GPIOs)
630 * gpio n: 4 bits starting at (4*n)
631 * 0000 = input, 0001 = output, others mean special-function
632 * base + 0x04: Control register, 4 bits per gpio (up to 8 additions GPIOs)
633 * gpio n: 4 bits starting at (4*n)
634 * 0000 = input, 0001 = output, others mean special-function
635 * base + 0x08: Data register, 1 bit per gpio
636 * bit n: data bit n
637 *
638 * To allow us to use the samsung_gpiolib_get and samsung_gpiolib_set
639 * routines we store the 'base + 0x4' address so that these routines see
640 * the data register at ourchip->base + 0x04.
641 */
642
643static int samsung_gpiolib_4bit2_input(struct gpio_chip *chip,
644 unsigned int offset)
645{
646 struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
647 void __iomem *base = ourchip->base;
648 void __iomem *regcon = base;
649 unsigned long con;
650
651 if (offset > 7)
652 offset -= 8;
653 else
654 regcon -= 4;
655
656 con = __raw_readl(regcon);
657 con &= ~(0xf << con_4bit_shift(offset));
658 __raw_writel(con, regcon);
659
660 gpio_dbg("%s: %p: CON %08lx\n", __func__, base, con);
661
662 return 0;
663}
664
665static int samsung_gpiolib_4bit2_output(struct gpio_chip *chip,
666 unsigned int offset, int value)
667{
668 struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
669 void __iomem *base = ourchip->base;
670 void __iomem *regcon = base;
671 unsigned long con;
672 unsigned long dat;
673 unsigned con_offset = offset;
674
675 if (con_offset > 7)
676 con_offset -= 8;
677 else
678 regcon -= 4;
679
680 con = __raw_readl(regcon);
681 con &= ~(0xf << con_4bit_shift(con_offset));
682 con |= 0x1 << con_4bit_shift(con_offset);
683
684 dat = __raw_readl(base + GPIODAT_OFF);
685
686 if (value)
687 dat |= 1 << offset;
688 else
689 dat &= ~(1 << offset);
690
691 __raw_writel(dat, base + GPIODAT_OFF);
692 __raw_writel(con, regcon);
693 __raw_writel(dat, base + GPIODAT_OFF);
694
695 gpio_dbg("%s: %p: CON %08lx, DAT %08lx\n", __func__, base, con, dat);
696
697 return 0;
698}
699
700#ifdef CONFIG_PLAT_S3C24XX
701/* The next set of routines are for the case of s3c24xx bank a */
702
703static int s3c24xx_gpiolib_banka_input(struct gpio_chip *chip, unsigned offset)
704{
705 return -EINVAL;
706}
707
708static int s3c24xx_gpiolib_banka_output(struct gpio_chip *chip,
709 unsigned offset, int value)
710{
711 struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
712 void __iomem *base = ourchip->base;
713 unsigned long flags;
714 unsigned long dat;
715 unsigned long con;
716
717 local_irq_save(flags);
718
719 con = __raw_readl(base + 0x00);
720 dat = __raw_readl(base + 0x04);
721
722 dat &= ~(1 << offset);
723 if (value)
724 dat |= 1 << offset;
725
726 __raw_writel(dat, base + 0x04);
727
728 con &= ~(1 << offset);
729
730 __raw_writel(con, base + 0x00);
731 __raw_writel(dat, base + 0x04);
732
733 local_irq_restore(flags);
734 return 0;
735}
736#endif
737
738/* The next set of routines are for the case of s5p64x0 bank r */
739
740static int s5p64x0_gpiolib_rbank_input(struct gpio_chip *chip,
741 unsigned int offset)
742{
743 struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
744 void __iomem *base = ourchip->base;
745 void __iomem *regcon = base;
746 unsigned long con;
747 unsigned long flags;
748
749 switch (offset) {
750 case 6:
751 offset += 1;
752 case 0:
753 case 1:
754 case 2:
755 case 3:
756 case 4:
757 case 5:
758 regcon -= 4;
759 break;
760 default:
761 offset -= 7;
762 break;
763 }
764
765 samsung_gpio_lock(ourchip, flags);
766
767 con = __raw_readl(regcon);
768 con &= ~(0xf << con_4bit_shift(offset));
769 __raw_writel(con, regcon);
770
771 samsung_gpio_unlock(ourchip, flags);
772
773 return 0;
774}
775
776static int s5p64x0_gpiolib_rbank_output(struct gpio_chip *chip,
777 unsigned int offset, int value)
778{
779 struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
780 void __iomem *base = ourchip->base;
781 void __iomem *regcon = base;
782 unsigned long con;
783 unsigned long dat;
784 unsigned long flags;
785 unsigned con_offset = offset;
786
787 switch (con_offset) {
788 case 6:
789 con_offset += 1;
790 case 0:
791 case 1:
792 case 2:
793 case 3:
794 case 4:
795 case 5:
796 regcon -= 4;
797 break;
798 default:
799 con_offset -= 7;
800 break;
801 }
802
803 samsung_gpio_lock(ourchip, flags);
804
805 con = __raw_readl(regcon);
806 con &= ~(0xf << con_4bit_shift(con_offset));
807 con |= 0x1 << con_4bit_shift(con_offset);
808
809 dat = __raw_readl(base + GPIODAT_OFF);
810 if (value)
811 dat |= 1 << offset;
812 else
813 dat &= ~(1 << offset);
814
815 __raw_writel(con, regcon);
816 __raw_writel(dat, base + GPIODAT_OFF);
817
818 samsung_gpio_unlock(ourchip, flags);
819
820 return 0;
821}
822
823static void samsung_gpiolib_set(struct gpio_chip *chip,
824 unsigned offset, int value)
825{
826 struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
827 void __iomem *base = ourchip->base;
828 unsigned long flags;
829 unsigned long dat;
830
831 samsung_gpio_lock(ourchip, flags);
832
833 dat = __raw_readl(base + 0x04);
834 dat &= ~(1 << offset);
835 if (value)
836 dat |= 1 << offset;
837 __raw_writel(dat, base + 0x04);
838
839 samsung_gpio_unlock(ourchip, flags);
840}
841
842static int samsung_gpiolib_get(struct gpio_chip *chip, unsigned offset)
843{
844 struct samsung_gpio_chip *ourchip = to_samsung_gpio(chip);
845 unsigned long val;
846
847 val = __raw_readl(ourchip->base + 0x04);
848 val >>= offset;
849 val &= 1;
850
851 return val;
852}
853
854/*
855 * CONFIG_S3C_GPIO_TRACK enables the tracking of the s3c specific gpios
856 * for use with the configuration calls, and other parts of the s3c gpiolib
857 * support code.
858 *
859 * Not all s3c support code will need this, as some configurations of cpu
860 * may only support one or two different configuration options and have an
861 * easy gpio to samsung_gpio_chip mapping function. If this is the case, then
862 * the machine support file should provide its own samsung_gpiolib_getchip()
863 * and any other necessary functions.
864 */
865
866#ifdef CONFIG_S3C_GPIO_TRACK
867struct samsung_gpio_chip *s3c_gpios[S3C_GPIO_END];
868
869static __init void s3c_gpiolib_track(struct samsung_gpio_chip *chip)
870{
871 unsigned int gpn;
872 int i;
873
874 gpn = chip->chip.base;
875 for (i = 0; i < chip->chip.ngpio; i++, gpn++) {
876 BUG_ON(gpn >= ARRAY_SIZE(s3c_gpios));
877 s3c_gpios[gpn] = chip;
878 }
879}
880#endif /* CONFIG_S3C_GPIO_TRACK */
881
882/*
883 * samsung_gpiolib_add() - add the Samsung gpio_chip.
884 * @chip: The chip to register
885 *
886 * This is a wrapper to gpiochip_add() that takes our specific gpio chip
887 * information and makes the necessary alterations for the platform and
888 * notes the information for use with the configuration systems and any
889 * other parts of the system.
890 */
891
892static void __init samsung_gpiolib_add(struct samsung_gpio_chip *chip)
893{
894 struct gpio_chip *gc = &chip->chip;
895 int ret;
896
897 BUG_ON(!chip->base);
898 BUG_ON(!gc->label);
899 BUG_ON(!gc->ngpio);
900
901 spin_lock_init(&chip->lock);
902
903 if (!gc->direction_input)
904 gc->direction_input = samsung_gpiolib_2bit_input;
905 if (!gc->direction_output)
906 gc->direction_output = samsung_gpiolib_2bit_output;
907 if (!gc->set)
908 gc->set = samsung_gpiolib_set;
909 if (!gc->get)
910 gc->get = samsung_gpiolib_get;
911
912#ifdef CONFIG_PM
913 if (chip->pm != NULL) {
914 if (!chip->pm->save || !chip->pm->resume)
915 printk(KERN_ERR "gpio: %s has missing PM functions\n",
916 gc->label);
917 } else
918 printk(KERN_ERR "gpio: %s has no PM function\n", gc->label);
919#endif
920
921 /* gpiochip_add() prints own failure message on error. */
922 ret = gpiochip_add(gc);
923 if (ret >= 0)
924 s3c_gpiolib_track(chip);
925}
926
927static void __init s3c24xx_gpiolib_add_chips(struct samsung_gpio_chip *chip,
928 int nr_chips, void __iomem *base)
929{
930 int i;
931 struct gpio_chip *gc = &chip->chip;
932
933 for (i = 0 ; i < nr_chips; i++, chip++) {
934 /* skip banks not present on SoC */
935 if (chip->chip.base >= S3C_GPIO_END)
936 continue;
937
938 if (!chip->config)
939 chip->config = &s3c24xx_gpiocfg_default;
940 if (!chip->pm)
941 chip->pm = __gpio_pm(&samsung_gpio_pm_2bit);
942 if ((base != NULL) && (chip->base == NULL))
943 chip->base = base + ((i) * 0x10);
944
945 if (!gc->direction_input)
946 gc->direction_input = samsung_gpiolib_2bit_input;
947 if (!gc->direction_output)
948 gc->direction_output = samsung_gpiolib_2bit_output;
949
950 samsung_gpiolib_add(chip);
951 }
952}
953
954static void __init samsung_gpiolib_add_2bit_chips(struct samsung_gpio_chip *chip,
955 int nr_chips, void __iomem *base,
956 unsigned int offset)
957{
958 int i;
959
960 for (i = 0 ; i < nr_chips; i++, chip++) {
961 chip->chip.direction_input = samsung_gpiolib_2bit_input;
962 chip->chip.direction_output = samsung_gpiolib_2bit_output;
963
964 if (!chip->config)
965 chip->config = &samsung_gpio_cfgs[7];
966 if (!chip->pm)
967 chip->pm = __gpio_pm(&samsung_gpio_pm_2bit);
968 if ((base != NULL) && (chip->base == NULL))
969 chip->base = base + ((i) * offset);
970
971 samsung_gpiolib_add(chip);
972 }
973}
974
975/*
976 * samsung_gpiolib_add_4bit_chips - 4bit single register GPIO config.
977 * @chip: The gpio chip that is being configured.
978 * @nr_chips: The no of chips (gpio ports) for the GPIO being configured.
979 *
980 * This helper deal with the GPIO cases where the control register has 4 bits
981 * of control per GPIO, generally in the form of:
982 * 0000 = Input
983 * 0001 = Output
984 * others = Special functions (dependent on bank)
985 *
986 * Note, since the code to deal with the case where there are two control
987 * registers instead of one, we do not have a separate set of function
988 * (samsung_gpiolib_add_4bit2_chips)for each case.
989 */
990
991static void __init samsung_gpiolib_add_4bit_chips(struct samsung_gpio_chip *chip,
992 int nr_chips, void __iomem *base)
993{
994 int i;
995
996 for (i = 0 ; i < nr_chips; i++, chip++) {
997 chip->chip.direction_input = samsung_gpiolib_4bit_input;
998 chip->chip.direction_output = samsung_gpiolib_4bit_output;
999
1000 if (!chip->config)
1001 chip->config = &samsung_gpio_cfgs[2];
1002 if (!chip->pm)
1003 chip->pm = __gpio_pm(&samsung_gpio_pm_4bit);
1004 if ((base != NULL) && (chip->base == NULL))
1005 chip->base = base + ((i) * 0x20);
1006
1007 samsung_gpiolib_add(chip);
1008 }
1009}
1010
1011static void __init samsung_gpiolib_add_4bit2_chips(struct samsung_gpio_chip *chip,
1012 int nr_chips)
1013{
1014 for (; nr_chips > 0; nr_chips--, chip++) {
1015 chip->chip.direction_input = samsung_gpiolib_4bit2_input;
1016 chip->chip.direction_output = samsung_gpiolib_4bit2_output;
1017
1018 if (!chip->config)
1019 chip->config = &samsung_gpio_cfgs[2];
1020 if (!chip->pm)
1021 chip->pm = __gpio_pm(&samsung_gpio_pm_4bit);
1022
1023 samsung_gpiolib_add(chip);
1024 }
1025}
1026
1027static void __init s5p64x0_gpiolib_add_rbank(struct samsung_gpio_chip *chip,
1028 int nr_chips)
1029{
1030 for (; nr_chips > 0; nr_chips--, chip++) {
1031 chip->chip.direction_input = s5p64x0_gpiolib_rbank_input;
1032 chip->chip.direction_output = s5p64x0_gpiolib_rbank_output;
1033
1034 if (!chip->pm)
1035 chip->pm = __gpio_pm(&samsung_gpio_pm_4bit);
1036
1037 samsung_gpiolib_add(chip);
1038 }
1039}
1040
1041int samsung_gpiolib_to_irq(struct gpio_chip *chip, unsigned int offset)
1042{
1043 struct samsung_gpio_chip *samsung_chip = container_of(chip, struct samsung_gpio_chip, chip);
1044
1045 return samsung_chip->irq_base + offset;
1046}
1047
1048#ifdef CONFIG_PLAT_S3C24XX
1049static int s3c24xx_gpiolib_fbank_to_irq(struct gpio_chip *chip, unsigned offset)
1050{
1051 if (offset < 4)
1052 return IRQ_EINT0 + offset;
1053
1054 if (offset < 8)
1055 return IRQ_EINT4 + offset - 4;
1056
1057 return -EINVAL;
1058}
1059#endif
1060
1061#ifdef CONFIG_PLAT_S3C64XX
1062static int s3c64xx_gpiolib_mbank_to_irq(struct gpio_chip *chip, unsigned pin)
1063{
1064 return pin < 5 ? IRQ_EINT(23) + pin : -ENXIO;
1065}
1066
1067static int s3c64xx_gpiolib_lbank_to_irq(struct gpio_chip *chip, unsigned pin)
1068{
1069 return pin >= 8 ? IRQ_EINT(16) + pin - 8 : -ENXIO;
1070}
1071#endif
1072
1073struct samsung_gpio_chip s3c24xx_gpios[] = {
1074#ifdef CONFIG_PLAT_S3C24XX
1075 {
1076 .config = &s3c24xx_gpiocfg_banka,
1077 .chip = {
1078 .base = S3C2410_GPA(0),
1079 .owner = THIS_MODULE,
1080 .label = "GPIOA",
1081 .ngpio = 24,
1082 .direction_input = s3c24xx_gpiolib_banka_input,
1083 .direction_output = s3c24xx_gpiolib_banka_output,
1084 },
1085 }, {
1086 .chip = {
1087 .base = S3C2410_GPB(0),
1088 .owner = THIS_MODULE,
1089 .label = "GPIOB",
1090 .ngpio = 16,
1091 },
1092 }, {
1093 .chip = {
1094 .base = S3C2410_GPC(0),
1095 .owner = THIS_MODULE,
1096 .label = "GPIOC",
1097 .ngpio = 16,
1098 },
1099 }, {
1100 .chip = {
1101 .base = S3C2410_GPD(0),
1102 .owner = THIS_MODULE,
1103 .label = "GPIOD",
1104 .ngpio = 16,
1105 },
1106 }, {
1107 .chip = {
1108 .base = S3C2410_GPE(0),
1109 .label = "GPIOE",
1110 .owner = THIS_MODULE,
1111 .ngpio = 16,
1112 },
1113 }, {
1114 .chip = {
1115 .base = S3C2410_GPF(0),
1116 .owner = THIS_MODULE,
1117 .label = "GPIOF",
1118 .ngpio = 8,
1119 .to_irq = s3c24xx_gpiolib_fbank_to_irq,
1120 },
1121 }, {
1122 .irq_base = IRQ_EINT8,
1123 .chip = {
1124 .base = S3C2410_GPG(0),
1125 .owner = THIS_MODULE,
1126 .label = "GPIOG",
1127 .ngpio = 16,
1128 .to_irq = samsung_gpiolib_to_irq,
1129 },
1130 }, {
1131 .chip = {
1132 .base = S3C2410_GPH(0),
1133 .owner = THIS_MODULE,
1134 .label = "GPIOH",
1135 .ngpio = 11,
1136 },
1137 },
1138 /* GPIOS for the S3C2443 and later devices. */
1139 {
1140 .base = S3C2440_GPJCON,
1141 .chip = {
1142 .base = S3C2410_GPJ(0),
1143 .owner = THIS_MODULE,
1144 .label = "GPIOJ",
1145 .ngpio = 16,
1146 },
1147 }, {
1148 .base = S3C2443_GPKCON,
1149 .chip = {
1150 .base = S3C2410_GPK(0),
1151 .owner = THIS_MODULE,
1152 .label = "GPIOK",
1153 .ngpio = 16,
1154 },
1155 }, {
1156 .base = S3C2443_GPLCON,
1157 .chip = {
1158 .base = S3C2410_GPL(0),
1159 .owner = THIS_MODULE,
1160 .label = "GPIOL",
1161 .ngpio = 15,
1162 },
1163 }, {
1164 .base = S3C2443_GPMCON,
1165 .chip = {
1166 .base = S3C2410_GPM(0),
1167 .owner = THIS_MODULE,
1168 .label = "GPIOM",
1169 .ngpio = 2,
1170 },
1171 },
1172#endif
1173};
1174
1175/*
1176 * GPIO bank summary:
1177 *
1178 * Bank GPIOs Style SlpCon ExtInt Group
1179 * A 8 4Bit Yes 1
1180 * B 7 4Bit Yes 1
1181 * C 8 4Bit Yes 2
1182 * D 5 4Bit Yes 3
1183 * E 5 4Bit Yes None
1184 * F 16 2Bit Yes 4 [1]
1185 * G 7 4Bit Yes 5
1186 * H 10 4Bit[2] Yes 6
1187 * I 16 2Bit Yes None
1188 * J 12 2Bit Yes None
1189 * K 16 4Bit[2] No None
1190 * L 15 4Bit[2] No None
1191 * M 6 4Bit No IRQ_EINT
1192 * N 16 2Bit No IRQ_EINT
1193 * O 16 2Bit Yes 7
1194 * P 15 2Bit Yes 8
1195 * Q 9 2Bit Yes 9
1196 *
1197 * [1] BANKF pins 14,15 do not form part of the external interrupt sources
1198 * [2] BANK has two control registers, GPxCON0 and GPxCON1
1199 */
1200
1201static struct samsung_gpio_chip s3c64xx_gpios_4bit[] = {
1202#ifdef CONFIG_PLAT_S3C64XX
1203 {
1204 .chip = {
1205 .base = S3C64XX_GPA(0),
1206 .ngpio = S3C64XX_GPIO_A_NR,
1207 .label = "GPA",
1208 },
1209 }, {
1210 .chip = {
1211 .base = S3C64XX_GPB(0),
1212 .ngpio = S3C64XX_GPIO_B_NR,
1213 .label = "GPB",
1214 },
1215 }, {
1216 .chip = {
1217 .base = S3C64XX_GPC(0),
1218 .ngpio = S3C64XX_GPIO_C_NR,
1219 .label = "GPC",
1220 },
1221 }, {
1222 .chip = {
1223 .base = S3C64XX_GPD(0),
1224 .ngpio = S3C64XX_GPIO_D_NR,
1225 .label = "GPD",
1226 },
1227 }, {
1228 .config = &samsung_gpio_cfgs[0],
1229 .chip = {
1230 .base = S3C64XX_GPE(0),
1231 .ngpio = S3C64XX_GPIO_E_NR,
1232 .label = "GPE",
1233 },
1234 }, {
1235 .base = S3C64XX_GPG_BASE,
1236 .chip = {
1237 .base = S3C64XX_GPG(0),
1238 .ngpio = S3C64XX_GPIO_G_NR,
1239 .label = "GPG",
1240 },
1241 }, {
1242 .base = S3C64XX_GPM_BASE,
1243 .config = &samsung_gpio_cfgs[1],
1244 .chip = {
1245 .base = S3C64XX_GPM(0),
1246 .ngpio = S3C64XX_GPIO_M_NR,
1247 .label = "GPM",
1248 .to_irq = s3c64xx_gpiolib_mbank_to_irq,
1249 },
1250 },
1251#endif
1252};
1253
1254static struct samsung_gpio_chip s3c64xx_gpios_4bit2[] = {
1255#ifdef CONFIG_PLAT_S3C64XX
1256 {
1257 .base = S3C64XX_GPH_BASE + 0x4,
1258 .chip = {
1259 .base = S3C64XX_GPH(0),
1260 .ngpio = S3C64XX_GPIO_H_NR,
1261 .label = "GPH",
1262 },
1263 }, {
1264 .base = S3C64XX_GPK_BASE + 0x4,
1265 .config = &samsung_gpio_cfgs[0],
1266 .chip = {
1267 .base = S3C64XX_GPK(0),
1268 .ngpio = S3C64XX_GPIO_K_NR,
1269 .label = "GPK",
1270 },
1271 }, {
1272 .base = S3C64XX_GPL_BASE + 0x4,
1273 .config = &samsung_gpio_cfgs[1],
1274 .chip = {
1275 .base = S3C64XX_GPL(0),
1276 .ngpio = S3C64XX_GPIO_L_NR,
1277 .label = "GPL",
1278 .to_irq = s3c64xx_gpiolib_lbank_to_irq,
1279 },
1280 },
1281#endif
1282};
1283
1284static struct samsung_gpio_chip s3c64xx_gpios_2bit[] = {
1285#ifdef CONFIG_PLAT_S3C64XX
1286 {
1287 .base = S3C64XX_GPF_BASE,
1288 .config = &samsung_gpio_cfgs[6],
1289 .chip = {
1290 .base = S3C64XX_GPF(0),
1291 .ngpio = S3C64XX_GPIO_F_NR,
1292 .label = "GPF",
1293 },
1294 }, {
1295 .config = &samsung_gpio_cfgs[7],
1296 .chip = {
1297 .base = S3C64XX_GPI(0),
1298 .ngpio = S3C64XX_GPIO_I_NR,
1299 .label = "GPI",
1300 },
1301 }, {
1302 .config = &samsung_gpio_cfgs[7],
1303 .chip = {
1304 .base = S3C64XX_GPJ(0),
1305 .ngpio = S3C64XX_GPIO_J_NR,
1306 .label = "GPJ",
1307 },
1308 }, {
1309 .config = &samsung_gpio_cfgs[6],
1310 .chip = {
1311 .base = S3C64XX_GPO(0),
1312 .ngpio = S3C64XX_GPIO_O_NR,
1313 .label = "GPO",
1314 },
1315 }, {
1316 .config = &samsung_gpio_cfgs[6],
1317 .chip = {
1318 .base = S3C64XX_GPP(0),
1319 .ngpio = S3C64XX_GPIO_P_NR,
1320 .label = "GPP",
1321 },
1322 }, {
1323 .config = &samsung_gpio_cfgs[6],
1324 .chip = {
1325 .base = S3C64XX_GPQ(0),
1326 .ngpio = S3C64XX_GPIO_Q_NR,
1327 .label = "GPQ",
1328 },
1329 }, {
1330 .base = S3C64XX_GPN_BASE,
1331 .irq_base = IRQ_EINT(0),
1332 .config = &samsung_gpio_cfgs[5],
1333 .chip = {
1334 .base = S3C64XX_GPN(0),
1335 .ngpio = S3C64XX_GPIO_N_NR,
1336 .label = "GPN",
1337 .to_irq = samsung_gpiolib_to_irq,
1338 },
1339 },
1340#endif
1341};
1342
1343/*
1344 * S5P6440 GPIO bank summary:
1345 *
1346 * Bank GPIOs Style SlpCon ExtInt Group
1347 * A 6 4Bit Yes 1
1348 * B 7 4Bit Yes 1
1349 * C 8 4Bit Yes 2
1350 * F 2 2Bit Yes 4 [1]
1351 * G 7 4Bit Yes 5
1352 * H 10 4Bit[2] Yes 6
1353 * I 16 2Bit Yes None
1354 * J 12 2Bit Yes None
1355 * N 16 2Bit No IRQ_EINT
1356 * P 8 2Bit Yes 8
1357 * R 15 4Bit[2] Yes 8
1358 */
1359
1360static struct samsung_gpio_chip s5p6440_gpios_4bit[] = {
1361#ifdef CONFIG_CPU_S5P6440
1362 {
1363 .chip = {
1364 .base = S5P6440_GPA(0),
1365 .ngpio = S5P6440_GPIO_A_NR,
1366 .label = "GPA",
1367 },
1368 }, {
1369 .chip = {
1370 .base = S5P6440_GPB(0),
1371 .ngpio = S5P6440_GPIO_B_NR,
1372 .label = "GPB",
1373 },
1374 }, {
1375 .chip = {
1376 .base = S5P6440_GPC(0),
1377 .ngpio = S5P6440_GPIO_C_NR,
1378 .label = "GPC",
1379 },
1380 }, {
1381 .base = S5P64X0_GPG_BASE,
1382 .chip = {
1383 .base = S5P6440_GPG(0),
1384 .ngpio = S5P6440_GPIO_G_NR,
1385 .label = "GPG",
1386 },
1387 },
1388#endif
1389};
1390
1391static struct samsung_gpio_chip s5p6440_gpios_4bit2[] = {
1392#ifdef CONFIG_CPU_S5P6440
1393 {
1394 .base = S5P64X0_GPH_BASE + 0x4,
1395 .chip = {
1396 .base = S5P6440_GPH(0),
1397 .ngpio = S5P6440_GPIO_H_NR,
1398 .label = "GPH",
1399 },
1400 },
1401#endif
1402};
1403
1404static struct samsung_gpio_chip s5p6440_gpios_rbank[] = {
1405#ifdef CONFIG_CPU_S5P6440
1406 {
1407 .base = S5P64X0_GPR_BASE + 0x4,
1408 .config = &s5p64x0_gpio_cfg_rbank,
1409 .chip = {
1410 .base = S5P6440_GPR(0),
1411 .ngpio = S5P6440_GPIO_R_NR,
1412 .label = "GPR",
1413 },
1414 },
1415#endif
1416};
1417
1418static struct samsung_gpio_chip s5p6440_gpios_2bit[] = {
1419#ifdef CONFIG_CPU_S5P6440
1420 {
1421 .base = S5P64X0_GPF_BASE,
1422 .config = &samsung_gpio_cfgs[6],
1423 .chip = {
1424 .base = S5P6440_GPF(0),
1425 .ngpio = S5P6440_GPIO_F_NR,
1426 .label = "GPF",
1427 },
1428 }, {
1429 .base = S5P64X0_GPI_BASE,
1430 .config = &samsung_gpio_cfgs[4],
1431 .chip = {
1432 .base = S5P6440_GPI(0),
1433 .ngpio = S5P6440_GPIO_I_NR,
1434 .label = "GPI",
1435 },
1436 }, {
1437 .base = S5P64X0_GPJ_BASE,
1438 .config = &samsung_gpio_cfgs[4],
1439 .chip = {
1440 .base = S5P6440_GPJ(0),
1441 .ngpio = S5P6440_GPIO_J_NR,
1442 .label = "GPJ",
1443 },
1444 }, {
1445 .base = S5P64X0_GPN_BASE,
1446 .config = &samsung_gpio_cfgs[5],
1447 .chip = {
1448 .base = S5P6440_GPN(0),
1449 .ngpio = S5P6440_GPIO_N_NR,
1450 .label = "GPN",
1451 },
1452 }, {
1453 .base = S5P64X0_GPP_BASE,
1454 .config = &samsung_gpio_cfgs[6],
1455 .chip = {
1456 .base = S5P6440_GPP(0),
1457 .ngpio = S5P6440_GPIO_P_NR,
1458 .label = "GPP",
1459 },
1460 },
1461#endif
1462};
1463
1464/*
1465 * S5P6450 GPIO bank summary:
1466 *
1467 * Bank GPIOs Style SlpCon ExtInt Group
1468 * A 6 4Bit Yes 1
1469 * B 7 4Bit Yes 1
1470 * C 8 4Bit Yes 2
1471 * D 8 4Bit Yes None
1472 * F 2 2Bit Yes None
1473 * G 14 4Bit[2] Yes 5
1474 * H 10 4Bit[2] Yes 6
1475 * I 16 2Bit Yes None
1476 * J 12 2Bit Yes None
1477 * K 5 4Bit Yes None
1478 * N 16 2Bit No IRQ_EINT
1479 * P 11 2Bit Yes 8
1480 * Q 14 2Bit Yes None
1481 * R 15 4Bit[2] Yes None
1482 * S 8 2Bit Yes None
1483 *
1484 * [1] BANKF pins 14,15 do not form part of the external interrupt sources
1485 * [2] BANK has two control registers, GPxCON0 and GPxCON1
1486 */
1487
1488static struct samsung_gpio_chip s5p6450_gpios_4bit[] = {
1489#ifdef CONFIG_CPU_S5P6450
1490 {
1491 .chip = {
1492 .base = S5P6450_GPA(0),
1493 .ngpio = S5P6450_GPIO_A_NR,
1494 .label = "GPA",
1495 },
1496 }, {
1497 .chip = {
1498 .base = S5P6450_GPB(0),
1499 .ngpio = S5P6450_GPIO_B_NR,
1500 .label = "GPB",
1501 },
1502 }, {
1503 .chip = {
1504 .base = S5P6450_GPC(0),
1505 .ngpio = S5P6450_GPIO_C_NR,
1506 .label = "GPC",
1507 },
1508 }, {
1509 .chip = {
1510 .base = S5P6450_GPD(0),
1511 .ngpio = S5P6450_GPIO_D_NR,
1512 .label = "GPD",
1513 },
1514 }, {
1515 .base = S5P6450_GPK_BASE,
1516 .chip = {
1517 .base = S5P6450_GPK(0),
1518 .ngpio = S5P6450_GPIO_K_NR,
1519 .label = "GPK",
1520 },
1521 },
1522#endif
1523};
1524
1525static struct samsung_gpio_chip s5p6450_gpios_4bit2[] = {
1526#ifdef CONFIG_CPU_S5P6450
1527 {
1528 .base = S5P64X0_GPG_BASE + 0x4,
1529 .chip = {
1530 .base = S5P6450_GPG(0),
1531 .ngpio = S5P6450_GPIO_G_NR,
1532 .label = "GPG",
1533 },
1534 }, {
1535 .base = S5P64X0_GPH_BASE + 0x4,
1536 .chip = {
1537 .base = S5P6450_GPH(0),
1538 .ngpio = S5P6450_GPIO_H_NR,
1539 .label = "GPH",
1540 },
1541 },
1542#endif
1543};
1544
1545static struct samsung_gpio_chip s5p6450_gpios_rbank[] = {
1546#ifdef CONFIG_CPU_S5P6450
1547 {
1548 .base = S5P64X0_GPR_BASE + 0x4,
1549 .config = &s5p64x0_gpio_cfg_rbank,
1550 .chip = {
1551 .base = S5P6450_GPR(0),
1552 .ngpio = S5P6450_GPIO_R_NR,
1553 .label = "GPR",
1554 },
1555 },
1556#endif
1557};
1558
1559static struct samsung_gpio_chip s5p6450_gpios_2bit[] = {
1560#ifdef CONFIG_CPU_S5P6450
1561 {
1562 .base = S5P64X0_GPF_BASE,
1563 .config = &samsung_gpio_cfgs[6],
1564 .chip = {
1565 .base = S5P6450_GPF(0),
1566 .ngpio = S5P6450_GPIO_F_NR,
1567 .label = "GPF",
1568 },
1569 }, {
1570 .base = S5P64X0_GPI_BASE,
1571 .config = &samsung_gpio_cfgs[4],
1572 .chip = {
1573 .base = S5P6450_GPI(0),
1574 .ngpio = S5P6450_GPIO_I_NR,
1575 .label = "GPI",
1576 },
1577 }, {
1578 .base = S5P64X0_GPJ_BASE,
1579 .config = &samsung_gpio_cfgs[4],
1580 .chip = {
1581 .base = S5P6450_GPJ(0),
1582 .ngpio = S5P6450_GPIO_J_NR,
1583 .label = "GPJ",
1584 },
1585 }, {
1586 .base = S5P64X0_GPN_BASE,
1587 .config = &samsung_gpio_cfgs[5],
1588 .chip = {
1589 .base = S5P6450_GPN(0),
1590 .ngpio = S5P6450_GPIO_N_NR,
1591 .label = "GPN",
1592 },
1593 }, {
1594 .base = S5P64X0_GPP_BASE,
1595 .config = &samsung_gpio_cfgs[6],
1596 .chip = {
1597 .base = S5P6450_GPP(0),
1598 .ngpio = S5P6450_GPIO_P_NR,
1599 .label = "GPP",
1600 },
1601 }, {
1602 .base = S5P6450_GPQ_BASE,
1603 .config = &samsung_gpio_cfgs[5],
1604 .chip = {
1605 .base = S5P6450_GPQ(0),
1606 .ngpio = S5P6450_GPIO_Q_NR,
1607 .label = "GPQ",
1608 },
1609 }, {
1610 .base = S5P6450_GPS_BASE,
1611 .config = &samsung_gpio_cfgs[6],
1612 .chip = {
1613 .base = S5P6450_GPS(0),
1614 .ngpio = S5P6450_GPIO_S_NR,
1615 .label = "GPS",
1616 },
1617 },
1618#endif
1619};
1620
1621/*
1622 * S5PC100 GPIO bank summary:
1623 *
1624 * Bank GPIOs Style INT Type
1625 * A0 8 4Bit GPIO_INT0
1626 * A1 5 4Bit GPIO_INT1
1627 * B 8 4Bit GPIO_INT2
1628 * C 5 4Bit GPIO_INT3
1629 * D 7 4Bit GPIO_INT4
1630 * E0 8 4Bit GPIO_INT5
1631 * E1 6 4Bit GPIO_INT6
1632 * F0 8 4Bit GPIO_INT7
1633 * F1 8 4Bit GPIO_INT8
1634 * F2 8 4Bit GPIO_INT9
1635 * F3 4 4Bit GPIO_INT10
1636 * G0 8 4Bit GPIO_INT11
1637 * G1 3 4Bit GPIO_INT12
1638 * G2 7 4Bit GPIO_INT13
1639 * G3 7 4Bit GPIO_INT14
1640 * H0 8 4Bit WKUP_INT
1641 * H1 8 4Bit WKUP_INT
1642 * H2 8 4Bit WKUP_INT
1643 * H3 8 4Bit WKUP_INT
1644 * I 8 4Bit GPIO_INT15
1645 * J0 8 4Bit GPIO_INT16
1646 * J1 5 4Bit GPIO_INT17
1647 * J2 8 4Bit GPIO_INT18
1648 * J3 8 4Bit GPIO_INT19
1649 * J4 4 4Bit GPIO_INT20
1650 * K0 8 4Bit None
1651 * K1 6 4Bit None
1652 * K2 8 4Bit None
1653 * K3 8 4Bit None
1654 * L0 8 4Bit None
1655 * L1 8 4Bit None
1656 * L2 8 4Bit None
1657 * L3 8 4Bit None
1658 */
1659
1660static struct samsung_gpio_chip s5pc100_gpios_4bit[] = {
1661#ifdef CONFIG_CPU_S5PC100
1662 {
1663 .chip = {
1664 .base = S5PC100_GPA0(0),
1665 .ngpio = S5PC100_GPIO_A0_NR,
1666 .label = "GPA0",
1667 },
1668 }, {
1669 .chip = {
1670 .base = S5PC100_GPA1(0),
1671 .ngpio = S5PC100_GPIO_A1_NR,
1672 .label = "GPA1",
1673 },
1674 }, {
1675 .chip = {
1676 .base = S5PC100_GPB(0),
1677 .ngpio = S5PC100_GPIO_B_NR,
1678 .label = "GPB",
1679 },
1680 }, {
1681 .chip = {
1682 .base = S5PC100_GPC(0),
1683 .ngpio = S5PC100_GPIO_C_NR,
1684 .label = "GPC",
1685 },
1686 }, {
1687 .chip = {
1688 .base = S5PC100_GPD(0),
1689 .ngpio = S5PC100_GPIO_D_NR,
1690 .label = "GPD",
1691 },
1692 }, {
1693 .chip = {
1694 .base = S5PC100_GPE0(0),
1695 .ngpio = S5PC100_GPIO_E0_NR,
1696 .label = "GPE0",
1697 },
1698 }, {
1699 .chip = {
1700 .base = S5PC100_GPE1(0),
1701 .ngpio = S5PC100_GPIO_E1_NR,
1702 .label = "GPE1",
1703 },
1704 }, {
1705 .chip = {
1706 .base = S5PC100_GPF0(0),
1707 .ngpio = S5PC100_GPIO_F0_NR,
1708 .label = "GPF0",
1709 },
1710 }, {
1711 .chip = {
1712 .base = S5PC100_GPF1(0),
1713 .ngpio = S5PC100_GPIO_F1_NR,
1714 .label = "GPF1",
1715 },
1716 }, {
1717 .chip = {
1718 .base = S5PC100_GPF2(0),
1719 .ngpio = S5PC100_GPIO_F2_NR,
1720 .label = "GPF2",
1721 },
1722 }, {
1723 .chip = {
1724 .base = S5PC100_GPF3(0),
1725 .ngpio = S5PC100_GPIO_F3_NR,
1726 .label = "GPF3",
1727 },
1728 }, {
1729 .chip = {
1730 .base = S5PC100_GPG0(0),
1731 .ngpio = S5PC100_GPIO_G0_NR,
1732 .label = "GPG0",
1733 },
1734 }, {
1735 .chip = {
1736 .base = S5PC100_GPG1(0),
1737 .ngpio = S5PC100_GPIO_G1_NR,
1738 .label = "GPG1",
1739 },
1740 }, {
1741 .chip = {
1742 .base = S5PC100_GPG2(0),
1743 .ngpio = S5PC100_GPIO_G2_NR,
1744 .label = "GPG2",
1745 },
1746 }, {
1747 .chip = {
1748 .base = S5PC100_GPG3(0),
1749 .ngpio = S5PC100_GPIO_G3_NR,
1750 .label = "GPG3",
1751 },
1752 }, {
1753 .chip = {
1754 .base = S5PC100_GPI(0),
1755 .ngpio = S5PC100_GPIO_I_NR,
1756 .label = "GPI",
1757 },
1758 }, {
1759 .chip = {
1760 .base = S5PC100_GPJ0(0),
1761 .ngpio = S5PC100_GPIO_J0_NR,
1762 .label = "GPJ0",
1763 },
1764 }, {
1765 .chip = {
1766 .base = S5PC100_GPJ1(0),
1767 .ngpio = S5PC100_GPIO_J1_NR,
1768 .label = "GPJ1",
1769 },
1770 }, {
1771 .chip = {
1772 .base = S5PC100_GPJ2(0),
1773 .ngpio = S5PC100_GPIO_J2_NR,
1774 .label = "GPJ2",
1775 },
1776 }, {
1777 .chip = {
1778 .base = S5PC100_GPJ3(0),
1779 .ngpio = S5PC100_GPIO_J3_NR,
1780 .label = "GPJ3",
1781 },
1782 }, {
1783 .chip = {
1784 .base = S5PC100_GPJ4(0),
1785 .ngpio = S5PC100_GPIO_J4_NR,
1786 .label = "GPJ4",
1787 },
1788 }, {
1789 .chip = {
1790 .base = S5PC100_GPK0(0),
1791 .ngpio = S5PC100_GPIO_K0_NR,
1792 .label = "GPK0",
1793 },
1794 }, {
1795 .chip = {
1796 .base = S5PC100_GPK1(0),
1797 .ngpio = S5PC100_GPIO_K1_NR,
1798 .label = "GPK1",
1799 },
1800 }, {
1801 .chip = {
1802 .base = S5PC100_GPK2(0),
1803 .ngpio = S5PC100_GPIO_K2_NR,
1804 .label = "GPK2",
1805 },
1806 }, {
1807 .chip = {
1808 .base = S5PC100_GPK3(0),
1809 .ngpio = S5PC100_GPIO_K3_NR,
1810 .label = "GPK3",
1811 },
1812 }, {
1813 .chip = {
1814 .base = S5PC100_GPL0(0),
1815 .ngpio = S5PC100_GPIO_L0_NR,
1816 .label = "GPL0",
1817 },
1818 }, {
1819 .chip = {
1820 .base = S5PC100_GPL1(0),
1821 .ngpio = S5PC100_GPIO_L1_NR,
1822 .label = "GPL1",
1823 },
1824 }, {
1825 .chip = {
1826 .base = S5PC100_GPL2(0),
1827 .ngpio = S5PC100_GPIO_L2_NR,
1828 .label = "GPL2",
1829 },
1830 }, {
1831 .chip = {
1832 .base = S5PC100_GPL3(0),
1833 .ngpio = S5PC100_GPIO_L3_NR,
1834 .label = "GPL3",
1835 },
1836 }, {
1837 .chip = {
1838 .base = S5PC100_GPL4(0),
1839 .ngpio = S5PC100_GPIO_L4_NR,
1840 .label = "GPL4",
1841 },
1842 }, {
1843 .base = (S5P_VA_GPIO + 0xC00),
1844 .irq_base = IRQ_EINT(0),
1845 .chip = {
1846 .base = S5PC100_GPH0(0),
1847 .ngpio = S5PC100_GPIO_H0_NR,
1848 .label = "GPH0",
1849 .to_irq = samsung_gpiolib_to_irq,
1850 },
1851 }, {
1852 .base = (S5P_VA_GPIO + 0xC20),
1853 .irq_base = IRQ_EINT(8),
1854 .chip = {
1855 .base = S5PC100_GPH1(0),
1856 .ngpio = S5PC100_GPIO_H1_NR,
1857 .label = "GPH1",
1858 .to_irq = samsung_gpiolib_to_irq,
1859 },
1860 }, {
1861 .base = (S5P_VA_GPIO + 0xC40),
1862 .irq_base = IRQ_EINT(16),
1863 .chip = {
1864 .base = S5PC100_GPH2(0),
1865 .ngpio = S5PC100_GPIO_H2_NR,
1866 .label = "GPH2",
1867 .to_irq = samsung_gpiolib_to_irq,
1868 },
1869 }, {
1870 .base = (S5P_VA_GPIO + 0xC60),
1871 .irq_base = IRQ_EINT(24),
1872 .chip = {
1873 .base = S5PC100_GPH3(0),
1874 .ngpio = S5PC100_GPIO_H3_NR,
1875 .label = "GPH3",
1876 .to_irq = samsung_gpiolib_to_irq,
1877 },
1878 },
1879#endif
1880};
1881
1882/*
1883 * Followings are the gpio banks in S5PV210/S5PC110
1884 *
1885 * The 'config' member when left to NULL, is initialized to the default
1886 * structure samsung_gpio_cfgs[3] in the init function below.
1887 *
1888 * The 'base' member is also initialized in the init function below.
1889 * Note: The initialization of 'base' member of samsung_gpio_chip structure
1890 * uses the above macro and depends on the banks being listed in order here.
1891 */
1892
1893static struct samsung_gpio_chip s5pv210_gpios_4bit[] = {
1894#ifdef CONFIG_CPU_S5PV210
1895 {
1896 .chip = {
1897 .base = S5PV210_GPA0(0),
1898 .ngpio = S5PV210_GPIO_A0_NR,
1899 .label = "GPA0",
1900 },
1901 }, {
1902 .chip = {
1903 .base = S5PV210_GPA1(0),
1904 .ngpio = S5PV210_GPIO_A1_NR,
1905 .label = "GPA1",
1906 },
1907 }, {
1908 .chip = {
1909 .base = S5PV210_GPB(0),
1910 .ngpio = S5PV210_GPIO_B_NR,
1911 .label = "GPB",
1912 },
1913 }, {
1914 .chip = {
1915 .base = S5PV210_GPC0(0),
1916 .ngpio = S5PV210_GPIO_C0_NR,
1917 .label = "GPC0",
1918 },
1919 }, {
1920 .chip = {
1921 .base = S5PV210_GPC1(0),
1922 .ngpio = S5PV210_GPIO_C1_NR,
1923 .label = "GPC1",
1924 },
1925 }, {
1926 .chip = {
1927 .base = S5PV210_GPD0(0),
1928 .ngpio = S5PV210_GPIO_D0_NR,
1929 .label = "GPD0",
1930 },
1931 }, {
1932 .chip = {
1933 .base = S5PV210_GPD1(0),
1934 .ngpio = S5PV210_GPIO_D1_NR,
1935 .label = "GPD1",
1936 },
1937 }, {
1938 .chip = {
1939 .base = S5PV210_GPE0(0),
1940 .ngpio = S5PV210_GPIO_E0_NR,
1941 .label = "GPE0",
1942 },
1943 }, {
1944 .chip = {
1945 .base = S5PV210_GPE1(0),
1946 .ngpio = S5PV210_GPIO_E1_NR,
1947 .label = "GPE1",
1948 },
1949 }, {
1950 .chip = {
1951 .base = S5PV210_GPF0(0),
1952 .ngpio = S5PV210_GPIO_F0_NR,
1953 .label = "GPF0",
1954 },
1955 }, {
1956 .chip = {
1957 .base = S5PV210_GPF1(0),
1958 .ngpio = S5PV210_GPIO_F1_NR,
1959 .label = "GPF1",
1960 },
1961 }, {
1962 .chip = {
1963 .base = S5PV210_GPF2(0),
1964 .ngpio = S5PV210_GPIO_F2_NR,
1965 .label = "GPF2",
1966 },
1967 }, {
1968 .chip = {
1969 .base = S5PV210_GPF3(0),
1970 .ngpio = S5PV210_GPIO_F3_NR,
1971 .label = "GPF3",
1972 },
1973 }, {
1974 .chip = {
1975 .base = S5PV210_GPG0(0),
1976 .ngpio = S5PV210_GPIO_G0_NR,
1977 .label = "GPG0",
1978 },
1979 }, {
1980 .chip = {
1981 .base = S5PV210_GPG1(0),
1982 .ngpio = S5PV210_GPIO_G1_NR,
1983 .label = "GPG1",
1984 },
1985 }, {
1986 .chip = {
1987 .base = S5PV210_GPG2(0),
1988 .ngpio = S5PV210_GPIO_G2_NR,
1989 .label = "GPG2",
1990 },
1991 }, {
1992 .chip = {
1993 .base = S5PV210_GPG3(0),
1994 .ngpio = S5PV210_GPIO_G3_NR,
1995 .label = "GPG3",
1996 },
1997 }, {
1998 .chip = {
1999 .base = S5PV210_GPI(0),
2000 .ngpio = S5PV210_GPIO_I_NR,
2001 .label = "GPI",
2002 },
2003 }, {
2004 .chip = {
2005 .base = S5PV210_GPJ0(0),
2006 .ngpio = S5PV210_GPIO_J0_NR,
2007 .label = "GPJ0",
2008 },
2009 }, {
2010 .chip = {
2011 .base = S5PV210_GPJ1(0),
2012 .ngpio = S5PV210_GPIO_J1_NR,
2013 .label = "GPJ1",
2014 },
2015 }, {
2016 .chip = {
2017 .base = S5PV210_GPJ2(0),
2018 .ngpio = S5PV210_GPIO_J2_NR,
2019 .label = "GPJ2",
2020 },
2021 }, {
2022 .chip = {
2023 .base = S5PV210_GPJ3(0),
2024 .ngpio = S5PV210_GPIO_J3_NR,
2025 .label = "GPJ3",
2026 },
2027 }, {
2028 .chip = {
2029 .base = S5PV210_GPJ4(0),
2030 .ngpio = S5PV210_GPIO_J4_NR,
2031 .label = "GPJ4",
2032 },
2033 }, {
2034 .chip = {
2035 .base = S5PV210_MP01(0),
2036 .ngpio = S5PV210_GPIO_MP01_NR,
2037 .label = "MP01",
2038 },
2039 }, {
2040 .chip = {
2041 .base = S5PV210_MP02(0),
2042 .ngpio = S5PV210_GPIO_MP02_NR,
2043 .label = "MP02",
2044 },
2045 }, {
2046 .chip = {
2047 .base = S5PV210_MP03(0),
2048 .ngpio = S5PV210_GPIO_MP03_NR,
2049 .label = "MP03",
2050 },
2051 }, {
2052 .chip = {
2053 .base = S5PV210_MP04(0),
2054 .ngpio = S5PV210_GPIO_MP04_NR,
2055 .label = "MP04",
2056 },
2057 }, {
2058 .chip = {
2059 .base = S5PV210_MP05(0),
2060 .ngpio = S5PV210_GPIO_MP05_NR,
2061 .label = "MP05",
2062 },
2063 }, {
2064 .base = (S5P_VA_GPIO + 0xC00),
2065 .irq_base = IRQ_EINT(0),
2066 .chip = {
2067 .base = S5PV210_GPH0(0),
2068 .ngpio = S5PV210_GPIO_H0_NR,
2069 .label = "GPH0",
2070 .to_irq = samsung_gpiolib_to_irq,
2071 },
2072 }, {
2073 .base = (S5P_VA_GPIO + 0xC20),
2074 .irq_base = IRQ_EINT(8),
2075 .chip = {
2076 .base = S5PV210_GPH1(0),
2077 .ngpio = S5PV210_GPIO_H1_NR,
2078 .label = "GPH1",
2079 .to_irq = samsung_gpiolib_to_irq,
2080 },
2081 }, {
2082 .base = (S5P_VA_GPIO + 0xC40),
2083 .irq_base = IRQ_EINT(16),
2084 .chip = {
2085 .base = S5PV210_GPH2(0),
2086 .ngpio = S5PV210_GPIO_H2_NR,
2087 .label = "GPH2",
2088 .to_irq = samsung_gpiolib_to_irq,
2089 },
2090 }, {
2091 .base = (S5P_VA_GPIO + 0xC60),
2092 .irq_base = IRQ_EINT(24),
2093 .chip = {
2094 .base = S5PV210_GPH3(0),
2095 .ngpio = S5PV210_GPIO_H3_NR,
2096 .label = "GPH3",
2097 .to_irq = samsung_gpiolib_to_irq,
2098 },
2099 },
2100#endif
2101};
2102
2103/*
2104 * Followings are the gpio banks in EXYNOS4210
2105 *
2106 * The 'config' member when left to NULL, is initialized to the default
2107 * structure samsung_gpio_cfgs[3] in the init function below.
2108 *
2109 * The 'base' member is also initialized in the init function below.
2110 * Note: The initialization of 'base' member of samsung_gpio_chip structure
2111 * uses the above macro and depends on the banks being listed in order here.
2112 */
2113
2114static struct samsung_gpio_chip exynos4_gpios_1[] = {
2115#ifdef CONFIG_ARCH_EXYNOS4
2116 {
2117 .chip = {
2118 .base = EXYNOS4_GPA0(0),
2119 .ngpio = EXYNOS4_GPIO_A0_NR,
2120 .label = "GPA0",
2121 },
2122 }, {
2123 .chip = {
2124 .base = EXYNOS4_GPA1(0),
2125 .ngpio = EXYNOS4_GPIO_A1_NR,
2126 .label = "GPA1",
2127 },
2128 }, {
2129 .chip = {
2130 .base = EXYNOS4_GPB(0),
2131 .ngpio = EXYNOS4_GPIO_B_NR,
2132 .label = "GPB",
2133 },
2134 }, {
2135 .chip = {
2136 .base = EXYNOS4_GPC0(0),
2137 .ngpio = EXYNOS4_GPIO_C0_NR,
2138 .label = "GPC0",
2139 },
2140 }, {
2141 .chip = {
2142 .base = EXYNOS4_GPC1(0),
2143 .ngpio = EXYNOS4_GPIO_C1_NR,
2144 .label = "GPC1",
2145 },
2146 }, {
2147 .chip = {
2148 .base = EXYNOS4_GPD0(0),
2149 .ngpio = EXYNOS4_GPIO_D0_NR,
2150 .label = "GPD0",
2151 },
2152 }, {
2153 .chip = {
2154 .base = EXYNOS4_GPD1(0),
2155 .ngpio = EXYNOS4_GPIO_D1_NR,
2156 .label = "GPD1",
2157 },
2158 }, {
2159 .chip = {
2160 .base = EXYNOS4_GPE0(0),
2161 .ngpio = EXYNOS4_GPIO_E0_NR,
2162 .label = "GPE0",
2163 },
2164 }, {
2165 .chip = {
2166 .base = EXYNOS4_GPE1(0),
2167 .ngpio = EXYNOS4_GPIO_E1_NR,
2168 .label = "GPE1",
2169 },
2170 }, {
2171 .chip = {
2172 .base = EXYNOS4_GPE2(0),
2173 .ngpio = EXYNOS4_GPIO_E2_NR,
2174 .label = "GPE2",
2175 },
2176 }, {
2177 .chip = {
2178 .base = EXYNOS4_GPE3(0),
2179 .ngpio = EXYNOS4_GPIO_E3_NR,
2180 .label = "GPE3",
2181 },
2182 }, {
2183 .chip = {
2184 .base = EXYNOS4_GPE4(0),
2185 .ngpio = EXYNOS4_GPIO_E4_NR,
2186 .label = "GPE4",
2187 },
2188 }, {
2189 .chip = {
2190 .base = EXYNOS4_GPF0(0),
2191 .ngpio = EXYNOS4_GPIO_F0_NR,
2192 .label = "GPF0",
2193 },
2194 }, {
2195 .chip = {
2196 .base = EXYNOS4_GPF1(0),
2197 .ngpio = EXYNOS4_GPIO_F1_NR,
2198 .label = "GPF1",
2199 },
2200 }, {
2201 .chip = {
2202 .base = EXYNOS4_GPF2(0),
2203 .ngpio = EXYNOS4_GPIO_F2_NR,
2204 .label = "GPF2",
2205 },
2206 }, {
2207 .chip = {
2208 .base = EXYNOS4_GPF3(0),
2209 .ngpio = EXYNOS4_GPIO_F3_NR,
2210 .label = "GPF3",
2211 },
2212 },
2213#endif
2214};
2215
2216static struct samsung_gpio_chip exynos4_gpios_2[] = {
2217#ifdef CONFIG_ARCH_EXYNOS4
2218 {
2219 .chip = {
2220 .base = EXYNOS4_GPJ0(0),
2221 .ngpio = EXYNOS4_GPIO_J0_NR,
2222 .label = "GPJ0",
2223 },
2224 }, {
2225 .chip = {
2226 .base = EXYNOS4_GPJ1(0),
2227 .ngpio = EXYNOS4_GPIO_J1_NR,
2228 .label = "GPJ1",
2229 },
2230 }, {
2231 .chip = {
2232 .base = EXYNOS4_GPK0(0),
2233 .ngpio = EXYNOS4_GPIO_K0_NR,
2234 .label = "GPK0",
2235 },
2236 }, {
2237 .chip = {
2238 .base = EXYNOS4_GPK1(0),
2239 .ngpio = EXYNOS4_GPIO_K1_NR,
2240 .label = "GPK1",
2241 },
2242 }, {
2243 .chip = {
2244 .base = EXYNOS4_GPK2(0),
2245 .ngpio = EXYNOS4_GPIO_K2_NR,
2246 .label = "GPK2",
2247 },
2248 }, {
2249 .chip = {
2250 .base = EXYNOS4_GPK3(0),
2251 .ngpio = EXYNOS4_GPIO_K3_NR,
2252 .label = "GPK3",
2253 },
2254 }, {
2255 .chip = {
2256 .base = EXYNOS4_GPL0(0),
2257 .ngpio = EXYNOS4_GPIO_L0_NR,
2258 .label = "GPL0",
2259 },
2260 }, {
2261 .chip = {
2262 .base = EXYNOS4_GPL1(0),
2263 .ngpio = EXYNOS4_GPIO_L1_NR,
2264 .label = "GPL1",
2265 },
2266 }, {
2267 .chip = {
2268 .base = EXYNOS4_GPL2(0),
2269 .ngpio = EXYNOS4_GPIO_L2_NR,
2270 .label = "GPL2",
2271 },
2272 }, {
2273 .config = &samsung_gpio_cfgs[8],
2274 .chip = {
2275 .base = EXYNOS4_GPY0(0),
2276 .ngpio = EXYNOS4_GPIO_Y0_NR,
2277 .label = "GPY0",
2278 },
2279 }, {
2280 .config = &samsung_gpio_cfgs[8],
2281 .chip = {
2282 .base = EXYNOS4_GPY1(0),
2283 .ngpio = EXYNOS4_GPIO_Y1_NR,
2284 .label = "GPY1",
2285 },
2286 }, {
2287 .config = &samsung_gpio_cfgs[8],
2288 .chip = {
2289 .base = EXYNOS4_GPY2(0),
2290 .ngpio = EXYNOS4_GPIO_Y2_NR,
2291 .label = "GPY2",
2292 },
2293 }, {
2294 .config = &samsung_gpio_cfgs[8],
2295 .chip = {
2296 .base = EXYNOS4_GPY3(0),
2297 .ngpio = EXYNOS4_GPIO_Y3_NR,
2298 .label = "GPY3",
2299 },
2300 }, {
2301 .config = &samsung_gpio_cfgs[8],
2302 .chip = {
2303 .base = EXYNOS4_GPY4(0),
2304 .ngpio = EXYNOS4_GPIO_Y4_NR,
2305 .label = "GPY4",
2306 },
2307 }, {
2308 .config = &samsung_gpio_cfgs[8],
2309 .chip = {
2310 .base = EXYNOS4_GPY5(0),
2311 .ngpio = EXYNOS4_GPIO_Y5_NR,
2312 .label = "GPY5",
2313 },
2314 }, {
2315 .config = &samsung_gpio_cfgs[8],
2316 .chip = {
2317 .base = EXYNOS4_GPY6(0),
2318 .ngpio = EXYNOS4_GPIO_Y6_NR,
2319 .label = "GPY6",
2320 },
2321 }, {
2322 .base = (S5P_VA_GPIO2 + 0xC00),
2323 .config = &samsung_gpio_cfgs[9],
2324 .irq_base = IRQ_EINT(0),
2325 .chip = {
2326 .base = EXYNOS4_GPX0(0),
2327 .ngpio = EXYNOS4_GPIO_X0_NR,
2328 .label = "GPX0",
2329 .to_irq = samsung_gpiolib_to_irq,
2330 },
2331 }, {
2332 .base = (S5P_VA_GPIO2 + 0xC20),
2333 .config = &samsung_gpio_cfgs[9],
2334 .irq_base = IRQ_EINT(8),
2335 .chip = {
2336 .base = EXYNOS4_GPX1(0),
2337 .ngpio = EXYNOS4_GPIO_X1_NR,
2338 .label = "GPX1",
2339 .to_irq = samsung_gpiolib_to_irq,
2340 },
2341 }, {
2342 .base = (S5P_VA_GPIO2 + 0xC40),
2343 .config = &samsung_gpio_cfgs[9],
2344 .irq_base = IRQ_EINT(16),
2345 .chip = {
2346 .base = EXYNOS4_GPX2(0),
2347 .ngpio = EXYNOS4_GPIO_X2_NR,
2348 .label = "GPX2",
2349 .to_irq = samsung_gpiolib_to_irq,
2350 },
2351 }, {
2352 .base = (S5P_VA_GPIO2 + 0xC60),
2353 .config = &samsung_gpio_cfgs[9],
2354 .irq_base = IRQ_EINT(24),
2355 .chip = {
2356 .base = EXYNOS4_GPX3(0),
2357 .ngpio = EXYNOS4_GPIO_X3_NR,
2358 .label = "GPX3",
2359 .to_irq = samsung_gpiolib_to_irq,
2360 },
2361 },
2362#endif
2363};
2364
2365static struct samsung_gpio_chip exynos4_gpios_3[] = {
2366#ifdef CONFIG_ARCH_EXYNOS4
2367 {
2368 .chip = {
2369 .base = EXYNOS4_GPZ(0),
2370 .ngpio = EXYNOS4_GPIO_Z_NR,
2371 .label = "GPZ",
2372 },
2373 },
2374#endif
2375};
2376
2377/* TODO: cleanup soc_is_* */
2378static __init int samsung_gpiolib_init(void)
2379{
2380 struct samsung_gpio_chip *chip;
2381 int i, nr_chips;
2382 int group = 0;
2383
2384 samsung_gpiolib_set_cfg(samsung_gpio_cfgs, ARRAY_SIZE(samsung_gpio_cfgs));
2385
2386 if (soc_is_s3c24xx()) {
2387 s3c24xx_gpiolib_add_chips(s3c24xx_gpios,
2388 ARRAY_SIZE(s3c24xx_gpios), S3C24XX_VA_GPIO);
2389 } else if (soc_is_s3c64xx()) {
2390 samsung_gpiolib_add_2bit_chips(s3c64xx_gpios_2bit,
2391 ARRAY_SIZE(s3c64xx_gpios_2bit),
2392 S3C64XX_VA_GPIO + 0xE0, 0x20);
2393 samsung_gpiolib_add_4bit_chips(s3c64xx_gpios_4bit,
2394 ARRAY_SIZE(s3c64xx_gpios_4bit),
2395 S3C64XX_VA_GPIO);
2396 samsung_gpiolib_add_4bit2_chips(s3c64xx_gpios_4bit2,
2397 ARRAY_SIZE(s3c64xx_gpios_4bit2));
2398 } else if (soc_is_s5p6440()) {
2399 samsung_gpiolib_add_2bit_chips(s5p6440_gpios_2bit,
2400 ARRAY_SIZE(s5p6440_gpios_2bit), NULL, 0x0);
2401 samsung_gpiolib_add_4bit_chips(s5p6440_gpios_4bit,
2402 ARRAY_SIZE(s5p6440_gpios_4bit), S5P_VA_GPIO);
2403 samsung_gpiolib_add_4bit2_chips(s5p6440_gpios_4bit2,
2404 ARRAY_SIZE(s5p6440_gpios_4bit2));
2405 s5p64x0_gpiolib_add_rbank(s5p6440_gpios_rbank,
2406 ARRAY_SIZE(s5p6440_gpios_rbank));
2407 } else if (soc_is_s5p6450()) {
2408 samsung_gpiolib_add_2bit_chips(s5p6450_gpios_2bit,
2409 ARRAY_SIZE(s5p6450_gpios_2bit), NULL, 0x0);
2410 samsung_gpiolib_add_4bit_chips(s5p6450_gpios_4bit,
2411 ARRAY_SIZE(s5p6450_gpios_4bit), S5P_VA_GPIO);
2412 samsung_gpiolib_add_4bit2_chips(s5p6450_gpios_4bit2,
2413 ARRAY_SIZE(s5p6450_gpios_4bit2));
2414 s5p64x0_gpiolib_add_rbank(s5p6450_gpios_rbank,
2415 ARRAY_SIZE(s5p6450_gpios_rbank));
2416 } else if (soc_is_s5pc100()) {
2417 group = 0;
2418 chip = s5pc100_gpios_4bit;
2419 nr_chips = ARRAY_SIZE(s5pc100_gpios_4bit);
2420
2421 for (i = 0; i < nr_chips; i++, chip++) {
2422 if (!chip->config) {
2423 chip->config = &samsung_gpio_cfgs[3];
2424 chip->group = group++;
2425 }
2426 }
2427 samsung_gpiolib_add_4bit_chips(s5pc100_gpios_4bit, nr_chips, S5P_VA_GPIO);
2428#if defined(CONFIG_CPU_S5PC100) && defined(CONFIG_S5P_GPIO_INT)
2429 s5p_register_gpioint_bank(IRQ_GPIOINT, 0, S5P_GPIOINT_GROUP_MAXNR);
2430#endif
2431 } else if (soc_is_s5pv210()) {
2432 group = 0;
2433 chip = s5pv210_gpios_4bit;
2434 nr_chips = ARRAY_SIZE(s5pv210_gpios_4bit);
2435
2436 for (i = 0; i < nr_chips; i++, chip++) {
2437 if (!chip->config) {
2438 chip->config = &samsung_gpio_cfgs[3];
2439 chip->group = group++;
2440 }
2441 }
2442 samsung_gpiolib_add_4bit_chips(s5pv210_gpios_4bit, nr_chips, S5P_VA_GPIO);
2443#if defined(CONFIG_CPU_S5PV210) && defined(CONFIG_S5P_GPIO_INT)
2444 s5p_register_gpioint_bank(IRQ_GPIOINT, 0, S5P_GPIOINT_GROUP_MAXNR);
2445#endif
2446 } else if (soc_is_exynos4210()) {
2447 group = 0;
2448
2449 /* gpio part1 */
2450 chip = exynos4_gpios_1;
2451 nr_chips = ARRAY_SIZE(exynos4_gpios_1);
2452
2453 for (i = 0; i < nr_chips; i++, chip++) {
2454 if (!chip->config) {
2455 chip->config = &exynos4_gpio_cfg;
2456 chip->group = group++;
2457 }
2458 }
2459 samsung_gpiolib_add_4bit_chips(exynos4_gpios_1, nr_chips, S5P_VA_GPIO1);
2460
2461 /* gpio part2 */
2462 chip = exynos4_gpios_2;
2463 nr_chips = ARRAY_SIZE(exynos4_gpios_2);
2464
2465 for (i = 0; i < nr_chips; i++, chip++) {
2466 if (!chip->config) {
2467 chip->config = &exynos4_gpio_cfg;
2468 chip->group = group++;
2469 }
2470 }
2471 samsung_gpiolib_add_4bit_chips(exynos4_gpios_2, nr_chips, S5P_VA_GPIO2);
2472
2473 /* gpio part3 */
2474 chip = exynos4_gpios_3;
2475 nr_chips = ARRAY_SIZE(exynos4_gpios_3);
2476
2477 for (i = 0; i < nr_chips; i++, chip++) {
2478 if (!chip->config) {
2479 chip->config = &exynos4_gpio_cfg;
2480 chip->group = group++;
2481 }
2482 }
2483 samsung_gpiolib_add_4bit_chips(exynos4_gpios_3, nr_chips, S5P_VA_GPIO3);
2484
2485#if defined(CONFIG_CPU_EXYNOS4210) && defined(CONFIG_S5P_GPIO_INT)
2486 s5p_register_gpioint_bank(IRQ_GPIO_XA, 0, IRQ_GPIO1_NR_GROUPS);
2487 s5p_register_gpioint_bank(IRQ_GPIO_XB, IRQ_GPIO1_NR_GROUPS, IRQ_GPIO2_NR_GROUPS);
2488#endif
2489 } else {
2490 WARN(1, "Unknown SoC in gpio-samsung, no GPIOs added\n");
2491 return -ENODEV;
2492 }
2493
2494 return 0;
2495}
2496core_initcall(samsung_gpiolib_init);
2497
2498int s3c_gpio_cfgpin(unsigned int pin, unsigned int config)
2499{
2500 struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
2501 unsigned long flags;
2502 int offset;
2503 int ret;
2504
2505 if (!chip)
2506 return -EINVAL;
2507
2508 offset = pin - chip->chip.base;
2509
2510 samsung_gpio_lock(chip, flags);
2511 ret = samsung_gpio_do_setcfg(chip, offset, config);
2512 samsung_gpio_unlock(chip, flags);
2513
2514 return ret;
2515}
2516EXPORT_SYMBOL(s3c_gpio_cfgpin);
2517
2518int s3c_gpio_cfgpin_range(unsigned int start, unsigned int nr,
2519 unsigned int cfg)
2520{
2521 int ret;
2522
2523 for (; nr > 0; nr--, start++) {
2524 ret = s3c_gpio_cfgpin(start, cfg);
2525 if (ret != 0)
2526 return ret;
2527 }
2528
2529 return 0;
2530}
2531EXPORT_SYMBOL_GPL(s3c_gpio_cfgpin_range);
2532
2533int s3c_gpio_cfgall_range(unsigned int start, unsigned int nr,
2534 unsigned int cfg, samsung_gpio_pull_t pull)
2535{
2536 int ret;
2537
2538 for (; nr > 0; nr--, start++) {
2539 s3c_gpio_setpull(start, pull);
2540 ret = s3c_gpio_cfgpin(start, cfg);
2541 if (ret != 0)
2542 return ret;
2543 }
2544
2545 return 0;
2546}
2547EXPORT_SYMBOL_GPL(s3c_gpio_cfgall_range);
2548
2549unsigned s3c_gpio_getcfg(unsigned int pin)
2550{
2551 struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
2552 unsigned long flags;
2553 unsigned ret = 0;
2554 int offset;
2555
2556 if (chip) {
2557 offset = pin - chip->chip.base;
2558
2559 samsung_gpio_lock(chip, flags);
2560 ret = samsung_gpio_do_getcfg(chip, offset);
2561 samsung_gpio_unlock(chip, flags);
2562 }
2563
2564 return ret;
2565}
2566EXPORT_SYMBOL(s3c_gpio_getcfg);
2567
2568int s3c_gpio_setpull(unsigned int pin, samsung_gpio_pull_t pull)
2569{
2570 struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
2571 unsigned long flags;
2572 int offset, ret;
2573
2574 if (!chip)
2575 return -EINVAL;
2576
2577 offset = pin - chip->chip.base;
2578
2579 samsung_gpio_lock(chip, flags);
2580 ret = samsung_gpio_do_setpull(chip, offset, pull);
2581 samsung_gpio_unlock(chip, flags);
2582
2583 return ret;
2584}
2585EXPORT_SYMBOL(s3c_gpio_setpull);
2586
2587samsung_gpio_pull_t s3c_gpio_getpull(unsigned int pin)
2588{
2589 struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
2590 unsigned long flags;
2591 int offset;
2592 u32 pup = 0;
2593
2594 if (chip) {
2595 offset = pin - chip->chip.base;
2596
2597 samsung_gpio_lock(chip, flags);
2598 pup = samsung_gpio_do_getpull(chip, offset);
2599 samsung_gpio_unlock(chip, flags);
2600 }
2601
2602 return (__force samsung_gpio_pull_t)pup;
2603}
2604EXPORT_SYMBOL(s3c_gpio_getpull);
2605
2606/* gpiolib wrappers until these are totally eliminated */
2607
2608void s3c2410_gpio_pullup(unsigned int pin, unsigned int to)
2609{
2610 int ret;
2611
2612 WARN_ON(to); /* should be none of these left */
2613
2614 if (!to) {
2615 /* if pull is enabled, try first with up, and if that
2616 * fails, try using down */
2617
2618 ret = s3c_gpio_setpull(pin, S3C_GPIO_PULL_UP);
2619 if (ret)
2620 s3c_gpio_setpull(pin, S3C_GPIO_PULL_DOWN);
2621 } else {
2622 s3c_gpio_setpull(pin, S3C_GPIO_PULL_NONE);
2623 }
2624}
2625EXPORT_SYMBOL(s3c2410_gpio_pullup);
2626
2627void s3c2410_gpio_setpin(unsigned int pin, unsigned int to)
2628{
2629 /* do this via gpiolib until all users removed */
2630
2631 gpio_request(pin, "temporary");
2632 gpio_set_value(pin, to);
2633 gpio_free(pin);
2634}
2635EXPORT_SYMBOL(s3c2410_gpio_setpin);
2636
2637unsigned int s3c2410_gpio_getpin(unsigned int pin)
2638{
2639 struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
2640 unsigned long offs = pin - chip->chip.base;
2641
2642 return __raw_readl(chip->base + 0x04) & (1 << offs);
2643}
2644EXPORT_SYMBOL(s3c2410_gpio_getpin);
2645
2646#ifdef CONFIG_S5P_GPIO_DRVSTR
2647s5p_gpio_drvstr_t s5p_gpio_get_drvstr(unsigned int pin)
2648{
2649 struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
2650 unsigned int off;
2651 void __iomem *reg;
2652 int shift;
2653 u32 drvstr;
2654
2655 if (!chip)
2656 return -EINVAL;
2657
2658 off = pin - chip->chip.base;
2659 shift = off * 2;
2660 reg = chip->base + 0x0C;
2661
2662 drvstr = __raw_readl(reg);
2663 drvstr = drvstr >> shift;
2664 drvstr &= 0x3;
2665
2666 return (__force s5p_gpio_drvstr_t)drvstr;
2667}
2668EXPORT_SYMBOL(s5p_gpio_get_drvstr);
2669
2670int s5p_gpio_set_drvstr(unsigned int pin, s5p_gpio_drvstr_t drvstr)
2671{
2672 struct samsung_gpio_chip *chip = samsung_gpiolib_getchip(pin);
2673 unsigned int off;
2674 void __iomem *reg;
2675 int shift;
2676 u32 tmp;
2677
2678 if (!chip)
2679 return -EINVAL;
2680
2681 off = pin - chip->chip.base;
2682 shift = off * 2;
2683 reg = chip->base + 0x0C;
2684
2685 tmp = __raw_readl(reg);
2686 tmp &= ~(0x3 << shift);
2687 tmp |= drvstr << shift;
2688
2689 __raw_writel(tmp, reg);
2690
2691 return 0;
2692}
2693EXPORT_SYMBOL(s5p_gpio_set_drvstr);
2694#endif /* CONFIG_S5P_GPIO_DRVSTR */
2695
2696#ifdef CONFIG_PLAT_S3C24XX
2697unsigned int s3c2410_modify_misccr(unsigned int clear, unsigned int change)
2698{
2699 unsigned long flags;
2700 unsigned long misccr;
2701
2702 local_irq_save(flags);
2703 misccr = __raw_readl(S3C24XX_MISCCR);
2704 misccr &= ~clear;
2705 misccr ^= change;
2706 __raw_writel(misccr, S3C24XX_MISCCR);
2707 local_irq_restore(flags);
2708
2709 return misccr;
2710}
2711EXPORT_SYMBOL(s3c2410_modify_misccr);
2712#endif
diff --git a/drivers/gpio/gpio-xilinx.c b/drivers/gpio/gpio-xilinx.c
index 846fbd5e31bf..0ce6ac9898b1 100644
--- a/drivers/gpio/gpio-xilinx.c
+++ b/drivers/gpio/gpio-xilinx.c
@@ -14,6 +14,7 @@
14 14
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/errno.h> 16#include <linux/errno.h>
17#include <linux/module.h>
17#include <linux/of_device.h> 18#include <linux/of_device.h>
18#include <linux/of_platform.h> 19#include <linux/of_platform.h>
19#include <linux/of_gpio.h> 20#include <linux/of_gpio.h>
diff --git a/drivers/gpu/drm/ati_pcigart.c b/drivers/gpu/drm/ati_pcigart.c
index 1c3649242208..9afe495c12c7 100644
--- a/drivers/gpu/drm/ati_pcigart.c
+++ b/drivers/gpu/drm/ati_pcigart.c
@@ -31,6 +31,7 @@
31 * DEALINGS IN THE SOFTWARE. 31 * DEALINGS IN THE SOFTWARE.
32 */ 32 */
33 33
34#include <linux/export.h>
34#include "drmP.h" 35#include "drmP.h"
35 36
36# define ATI_PCIGART_PAGE_SIZE 4096 /**< PCI GART page size */ 37# define ATI_PCIGART_PAGE_SIZE 4096 /**< PCI GART page size */
diff --git a/drivers/gpu/drm/drm_buffer.c b/drivers/gpu/drm/drm_buffer.c
index 529a0dbe9fc6..08ccefedb327 100644
--- a/drivers/gpu/drm/drm_buffer.c
+++ b/drivers/gpu/drm/drm_buffer.c
@@ -32,6 +32,7 @@
32 * Pauli Nieminen <suokkos-at-gmail-dot-com> 32 * Pauli Nieminen <suokkos-at-gmail-dot-com>
33 */ 33 */
34 34
35#include <linux/export.h>
35#include "drm_buffer.h" 36#include "drm_buffer.h"
36 37
37/** 38/**
diff --git a/drivers/gpu/drm/drm_bufs.c b/drivers/gpu/drm/drm_bufs.c
index 61e1ef90d4e5..30372f7b2d45 100644
--- a/drivers/gpu/drm/drm_bufs.c
+++ b/drivers/gpu/drm/drm_bufs.c
@@ -36,6 +36,7 @@
36#include <linux/vmalloc.h> 36#include <linux/vmalloc.h>
37#include <linux/slab.h> 37#include <linux/slab.h>
38#include <linux/log2.h> 38#include <linux/log2.h>
39#include <linux/export.h>
39#include <asm/shmparam.h> 40#include <asm/shmparam.h>
40#include "drmP.h" 41#include "drmP.h"
41 42
diff --git a/drivers/gpu/drm/drm_cache.c b/drivers/gpu/drm/drm_cache.c
index 0e3bd5b54b78..592865381c6e 100644
--- a/drivers/gpu/drm/drm_cache.c
+++ b/drivers/gpu/drm/drm_cache.c
@@ -28,6 +28,7 @@
28 * Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com> 28 * Authors: Thomas Hellström <thomas-at-tungstengraphics-dot-com>
29 */ 29 */
30 30
31#include <linux/export.h>
31#include "drmP.h" 32#include "drmP.h"
32 33
33#if defined(CONFIG_X86) 34#if defined(CONFIG_X86)
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index fe738f05309b..711d9653abd0 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -31,6 +31,7 @@
31 */ 31 */
32#include <linux/list.h> 32#include <linux/list.h>
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include <linux/export.h>
34#include "drm.h" 35#include "drm.h"
35#include "drmP.h" 36#include "drmP.h"
36#include "drm_crtc.h" 37#include "drm_crtc.h"
diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
index f2366440b738..2957636161e8 100644
--- a/drivers/gpu/drm/drm_crtc_helper.c
+++ b/drivers/gpu/drm/drm_crtc_helper.c
@@ -29,6 +29,9 @@
29 * Jesse Barnes <jesse.barnes@intel.com> 29 * Jesse Barnes <jesse.barnes@intel.com>
30 */ 30 */
31 31
32#include <linux/export.h>
33#include <linux/moduleparam.h>
34
32#include "drmP.h" 35#include "drmP.h"
33#include "drm_crtc.h" 36#include "drm_crtc.h"
34#include "drm_crtc_helper.h" 37#include "drm_crtc_helper.h"
diff --git a/drivers/gpu/drm/drm_debugfs.c b/drivers/gpu/drm/drm_debugfs.c
index b9dc2629ea9a..d067c12ba940 100644
--- a/drivers/gpu/drm/drm_debugfs.c
+++ b/drivers/gpu/drm/drm_debugfs.c
@@ -33,6 +33,7 @@
33#include <linux/debugfs.h> 33#include <linux/debugfs.h>
34#include <linux/seq_file.h> 34#include <linux/seq_file.h>
35#include <linux/slab.h> 35#include <linux/slab.h>
36#include <linux/export.h>
36#include "drmP.h" 37#include "drmP.h"
37 38
38#if defined(CONFIG_DEBUG_FS) 39#if defined(CONFIG_DEBUG_FS)
diff --git a/drivers/gpu/drm/drm_dma.c b/drivers/gpu/drm/drm_dma.c
index 252cbd74df0e..cfb4e333ec0f 100644
--- a/drivers/gpu/drm/drm_dma.c
+++ b/drivers/gpu/drm/drm_dma.c
@@ -33,6 +33,7 @@
33 * OTHER DEALINGS IN THE SOFTWARE. 33 * OTHER DEALINGS IN THE SOFTWARE.
34 */ 34 */
35 35
36#include <linux/export.h>
36#include "drmP.h" 37#include "drmP.h"
37 38
38/** 39/**
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index 7a87e0878f30..fc81af9dbf42 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -48,6 +48,7 @@
48 48
49#include <linux/debugfs.h> 49#include <linux/debugfs.h>
50#include <linux/slab.h> 50#include <linux/slab.h>
51#include <linux/export.h>
51#include "drmP.h" 52#include "drmP.h"
52#include "drm_core.h" 53#include "drm_core.h"
53 54
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index fe39c3570538..3e927ce7557d 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -30,6 +30,7 @@
30#include <linux/kernel.h> 30#include <linux/kernel.h>
31#include <linux/slab.h> 31#include <linux/slab.h>
32#include <linux/i2c.h> 32#include <linux/i2c.h>
33#include <linux/export.h>
33#include "drmP.h" 34#include "drmP.h"
34#include "drm_edid.h" 35#include "drm_edid.h"
35#include "drm_edid_modes.h" 36#include "drm_edid_modes.h"
diff --git a/drivers/gpu/drm/drm_encoder_slave.c b/drivers/gpu/drm/drm_encoder_slave.c
index d62c064fbaa0..fb943551060e 100644
--- a/drivers/gpu/drm/drm_encoder_slave.c
+++ b/drivers/gpu/drm/drm_encoder_slave.c
@@ -24,6 +24,8 @@
24 * 24 *
25 */ 25 */
26 26
27#include <linux/module.h>
28
27#include "drm_encoder_slave.h" 29#include "drm_encoder_slave.h"
28 30
29/** 31/**
diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
index f7c6854eb4dd..80fe39d98b0c 100644
--- a/drivers/gpu/drm/drm_fb_helper.c
+++ b/drivers/gpu/drm/drm_fb_helper.c
@@ -31,6 +31,7 @@
31#include <linux/sysrq.h> 31#include <linux/sysrq.h>
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/fb.h> 33#include <linux/fb.h>
34#include <linux/module.h>
34#include "drmP.h" 35#include "drmP.h"
35#include "drm_crtc.h" 36#include "drm_crtc.h"
36#include "drm_fb_helper.h" 37#include "drm_fb_helper.h"
diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
index 2ec7d48fc4a8..4911e1d1dcf2 100644
--- a/drivers/gpu/drm/drm_fops.c
+++ b/drivers/gpu/drm/drm_fops.c
@@ -37,6 +37,7 @@
37#include "drmP.h" 37#include "drmP.h"
38#include <linux/poll.h> 38#include <linux/poll.h>
39#include <linux/slab.h> 39#include <linux/slab.h>
40#include <linux/module.h>
40 41
41/* from BKL pushdown: note that nothing else serializes idr_find() */ 42/* from BKL pushdown: note that nothing else serializes idr_find() */
42DEFINE_MUTEX(drm_global_mutex); 43DEFINE_MUTEX(drm_global_mutex);
diff --git a/drivers/gpu/drm/drm_hashtab.c b/drivers/gpu/drm/drm_hashtab.c
index e3a75688f3cd..68dc8744b630 100644
--- a/drivers/gpu/drm/drm_hashtab.c
+++ b/drivers/gpu/drm/drm_hashtab.c
@@ -36,6 +36,7 @@
36#include "drm_hashtab.h" 36#include "drm_hashtab.h"
37#include <linux/hash.h> 37#include <linux/hash.h>
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/export.h>
39 40
40int drm_ht_create(struct drm_open_hash *ht, unsigned int order) 41int drm_ht_create(struct drm_open_hash *ht, unsigned int order)
41{ 42{
diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
index 4a058c7af6c0..ddd70db45f76 100644
--- a/drivers/gpu/drm/drm_ioc32.c
+++ b/drivers/gpu/drm/drm_ioc32.c
@@ -29,6 +29,7 @@
29 */ 29 */
30#include <linux/compat.h> 30#include <linux/compat.h>
31#include <linux/ratelimit.h> 31#include <linux/ratelimit.h>
32#include <linux/export.h>
32 33
33#include "drmP.h" 34#include "drmP.h"
34#include "drm_core.h" 35#include "drm_core.h"
diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c
index 3830e9e478c0..cb3794a00f98 100644
--- a/drivers/gpu/drm/drm_irq.c
+++ b/drivers/gpu/drm/drm_irq.c
@@ -40,6 +40,7 @@
40#include <linux/slab.h> 40#include <linux/slab.h>
41 41
42#include <linux/vgaarb.h> 42#include <linux/vgaarb.h>
43#include <linux/export.h>
43 44
44/* Access macro for slots in vblank timestamp ringbuffer. */ 45/* Access macro for slots in vblank timestamp ringbuffer. */
45#define vblanktimestamp(dev, crtc, count) ( \ 46#define vblanktimestamp(dev, crtc, count) ( \
diff --git a/drivers/gpu/drm/drm_memory.c b/drivers/gpu/drm/drm_memory.c
index c9b805000a11..c8b6b66d428d 100644
--- a/drivers/gpu/drm/drm_memory.c
+++ b/drivers/gpu/drm/drm_memory.c
@@ -34,6 +34,7 @@
34 */ 34 */
35 35
36#include <linux/highmem.h> 36#include <linux/highmem.h>
37#include <linux/export.h>
37#include "drmP.h" 38#include "drmP.h"
38 39
39/** 40/**
diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c
index 959186cbf328..961fb54f4266 100644
--- a/drivers/gpu/drm/drm_mm.c
+++ b/drivers/gpu/drm/drm_mm.c
@@ -45,6 +45,7 @@
45#include "drm_mm.h" 45#include "drm_mm.h"
46#include <linux/slab.h> 46#include <linux/slab.h>
47#include <linux/seq_file.h> 47#include <linux/seq_file.h>
48#include <linux/export.h>
48 49
49#define MM_UNUSED_TARGET 4 50#define MM_UNUSED_TARGET 4
50 51
diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index ad74fb4dc542..fb8e46b4e8bc 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -32,6 +32,7 @@
32 32
33#include <linux/list.h> 33#include <linux/list.h>
34#include <linux/list_sort.h> 34#include <linux/list_sort.h>
35#include <linux/export.h>
35#include "drmP.h" 36#include "drmP.h"
36#include "drm.h" 37#include "drm.h"
37#include "drm_crtc.h" 38#include "drm_crtc.h"
diff --git a/drivers/gpu/drm/drm_pci.c b/drivers/gpu/drm/drm_pci.c
index b6a19cb07caf..d4d10b7880cf 100644
--- a/drivers/gpu/drm/drm_pci.c
+++ b/drivers/gpu/drm/drm_pci.c
@@ -39,6 +39,7 @@
39#include <linux/pci.h> 39#include <linux/pci.h>
40#include <linux/slab.h> 40#include <linux/slab.h>
41#include <linux/dma-mapping.h> 41#include <linux/dma-mapping.h>
42#include <linux/export.h>
42#include "drmP.h" 43#include "drmP.h"
43 44
44/**********************************************************************/ 45/**********************************************************************/
diff --git a/drivers/gpu/drm/drm_platform.c b/drivers/gpu/drm/drm_platform.c
index 2a8b6265ad3d..ae9db5e2b27c 100644
--- a/drivers/gpu/drm/drm_platform.c
+++ b/drivers/gpu/drm/drm_platform.c
@@ -25,6 +25,7 @@
25 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 */ 26 */
27 27
28#include <linux/export.h>
28#include "drmP.h" 29#include "drmP.h"
29 30
30/** 31/**
diff --git a/drivers/gpu/drm/drm_proc.c b/drivers/gpu/drm/drm_proc.c
index 0f3c4e3cafc3..fff87221f9e9 100644
--- a/drivers/gpu/drm/drm_proc.c
+++ b/drivers/gpu/drm/drm_proc.c
@@ -39,6 +39,7 @@
39 39
40#include <linux/seq_file.h> 40#include <linux/seq_file.h>
41#include <linux/slab.h> 41#include <linux/slab.h>
42#include <linux/export.h>
42#include "drmP.h" 43#include "drmP.h"
43 44
44/*************************************************** 45/***************************************************
diff --git a/drivers/gpu/drm/drm_sman.c b/drivers/gpu/drm/drm_sman.c
index 34664587a74e..cebce45f4429 100644
--- a/drivers/gpu/drm/drm_sman.c
+++ b/drivers/gpu/drm/drm_sman.c
@@ -36,6 +36,7 @@
36 * Thomas Hellström <thomas-at-tungstengraphics-dot-com> 36 * Thomas Hellström <thomas-at-tungstengraphics-dot-com>
37 */ 37 */
38 38
39#include <linux/export.h>
39#include "drm_sman.h" 40#include "drm_sman.h"
40 41
41struct drm_owner_item { 42struct drm_owner_item {
diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
index 2eee8e016b38..0f9ef9bf6730 100644
--- a/drivers/gpu/drm/drm_sysfs.c
+++ b/drivers/gpu/drm/drm_sysfs.c
@@ -16,6 +16,7 @@
16#include <linux/kdev_t.h> 16#include <linux/kdev_t.h>
17#include <linux/gfp.h> 17#include <linux/gfp.h>
18#include <linux/err.h> 18#include <linux/err.h>
19#include <linux/export.h>
19 20
20#include "drm_sysfs.h" 21#include "drm_sysfs.h"
21#include "drm_core.h" 22#include "drm_core.h"
diff --git a/drivers/gpu/drm/drm_usb.c b/drivers/gpu/drm/drm_usb.c
index 206d2300d873..445003f4dc93 100644
--- a/drivers/gpu/drm/drm_usb.c
+++ b/drivers/gpu/drm/drm_usb.c
@@ -1,5 +1,6 @@
1#include "drmP.h" 1#include "drmP.h"
2#include <linux/usb.h> 2#include <linux/usb.h>
3#include <linux/export.h>
3 4
4#ifdef CONFIG_USB 5#ifdef CONFIG_USB
5int drm_get_usb_dev(struct usb_interface *interface, 6int drm_get_usb_dev(struct usb_interface *interface,
diff --git a/drivers/gpu/drm/drm_vm.c b/drivers/gpu/drm/drm_vm.c
index 5db96d45fc71..8c03eaf41448 100644
--- a/drivers/gpu/drm/drm_vm.c
+++ b/drivers/gpu/drm/drm_vm.c
@@ -34,6 +34,7 @@
34 */ 34 */
35 35
36#include "drmP.h" 36#include "drmP.h"
37#include <linux/export.h>
37#if defined(__ia64__) 38#if defined(__ia64__)
38#include <linux/efi.h> 39#include <linux/efi.h>
39#include <linux/slab.h> 40#include <linux/slab.h>
diff --git a/drivers/gpu/drm/i2c/ch7006_drv.c b/drivers/gpu/drm/i2c/ch7006_drv.c
index 08792a740f18..07d55df6623e 100644
--- a/drivers/gpu/drm/i2c/ch7006_drv.c
+++ b/drivers/gpu/drm/i2c/ch7006_drv.c
@@ -24,6 +24,8 @@
24 * 24 *
25 */ 25 */
26 26
27#include <linux/module.h>
28
27#include "ch7006_priv.h" 29#include "ch7006_priv.h"
28 30
29/* DRM encoder functions */ 31/* DRM encoder functions */
diff --git a/drivers/gpu/drm/i2c/sil164_drv.c b/drivers/gpu/drm/i2c/sil164_drv.c
index 0b6773290c08..b7d45ab4ba69 100644
--- a/drivers/gpu/drm/i2c/sil164_drv.c
+++ b/drivers/gpu/drm/i2c/sil164_drv.c
@@ -24,6 +24,8 @@
24 * 24 *
25 */ 25 */
26 26
27#include <linux/module.h>
28
27#include "drmP.h" 29#include "drmP.h"
28#include "drm_crtc_helper.h" 30#include "drm_crtc_helper.h"
29#include "drm_encoder_slave.h" 31#include "drm_encoder_slave.h"
diff --git a/drivers/gpu/drm/i810/i810_drv.c b/drivers/gpu/drm/i810/i810_drv.c
index 6f98d059f68a..d4266bdf6fb4 100644
--- a/drivers/gpu/drm/i810/i810_drv.c
+++ b/drivers/gpu/drm/i810/i810_drv.c
@@ -30,6 +30,8 @@
30 * Gareth Hughes <gareth@valinux.com> 30 * Gareth Hughes <gareth@valinux.com>
31 */ 31 */
32 32
33#include <linux/module.h>
34
33#include "drmP.h" 35#include "drmP.h"
34#include "drm.h" 36#include "drm.h"
35#include "i810_drm.h" 37#include "i810_drm.h"
diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index 8e95d66800b0..d14b44e13f51 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -29,6 +29,7 @@
29#include <linux/seq_file.h> 29#include <linux/seq_file.h>
30#include <linux/debugfs.h> 30#include <linux/debugfs.h>
31#include <linux/slab.h> 31#include <linux/slab.h>
32#include <linux/export.h>
32#include "drmP.h" 33#include "drmP.h"
33#include "drm.h" 34#include "drm.h"
34#include "intel_drv.h" 35#include "intel_drv.h"
diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
index 2eac955dee18..a9533c54c93c 100644
--- a/drivers/gpu/drm/i915/i915_dma.c
+++ b/drivers/gpu/drm/i915/i915_dma.c
@@ -41,6 +41,7 @@
41#include <linux/pnp.h> 41#include <linux/pnp.h>
42#include <linux/vga_switcheroo.h> 42#include <linux/vga_switcheroo.h>
43#include <linux/slab.h> 43#include <linux/slab.h>
44#include <linux/module.h>
44#include <acpi/video.h> 45#include <acpi/video.h>
45 46
46static void i915_write_hws_pga(struct drm_device *dev) 47static void i915_write_hws_pga(struct drm_device *dev)
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 4c8d681c2151..cc531bb59c26 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -35,6 +35,7 @@
35#include "intel_drv.h" 35#include "intel_drv.h"
36 36
37#include <linux/console.h> 37#include <linux/console.h>
38#include <linux/module.h>
38#include "drm_crtc_helper.h" 39#include "drm_crtc_helper.h"
39 40
40static int i915_modeset __read_mostly = -1; 41static int i915_modeset __read_mostly = -1;
diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index fc1a0832af4f..09b318b0227f 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -27,6 +27,7 @@
27 27
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/export.h>
30#include "drmP.h" 31#include "drmP.h"
31#include "drm.h" 32#include "drm.h"
32#include "drm_crtc.h" 33#include "drm_crtc.h"
diff --git a/drivers/gpu/drm/i915/intel_i2c.c b/drivers/gpu/drm/i915/intel_i2c.c
index 9ed5380e5a53..d30ccccb9d73 100644
--- a/drivers/gpu/drm/i915/intel_i2c.c
+++ b/drivers/gpu/drm/i915/intel_i2c.c
@@ -28,6 +28,7 @@
28 */ 28 */
29#include <linux/i2c.h> 29#include <linux/i2c.h>
30#include <linux/i2c-algo-bit.h> 30#include <linux/i2c-algo-bit.h>
31#include <linux/export.h>
31#include "drmP.h" 32#include "drmP.h"
32#include "drm.h" 33#include "drm.h"
33#include "intel_drv.h" 34#include "intel_drv.h"
diff --git a/drivers/gpu/drm/i915/intel_sdvo.c b/drivers/gpu/drm/i915/intel_sdvo.c
index 6db3b1ccb6eb..3003fb25aefd 100644
--- a/drivers/gpu/drm/i915/intel_sdvo.c
+++ b/drivers/gpu/drm/i915/intel_sdvo.c
@@ -28,6 +28,7 @@
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/delay.h> 30#include <linux/delay.h>
31#include <linux/export.h>
31#include "drmP.h" 32#include "drmP.h"
32#include "drm.h" 33#include "drm.h"
33#include "drm_crtc.h" 34#include "drm_crtc.h"
diff --git a/drivers/gpu/drm/mga/mga_drv.c b/drivers/gpu/drm/mga/mga_drv.c
index 42d31874edf2..33daa29eea66 100644
--- a/drivers/gpu/drm/mga/mga_drv.c
+++ b/drivers/gpu/drm/mga/mga_drv.c
@@ -29,6 +29,8 @@
29 * Gareth Hughes <gareth@valinux.com> 29 * Gareth Hughes <gareth@valinux.com>
30 */ 30 */
31 31
32#include <linux/module.h>
33
32#include "drmP.h" 34#include "drmP.h"
33#include "drm.h" 35#include "drm.h"
34#include "mga_drm.h" 36#include "mga_drm.h"
diff --git a/drivers/gpu/drm/mga/mga_warp.c b/drivers/gpu/drm/mga/mga_warp.c
index f172bd5c257f..722a91b69b0c 100644
--- a/drivers/gpu/drm/mga/mga_warp.c
+++ b/drivers/gpu/drm/mga/mga_warp.c
@@ -30,6 +30,7 @@
30#include <linux/firmware.h> 30#include <linux/firmware.h>
31#include <linux/ihex.h> 31#include <linux/ihex.h>
32#include <linux/platform_device.h> 32#include <linux/platform_device.h>
33#include <linux/module.h>
33 34
34#include "drmP.h" 35#include "drmP.h"
35#include "drm.h" 36#include "drm.h"
diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.c b/drivers/gpu/drm/nouveau/nouveau_drv.c
index c1e01f37b9d1..9f7bb1295262 100644
--- a/drivers/gpu/drm/nouveau/nouveau_drv.c
+++ b/drivers/gpu/drm/nouveau/nouveau_drv.c
@@ -23,6 +23,7 @@
23 */ 23 */
24 24
25#include <linux/console.h> 25#include <linux/console.h>
26#include <linux/module.h>
26 27
27#include "drmP.h" 28#include "drmP.h"
28#include "drm.h" 29#include "drm.h"
diff --git a/drivers/gpu/drm/nouveau/nouveau_i2c.c b/drivers/gpu/drm/nouveau/nouveau_i2c.c
index f6a27fabcfe0..c6143df48b9f 100644
--- a/drivers/gpu/drm/nouveau/nouveau_i2c.c
+++ b/drivers/gpu/drm/nouveau/nouveau_i2c.c
@@ -22,6 +22,8 @@
22 * Authors: Ben Skeggs 22 * Authors: Ben Skeggs
23 */ 23 */
24 24
25#include <linux/module.h>
26
25#include "drmP.h" 27#include "drmP.h"
26#include "nouveau_drv.h" 28#include "nouveau_drv.h"
27#include "nouveau_i2c.h" 29#include "nouveau_i2c.h"
diff --git a/drivers/gpu/drm/nouveau/nouveau_temp.c b/drivers/gpu/drm/nouveau/nouveau_temp.c
index 081ca7b03e8a..5a46446dd5a8 100644
--- a/drivers/gpu/drm/nouveau/nouveau_temp.c
+++ b/drivers/gpu/drm/nouveau/nouveau_temp.c
@@ -22,6 +22,8 @@
22 * Authors: Martin Peres 22 * Authors: Martin Peres
23 */ 23 */
24 24
25#include <linux/module.h>
26
25#include "drmP.h" 27#include "drmP.h"
26 28
27#include "nouveau_drv.h" 29#include "nouveau_drv.h"
diff --git a/drivers/gpu/drm/nouveau/nvc0_graph.c b/drivers/gpu/drm/nouveau/nvc0_graph.c
index 4b8d0b3f7d2b..bbdbc51830c8 100644
--- a/drivers/gpu/drm/nouveau/nvc0_graph.c
+++ b/drivers/gpu/drm/nouveau/nvc0_graph.c
@@ -23,6 +23,7 @@
23 */ 23 */
24 24
25#include <linux/firmware.h> 25#include <linux/firmware.h>
26#include <linux/module.h>
26 27
27#include "drmP.h" 28#include "drmP.h"
28 29
diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
index 570e190710bd..bcac90b543ad 100644
--- a/drivers/gpu/drm/r128/r128_cce.c
+++ b/drivers/gpu/drm/r128/r128_cce.c
@@ -32,6 +32,7 @@
32#include <linux/firmware.h> 32#include <linux/firmware.h>
33#include <linux/platform_device.h> 33#include <linux/platform_device.h>
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/module.h>
35 36
36#include "drmP.h" 37#include "drmP.h"
37#include "drm.h" 38#include "drm.h"
diff --git a/drivers/gpu/drm/r128/r128_drv.c b/drivers/gpu/drm/r128/r128_drv.c
index b9e8efd2b754..4c8796ba6dd8 100644
--- a/drivers/gpu/drm/r128/r128_drv.c
+++ b/drivers/gpu/drm/r128/r128_drv.c
@@ -29,6 +29,8 @@
29 * Gareth Hughes <gareth@valinux.com> 29 * Gareth Hughes <gareth@valinux.com>
30 */ 30 */
31 31
32#include <linux/module.h>
33
32#include "drmP.h" 34#include "drmP.h"
33#include "drm.h" 35#include "drm.h"
34#include "r128_drm.h" 36#include "r128_drm.h"
diff --git a/drivers/gpu/drm/radeon/ni.c b/drivers/gpu/drm/radeon/ni.c
index 556b7bc3418b..fdb93f884575 100644
--- a/drivers/gpu/drm/radeon/ni.c
+++ b/drivers/gpu/drm/radeon/ni.c
@@ -24,6 +24,7 @@
24#include <linux/firmware.h> 24#include <linux/firmware.h>
25#include <linux/platform_device.h> 25#include <linux/platform_device.h>
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/module.h>
27#include "drmP.h" 28#include "drmP.h"
28#include "radeon.h" 29#include "radeon.h"
29#include "radeon_asic.h" 30#include "radeon_asic.h"
diff --git a/drivers/gpu/drm/radeon/r100.c b/drivers/gpu/drm/radeon/r100.c
index 8f8b8fa14357..cbf49f4f408e 100644
--- a/drivers/gpu/drm/radeon/r100.c
+++ b/drivers/gpu/drm/radeon/r100.c
@@ -41,6 +41,7 @@
41 41
42#include <linux/firmware.h> 42#include <linux/firmware.h>
43#include <linux/platform_device.h> 43#include <linux/platform_device.h>
44#include <linux/module.h>
44 45
45#include "r100_reg_safe.h" 46#include "r100_reg_safe.h"
46#include "rn50_reg_safe.h" 47#include "rn50_reg_safe.h"
diff --git a/drivers/gpu/drm/radeon/r600.c b/drivers/gpu/drm/radeon/r600.c
index 12470b090ddf..4e777c1e4b7b 100644
--- a/drivers/gpu/drm/radeon/r600.c
+++ b/drivers/gpu/drm/radeon/r600.c
@@ -29,6 +29,7 @@
29#include <linux/seq_file.h> 29#include <linux/seq_file.h>
30#include <linux/firmware.h> 30#include <linux/firmware.h>
31#include <linux/platform_device.h> 31#include <linux/platform_device.h>
32#include <linux/module.h>
32#include "drmP.h" 33#include "drmP.h"
33#include "radeon_drm.h" 34#include "radeon_drm.h"
34#include "radeon.h" 35#include "radeon.h"
diff --git a/drivers/gpu/drm/radeon/r600_cp.c b/drivers/gpu/drm/radeon/r600_cp.c
index 45fd592f9606..c9db4931913f 100644
--- a/drivers/gpu/drm/radeon/r600_cp.c
+++ b/drivers/gpu/drm/radeon/r600_cp.c
@@ -26,6 +26,8 @@
26 * Alex Deucher <alexander.deucher@amd.com> 26 * Alex Deucher <alexander.deucher@amd.com>
27 */ 27 */
28 28
29#include <linux/module.h>
30
29#include "drmP.h" 31#include "drmP.h"
30#include "drm.h" 32#include "drm.h"
31#include "radeon_drm.h" 33#include "radeon_drm.h"
diff --git a/drivers/gpu/drm/radeon/radeon_cp.c b/drivers/gpu/drm/radeon/radeon_cp.c
index 045ec59478f9..72ae8266b8e9 100644
--- a/drivers/gpu/drm/radeon/radeon_cp.c
+++ b/drivers/gpu/drm/radeon/radeon_cp.c
@@ -29,6 +29,8 @@
29 * Gareth Hughes <gareth@valinux.com> 29 * Gareth Hughes <gareth@valinux.com>
30 */ 30 */
31 31
32#include <linux/module.h>
33
32#include "drmP.h" 34#include "drmP.h"
33#include "drm.h" 35#include "drm.h"
34#include "drm_sarea.h" 36#include "drm_sarea.h"
diff --git a/drivers/gpu/drm/radeon/radeon_drv.c b/drivers/gpu/drm/radeon/radeon_drv.c
index e71d2ed7fa11..969933833ccb 100644
--- a/drivers/gpu/drm/radeon/radeon_drv.c
+++ b/drivers/gpu/drm/radeon/radeon_drv.c
@@ -36,6 +36,7 @@
36 36
37#include "drm_pciids.h" 37#include "drm_pciids.h"
38#include <linux/console.h> 38#include <linux/console.h>
39#include <linux/module.h>
39 40
40 41
41/* 42/*
diff --git a/drivers/gpu/drm/radeon/radeon_i2c.c b/drivers/gpu/drm/radeon/radeon_i2c.c
index 02cb7da4124d..e6d110ce2331 100644
--- a/drivers/gpu/drm/radeon/radeon_i2c.c
+++ b/drivers/gpu/drm/radeon/radeon_i2c.c
@@ -23,6 +23,8 @@
23 * Authors: Dave Airlie 23 * Authors: Dave Airlie
24 * Alex Deucher 24 * Alex Deucher
25 */ 25 */
26#include <linux/export.h>
27
26#include "drmP.h" 28#include "drmP.h"
27#include "radeon_drm.h" 29#include "radeon_drm.h"
28#include "radeon.h" 30#include "radeon.h"
diff --git a/drivers/gpu/drm/savage/savage_drv.c b/drivers/gpu/drm/savage/savage_drv.c
index 6464490b240b..5468d1cd3296 100644
--- a/drivers/gpu/drm/savage/savage_drv.c
+++ b/drivers/gpu/drm/savage/savage_drv.c
@@ -23,6 +23,8 @@
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */ 24 */
25 25
26#include <linux/module.h>
27
26#include "drmP.h" 28#include "drmP.h"
27#include "savage_drm.h" 29#include "savage_drm.h"
28#include "savage_drv.h" 30#include "savage_drv.h"
diff --git a/drivers/gpu/drm/sis/sis_drv.c b/drivers/gpu/drm/sis/sis_drv.c
index 46d5be6e97e5..a9c5716bea4e 100644
--- a/drivers/gpu/drm/sis/sis_drv.c
+++ b/drivers/gpu/drm/sis/sis_drv.c
@@ -25,6 +25,8 @@
25 * 25 *
26 */ 26 */
27 27
28#include <linux/module.h>
29
28#include "drmP.h" 30#include "drmP.h"
29#include "sis_drm.h" 31#include "sis_drm.h"
30#include "sis_drv.h" 32#include "sis_drv.h"
diff --git a/drivers/gpu/drm/tdfx/tdfx_drv.c b/drivers/gpu/drm/tdfx/tdfx_drv.c
index 8bf98810a8d6..cda29911e332 100644
--- a/drivers/gpu/drm/tdfx/tdfx_drv.c
+++ b/drivers/gpu/drm/tdfx/tdfx_drv.c
@@ -30,6 +30,8 @@
30 * Gareth Hughes <gareth@valinux.com> 30 * Gareth Hughes <gareth@valinux.com>
31 */ 31 */
32 32
33#include <linux/module.h>
34
33#include "drmP.h" 35#include "drmP.h"
34#include "tdfx_drv.h" 36#include "tdfx_drv.h"
35 37
diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
index 58c271ebc0f7..f9cc548d6d98 100644
--- a/drivers/gpu/drm/ttm/ttm_tt.c
+++ b/drivers/gpu/drm/ttm/ttm_tt.c
@@ -35,6 +35,7 @@
35#include <linux/file.h> 35#include <linux/file.h>
36#include <linux/swap.h> 36#include <linux/swap.h>
37#include <linux/slab.h> 37#include <linux/slab.h>
38#include <linux/export.h>
38#include "drm_cache.h" 39#include "drm_cache.h"
39#include "drm_mem_util.h" 40#include "drm_mem_util.h"
40#include "ttm/ttm_module.h" 41#include "ttm/ttm_module.h"
diff --git a/drivers/gpu/drm/via/via_drv.c b/drivers/gpu/drm/via/via_drv.c
index 920a55214bcf..a83e86d3956c 100644
--- a/drivers/gpu/drm/via/via_drv.c
+++ b/drivers/gpu/drm/via/via_drv.c
@@ -22,6 +22,8 @@
22 * DEALINGS IN THE SOFTWARE. 22 * DEALINGS IN THE SOFTWARE.
23 */ 23 */
24 24
25#include <linux/module.h>
26
25#include "drmP.h" 27#include "drmP.h"
26#include "via_drm.h" 28#include "via_drm.h"
27#include "via_drv.h" 29#include "via_drv.h"
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index 13afddc1f034..1805b8c2a948 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -24,6 +24,7 @@
24 * USE OR OTHER DEALINGS IN THE SOFTWARE. 24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * 25 *
26 **************************************************************************/ 26 **************************************************************************/
27#include <linux/module.h>
27 28
28#include "drmP.h" 29#include "drmP.h"
29#include "vmwgfx_drv.h" 30#include "vmwgfx_drv.h"
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fb.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fb.c
index 070797b7b03a..34e51a1695b8 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fb.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fb.c
@@ -26,6 +26,8 @@
26 * 26 *
27 **************************************************************************/ 27 **************************************************************************/
28 28
29#include <linux/export.h>
30
29#include "drmP.h" 31#include "drmP.h"
30#include "vmwgfx_drv.h" 32#include "vmwgfx_drv.h"
31 33
diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
index 9bc7b03269df..299d23871122 100644
--- a/drivers/hid/hid-apple.c
+++ b/drivers/hid/hid-apple.c
@@ -183,9 +183,6 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
183 if (hid->product >= USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI && 183 if (hid->product >= USB_DEVICE_ID_APPLE_WELLSPRING4_ANSI &&
184 hid->product <= USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS) 184 hid->product <= USB_DEVICE_ID_APPLE_WELLSPRING4A_JIS)
185 table = macbookair_fn_keys; 185 table = macbookair_fn_keys;
186 else if (hid->product >= USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI &&
187 hid->product <= USB_DEVICE_ID_APPLE_WELLSPRING6_JIS)
188 table = macbookair_fn_keys;
189 else if (hid->product < 0x21d || hid->product >= 0x300) 186 else if (hid->product < 0x21d || hid->product >= 0x300)
190 table = powerbook_fn_keys; 187 table = powerbook_fn_keys;
191 else 188 else
@@ -458,6 +455,9 @@ static const struct hid_device_id apple_devices[] = {
458 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO), 455 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO),
459 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN | 456 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
460 APPLE_ISO_KEYBOARD }, 457 APPLE_ISO_KEYBOARD },
458 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO),
459 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
460 APPLE_ISO_KEYBOARD },
461 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS), 461 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS),
462 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, 462 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
463 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI), 463 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI),
@@ -508,6 +508,12 @@ static const struct hid_device_id apple_devices[] = {
508 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD }, 508 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
509 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS), 509 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS),
510 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS }, 510 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
511 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI),
512 .driver_data = APPLE_HAS_FN },
513 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO),
514 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
515 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS),
516 .driver_data = APPLE_HAS_FN | APPLE_RDESC_JIS },
511 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI), 517 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI),
512 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN }, 518 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
513 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO), 519 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO),
diff --git a/drivers/hid/hid-axff.c b/drivers/hid/hid-axff.c
index 3bdb4500f95e..5be858dd9a15 100644
--- a/drivers/hid/hid-axff.c
+++ b/drivers/hid/hid-axff.c
@@ -31,6 +31,7 @@
31#include <linux/slab.h> 31#include <linux/slab.h>
32#include <linux/usb.h> 32#include <linux/usb.h>
33#include <linux/hid.h> 33#include <linux/hid.h>
34#include <linux/module.h>
34 35
35#include "hid-ids.h" 36#include "hid-ids.h"
36 37
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 91adcc5bad28..848a56c0279c 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1362,6 +1362,9 @@ static const struct hid_device_id hid_have_special_driver[] = {
1362 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) }, 1362 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) },
1363 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) }, 1363 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) },
1364 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) }, 1364 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) },
1365 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI) },
1366 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO) },
1367 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS) },
1365 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ANSI) }, 1368 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ANSI) },
1366 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ISO) }, 1369 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_ISO) },
1367 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_JIS) }, 1370 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_REVB_JIS) },
@@ -1374,6 +1377,7 @@ static const struct hid_device_id hid_have_special_driver[] = {
1374 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI) }, 1377 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI) },
1375 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO) }, 1378 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO) },
1376 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) }, 1379 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS) },
1380 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO) },
1377 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) }, 1381 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
1378 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) }, 1382 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
1379 { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_T91MT) }, 1383 { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_T91MT) },
@@ -1942,6 +1946,9 @@ static const struct hid_device_id hid_mouse_ignore_list[] = {
1942 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) }, 1946 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ANSI) },
1943 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) }, 1947 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_ISO) },
1944 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) }, 1948 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5_JIS) },
1949 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI) },
1950 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO) },
1951 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS) },
1945 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI) }, 1952 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ANSI) },
1946 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO) }, 1953 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_ISO) },
1947 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS) }, 1954 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING6_JIS) },
diff --git a/drivers/hid/hid-debug.c b/drivers/hid/hid-debug.c
index 9a243ca96e6d..ee80d733801d 100644
--- a/drivers/hid/hid-debug.c
+++ b/drivers/hid/hid-debug.c
@@ -31,6 +31,7 @@
31#include <linux/debugfs.h> 31#include <linux/debugfs.h>
32#include <linux/seq_file.h> 32#include <linux/seq_file.h>
33#include <linux/sched.h> 33#include <linux/sched.h>
34#include <linux/export.h>
34#include <linux/slab.h> 35#include <linux/slab.h>
35#include <linux/uaccess.h> 36#include <linux/uaccess.h>
36#include <linux/poll.h> 37#include <linux/poll.h>
diff --git a/drivers/hid/hid-dr.c b/drivers/hid/hid-dr.c
index 61eece47204d..e832f44ae383 100644
--- a/drivers/hid/hid-dr.c
+++ b/drivers/hid/hid-dr.c
@@ -31,6 +31,7 @@
31#include <linux/slab.h> 31#include <linux/slab.h>
32#include <linux/usb.h> 32#include <linux/usb.h>
33#include <linux/hid.h> 33#include <linux/hid.h>
34#include <linux/module.h>
34 35
35#include "hid-ids.h" 36#include "hid-ids.h"
36 37
diff --git a/drivers/hid/hid-emsff.c b/drivers/hid/hid-emsff.c
index a5dc13fe367b..9bdde867a02f 100644
--- a/drivers/hid/hid-emsff.c
+++ b/drivers/hid/hid-emsff.c
@@ -24,6 +24,7 @@
24#include <linux/hid.h> 24#include <linux/hid.h>
25#include <linux/input.h> 25#include <linux/input.h>
26#include <linux/usb.h> 26#include <linux/usb.h>
27#include <linux/module.h>
27 28
28#include "hid-ids.h" 29#include "hid-ids.h"
29#include "usbhid/usbhid.h" 30#include "usbhid/usbhid.h"
diff --git a/drivers/hid/hid-gaff.c b/drivers/hid/hid-gaff.c
index 279ba530003c..f1e1bcf67427 100644
--- a/drivers/hid/hid-gaff.c
+++ b/drivers/hid/hid-gaff.c
@@ -31,6 +31,7 @@
31#include <linux/slab.h> 31#include <linux/slab.h>
32#include <linux/usb.h> 32#include <linux/usb.h>
33#include <linux/hid.h> 33#include <linux/hid.h>
34#include <linux/module.h>
34#include "hid-ids.h" 35#include "hid-ids.h"
35 36
36#ifdef CONFIG_GREENASIA_FF 37#ifdef CONFIG_GREENASIA_FF
diff --git a/drivers/hid/hid-holtekff.c b/drivers/hid/hid-holtekff.c
index 91e3a032112b..4e7542151e22 100644
--- a/drivers/hid/hid-holtekff.c
+++ b/drivers/hid/hid-holtekff.c
@@ -25,6 +25,7 @@
25 25
26#include <linux/hid.h> 26#include <linux/hid.h>
27#include <linux/input.h> 27#include <linux/input.h>
28#include <linux/module.h>
28#include <linux/slab.h> 29#include <linux/slab.h>
29#include <linux/usb.h> 30#include <linux/usb.h>
30 31
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 1680e99b4816..06ce996b8b65 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -112,6 +112,9 @@
112#define USB_DEVICE_ID_APPLE_ALU_REVB_ANSI 0x024f 112#define USB_DEVICE_ID_APPLE_ALU_REVB_ANSI 0x024f
113#define USB_DEVICE_ID_APPLE_ALU_REVB_ISO 0x0250 113#define USB_DEVICE_ID_APPLE_ALU_REVB_ISO 0x0250
114#define USB_DEVICE_ID_APPLE_ALU_REVB_JIS 0x0251 114#define USB_DEVICE_ID_APPLE_ALU_REVB_JIS 0x0251
115#define USB_DEVICE_ID_APPLE_WELLSPRING5A_ANSI 0x0252
116#define USB_DEVICE_ID_APPLE_WELLSPRING5A_ISO 0x0253
117#define USB_DEVICE_ID_APPLE_WELLSPRING5A_JIS 0x0254
115#define USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI 0x0249 118#define USB_DEVICE_ID_APPLE_WELLSPRING6A_ANSI 0x0249
116#define USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO 0x024a 119#define USB_DEVICE_ID_APPLE_WELLSPRING6A_ISO 0x024a
117#define USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS 0x024b 120#define USB_DEVICE_ID_APPLE_WELLSPRING6A_JIS 0x024b
@@ -121,6 +124,7 @@
121#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI 0x0239 124#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ANSI 0x0239
122#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO 0x023a 125#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_ISO 0x023a
123#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS 0x023b 126#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS 0x023b
127#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2011_ISO 0x0256
124#define USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY 0x030a 128#define USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY 0x030a
125#define USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY 0x030b 129#define USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY 0x030b
126#define USB_DEVICE_ID_APPLE_ATV_IRCONTROL 0x8241 130#define USB_DEVICE_ID_APPLE_ATV_IRCONTROL 0x8241
diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
index fa5d7a1ffa9e..f1c909f1b239 100644
--- a/drivers/hid/hid-multitouch.c
+++ b/drivers/hid/hid-multitouch.c
@@ -291,7 +291,6 @@ static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi,
291 td->last_slot_field = usage->hid; 291 td->last_slot_field = usage->hid;
292 td->last_field_index = field->index; 292 td->last_field_index = field->index;
293 td->last_mt_collection = usage->collection_index; 293 td->last_mt_collection = usage->collection_index;
294 hdev->quirks &= ~HID_QUIRK_MULTITOUCH;
295 return 1; 294 return 1;
296 case HID_DG_WIDTH: 295 case HID_DG_WIDTH:
297 hid_map_usage(hi, usage, bit, max, 296 hid_map_usage(hi, usage, bit, max,
@@ -530,44 +529,12 @@ static void mt_set_input_mode(struct hid_device *hdev)
530 } 529 }
531} 530}
532 531
533/* a list of devices for which there is a specialized multitouch driver */
534static const struct hid_device_id mt_have_special_driver[] = {
535 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, 0x0001) },
536 { HID_USB_DEVICE(USB_VENDOR_ID_NTRIG, 0x0006) },
537 { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA,
538 USB_DEVICE_ID_PIXART_IMAGING_INC_OPTICAL_TOUCH_SCREEN) },
539 { HID_USB_DEVICE(USB_VENDOR_ID_QUANTA,
540 USB_DEVICE_ID_QUANTA_OPTICAL_TOUCH) },
541 { }
542};
543
544static bool mt_match_one_id(struct hid_device *hdev,
545 const struct hid_device_id *id)
546{
547 return id->bus == hdev->bus &&
548 (id->vendor == HID_ANY_ID || id->vendor == hdev->vendor) &&
549 (id->product == HID_ANY_ID || id->product == hdev->product);
550}
551
552static const struct hid_device_id *mt_match_id(struct hid_device *hdev,
553 const struct hid_device_id *id)
554{
555 for (; id->bus; id++)
556 if (mt_match_one_id(hdev, id))
557 return id;
558
559 return NULL;
560}
561
562static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) 532static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
563{ 533{
564 int ret, i; 534 int ret, i;
565 struct mt_device *td; 535 struct mt_device *td;
566 struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */ 536 struct mt_class *mtclass = mt_classes; /* MT_CLS_DEFAULT */
567 537
568 if (mt_match_id(hdev, mt_have_special_driver))
569 return -ENODEV;
570
571 for (i = 0; mt_classes[i].name ; i++) { 538 for (i = 0; mt_classes[i].name ; i++) {
572 if (id->driver_data == mt_classes[i].name) { 539 if (id->driver_data == mt_classes[i].name) {
573 mtclass = &(mt_classes[i]); 540 mtclass = &(mt_classes[i]);
@@ -575,6 +542,10 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
575 } 542 }
576 } 543 }
577 544
545 /* This allows the driver to correctly support devices
546 * that emit events over several HID messages.
547 */
548 hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC;
578 549
579 td = kzalloc(sizeof(struct mt_device), GFP_KERNEL); 550 td = kzalloc(sizeof(struct mt_device), GFP_KERNEL);
580 if (!td) { 551 if (!td) {
@@ -590,16 +561,10 @@ static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id)
590 if (ret != 0) 561 if (ret != 0)
591 goto fail; 562 goto fail;
592 563
593 hdev->quirks |= HID_QUIRK_MULTITOUCH;
594 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); 564 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
595 if (ret) 565 if (ret)
596 goto fail; 566 goto fail;
597 567
598 /* This allows the driver to correctly support devices
599 * that emit events over several HID messages.
600 */
601 hdev->quirks |= HID_QUIRK_NO_INPUT_SYNC;
602
603 td->slots = kzalloc(td->maxcontacts * sizeof(struct mt_slot), 568 td->slots = kzalloc(td->maxcontacts * sizeof(struct mt_slot),
604 GFP_KERNEL); 569 GFP_KERNEL);
605 if (!td->slots) { 570 if (!td->slots) {
@@ -793,10 +758,6 @@ static const struct hid_device_id mt_devices[] = {
793 HID_USB_DEVICE(USB_VENDOR_ID_XAT, 758 HID_USB_DEVICE(USB_VENDOR_ID_XAT,
794 USB_DEVICE_ID_XAT_CSR) }, 759 USB_DEVICE_ID_XAT_CSR) },
795 760
796 /* Rest of the world */
797 { .driver_data = MT_CLS_DEFAULT,
798 HID_USB_DEVICE(HID_ANY_ID, HID_ANY_ID) },
799
800 { } 761 { }
801}; 762};
802MODULE_DEVICE_TABLE(hid, mt_devices); 763MODULE_DEVICE_TABLE(hid, mt_devices);
diff --git a/drivers/hid/hid-picolcd.c b/drivers/hid/hid-picolcd.c
index 1782693819f3..01e7d2cd7c26 100644
--- a/drivers/hid/hid-picolcd.c
+++ b/drivers/hid/hid-picolcd.c
@@ -36,6 +36,7 @@
36 36
37#include <linux/completion.h> 37#include <linux/completion.h>
38#include <linux/uaccess.h> 38#include <linux/uaccess.h>
39#include <linux/module.h>
39 40
40#define PICOLCD_NAME "PicoLCD (graphic)" 41#define PICOLCD_NAME "PicoLCD (graphic)"
41 42
diff --git a/drivers/hid/hid-pl.c b/drivers/hid/hid-pl.c
index 06e5300d43d2..070f93a5c11b 100644
--- a/drivers/hid/hid-pl.c
+++ b/drivers/hid/hid-pl.c
@@ -40,6 +40,7 @@
40 40
41#include <linux/input.h> 41#include <linux/input.h>
42#include <linux/slab.h> 42#include <linux/slab.h>
43#include <linux/module.h>
43#include <linux/usb.h> 44#include <linux/usb.h>
44#include <linux/hid.h> 45#include <linux/hid.h>
45 46
diff --git a/drivers/hid/hid-roccat-common.c b/drivers/hid/hid-roccat-common.c
index edf898dee28b..b07e7f96a358 100644
--- a/drivers/hid/hid-roccat-common.c
+++ b/drivers/hid/hid-roccat-common.c
@@ -13,6 +13,7 @@
13 13
14#include <linux/hid.h> 14#include <linux/hid.h>
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/module.h>
16#include "hid-roccat-common.h" 17#include "hid-roccat-common.h"
17 18
18static inline uint16_t roccat_common_feature_report(uint8_t report_id) 19static inline uint16_t roccat_common_feature_report(uint8_t report_id)
diff --git a/drivers/hid/hid-roccat.c b/drivers/hid/hid-roccat.c
index 5666e7587b18..b685b04dbf9d 100644
--- a/drivers/hid/hid-roccat.c
+++ b/drivers/hid/hid-roccat.c
@@ -27,6 +27,7 @@
27#include <linux/poll.h> 27#include <linux/poll.h>
28#include <linux/sched.h> 28#include <linux/sched.h>
29#include <linux/hid-roccat.h> 29#include <linux/hid-roccat.h>
30#include <linux/module.h>
30 31
31#define ROCCAT_FIRST_MINOR 0 32#define ROCCAT_FIRST_MINOR 0
32#define ROCCAT_MAX_DEVICES 8 33#define ROCCAT_MAX_DEVICES 8
@@ -162,27 +163,27 @@ static int roccat_open(struct inode *inode, struct file *file)
162 163
163 device = devices[minor]; 164 device = devices[minor];
164 165
165 mutex_lock(&device->readers_lock);
166
167 if (!device) { 166 if (!device) {
168 pr_emerg("roccat device with minor %d doesn't exist\n", minor); 167 pr_emerg("roccat device with minor %d doesn't exist\n", minor);
169 error = -ENODEV; 168 error = -ENODEV;
170 goto exit_err; 169 goto exit_err_devices;
171 } 170 }
172 171
172 mutex_lock(&device->readers_lock);
173
173 if (!device->open++) { 174 if (!device->open++) {
174 /* power on device on adding first reader */ 175 /* power on device on adding first reader */
175 error = hid_hw_power(device->hid, PM_HINT_FULLON); 176 error = hid_hw_power(device->hid, PM_HINT_FULLON);
176 if (error < 0) { 177 if (error < 0) {
177 --device->open; 178 --device->open;
178 goto exit_err; 179 goto exit_err_readers;
179 } 180 }
180 181
181 error = hid_hw_open(device->hid); 182 error = hid_hw_open(device->hid);
182 if (error < 0) { 183 if (error < 0) {
183 hid_hw_power(device->hid, PM_HINT_NORMAL); 184 hid_hw_power(device->hid, PM_HINT_NORMAL);
184 --device->open; 185 --device->open;
185 goto exit_err; 186 goto exit_err_readers;
186 } 187 }
187 } 188 }
188 189
@@ -193,13 +194,13 @@ static int roccat_open(struct inode *inode, struct file *file)
193 list_add_tail(&reader->node, &device->readers); 194 list_add_tail(&reader->node, &device->readers);
194 file->private_data = reader; 195 file->private_data = reader;
195 196
196exit_unlock: 197exit_err_readers:
197 mutex_unlock(&device->readers_lock); 198 mutex_unlock(&device->readers_lock);
199exit_err_devices:
198 mutex_unlock(&devices_lock); 200 mutex_unlock(&devices_lock);
201 if (error)
202 kfree(reader);
199 return error; 203 return error;
200exit_err:
201 kfree(reader);
202 goto exit_unlock;
203} 204}
204 205
205static int roccat_release(struct inode *inode, struct file *file) 206static int roccat_release(struct inode *inode, struct file *file)
diff --git a/drivers/hid/hid-sjoy.c b/drivers/hid/hid-sjoy.c
index 670da9109f86..4b1448613ea6 100644
--- a/drivers/hid/hid-sjoy.c
+++ b/drivers/hid/hid-sjoy.c
@@ -30,6 +30,7 @@
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/usb.h> 31#include <linux/usb.h>
32#include <linux/hid.h> 32#include <linux/hid.h>
33#include <linux/module.h>
33#include "hid-ids.h" 34#include "hid-ids.h"
34 35
35#ifdef CONFIG_SMARTJOYPLUS_FF 36#ifdef CONFIG_SMARTJOYPLUS_FF
diff --git a/drivers/hid/hid-tmff.c b/drivers/hid/hid-tmff.c
index 575862b0688e..83a933b9c2e9 100644
--- a/drivers/hid/hid-tmff.c
+++ b/drivers/hid/hid-tmff.c
@@ -31,6 +31,7 @@
31#include <linux/input.h> 31#include <linux/input.h>
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/usb.h> 33#include <linux/usb.h>
34#include <linux/module.h>
34 35
35#include "hid-ids.h" 36#include "hid-ids.h"
36 37
diff --git a/drivers/hid/hid-zpff.c b/drivers/hid/hid-zpff.c
index f31fab012f2f..f6ba81df71bd 100644
--- a/drivers/hid/hid-zpff.c
+++ b/drivers/hid/hid-zpff.c
@@ -25,6 +25,7 @@
25#include <linux/input.h> 25#include <linux/input.h>
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/usb.h> 27#include <linux/usb.h>
28#include <linux/module.h>
28 29
29#include "hid-ids.h" 30#include "hid-ids.h"
30 31
diff --git a/drivers/hid/usbhid/hid-quirks.c b/drivers/hid/usbhid/hid-quirks.c
index 4ea464151c3b..5028d60a22a1 100644
--- a/drivers/hid/usbhid/hid-quirks.c
+++ b/drivers/hid/usbhid/hid-quirks.c
@@ -16,6 +16,7 @@
16 */ 16 */
17 17
18#include <linux/hid.h> 18#include <linux/hid.h>
19#include <linux/export.h>
19#include <linux/slab.h> 20#include <linux/slab.h>
20 21
21#include "../hid-ids.h" 22#include "../hid-ids.h"
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 9b347acf1559..9ec854ae118b 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -335,6 +335,7 @@ config SENSORS_I5K_AMB
335 335
336config SENSORS_F71805F 336config SENSORS_F71805F
337 tristate "Fintek F71805F/FG, F71806F/FG and F71872F/FG" 337 tristate "Fintek F71805F/FG, F71806F/FG and F71872F/FG"
338 depends on !PPC
338 help 339 help
339 If you say yes here you get support for hardware monitoring 340 If you say yes here you get support for hardware monitoring
340 features of the Fintek F71805F/FG, F71806F/FG and F71872F/FG 341 features of the Fintek F71805F/FG, F71806F/FG and F71872F/FG
@@ -345,6 +346,7 @@ config SENSORS_F71805F
345 346
346config SENSORS_F71882FG 347config SENSORS_F71882FG
347 tristate "Fintek F71882FG and compatibles" 348 tristate "Fintek F71882FG and compatibles"
349 depends on !PPC
348 help 350 help
349 If you say yes here you get support for hardware monitoring 351 If you say yes here you get support for hardware monitoring
350 features of many Fintek Super-I/O (LPC) chips. The currently 352 features of many Fintek Super-I/O (LPC) chips. The currently
@@ -468,6 +470,7 @@ config SENSORS_IBMPEX
468 470
469config SENSORS_IT87 471config SENSORS_IT87
470 tristate "ITE IT87xx and compatibles" 472 tristate "ITE IT87xx and compatibles"
473 depends on !PPC
471 select HWMON_VID 474 select HWMON_VID
472 help 475 help
473 If you say yes here you get support for ITE IT8705F, IT8712F, 476 If you say yes here you get support for ITE IT8705F, IT8712F,
@@ -824,6 +827,7 @@ config SENSORS_NTC_THERMISTOR
824 827
825config SENSORS_PC87360 828config SENSORS_PC87360
826 tristate "National Semiconductor PC87360 family" 829 tristate "National Semiconductor PC87360 family"
830 depends on !PPC
827 select HWMON_VID 831 select HWMON_VID
828 help 832 help
829 If you say yes here you get access to the hardware monitoring 833 If you say yes here you get access to the hardware monitoring
@@ -837,6 +841,7 @@ config SENSORS_PC87360
837 841
838config SENSORS_PC87427 842config SENSORS_PC87427
839 tristate "National Semiconductor PC87427" 843 tristate "National Semiconductor PC87427"
844 depends on !PPC
840 help 845 help
841 If you say yes here you get access to the hardware monitoring 846 If you say yes here you get access to the hardware monitoring
842 functions of the National Semiconductor PC87427 Super-I/O chip. 847 functions of the National Semiconductor PC87427 Super-I/O chip.
@@ -928,7 +933,7 @@ config SENSORS_SMM665
928 933
929config SENSORS_DME1737 934config SENSORS_DME1737
930 tristate "SMSC DME1737, SCH311x and compatibles" 935 tristate "SMSC DME1737, SCH311x and compatibles"
931 depends on I2C && EXPERIMENTAL 936 depends on I2C && EXPERIMENTAL && !PPC
932 select HWMON_VID 937 select HWMON_VID
933 help 938 help
934 If you say yes here you get support for the hardware monitoring 939 If you say yes here you get support for the hardware monitoring
@@ -970,6 +975,7 @@ config SENSORS_EMC6W201
970 975
971config SENSORS_SMSC47M1 976config SENSORS_SMSC47M1
972 tristate "SMSC LPC47M10x and compatibles" 977 tristate "SMSC LPC47M10x and compatibles"
978 depends on !PPC
973 help 979 help
974 If you say yes here you get support for the integrated fan 980 If you say yes here you get support for the integrated fan
975 monitoring and control capabilities of the SMSC LPC47B27x, 981 monitoring and control capabilities of the SMSC LPC47B27x,
@@ -1003,7 +1009,7 @@ config SENSORS_SMSC47M192
1003 1009
1004config SENSORS_SMSC47B397 1010config SENSORS_SMSC47B397
1005 tristate "SMSC LPC47B397-NC" 1011 tristate "SMSC LPC47B397-NC"
1006 depends on EXPERIMENTAL 1012 depends on EXPERIMENTAL && !PPC
1007 help 1013 help
1008 If you say yes here you get support for the SMSC LPC47B397-NC 1014 If you say yes here you get support for the SMSC LPC47B397-NC
1009 sensor chip. 1015 sensor chip.
@@ -1017,6 +1023,7 @@ config SENSORS_SCH56XX_COMMON
1017 1023
1018config SENSORS_SCH5627 1024config SENSORS_SCH5627
1019 tristate "SMSC SCH5627" 1025 tristate "SMSC SCH5627"
1026 depends on !PPC
1020 select SENSORS_SCH56XX_COMMON 1027 select SENSORS_SCH56XX_COMMON
1021 help 1028 help
1022 If you say yes here you get support for the hardware monitoring 1029 If you say yes here you get support for the hardware monitoring
@@ -1027,6 +1034,7 @@ config SENSORS_SCH5627
1027 1034
1028config SENSORS_SCH5636 1035config SENSORS_SCH5636
1029 tristate "SMSC SCH5636" 1036 tristate "SMSC SCH5636"
1037 depends on !PPC
1030 select SENSORS_SCH56XX_COMMON 1038 select SENSORS_SCH56XX_COMMON
1031 help 1039 help
1032 SMSC SCH5636 Super I/O chips include an embedded microcontroller for 1040 SMSC SCH5636 Super I/O chips include an embedded microcontroller for
@@ -1150,6 +1158,7 @@ config SENSORS_VIA686A
1150 1158
1151config SENSORS_VT1211 1159config SENSORS_VT1211
1152 tristate "VIA VT1211" 1160 tristate "VIA VT1211"
1161 depends on !PPC
1153 select HWMON_VID 1162 select HWMON_VID
1154 help 1163 help
1155 If you say yes here then you get support for hardware monitoring 1164 If you say yes here then you get support for hardware monitoring
@@ -1262,6 +1271,7 @@ config SENSORS_W83L786NG
1262 1271
1263config SENSORS_W83627HF 1272config SENSORS_W83627HF
1264 tristate "Winbond W83627HF, W83627THF, W83637HF, W83687THF, W83697HF" 1273 tristate "Winbond W83627HF, W83627THF, W83637HF, W83687THF, W83697HF"
1274 depends on !PPC
1265 select HWMON_VID 1275 select HWMON_VID
1266 help 1276 help
1267 If you say yes here you get support for the Winbond W836X7 series 1277 If you say yes here you get support for the Winbond W836X7 series
@@ -1272,7 +1282,8 @@ config SENSORS_W83627HF
1272 will be called w83627hf. 1282 will be called w83627hf.
1273 1283
1274config SENSORS_W83627EHF 1284config SENSORS_W83627EHF
1275 tristate "Winbond W83627EHF/EHG/DHG, W83667HG, NCT6775F, NCT6776F" 1285 tristate "Winbond W83627EHF/EHG/DHG/UHG, W83667HG, NCT6775F, NCT6776F"
1286 depends on !PPC
1276 select HWMON_VID 1287 select HWMON_VID
1277 help 1288 help
1278 If you say yes here you get support for the hardware 1289 If you say yes here you get support for the hardware
@@ -1281,7 +1292,8 @@ config SENSORS_W83627EHF
1281 This driver also supports the W83627EHG, which is the lead-free 1292 This driver also supports the W83627EHG, which is the lead-free
1282 version of the W83627EHF, and the W83627DHG, which is a similar 1293 version of the W83627EHF, and the W83627DHG, which is a similar
1283 chip suited for specific Intel processors that use PECI such as 1294 chip suited for specific Intel processors that use PECI such as
1284 the Core 2 Duo. 1295 the Core 2 Duo. And also the W83627UHG, which is a stripped down
1296 version of the W83627DHG (as far as hardware monitoring goes.)
1285 1297
1286 This driver also supports Nuvoton W83667HG, W83667HG-B, NCT6775F 1298 This driver also supports Nuvoton W83667HG, W83667HG-B, NCT6775F
1287 (also known as W83667HG-I), and NCT6776F. 1299 (also known as W83667HG-I), and NCT6776F.
diff --git a/drivers/hwmon/ad7414.c b/drivers/hwmon/ad7414.c
index d46c0c758ddf..df29a7fff9e7 100644
--- a/drivers/hwmon/ad7414.c
+++ b/drivers/hwmon/ad7414.c
@@ -58,10 +58,9 @@ static inline int ad7414_temp_from_reg(s16 reg)
58 58
59static inline int ad7414_read(struct i2c_client *client, u8 reg) 59static inline int ad7414_read(struct i2c_client *client, u8 reg)
60{ 60{
61 if (reg == AD7414_REG_TEMP) { 61 if (reg == AD7414_REG_TEMP)
62 int value = i2c_smbus_read_word_data(client, reg); 62 return i2c_smbus_read_word_swapped(client, reg);
63 return (value < 0) ? value : swab16(value); 63 else
64 } else
65 return i2c_smbus_read_byte_data(client, reg); 64 return i2c_smbus_read_byte_data(client, reg);
66} 65}
67 66
diff --git a/drivers/hwmon/ad7418.c b/drivers/hwmon/ad7418.c
index ffc781fec185..8cb718ce8237 100644
--- a/drivers/hwmon/ad7418.c
+++ b/drivers/hwmon/ad7418.c
@@ -76,20 +76,6 @@ static struct i2c_driver ad7418_driver = {
76 .id_table = ad7418_id, 76 .id_table = ad7418_id,
77}; 77};
78 78
79/* All registers are word-sized, except for the configuration registers.
80 * AD7418 uses a high-byte first convention. Do NOT use those functions to
81 * access the configuration registers CONF and CONF2, as they are byte-sized.
82 */
83static inline int ad7418_read(struct i2c_client *client, u8 reg)
84{
85 return swab16(i2c_smbus_read_word_data(client, reg));
86}
87
88static inline int ad7418_write(struct i2c_client *client, u8 reg, u16 value)
89{
90 return i2c_smbus_write_word_data(client, reg, swab16(value));
91}
92
93static void ad7418_init_client(struct i2c_client *client) 79static void ad7418_init_client(struct i2c_client *client)
94{ 80{
95 struct ad7418_data *data = i2c_get_clientdata(client); 81 struct ad7418_data *data = i2c_get_clientdata(client);
@@ -128,7 +114,9 @@ static struct ad7418_data *ad7418_update_device(struct device *dev)
128 udelay(30); 114 udelay(30);
129 115
130 for (i = 0; i < 3; i++) { 116 for (i = 0; i < 3; i++) {
131 data->temp[i] = ad7418_read(client, AD7418_REG_TEMP[i]); 117 data->temp[i] =
118 i2c_smbus_read_word_swapped(client,
119 AD7418_REG_TEMP[i]);
132 } 120 }
133 121
134 for (i = 0, ch = 4; i < data->adc_max; i++, ch--) { 122 for (i = 0, ch = 4; i < data->adc_max; i++, ch--) {
@@ -138,11 +126,12 @@ static struct ad7418_data *ad7418_update_device(struct device *dev)
138 126
139 udelay(15); 127 udelay(15);
140 data->in[data->adc_max - 1 - i] = 128 data->in[data->adc_max - 1 - i] =
141 ad7418_read(client, AD7418_REG_ADC); 129 i2c_smbus_read_word_swapped(client,
130 AD7418_REG_ADC);
142 } 131 }
143 132
144 /* restore old configuration value */ 133 /* restore old configuration value */
145 ad7418_write(client, AD7418_REG_CONF, cfg); 134 i2c_smbus_write_word_swapped(client, AD7418_REG_CONF, cfg);
146 135
147 data->last_updated = jiffies; 136 data->last_updated = jiffies;
148 data->valid = 1; 137 data->valid = 1;
@@ -182,7 +171,9 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *devattr,
182 171
183 mutex_lock(&data->lock); 172 mutex_lock(&data->lock);
184 data->temp[attr->index] = LM75_TEMP_TO_REG(temp); 173 data->temp[attr->index] = LM75_TEMP_TO_REG(temp);
185 ad7418_write(client, AD7418_REG_TEMP[attr->index], data->temp[attr->index]); 174 i2c_smbus_write_word_swapped(client,
175 AD7418_REG_TEMP[attr->index],
176 data->temp[attr->index]);
186 mutex_unlock(&data->lock); 177 mutex_unlock(&data->lock);
187 return count; 178 return count;
188} 179}
diff --git a/drivers/hwmon/ads1015.c b/drivers/hwmon/ads1015.c
index e9beeda4cbe5..eedca3cf9968 100644
--- a/drivers/hwmon/ads1015.c
+++ b/drivers/hwmon/ads1015.c
@@ -59,19 +59,6 @@ struct ads1015_data {
59 struct ads1015_channel_data channel_data[ADS1015_CHANNELS]; 59 struct ads1015_channel_data channel_data[ADS1015_CHANNELS];
60}; 60};
61 61
62static s32 ads1015_read_reg(struct i2c_client *client, unsigned int reg)
63{
64 s32 data = i2c_smbus_read_word_data(client, reg);
65
66 return (data < 0) ? data : swab16(data);
67}
68
69static s32 ads1015_write_reg(struct i2c_client *client, unsigned int reg,
70 u16 val)
71{
72 return i2c_smbus_write_word_data(client, reg, swab16(val));
73}
74
75static int ads1015_read_value(struct i2c_client *client, unsigned int channel, 62static int ads1015_read_value(struct i2c_client *client, unsigned int channel,
76 int *value) 63 int *value)
77{ 64{
@@ -87,7 +74,7 @@ static int ads1015_read_value(struct i2c_client *client, unsigned int channel,
87 mutex_lock(&data->update_lock); 74 mutex_lock(&data->update_lock);
88 75
89 /* get channel parameters */ 76 /* get channel parameters */
90 res = ads1015_read_reg(client, ADS1015_CONFIG); 77 res = i2c_smbus_read_word_swapped(client, ADS1015_CONFIG);
91 if (res < 0) 78 if (res < 0)
92 goto err_unlock; 79 goto err_unlock;
93 config = res; 80 config = res;
@@ -101,13 +88,13 @@ static int ads1015_read_value(struct i2c_client *client, unsigned int channel,
101 config |= (pga & 0x0007) << 9; 88 config |= (pga & 0x0007) << 9;
102 config |= (data_rate & 0x0007) << 5; 89 config |= (data_rate & 0x0007) << 5;
103 90
104 res = ads1015_write_reg(client, ADS1015_CONFIG, config); 91 res = i2c_smbus_write_word_swapped(client, ADS1015_CONFIG, config);
105 if (res < 0) 92 if (res < 0)
106 goto err_unlock; 93 goto err_unlock;
107 94
108 /* wait until conversion finished */ 95 /* wait until conversion finished */
109 msleep(conversion_time_ms); 96 msleep(conversion_time_ms);
110 res = ads1015_read_reg(client, ADS1015_CONFIG); 97 res = i2c_smbus_read_word_swapped(client, ADS1015_CONFIG);
111 if (res < 0) 98 if (res < 0)
112 goto err_unlock; 99 goto err_unlock;
113 config = res; 100 config = res;
@@ -117,7 +104,7 @@ static int ads1015_read_value(struct i2c_client *client, unsigned int channel,
117 goto err_unlock; 104 goto err_unlock;
118 } 105 }
119 106
120 res = ads1015_read_reg(client, ADS1015_CONVERSION); 107 res = i2c_smbus_read_word_swapped(client, ADS1015_CONVERSION);
121 if (res < 0) 108 if (res < 0)
122 goto err_unlock; 109 goto err_unlock;
123 conversion = res; 110 conversion = res;
diff --git a/drivers/hwmon/ads7828.c b/drivers/hwmon/ads7828.c
index c42c5a69a664..cfcc3b6fb6bf 100644
--- a/drivers/hwmon/ads7828.c
+++ b/drivers/hwmon/ads7828.c
@@ -74,13 +74,6 @@ static int ads7828_detect(struct i2c_client *client,
74static int ads7828_probe(struct i2c_client *client, 74static int ads7828_probe(struct i2c_client *client,
75 const struct i2c_device_id *id); 75 const struct i2c_device_id *id);
76 76
77/* The ADS7828 returns the 12-bit sample in two bytes,
78 these are read as a word then byte-swapped */
79static u16 ads7828_read_value(struct i2c_client *client, u8 reg)
80{
81 return swab16(i2c_smbus_read_word_data(client, reg));
82}
83
84static inline u8 channel_cmd_byte(int ch) 77static inline u8 channel_cmd_byte(int ch)
85{ 78{
86 /* cmd byte C2,C1,C0 - see datasheet */ 79 /* cmd byte C2,C1,C0 - see datasheet */
@@ -104,7 +97,8 @@ static struct ads7828_data *ads7828_update_device(struct device *dev)
104 97
105 for (ch = 0; ch < ADS7828_NCH; ch++) { 98 for (ch = 0; ch < ADS7828_NCH; ch++) {
106 u8 cmd = channel_cmd_byte(ch); 99 u8 cmd = channel_cmd_byte(ch);
107 data->adc_input[ch] = ads7828_read_value(client, cmd); 100 data->adc_input[ch] =
101 i2c_smbus_read_word_swapped(client, cmd);
108 } 102 }
109 data->last_updated = jiffies; 103 data->last_updated = jiffies;
110 data->valid = 1; 104 data->valid = 1;
@@ -203,7 +197,7 @@ static int ads7828_detect(struct i2c_client *client,
203 for (ch = 0; ch < ADS7828_NCH; ch++) { 197 for (ch = 0; ch < ADS7828_NCH; ch++) {
204 u16 in_data; 198 u16 in_data;
205 u8 cmd = channel_cmd_byte(ch); 199 u8 cmd = channel_cmd_byte(ch);
206 in_data = ads7828_read_value(client, cmd); 200 in_data = i2c_smbus_read_word_swapped(client, cmd);
207 if (in_data & 0xF000) { 201 if (in_data & 0xF000) {
208 pr_debug("%s : Doesn't look like an ads7828 device\n", 202 pr_debug("%s : Doesn't look like an ads7828 device\n",
209 __func__); 203 __func__);
diff --git a/drivers/hwmon/asb100.c b/drivers/hwmon/asb100.c
index c02a052d3085..d7bd1f3f2a31 100644
--- a/drivers/hwmon/asb100.c
+++ b/drivers/hwmon/asb100.c
@@ -829,17 +829,17 @@ static int asb100_read_value(struct i2c_client *client, u16 reg)
829 /* convert from ISA to LM75 I2C addresses */ 829 /* convert from ISA to LM75 I2C addresses */
830 switch (reg & 0xff) { 830 switch (reg & 0xff) {
831 case 0x50: /* TEMP */ 831 case 0x50: /* TEMP */
832 res = swab16(i2c_smbus_read_word_data(cl, 0)); 832 res = i2c_smbus_read_word_swapped(cl, 0);
833 break; 833 break;
834 case 0x52: /* CONFIG */ 834 case 0x52: /* CONFIG */
835 res = i2c_smbus_read_byte_data(cl, 1); 835 res = i2c_smbus_read_byte_data(cl, 1);
836 break; 836 break;
837 case 0x53: /* HYST */ 837 case 0x53: /* HYST */
838 res = swab16(i2c_smbus_read_word_data(cl, 2)); 838 res = i2c_smbus_read_word_swapped(cl, 2);
839 break; 839 break;
840 case 0x55: /* MAX */ 840 case 0x55: /* MAX */
841 default: 841 default:
842 res = swab16(i2c_smbus_read_word_data(cl, 3)); 842 res = i2c_smbus_read_word_swapped(cl, 3);
843 break; 843 break;
844 } 844 }
845 } 845 }
@@ -877,10 +877,10 @@ static void asb100_write_value(struct i2c_client *client, u16 reg, u16 value)
877 i2c_smbus_write_byte_data(cl, 1, value & 0xff); 877 i2c_smbus_write_byte_data(cl, 1, value & 0xff);
878 break; 878 break;
879 case 0x53: /* HYST */ 879 case 0x53: /* HYST */
880 i2c_smbus_write_word_data(cl, 2, swab16(value)); 880 i2c_smbus_write_word_swapped(cl, 2, value);
881 break; 881 break;
882 case 0x55: /* MAX */ 882 case 0x55: /* MAX */
883 i2c_smbus_write_word_data(cl, 3, swab16(value)); 883 i2c_smbus_write_word_swapped(cl, 3, value);
884 break; 884 break;
885 } 885 }
886 } 886 }
diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
index ce18c046f728..104b3767516c 100644
--- a/drivers/hwmon/coretemp.c
+++ b/drivers/hwmon/coretemp.c
@@ -60,14 +60,13 @@ MODULE_PARM_DESC(tjmax, "TjMax value in degrees Celsius");
60#ifdef CONFIG_SMP 60#ifdef CONFIG_SMP
61#define TO_PHYS_ID(cpu) cpu_data(cpu).phys_proc_id 61#define TO_PHYS_ID(cpu) cpu_data(cpu).phys_proc_id
62#define TO_CORE_ID(cpu) cpu_data(cpu).cpu_core_id 62#define TO_CORE_ID(cpu) cpu_data(cpu).cpu_core_id
63#define TO_ATTR_NO(cpu) (TO_CORE_ID(cpu) + BASE_SYSFS_ATTR_NO)
64#define for_each_sibling(i, cpu) for_each_cpu(i, cpu_sibling_mask(cpu)) 63#define for_each_sibling(i, cpu) for_each_cpu(i, cpu_sibling_mask(cpu))
65#else 64#else
66#define TO_PHYS_ID(cpu) (cpu) 65#define TO_PHYS_ID(cpu) (cpu)
67#define TO_CORE_ID(cpu) (cpu) 66#define TO_CORE_ID(cpu) (cpu)
68#define TO_ATTR_NO(cpu) (cpu)
69#define for_each_sibling(i, cpu) for (i = 0; false; ) 67#define for_each_sibling(i, cpu) for (i = 0; false; )
70#endif 68#endif
69#define TO_ATTR_NO(cpu) (TO_CORE_ID(cpu) + BASE_SYSFS_ATTR_NO)
71 70
72/* 71/*
73 * Per-Core Temperature Data 72 * Per-Core Temperature Data
diff --git a/drivers/hwmon/ds1621.c b/drivers/hwmon/ds1621.c
index e11363467a8d..ef1ac996752e 100644
--- a/drivers/hwmon/ds1621.c
+++ b/drivers/hwmon/ds1621.c
@@ -80,24 +80,6 @@ struct ds1621_data {
80 u8 conf; /* Register encoding, combined */ 80 u8 conf; /* Register encoding, combined */
81}; 81};
82 82
83/* Temperature registers are word-sized.
84 DS1621 uses a high-byte first convention, which is exactly opposite to
85 the SMBus standard. */
86static int ds1621_read_temp(struct i2c_client *client, u8 reg)
87{
88 int ret;
89
90 ret = i2c_smbus_read_word_data(client, reg);
91 if (ret < 0)
92 return ret;
93 return swab16(ret);
94}
95
96static int ds1621_write_temp(struct i2c_client *client, u8 reg, u16 value)
97{
98 return i2c_smbus_write_word_data(client, reg, swab16(value));
99}
100
101static void ds1621_init_client(struct i2c_client *client) 83static void ds1621_init_client(struct i2c_client *client)
102{ 84{
103 u8 conf, new_conf; 85 u8 conf, new_conf;
@@ -136,7 +118,7 @@ static struct ds1621_data *ds1621_update_client(struct device *dev)
136 data->conf = i2c_smbus_read_byte_data(client, DS1621_REG_CONF); 118 data->conf = i2c_smbus_read_byte_data(client, DS1621_REG_CONF);
137 119
138 for (i = 0; i < ARRAY_SIZE(data->temp); i++) 120 for (i = 0; i < ARRAY_SIZE(data->temp); i++)
139 data->temp[i] = ds1621_read_temp(client, 121 data->temp[i] = i2c_smbus_read_word_swapped(client,
140 DS1621_REG_TEMP[i]); 122 DS1621_REG_TEMP[i]);
141 123
142 /* reset alarms if necessary */ 124 /* reset alarms if necessary */
@@ -177,8 +159,8 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da,
177 159
178 mutex_lock(&data->update_lock); 160 mutex_lock(&data->update_lock);
179 data->temp[attr->index] = val; 161 data->temp[attr->index] = val;
180 ds1621_write_temp(client, DS1621_REG_TEMP[attr->index], 162 i2c_smbus_write_word_swapped(client, DS1621_REG_TEMP[attr->index],
181 data->temp[attr->index]); 163 data->temp[attr->index]);
182 mutex_unlock(&data->update_lock); 164 mutex_unlock(&data->update_lock);
183 return count; 165 return count;
184} 166}
diff --git a/drivers/hwmon/ds620.c b/drivers/hwmon/ds620.c
index 4f7c3fc40a89..225ae4f36583 100644
--- a/drivers/hwmon/ds620.c
+++ b/drivers/hwmon/ds620.c
@@ -75,33 +75,13 @@ struct ds620_data {
75 s16 temp[3]; /* Register values, word */ 75 s16 temp[3]; /* Register values, word */
76}; 76};
77 77
78/*
79 * Temperature registers are word-sized.
80 * DS620 uses a high-byte first convention, which is exactly opposite to
81 * the SMBus standard.
82 */
83static int ds620_read_temp(struct i2c_client *client, u8 reg)
84{
85 int ret;
86
87 ret = i2c_smbus_read_word_data(client, reg);
88 if (ret < 0)
89 return ret;
90 return swab16(ret);
91}
92
93static int ds620_write_temp(struct i2c_client *client, u8 reg, u16 value)
94{
95 return i2c_smbus_write_word_data(client, reg, swab16(value));
96}
97
98static void ds620_init_client(struct i2c_client *client) 78static void ds620_init_client(struct i2c_client *client)
99{ 79{
100 struct ds620_platform_data *ds620_info = client->dev.platform_data; 80 struct ds620_platform_data *ds620_info = client->dev.platform_data;
101 u16 conf, new_conf; 81 u16 conf, new_conf;
102 82
103 new_conf = conf = 83 new_conf = conf =
104 swab16(i2c_smbus_read_word_data(client, DS620_REG_CONF)); 84 i2c_smbus_read_word_swapped(client, DS620_REG_CONF);
105 85
106 /* switch to continuous conversion mode */ 86 /* switch to continuous conversion mode */
107 new_conf &= ~DS620_REG_CONFIG_1SHOT; 87 new_conf &= ~DS620_REG_CONFIG_1SHOT;
@@ -118,8 +98,7 @@ static void ds620_init_client(struct i2c_client *client)
118 new_conf |= DS620_REG_CONFIG_R1 | DS620_REG_CONFIG_R0; 98 new_conf |= DS620_REG_CONFIG_R1 | DS620_REG_CONFIG_R0;
119 99
120 if (conf != new_conf) 100 if (conf != new_conf)
121 i2c_smbus_write_word_data(client, DS620_REG_CONF, 101 i2c_smbus_write_word_swapped(client, DS620_REG_CONF, new_conf);
122 swab16(new_conf));
123 102
124 /* start conversion */ 103 /* start conversion */
125 i2c_smbus_write_byte(client, DS620_COM_START); 104 i2c_smbus_write_byte(client, DS620_COM_START);
@@ -141,8 +120,8 @@ static struct ds620_data *ds620_update_client(struct device *dev)
141 dev_dbg(&client->dev, "Starting ds620 update\n"); 120 dev_dbg(&client->dev, "Starting ds620 update\n");
142 121
143 for (i = 0; i < ARRAY_SIZE(data->temp); i++) { 122 for (i = 0; i < ARRAY_SIZE(data->temp); i++) {
144 res = ds620_read_temp(client, 123 res = i2c_smbus_read_word_swapped(client,
145 DS620_REG_TEMP[i]); 124 DS620_REG_TEMP[i]);
146 if (res < 0) { 125 if (res < 0) {
147 ret = ERR_PTR(res); 126 ret = ERR_PTR(res);
148 goto abort; 127 goto abort;
@@ -191,8 +170,8 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da,
191 170
192 mutex_lock(&data->update_lock); 171 mutex_lock(&data->update_lock);
193 data->temp[attr->index] = val; 172 data->temp[attr->index] = val;
194 ds620_write_temp(client, DS620_REG_TEMP[attr->index], 173 i2c_smbus_write_word_swapped(client, DS620_REG_TEMP[attr->index],
195 data->temp[attr->index]); 174 data->temp[attr->index]);
196 mutex_unlock(&data->update_lock); 175 mutex_unlock(&data->update_lock);
197 return count; 176 return count;
198} 177}
@@ -210,16 +189,15 @@ static ssize_t show_alarm(struct device *dev, struct device_attribute *da,
210 return PTR_ERR(data); 189 return PTR_ERR(data);
211 190
212 /* reset alarms if necessary */ 191 /* reset alarms if necessary */
213 res = i2c_smbus_read_word_data(client, DS620_REG_CONF); 192 res = i2c_smbus_read_word_swapped(client, DS620_REG_CONF);
214 if (res < 0) 193 if (res < 0)
215 return res; 194 return res;
216 195
217 conf = swab16(res); 196 new_conf = conf = res;
218 new_conf = conf;
219 new_conf &= ~attr->index; 197 new_conf &= ~attr->index;
220 if (conf != new_conf) { 198 if (conf != new_conf) {
221 res = i2c_smbus_write_word_data(client, DS620_REG_CONF, 199 res = i2c_smbus_write_word_swapped(client, DS620_REG_CONF,
222 swab16(new_conf)); 200 new_conf);
223 if (res < 0) 201 if (res < 0)
224 return res; 202 return res;
225 } 203 }
diff --git a/drivers/hwmon/gl518sm.c b/drivers/hwmon/gl518sm.c
index e7ae5743e181..a13e2da97e30 100644
--- a/drivers/hwmon/gl518sm.c
+++ b/drivers/hwmon/gl518sm.c
@@ -591,7 +591,7 @@ static int gl518_remove(struct i2c_client *client)
591static int gl518_read_value(struct i2c_client *client, u8 reg) 591static int gl518_read_value(struct i2c_client *client, u8 reg)
592{ 592{
593 if ((reg >= 0x07) && (reg <= 0x0c)) 593 if ((reg >= 0x07) && (reg <= 0x0c))
594 return swab16(i2c_smbus_read_word_data(client, reg)); 594 return i2c_smbus_read_word_swapped(client, reg);
595 else 595 else
596 return i2c_smbus_read_byte_data(client, reg); 596 return i2c_smbus_read_byte_data(client, reg);
597} 597}
@@ -599,7 +599,7 @@ static int gl518_read_value(struct i2c_client *client, u8 reg)
599static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value) 599static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value)
600{ 600{
601 if ((reg >= 0x07) && (reg <= 0x0c)) 601 if ((reg >= 0x07) && (reg <= 0x0c))
602 return i2c_smbus_write_word_data(client, reg, swab16(value)); 602 return i2c_smbus_write_word_swapped(client, reg, value);
603 else 603 else
604 return i2c_smbus_write_byte_data(client, reg, value); 604 return i2c_smbus_write_byte_data(client, reg, value);
605} 605}
diff --git a/drivers/hwmon/gl520sm.c b/drivers/hwmon/gl520sm.c
index 131ea8625f08..cd6085bbfba7 100644
--- a/drivers/hwmon/gl520sm.c
+++ b/drivers/hwmon/gl520sm.c
@@ -821,7 +821,7 @@ static int gl520_remove(struct i2c_client *client)
821static int gl520_read_value(struct i2c_client *client, u8 reg) 821static int gl520_read_value(struct i2c_client *client, u8 reg)
822{ 822{
823 if ((reg >= 0x07) && (reg <= 0x0c)) 823 if ((reg >= 0x07) && (reg <= 0x0c))
824 return swab16(i2c_smbus_read_word_data(client, reg)); 824 return i2c_smbus_read_word_swapped(client, reg);
825 else 825 else
826 return i2c_smbus_read_byte_data(client, reg); 826 return i2c_smbus_read_byte_data(client, reg);
827} 827}
@@ -829,7 +829,7 @@ static int gl520_read_value(struct i2c_client *client, u8 reg)
829static int gl520_write_value(struct i2c_client *client, u8 reg, u16 value) 829static int gl520_write_value(struct i2c_client *client, u8 reg, u16 value)
830{ 830{
831 if ((reg >= 0x07) && (reg <= 0x0c)) 831 if ((reg >= 0x07) && (reg <= 0x0c))
832 return i2c_smbus_write_word_data(client, reg, swab16(value)); 832 return i2c_smbus_write_word_swapped(client, reg, value);
833 else 833 else
834 return i2c_smbus_write_byte_data(client, reg, value); 834 return i2c_smbus_write_byte_data(client, reg, value);
835} 835}
diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
index 783d0c17b762..6a967d7dbdee 100644
--- a/drivers/hwmon/ibmaem.c
+++ b/drivers/hwmon/ibmaem.c
@@ -147,8 +147,9 @@ struct aem_data {
147 int id; 147 int id;
148 struct aem_ipmi_data ipmi; 148 struct aem_ipmi_data ipmi;
149 149
150 /* Function to update sensors */ 150 /* Function and buffer to update sensors */
151 void (*update)(struct aem_data *data); 151 void (*update)(struct aem_data *data);
152 struct aem_read_sensor_resp *rs_resp;
152 153
153 /* 154 /*
154 * AEM 1.x sensors: 155 * AEM 1.x sensors:
@@ -245,8 +246,6 @@ static void aem_bmc_gone(int iface);
245static void aem_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data); 246static void aem_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data);
246 247
247static void aem_remove_sensors(struct aem_data *data); 248static void aem_remove_sensors(struct aem_data *data);
248static int aem_init_aem1(struct aem_ipmi_data *probe);
249static int aem_init_aem2(struct aem_ipmi_data *probe);
250static int aem1_find_sensors(struct aem_data *data); 249static int aem1_find_sensors(struct aem_data *data);
251static int aem2_find_sensors(struct aem_data *data); 250static int aem2_find_sensors(struct aem_data *data);
252static void update_aem1_sensors(struct aem_data *data); 251static void update_aem1_sensors(struct aem_data *data);
@@ -357,13 +356,14 @@ static void aem_msg_handler(struct ipmi_recv_msg *msg, void *user_msg_data)
357 356
358/* Sensor support functions */ 357/* Sensor support functions */
359 358
360/* Read a sensor value */ 359/* Read a sensor value; must be called with data->lock held */
361static int aem_read_sensor(struct aem_data *data, u8 elt, u8 reg, 360static int aem_read_sensor(struct aem_data *data, u8 elt, u8 reg,
362 void *buf, size_t size) 361 void *buf, size_t size)
363{ 362{
364 int rs_size, res; 363 int rs_size, res;
365 struct aem_read_sensor_req rs_req; 364 struct aem_read_sensor_req rs_req;
366 struct aem_read_sensor_resp *rs_resp; 365 /* Use preallocated rx buffer */
366 struct aem_read_sensor_resp *rs_resp = data->rs_resp;
367 struct aem_ipmi_data *ipmi = &data->ipmi; 367 struct aem_ipmi_data *ipmi = &data->ipmi;
368 368
369 /* AEM registers are 1, 2, 4 or 8 bytes */ 369 /* AEM registers are 1, 2, 4 or 8 bytes */
@@ -389,10 +389,6 @@ static int aem_read_sensor(struct aem_data *data, u8 elt, u8 reg,
389 ipmi->tx_message.data_len = sizeof(rs_req); 389 ipmi->tx_message.data_len = sizeof(rs_req);
390 390
391 rs_size = sizeof(*rs_resp) + size; 391 rs_size = sizeof(*rs_resp) + size;
392 rs_resp = kzalloc(rs_size, GFP_KERNEL);
393 if (!rs_resp)
394 return -ENOMEM;
395
396 ipmi->rx_msg_data = rs_resp; 392 ipmi->rx_msg_data = rs_resp;
397 ipmi->rx_msg_len = rs_size; 393 ipmi->rx_msg_len = rs_size;
398 394
@@ -435,7 +431,6 @@ static int aem_read_sensor(struct aem_data *data, u8 elt, u8 reg,
435 res = 0; 431 res = 0;
436 432
437out: 433out:
438 kfree(rs_resp);
439 return res; 434 return res;
440} 435}
441 436
@@ -493,6 +488,7 @@ static void aem_delete(struct aem_data *data)
493{ 488{
494 list_del(&data->list); 489 list_del(&data->list);
495 aem_remove_sensors(data); 490 aem_remove_sensors(data);
491 kfree(data->rs_resp);
496 hwmon_device_unregister(data->hwmon_dev); 492 hwmon_device_unregister(data->hwmon_dev);
497 ipmi_destroy_user(data->ipmi.user); 493 ipmi_destroy_user(data->ipmi.user);
498 platform_set_drvdata(data->pdev, NULL); 494 platform_set_drvdata(data->pdev, NULL);
@@ -570,24 +566,31 @@ static int aem_init_aem1_inst(struct aem_ipmi_data *probe, u8 module_handle)
570 platform_set_drvdata(data->pdev, data); 566 platform_set_drvdata(data->pdev, data);
571 567
572 /* Set up IPMI interface */ 568 /* Set up IPMI interface */
573 if (aem_init_ipmi_data(&data->ipmi, probe->interface, 569 res = aem_init_ipmi_data(&data->ipmi, probe->interface,
574 probe->bmc_device)) 570 probe->bmc_device);
571 if (res)
575 goto ipmi_err; 572 goto ipmi_err;
576 573
577 /* Register with hwmon */ 574 /* Register with hwmon */
578 data->hwmon_dev = hwmon_device_register(&data->pdev->dev); 575 data->hwmon_dev = hwmon_device_register(&data->pdev->dev);
579
580 if (IS_ERR(data->hwmon_dev)) { 576 if (IS_ERR(data->hwmon_dev)) {
581 dev_err(&data->pdev->dev, "Unable to register hwmon " 577 dev_err(&data->pdev->dev, "Unable to register hwmon "
582 "device for IPMI interface %d\n", 578 "device for IPMI interface %d\n",
583 probe->interface); 579 probe->interface);
580 res = PTR_ERR(data->hwmon_dev);
584 goto hwmon_reg_err; 581 goto hwmon_reg_err;
585 } 582 }
586 583
587 data->update = update_aem1_sensors; 584 data->update = update_aem1_sensors;
585 data->rs_resp = kzalloc(sizeof(*(data->rs_resp)) + 8, GFP_KERNEL);
586 if (!data->rs_resp) {
587 res = -ENOMEM;
588 goto alloc_resp_err;
589 }
588 590
589 /* Find sensors */ 591 /* Find sensors */
590 if (aem1_find_sensors(data)) 592 res = aem1_find_sensors(data);
593 if (res)
591 goto sensor_err; 594 goto sensor_err;
592 595
593 /* Add to our list of AEM devices */ 596 /* Add to our list of AEM devices */
@@ -599,6 +602,8 @@ static int aem_init_aem1_inst(struct aem_ipmi_data *probe, u8 module_handle)
599 return 0; 602 return 0;
600 603
601sensor_err: 604sensor_err:
605 kfree(data->rs_resp);
606alloc_resp_err:
602 hwmon_device_unregister(data->hwmon_dev); 607 hwmon_device_unregister(data->hwmon_dev);
603hwmon_reg_err: 608hwmon_reg_err:
604 ipmi_destroy_user(data->ipmi.user); 609 ipmi_destroy_user(data->ipmi.user);
@@ -614,7 +619,7 @@ id_err:
614} 619}
615 620
616/* Find and initialize all AEM1 instances */ 621/* Find and initialize all AEM1 instances */
617static int aem_init_aem1(struct aem_ipmi_data *probe) 622static void aem_init_aem1(struct aem_ipmi_data *probe)
618{ 623{
619 int num, i, err; 624 int num, i, err;
620 625
@@ -625,11 +630,8 @@ static int aem_init_aem1(struct aem_ipmi_data *probe)
625 dev_err(probe->bmc_device, 630 dev_err(probe->bmc_device,
626 "Error %d initializing AEM1 0x%X\n", 631 "Error %d initializing AEM1 0x%X\n",
627 err, i); 632 err, i);
628 return err;
629 } 633 }
630 } 634 }
631
632 return 0;
633} 635}
634 636
635/* Probe functions for AEM2 devices */ 637/* Probe functions for AEM2 devices */
@@ -704,24 +706,31 @@ static int aem_init_aem2_inst(struct aem_ipmi_data *probe,
704 platform_set_drvdata(data->pdev, data); 706 platform_set_drvdata(data->pdev, data);
705 707
706 /* Set up IPMI interface */ 708 /* Set up IPMI interface */
707 if (aem_init_ipmi_data(&data->ipmi, probe->interface, 709 res = aem_init_ipmi_data(&data->ipmi, probe->interface,
708 probe->bmc_device)) 710 probe->bmc_device);
711 if (res)
709 goto ipmi_err; 712 goto ipmi_err;
710 713
711 /* Register with hwmon */ 714 /* Register with hwmon */
712 data->hwmon_dev = hwmon_device_register(&data->pdev->dev); 715 data->hwmon_dev = hwmon_device_register(&data->pdev->dev);
713
714 if (IS_ERR(data->hwmon_dev)) { 716 if (IS_ERR(data->hwmon_dev)) {
715 dev_err(&data->pdev->dev, "Unable to register hwmon " 717 dev_err(&data->pdev->dev, "Unable to register hwmon "
716 "device for IPMI interface %d\n", 718 "device for IPMI interface %d\n",
717 probe->interface); 719 probe->interface);
720 res = PTR_ERR(data->hwmon_dev);
718 goto hwmon_reg_err; 721 goto hwmon_reg_err;
719 } 722 }
720 723
721 data->update = update_aem2_sensors; 724 data->update = update_aem2_sensors;
725 data->rs_resp = kzalloc(sizeof(*(data->rs_resp)) + 8, GFP_KERNEL);
726 if (!data->rs_resp) {
727 res = -ENOMEM;
728 goto alloc_resp_err;
729 }
722 730
723 /* Find sensors */ 731 /* Find sensors */
724 if (aem2_find_sensors(data)) 732 res = aem2_find_sensors(data);
733 if (res)
725 goto sensor_err; 734 goto sensor_err;
726 735
727 /* Add to our list of AEM devices */ 736 /* Add to our list of AEM devices */
@@ -733,6 +742,8 @@ static int aem_init_aem2_inst(struct aem_ipmi_data *probe,
733 return 0; 742 return 0;
734 743
735sensor_err: 744sensor_err:
745 kfree(data->rs_resp);
746alloc_resp_err:
736 hwmon_device_unregister(data->hwmon_dev); 747 hwmon_device_unregister(data->hwmon_dev);
737hwmon_reg_err: 748hwmon_reg_err:
738 ipmi_destroy_user(data->ipmi.user); 749 ipmi_destroy_user(data->ipmi.user);
@@ -748,7 +759,7 @@ id_err:
748} 759}
749 760
750/* Find and initialize all AEM2 instances */ 761/* Find and initialize all AEM2 instances */
751static int aem_init_aem2(struct aem_ipmi_data *probe) 762static void aem_init_aem2(struct aem_ipmi_data *probe)
752{ 763{
753 struct aem_find_instance_resp fi_resp; 764 struct aem_find_instance_resp fi_resp;
754 int err; 765 int err;
@@ -767,12 +778,9 @@ static int aem_init_aem2(struct aem_ipmi_data *probe)
767 dev_err(probe->bmc_device, 778 dev_err(probe->bmc_device,
768 "Error %d initializing AEM2 0x%X\n", 779 "Error %d initializing AEM2 0x%X\n",
769 err, fi_resp.module_handle); 780 err, fi_resp.module_handle);
770 return err;
771 } 781 }
772 i++; 782 i++;
773 } 783 }
774
775 return 0;
776} 784}
777 785
778/* Probe a BMC for AEM firmware instances */ 786/* Probe a BMC for AEM firmware instances */
diff --git a/drivers/hwmon/jc42.c b/drivers/hwmon/jc42.c
index 02cebb74e206..2d3d72805ff4 100644
--- a/drivers/hwmon/jc42.c
+++ b/drivers/hwmon/jc42.c
@@ -154,8 +154,6 @@ static int jc42_probe(struct i2c_client *client,
154 const struct i2c_device_id *id); 154 const struct i2c_device_id *id);
155static int jc42_detect(struct i2c_client *client, struct i2c_board_info *info); 155static int jc42_detect(struct i2c_client *client, struct i2c_board_info *info);
156static int jc42_remove(struct i2c_client *client); 156static int jc42_remove(struct i2c_client *client);
157static int jc42_read_value(struct i2c_client *client, u8 reg);
158static int jc42_write_value(struct i2c_client *client, u8 reg, u16 value);
159 157
160static struct jc42_data *jc42_update_device(struct device *dev); 158static struct jc42_data *jc42_update_device(struct device *dev);
161 159
@@ -187,7 +185,7 @@ static int jc42_suspend(struct device *dev)
187 struct jc42_data *data = i2c_get_clientdata(client); 185 struct jc42_data *data = i2c_get_clientdata(client);
188 186
189 data->config |= JC42_CFG_SHUTDOWN; 187 data->config |= JC42_CFG_SHUTDOWN;
190 jc42_write_value(client, JC42_REG_CONFIG, data->config); 188 i2c_smbus_write_word_swapped(client, JC42_REG_CONFIG, data->config);
191 return 0; 189 return 0;
192} 190}
193 191
@@ -197,7 +195,7 @@ static int jc42_resume(struct device *dev)
197 struct jc42_data *data = i2c_get_clientdata(client); 195 struct jc42_data *data = i2c_get_clientdata(client);
198 196
199 data->config &= ~JC42_CFG_SHUTDOWN; 197 data->config &= ~JC42_CFG_SHUTDOWN;
200 jc42_write_value(client, JC42_REG_CONFIG, data->config); 198 i2c_smbus_write_word_swapped(client, JC42_REG_CONFIG, data->config);
201 return 0; 199 return 0;
202} 200}
203 201
@@ -315,7 +313,7 @@ static ssize_t set_##value(struct device *dev, \
315 return -EINVAL; \ 313 return -EINVAL; \
316 mutex_lock(&data->update_lock); \ 314 mutex_lock(&data->update_lock); \
317 data->value = jc42_temp_to_reg(val, data->extended); \ 315 data->value = jc42_temp_to_reg(val, data->extended); \
318 err = jc42_write_value(client, reg, data->value); \ 316 err = i2c_smbus_write_word_swapped(client, reg, data->value); \
319 if (err < 0) \ 317 if (err < 0) \
320 ret = err; \ 318 ret = err; \
321 mutex_unlock(&data->update_lock); \ 319 mutex_unlock(&data->update_lock); \
@@ -357,7 +355,8 @@ static ssize_t set_temp_crit_hyst(struct device *dev,
357 data->config = (data->config 355 data->config = (data->config
358 & ~(JC42_CFG_HYST_MASK << JC42_CFG_HYST_SHIFT)) 356 & ~(JC42_CFG_HYST_MASK << JC42_CFG_HYST_SHIFT))
359 | (hyst << JC42_CFG_HYST_SHIFT); 357 | (hyst << JC42_CFG_HYST_SHIFT);
360 err = jc42_write_value(client, JC42_REG_CONFIG, data->config); 358 err = i2c_smbus_write_word_swapped(client, JC42_REG_CONFIG,
359 data->config);
361 if (err < 0) 360 if (err < 0)
362 ret = err; 361 ret = err;
363 mutex_unlock(&data->update_lock); 362 mutex_unlock(&data->update_lock);
@@ -452,10 +451,10 @@ static int jc42_detect(struct i2c_client *new_client,
452 I2C_FUNC_SMBUS_WORD_DATA)) 451 I2C_FUNC_SMBUS_WORD_DATA))
453 return -ENODEV; 452 return -ENODEV;
454 453
455 cap = jc42_read_value(new_client, JC42_REG_CAP); 454 cap = i2c_smbus_read_word_swapped(new_client, JC42_REG_CAP);
456 config = jc42_read_value(new_client, JC42_REG_CONFIG); 455 config = i2c_smbus_read_word_swapped(new_client, JC42_REG_CONFIG);
457 manid = jc42_read_value(new_client, JC42_REG_MANID); 456 manid = i2c_smbus_read_word_swapped(new_client, JC42_REG_MANID);
458 devid = jc42_read_value(new_client, JC42_REG_DEVICEID); 457 devid = i2c_smbus_read_word_swapped(new_client, JC42_REG_DEVICEID);
459 458
460 if (cap < 0 || config < 0 || manid < 0 || devid < 0) 459 if (cap < 0 || config < 0 || manid < 0 || devid < 0)
461 return -ENODEV; 460 return -ENODEV;
@@ -489,14 +488,14 @@ static int jc42_probe(struct i2c_client *new_client,
489 i2c_set_clientdata(new_client, data); 488 i2c_set_clientdata(new_client, data);
490 mutex_init(&data->update_lock); 489 mutex_init(&data->update_lock);
491 490
492 cap = jc42_read_value(new_client, JC42_REG_CAP); 491 cap = i2c_smbus_read_word_swapped(new_client, JC42_REG_CAP);
493 if (cap < 0) { 492 if (cap < 0) {
494 err = -EINVAL; 493 err = -EINVAL;
495 goto exit_free; 494 goto exit_free;
496 } 495 }
497 data->extended = !!(cap & JC42_CAP_RANGE); 496 data->extended = !!(cap & JC42_CAP_RANGE);
498 497
499 config = jc42_read_value(new_client, JC42_REG_CONFIG); 498 config = i2c_smbus_read_word_swapped(new_client, JC42_REG_CONFIG);
500 if (config < 0) { 499 if (config < 0) {
501 err = -EINVAL; 500 err = -EINVAL;
502 goto exit_free; 501 goto exit_free;
@@ -504,7 +503,8 @@ static int jc42_probe(struct i2c_client *new_client,
504 data->orig_config = config; 503 data->orig_config = config;
505 if (config & JC42_CFG_SHUTDOWN) { 504 if (config & JC42_CFG_SHUTDOWN) {
506 config &= ~JC42_CFG_SHUTDOWN; 505 config &= ~JC42_CFG_SHUTDOWN;
507 jc42_write_value(new_client, JC42_REG_CONFIG, config); 506 i2c_smbus_write_word_swapped(new_client, JC42_REG_CONFIG,
507 config);
508 } 508 }
509 data->config = config; 509 data->config = config;
510 510
@@ -535,25 +535,12 @@ static int jc42_remove(struct i2c_client *client)
535 hwmon_device_unregister(data->hwmon_dev); 535 hwmon_device_unregister(data->hwmon_dev);
536 sysfs_remove_group(&client->dev.kobj, &jc42_group); 536 sysfs_remove_group(&client->dev.kobj, &jc42_group);
537 if (data->config != data->orig_config) 537 if (data->config != data->orig_config)
538 jc42_write_value(client, JC42_REG_CONFIG, data->orig_config); 538 i2c_smbus_write_word_swapped(client, JC42_REG_CONFIG,
539 data->orig_config);
539 kfree(data); 540 kfree(data);
540 return 0; 541 return 0;
541} 542}
542 543
543/* All registers are word-sized. */
544static int jc42_read_value(struct i2c_client *client, u8 reg)
545{
546 int ret = i2c_smbus_read_word_data(client, reg);
547 if (ret < 0)
548 return ret;
549 return swab16(ret);
550}
551
552static int jc42_write_value(struct i2c_client *client, u8 reg, u16 value)
553{
554 return i2c_smbus_write_word_data(client, reg, swab16(value));
555}
556
557static struct jc42_data *jc42_update_device(struct device *dev) 544static struct jc42_data *jc42_update_device(struct device *dev)
558{ 545{
559 struct i2c_client *client = to_i2c_client(dev); 546 struct i2c_client *client = to_i2c_client(dev);
@@ -564,28 +551,29 @@ static struct jc42_data *jc42_update_device(struct device *dev)
564 mutex_lock(&data->update_lock); 551 mutex_lock(&data->update_lock);
565 552
566 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { 553 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
567 val = jc42_read_value(client, JC42_REG_TEMP); 554 val = i2c_smbus_read_word_swapped(client, JC42_REG_TEMP);
568 if (val < 0) { 555 if (val < 0) {
569 ret = ERR_PTR(val); 556 ret = ERR_PTR(val);
570 goto abort; 557 goto abort;
571 } 558 }
572 data->temp_input = val; 559 data->temp_input = val;
573 560
574 val = jc42_read_value(client, JC42_REG_TEMP_CRITICAL); 561 val = i2c_smbus_read_word_swapped(client,
562 JC42_REG_TEMP_CRITICAL);
575 if (val < 0) { 563 if (val < 0) {
576 ret = ERR_PTR(val); 564 ret = ERR_PTR(val);
577 goto abort; 565 goto abort;
578 } 566 }
579 data->temp_crit = val; 567 data->temp_crit = val;
580 568
581 val = jc42_read_value(client, JC42_REG_TEMP_LOWER); 569 val = i2c_smbus_read_word_swapped(client, JC42_REG_TEMP_LOWER);
582 if (val < 0) { 570 if (val < 0) {
583 ret = ERR_PTR(val); 571 ret = ERR_PTR(val);
584 goto abort; 572 goto abort;
585 } 573 }
586 data->temp_min = val; 574 data->temp_min = val;
587 575
588 val = jc42_read_value(client, JC42_REG_TEMP_UPPER); 576 val = i2c_smbus_read_word_swapped(client, JC42_REG_TEMP_UPPER);
589 if (val < 0) { 577 if (val < 0) {
590 ret = ERR_PTR(val); 578 ret = ERR_PTR(val);
591 goto abort; 579 goto abort;
diff --git a/drivers/hwmon/lm73.c b/drivers/hwmon/lm73.c
index 29b9030d42c3..9e64d96620d3 100644
--- a/drivers/hwmon/lm73.c
+++ b/drivers/hwmon/lm73.c
@@ -34,7 +34,7 @@ static const unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4c,
34#define LM73_REG_CTRL 0x04 34#define LM73_REG_CTRL 0x04
35#define LM73_REG_ID 0x07 35#define LM73_REG_ID 0x07
36 36
37#define LM73_ID 0x9001 /* or 0x190 after a swab16() */ 37#define LM73_ID 0x9001 /* 0x0190, byte-swapped */
38#define DRVNAME "lm73" 38#define DRVNAME "lm73"
39#define LM73_TEMP_MIN (-40) 39#define LM73_TEMP_MIN (-40)
40#define LM73_TEMP_MAX 150 40#define LM73_TEMP_MAX 150
@@ -57,7 +57,7 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *da,
57 /* Write value */ 57 /* Write value */
58 value = (short) SENSORS_LIMIT(temp/250, (LM73_TEMP_MIN*4), 58 value = (short) SENSORS_LIMIT(temp/250, (LM73_TEMP_MIN*4),
59 (LM73_TEMP_MAX*4)) << 5; 59 (LM73_TEMP_MAX*4)) << 5;
60 i2c_smbus_write_word_data(client, attr->index, swab16(value)); 60 i2c_smbus_write_word_swapped(client, attr->index, value);
61 return count; 61 return count;
62} 62}
63 63
@@ -68,8 +68,8 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *da,
68 struct i2c_client *client = to_i2c_client(dev); 68 struct i2c_client *client = to_i2c_client(dev);
69 /* use integer division instead of equivalent right shift to 69 /* use integer division instead of equivalent right shift to
70 guarantee arithmetic shift and preserve the sign */ 70 guarantee arithmetic shift and preserve the sign */
71 int temp = ((s16) (swab16(i2c_smbus_read_word_data(client, 71 int temp = ((s16) (i2c_smbus_read_word_swapped(client,
72 attr->index)))*250) / 32; 72 attr->index))*250) / 32;
73 return sprintf(buf, "%d\n", temp); 73 return sprintf(buf, "%d\n", temp);
74} 74}
75 75
@@ -150,17 +150,31 @@ static int lm73_detect(struct i2c_client *new_client,
150 struct i2c_board_info *info) 150 struct i2c_board_info *info)
151{ 151{
152 struct i2c_adapter *adapter = new_client->adapter; 152 struct i2c_adapter *adapter = new_client->adapter;
153 u16 id; 153 int id, ctrl, conf;
154 u8 ctrl;
155 154
156 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | 155 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
157 I2C_FUNC_SMBUS_WORD_DATA)) 156 I2C_FUNC_SMBUS_WORD_DATA))
158 return -ENODEV; 157 return -ENODEV;
159 158
159 /*
160 * Do as much detection as possible with byte reads first, as word
161 * reads can confuse other devices.
162 */
163 ctrl = i2c_smbus_read_byte_data(new_client, LM73_REG_CTRL);
164 if (ctrl < 0 || (ctrl & 0x10))
165 return -ENODEV;
166
167 conf = i2c_smbus_read_byte_data(new_client, LM73_REG_CONF);
168 if (conf < 0 || (conf & 0x0c))
169 return -ENODEV;
170
171 id = i2c_smbus_read_byte_data(new_client, LM73_REG_ID);
172 if (id < 0 || id != (LM73_ID & 0xff))
173 return -ENODEV;
174
160 /* Check device ID */ 175 /* Check device ID */
161 id = i2c_smbus_read_word_data(new_client, LM73_REG_ID); 176 id = i2c_smbus_read_word_data(new_client, LM73_REG_ID);
162 ctrl = i2c_smbus_read_byte_data(new_client, LM73_REG_CTRL); 177 if (id < 0 || id != LM73_ID)
163 if ((id != LM73_ID) || (ctrl & 0x10))
164 return -ENODEV; 178 return -ENODEV;
165 179
166 strlcpy(info->type, "lm73", I2C_NAME_SIZE); 180 strlcpy(info->type, "lm73", I2C_NAME_SIZE);
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
index 90126a2a1e44..1888dd0fc05f 100644
--- a/drivers/hwmon/lm75.c
+++ b/drivers/hwmon/lm75.c
@@ -384,13 +384,10 @@ static struct i2c_driver lm75_driver = {
384 */ 384 */
385static int lm75_read_value(struct i2c_client *client, u8 reg) 385static int lm75_read_value(struct i2c_client *client, u8 reg)
386{ 386{
387 int value;
388
389 if (reg == LM75_REG_CONF) 387 if (reg == LM75_REG_CONF)
390 return i2c_smbus_read_byte_data(client, reg); 388 return i2c_smbus_read_byte_data(client, reg);
391 389 else
392 value = i2c_smbus_read_word_data(client, reg); 390 return i2c_smbus_read_word_swapped(client, reg);
393 return (value < 0) ? value : swab16(value);
394} 391}
395 392
396static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value) 393static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value)
@@ -398,7 +395,7 @@ static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value)
398 if (reg == LM75_REG_CONF) 395 if (reg == LM75_REG_CONF)
399 return i2c_smbus_write_byte_data(client, reg, value); 396 return i2c_smbus_write_byte_data(client, reg, value);
400 else 397 else
401 return i2c_smbus_write_word_data(client, reg, swab16(value)); 398 return i2c_smbus_write_word_swapped(client, reg, value);
402} 399}
403 400
404static struct lm75_data *lm75_update_device(struct device *dev) 401static struct lm75_data *lm75_update_device(struct device *dev)
diff --git a/drivers/hwmon/lm77.c b/drivers/hwmon/lm77.c
index b28a297be50c..8dfc6782d596 100644
--- a/drivers/hwmon/lm77.c
+++ b/drivers/hwmon/lm77.c
@@ -365,7 +365,7 @@ static u16 lm77_read_value(struct i2c_client *client, u8 reg)
365 if (reg == LM77_REG_CONF) 365 if (reg == LM77_REG_CONF)
366 return i2c_smbus_read_byte_data(client, reg); 366 return i2c_smbus_read_byte_data(client, reg);
367 else 367 else
368 return swab16(i2c_smbus_read_word_data(client, reg)); 368 return i2c_smbus_read_word_swapped(client, reg);
369} 369}
370 370
371static int lm77_write_value(struct i2c_client *client, u8 reg, u16 value) 371static int lm77_write_value(struct i2c_client *client, u8 reg, u16 value)
@@ -373,7 +373,7 @@ static int lm77_write_value(struct i2c_client *client, u8 reg, u16 value)
373 if (reg == LM77_REG_CONF) 373 if (reg == LM77_REG_CONF)
374 return i2c_smbus_write_byte_data(client, reg, value); 374 return i2c_smbus_write_byte_data(client, reg, value);
375 else 375 else
376 return i2c_smbus_write_word_data(client, reg, swab16(value)); 376 return i2c_smbus_write_word_swapped(client, reg, value);
377} 377}
378 378
379static void lm77_init_client(struct i2c_client *client) 379static void lm77_init_client(struct i2c_client *client)
diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
index 90ddb8774210..615bc4f4e530 100644
--- a/drivers/hwmon/lm90.c
+++ b/drivers/hwmon/lm90.c
@@ -1105,41 +1105,37 @@ static DEVICE_ATTR(pec, S_IWUSR | S_IRUGO, show_pec, set_pec);
1105 */ 1105 */
1106 1106
1107/* Return 0 if detection is successful, -ENODEV otherwise */ 1107/* Return 0 if detection is successful, -ENODEV otherwise */
1108static int lm90_detect(struct i2c_client *new_client, 1108static int lm90_detect(struct i2c_client *client,
1109 struct i2c_board_info *info) 1109 struct i2c_board_info *info)
1110{ 1110{
1111 struct i2c_adapter *adapter = new_client->adapter; 1111 struct i2c_adapter *adapter = client->adapter;
1112 int address = new_client->addr; 1112 int address = client->addr;
1113 const char *name = NULL; 1113 const char *name = NULL;
1114 int man_id, chip_id, reg_config1, reg_config2, reg_convrate; 1114 int man_id, chip_id, config1, config2, convrate;
1115 1115
1116 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 1116 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1117 return -ENODEV; 1117 return -ENODEV;
1118 1118
1119 /* detection and identification */ 1119 /* detection and identification */
1120 if ((man_id = i2c_smbus_read_byte_data(new_client, 1120 man_id = i2c_smbus_read_byte_data(client, LM90_REG_R_MAN_ID);
1121 LM90_REG_R_MAN_ID)) < 0 1121 chip_id = i2c_smbus_read_byte_data(client, LM90_REG_R_CHIP_ID);
1122 || (chip_id = i2c_smbus_read_byte_data(new_client, 1122 config1 = i2c_smbus_read_byte_data(client, LM90_REG_R_CONFIG1);
1123 LM90_REG_R_CHIP_ID)) < 0 1123 convrate = i2c_smbus_read_byte_data(client, LM90_REG_R_CONVRATE);
1124 || (reg_config1 = i2c_smbus_read_byte_data(new_client, 1124 if (man_id < 0 || chip_id < 0 || config1 < 0 || convrate < 0)
1125 LM90_REG_R_CONFIG1)) < 0
1126 || (reg_convrate = i2c_smbus_read_byte_data(new_client,
1127 LM90_REG_R_CONVRATE)) < 0)
1128 return -ENODEV; 1125 return -ENODEV;
1129 1126
1130 if (man_id == 0x01 || man_id == 0x5C || man_id == 0x41) { 1127 if (man_id == 0x01 || man_id == 0x5C || man_id == 0x41) {
1131 reg_config2 = i2c_smbus_read_byte_data(new_client, 1128 config2 = i2c_smbus_read_byte_data(client, LM90_REG_R_CONFIG2);
1132 LM90_REG_R_CONFIG2); 1129 if (config2 < 0)
1133 if (reg_config2 < 0)
1134 return -ENODEV; 1130 return -ENODEV;
1135 } else 1131 } else
1136 reg_config2 = 0; /* Make compiler happy */ 1132 config2 = 0; /* Make compiler happy */
1137 1133
1138 if ((address == 0x4C || address == 0x4D) 1134 if ((address == 0x4C || address == 0x4D)
1139 && man_id == 0x01) { /* National Semiconductor */ 1135 && man_id == 0x01) { /* National Semiconductor */
1140 if ((reg_config1 & 0x2A) == 0x00 1136 if ((config1 & 0x2A) == 0x00
1141 && (reg_config2 & 0xF8) == 0x00 1137 && (config2 & 0xF8) == 0x00
1142 && reg_convrate <= 0x09) { 1138 && convrate <= 0x09) {
1143 if (address == 0x4C 1139 if (address == 0x4C
1144 && (chip_id & 0xF0) == 0x20) { /* LM90 */ 1140 && (chip_id & 0xF0) == 0x20) { /* LM90 */
1145 name = "lm90"; 1141 name = "lm90";
@@ -1163,8 +1159,8 @@ static int lm90_detect(struct i2c_client *new_client,
1163 if ((address == 0x4C || address == 0x4D) 1159 if ((address == 0x4C || address == 0x4D)
1164 && man_id == 0x41) { /* Analog Devices */ 1160 && man_id == 0x41) { /* Analog Devices */
1165 if ((chip_id & 0xF0) == 0x40 /* ADM1032 */ 1161 if ((chip_id & 0xF0) == 0x40 /* ADM1032 */
1166 && (reg_config1 & 0x3F) == 0x00 1162 && (config1 & 0x3F) == 0x00
1167 && reg_convrate <= 0x0A) { 1163 && convrate <= 0x0A) {
1168 name = "adm1032"; 1164 name = "adm1032";
1169 /* The ADM1032 supports PEC, but only if combined 1165 /* The ADM1032 supports PEC, but only if combined
1170 transactions are not used. */ 1166 transactions are not used. */
@@ -1173,18 +1169,18 @@ static int lm90_detect(struct i2c_client *new_client,
1173 info->flags |= I2C_CLIENT_PEC; 1169 info->flags |= I2C_CLIENT_PEC;
1174 } else 1170 } else
1175 if (chip_id == 0x51 /* ADT7461 */ 1171 if (chip_id == 0x51 /* ADT7461 */
1176 && (reg_config1 & 0x1B) == 0x00 1172 && (config1 & 0x1B) == 0x00
1177 && reg_convrate <= 0x0A) { 1173 && convrate <= 0x0A) {
1178 name = "adt7461"; 1174 name = "adt7461";
1179 } else 1175 } else
1180 if (chip_id == 0x57 /* ADT7461A, NCT1008 */ 1176 if (chip_id == 0x57 /* ADT7461A, NCT1008 */
1181 && (reg_config1 & 0x1B) == 0x00 1177 && (config1 & 0x1B) == 0x00
1182 && reg_convrate <= 0x0A) { 1178 && convrate <= 0x0A) {
1183 name = "adt7461a"; 1179 name = "adt7461a";
1184 } 1180 }
1185 } else 1181 } else
1186 if (man_id == 0x4D) { /* Maxim */ 1182 if (man_id == 0x4D) { /* Maxim */
1187 int reg_emerg, reg_emerg2, reg_status2; 1183 int emerg, emerg2, status2;
1188 1184
1189 /* 1185 /*
1190 * We read MAX6659_REG_R_REMOTE_EMERG twice, and re-read 1186 * We read MAX6659_REG_R_REMOTE_EMERG twice, and re-read
@@ -1192,13 +1188,15 @@ static int lm90_detect(struct i2c_client *new_client,
1192 * exists, both readings will reflect the same value. Otherwise, 1188 * exists, both readings will reflect the same value. Otherwise,
1193 * the readings will be different. 1189 * the readings will be different.
1194 */ 1190 */
1195 if ((reg_emerg = i2c_smbus_read_byte_data(new_client, 1191 emerg = i2c_smbus_read_byte_data(client,
1196 MAX6659_REG_R_REMOTE_EMERG)) < 0 1192 MAX6659_REG_R_REMOTE_EMERG);
1197 || i2c_smbus_read_byte_data(new_client, LM90_REG_R_MAN_ID) < 0 1193 man_id = i2c_smbus_read_byte_data(client,
1198 || (reg_emerg2 = i2c_smbus_read_byte_data(new_client, 1194 LM90_REG_R_MAN_ID);
1199 MAX6659_REG_R_REMOTE_EMERG)) < 0 1195 emerg2 = i2c_smbus_read_byte_data(client,
1200 || (reg_status2 = i2c_smbus_read_byte_data(new_client, 1196 MAX6659_REG_R_REMOTE_EMERG);
1201 MAX6696_REG_R_STATUS2)) < 0) 1197 status2 = i2c_smbus_read_byte_data(client,
1198 MAX6696_REG_R_STATUS2);
1199 if (emerg < 0 || man_id < 0 || emerg2 < 0 || status2 < 0)
1202 return -ENODEV; 1200 return -ENODEV;
1203 1201
1204 /* 1202 /*
@@ -1216,8 +1214,8 @@ static int lm90_detect(struct i2c_client *new_client,
1216 */ 1214 */
1217 if (chip_id == man_id 1215 if (chip_id == man_id
1218 && (address == 0x4C || address == 0x4D || address == 0x4E) 1216 && (address == 0x4C || address == 0x4D || address == 0x4E)
1219 && (reg_config1 & 0x1F) == (man_id & 0x0F) 1217 && (config1 & 0x1F) == (man_id & 0x0F)
1220 && reg_convrate <= 0x09) { 1218 && convrate <= 0x09) {
1221 if (address == 0x4C) 1219 if (address == 0x4C)
1222 name = "max6657"; 1220 name = "max6657";
1223 else 1221 else
@@ -1235,10 +1233,10 @@ static int lm90_detect(struct i2c_client *new_client,
1235 * one of those registers exists. 1233 * one of those registers exists.
1236 */ 1234 */
1237 if (chip_id == 0x01 1235 if (chip_id == 0x01
1238 && (reg_config1 & 0x10) == 0x00 1236 && (config1 & 0x10) == 0x00
1239 && (reg_status2 & 0x01) == 0x00 1237 && (status2 & 0x01) == 0x00
1240 && reg_emerg == reg_emerg2 1238 && emerg == emerg2
1241 && reg_convrate <= 0x07) { 1239 && convrate <= 0x07) {
1242 name = "max6696"; 1240 name = "max6696";
1243 } else 1241 } else
1244 /* 1242 /*
@@ -1248,8 +1246,8 @@ static int lm90_detect(struct i2c_client *new_client,
1248 * second to last bit of config1 (software reset). 1246 * second to last bit of config1 (software reset).
1249 */ 1247 */
1250 if (chip_id == 0x01 1248 if (chip_id == 0x01
1251 && (reg_config1 & 0x03) == 0x00 1249 && (config1 & 0x03) == 0x00
1252 && reg_convrate <= 0x07) { 1250 && convrate <= 0x07) {
1253 name = "max6680"; 1251 name = "max6680";
1254 } else 1252 } else
1255 /* 1253 /*
@@ -1258,21 +1256,21 @@ static int lm90_detect(struct i2c_client *new_client,
1258 * register are unused and should return zero when read. 1256 * register are unused and should return zero when read.
1259 */ 1257 */
1260 if (chip_id == 0x59 1258 if (chip_id == 0x59
1261 && (reg_config1 & 0x3f) == 0x00 1259 && (config1 & 0x3f) == 0x00
1262 && reg_convrate <= 0x07) { 1260 && convrate <= 0x07) {
1263 name = "max6646"; 1261 name = "max6646";
1264 } 1262 }
1265 } else 1263 } else
1266 if (address == 0x4C 1264 if (address == 0x4C
1267 && man_id == 0x5C) { /* Winbond/Nuvoton */ 1265 && man_id == 0x5C) { /* Winbond/Nuvoton */
1268 if ((reg_config1 & 0x2A) == 0x00 1266 if ((config1 & 0x2A) == 0x00
1269 && (reg_config2 & 0xF8) == 0x00) { 1267 && (config2 & 0xF8) == 0x00) {
1270 if (chip_id == 0x01 /* W83L771W/G */ 1268 if (chip_id == 0x01 /* W83L771W/G */
1271 && reg_convrate <= 0x09) { 1269 && convrate <= 0x09) {
1272 name = "w83l771"; 1270 name = "w83l771";
1273 } else 1271 } else
1274 if ((chip_id & 0xFE) == 0x10 /* W83L771AWG/ASG */ 1272 if ((chip_id & 0xFE) == 0x10 /* W83L771AWG/ASG */
1275 && reg_convrate <= 0x08) { 1273 && convrate <= 0x08) {
1276 name = "w83l771"; 1274 name = "w83l771";
1277 } 1275 }
1278 } 1276 }
@@ -1280,9 +1278,9 @@ static int lm90_detect(struct i2c_client *new_client,
1280 if (address >= 0x48 && address <= 0x4F 1278 if (address >= 0x48 && address <= 0x4F
1281 && man_id == 0xA1) { /* NXP Semiconductor/Philips */ 1279 && man_id == 0xA1) { /* NXP Semiconductor/Philips */
1282 if (chip_id == 0x00 1280 if (chip_id == 0x00
1283 && (reg_config1 & 0x2A) == 0x00 1281 && (config1 & 0x2A) == 0x00
1284 && (reg_config2 & 0xFE) == 0x00 1282 && (config2 & 0xFE) == 0x00
1285 && reg_convrate <= 0x09) { 1283 && convrate <= 0x09) {
1286 name = "sa56004"; 1284 name = "sa56004";
1287 } 1285 }
1288 } 1286 }
@@ -1301,19 +1299,18 @@ static int lm90_detect(struct i2c_client *new_client,
1301 1299
1302static void lm90_remove_files(struct i2c_client *client, struct lm90_data *data) 1300static void lm90_remove_files(struct i2c_client *client, struct lm90_data *data)
1303{ 1301{
1302 struct device *dev = &client->dev;
1303
1304 if (data->flags & LM90_HAVE_TEMP3) 1304 if (data->flags & LM90_HAVE_TEMP3)
1305 sysfs_remove_group(&client->dev.kobj, &lm90_temp3_group); 1305 sysfs_remove_group(&dev->kobj, &lm90_temp3_group);
1306 if (data->flags & LM90_HAVE_EMERGENCY_ALARM) 1306 if (data->flags & LM90_HAVE_EMERGENCY_ALARM)
1307 sysfs_remove_group(&client->dev.kobj, 1307 sysfs_remove_group(&dev->kobj, &lm90_emergency_alarm_group);
1308 &lm90_emergency_alarm_group);
1309 if (data->flags & LM90_HAVE_EMERGENCY) 1308 if (data->flags & LM90_HAVE_EMERGENCY)
1310 sysfs_remove_group(&client->dev.kobj, 1309 sysfs_remove_group(&dev->kobj, &lm90_emergency_group);
1311 &lm90_emergency_group);
1312 if (data->flags & LM90_HAVE_OFFSET) 1310 if (data->flags & LM90_HAVE_OFFSET)
1313 device_remove_file(&client->dev, 1311 device_remove_file(dev, &sensor_dev_attr_temp2_offset.dev_attr);
1314 &sensor_dev_attr_temp2_offset.dev_attr); 1312 device_remove_file(dev, &dev_attr_pec);
1315 device_remove_file(&client->dev, &dev_attr_pec); 1313 sysfs_remove_group(&dev->kobj, &lm90_group);
1316 sysfs_remove_group(&client->dev.kobj, &lm90_group);
1317} 1314}
1318 1315
1319static void lm90_init_client(struct i2c_client *client) 1316static void lm90_init_client(struct i2c_client *client)
@@ -1362,10 +1359,11 @@ static void lm90_init_client(struct i2c_client *client)
1362 i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config); 1359 i2c_smbus_write_byte_data(client, LM90_REG_W_CONFIG1, config);
1363} 1360}
1364 1361
1365static int lm90_probe(struct i2c_client *new_client, 1362static int lm90_probe(struct i2c_client *client,
1366 const struct i2c_device_id *id) 1363 const struct i2c_device_id *id)
1367{ 1364{
1368 struct i2c_adapter *adapter = to_i2c_adapter(new_client->dev.parent); 1365 struct device *dev = &client->dev;
1366 struct i2c_adapter *adapter = to_i2c_adapter(dev->parent);
1369 struct lm90_data *data; 1367 struct lm90_data *data;
1370 int err; 1368 int err;
1371 1369
@@ -1374,14 +1372,14 @@ static int lm90_probe(struct i2c_client *new_client,
1374 err = -ENOMEM; 1372 err = -ENOMEM;
1375 goto exit; 1373 goto exit;
1376 } 1374 }
1377 i2c_set_clientdata(new_client, data); 1375 i2c_set_clientdata(client, data);
1378 mutex_init(&data->update_lock); 1376 mutex_init(&data->update_lock);
1379 1377
1380 /* Set the device type */ 1378 /* Set the device type */
1381 data->kind = id->driver_data; 1379 data->kind = id->driver_data;
1382 if (data->kind == adm1032) { 1380 if (data->kind == adm1032) {
1383 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) 1381 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE))
1384 new_client->flags &= ~I2C_CLIENT_PEC; 1382 client->flags &= ~I2C_CLIENT_PEC;
1385 } 1383 }
1386 1384
1387 /* Different devices have different alarm bits triggering the 1385 /* Different devices have different alarm bits triggering the
@@ -1396,43 +1394,41 @@ static int lm90_probe(struct i2c_client *new_client,
1396 data->max_convrate = lm90_params[data->kind].max_convrate; 1394 data->max_convrate = lm90_params[data->kind].max_convrate;
1397 1395
1398 /* Initialize the LM90 chip */ 1396 /* Initialize the LM90 chip */
1399 lm90_init_client(new_client); 1397 lm90_init_client(client);
1400 1398
1401 /* Register sysfs hooks */ 1399 /* Register sysfs hooks */
1402 err = sysfs_create_group(&new_client->dev.kobj, &lm90_group); 1400 err = sysfs_create_group(&dev->kobj, &lm90_group);
1403 if (err) 1401 if (err)
1404 goto exit_free; 1402 goto exit_free;
1405 if (new_client->flags & I2C_CLIENT_PEC) { 1403 if (client->flags & I2C_CLIENT_PEC) {
1406 err = device_create_file(&new_client->dev, &dev_attr_pec); 1404 err = device_create_file(dev, &dev_attr_pec);
1407 if (err) 1405 if (err)
1408 goto exit_remove_files; 1406 goto exit_remove_files;
1409 } 1407 }
1410 if (data->flags & LM90_HAVE_OFFSET) { 1408 if (data->flags & LM90_HAVE_OFFSET) {
1411 err = device_create_file(&new_client->dev, 1409 err = device_create_file(dev,
1412 &sensor_dev_attr_temp2_offset.dev_attr); 1410 &sensor_dev_attr_temp2_offset.dev_attr);
1413 if (err) 1411 if (err)
1414 goto exit_remove_files; 1412 goto exit_remove_files;
1415 } 1413 }
1416 if (data->flags & LM90_HAVE_EMERGENCY) { 1414 if (data->flags & LM90_HAVE_EMERGENCY) {
1417 err = sysfs_create_group(&new_client->dev.kobj, 1415 err = sysfs_create_group(&dev->kobj, &lm90_emergency_group);
1418 &lm90_emergency_group);
1419 if (err) 1416 if (err)
1420 goto exit_remove_files; 1417 goto exit_remove_files;
1421 } 1418 }
1422 if (data->flags & LM90_HAVE_EMERGENCY_ALARM) { 1419 if (data->flags & LM90_HAVE_EMERGENCY_ALARM) {
1423 err = sysfs_create_group(&new_client->dev.kobj, 1420 err = sysfs_create_group(&dev->kobj,
1424 &lm90_emergency_alarm_group); 1421 &lm90_emergency_alarm_group);
1425 if (err) 1422 if (err)
1426 goto exit_remove_files; 1423 goto exit_remove_files;
1427 } 1424 }
1428 if (data->flags & LM90_HAVE_TEMP3) { 1425 if (data->flags & LM90_HAVE_TEMP3) {
1429 err = sysfs_create_group(&new_client->dev.kobj, 1426 err = sysfs_create_group(&dev->kobj, &lm90_temp3_group);
1430 &lm90_temp3_group);
1431 if (err) 1427 if (err)
1432 goto exit_remove_files; 1428 goto exit_remove_files;
1433 } 1429 }
1434 1430
1435 data->hwmon_dev = hwmon_device_register(&new_client->dev); 1431 data->hwmon_dev = hwmon_device_register(dev);
1436 if (IS_ERR(data->hwmon_dev)) { 1432 if (IS_ERR(data->hwmon_dev)) {
1437 err = PTR_ERR(data->hwmon_dev); 1433 err = PTR_ERR(data->hwmon_dev);
1438 goto exit_remove_files; 1434 goto exit_remove_files;
@@ -1441,7 +1437,7 @@ static int lm90_probe(struct i2c_client *new_client,
1441 return 0; 1437 return 0;
1442 1438
1443exit_remove_files: 1439exit_remove_files:
1444 lm90_remove_files(new_client, data); 1440 lm90_remove_files(client, data);
1445exit_free: 1441exit_free:
1446 kfree(data); 1442 kfree(data);
1447exit: 1443exit:
diff --git a/drivers/hwmon/lm92.c b/drivers/hwmon/lm92.c
index 7c31e6205f85..8fcbd4d422c5 100644
--- a/drivers/hwmon/lm92.c
+++ b/drivers/hwmon/lm92.c
@@ -117,16 +117,16 @@ static struct lm92_data *lm92_update_device(struct device *dev)
117 if (time_after(jiffies, data->last_updated + HZ) 117 if (time_after(jiffies, data->last_updated + HZ)
118 || !data->valid) { 118 || !data->valid) {
119 dev_dbg(&client->dev, "Updating lm92 data\n"); 119 dev_dbg(&client->dev, "Updating lm92 data\n");
120 data->temp1_input = swab16(i2c_smbus_read_word_data(client, 120 data->temp1_input = i2c_smbus_read_word_swapped(client,
121 LM92_REG_TEMP)); 121 LM92_REG_TEMP);
122 data->temp1_hyst = swab16(i2c_smbus_read_word_data(client, 122 data->temp1_hyst = i2c_smbus_read_word_swapped(client,
123 LM92_REG_TEMP_HYST)); 123 LM92_REG_TEMP_HYST);
124 data->temp1_crit = swab16(i2c_smbus_read_word_data(client, 124 data->temp1_crit = i2c_smbus_read_word_swapped(client,
125 LM92_REG_TEMP_CRIT)); 125 LM92_REG_TEMP_CRIT);
126 data->temp1_min = swab16(i2c_smbus_read_word_data(client, 126 data->temp1_min = i2c_smbus_read_word_swapped(client,
127 LM92_REG_TEMP_LOW)); 127 LM92_REG_TEMP_LOW);
128 data->temp1_max = swab16(i2c_smbus_read_word_data(client, 128 data->temp1_max = i2c_smbus_read_word_swapped(client,
129 LM92_REG_TEMP_HIGH)); 129 LM92_REG_TEMP_HIGH);
130 130
131 data->last_updated = jiffies; 131 data->last_updated = jiffies;
132 data->valid = 1; 132 data->valid = 1;
@@ -158,7 +158,7 @@ static ssize_t set_##value(struct device *dev, struct device_attribute *attr, co
158 \ 158 \
159 mutex_lock(&data->update_lock); \ 159 mutex_lock(&data->update_lock); \
160 data->value = TEMP_TO_REG(val); \ 160 data->value = TEMP_TO_REG(val); \
161 i2c_smbus_write_word_data(client, reg, swab16(data->value)); \ 161 i2c_smbus_write_word_swapped(client, reg, data->value); \
162 mutex_unlock(&data->update_lock); \ 162 mutex_unlock(&data->update_lock); \
163 return count; \ 163 return count; \
164} 164}
@@ -194,8 +194,8 @@ static ssize_t set_temp1_crit_hyst(struct device *dev, struct device_attribute *
194 194
195 mutex_lock(&data->update_lock); 195 mutex_lock(&data->update_lock);
196 data->temp1_hyst = TEMP_FROM_REG(data->temp1_crit) - val; 196 data->temp1_hyst = TEMP_FROM_REG(data->temp1_crit) - val;
197 i2c_smbus_write_word_data(client, LM92_REG_TEMP_HYST, 197 i2c_smbus_write_word_swapped(client, LM92_REG_TEMP_HYST,
198 swab16(TEMP_TO_REG(data->temp1_hyst))); 198 TEMP_TO_REG(data->temp1_hyst));
199 mutex_unlock(&data->update_lock); 199 mutex_unlock(&data->update_lock);
200 return count; 200 return count;
201} 201}
diff --git a/drivers/hwmon/max16065.c b/drivers/hwmon/max16065.c
index dd2d7b9620c2..385886a4f224 100644
--- a/drivers/hwmon/max16065.c
+++ b/drivers/hwmon/max16065.c
@@ -137,10 +137,10 @@ static int max16065_read_adc(struct i2c_client *client, int reg)
137{ 137{
138 int rv; 138 int rv;
139 139
140 rv = i2c_smbus_read_word_data(client, reg); 140 rv = i2c_smbus_read_word_swapped(client, reg);
141 if (unlikely(rv < 0)) 141 if (unlikely(rv < 0))
142 return rv; 142 return rv;
143 return ((rv & 0xff) << 2) | ((rv >> 14) & 0x03); 143 return rv >> 6;
144} 144}
145 145
146static struct max16065_data *max16065_update_device(struct device *dev) 146static struct max16065_data *max16065_update_device(struct device *dev)
diff --git a/drivers/hwmon/mc13783-adc.c b/drivers/hwmon/mc13783-adc.c
index d5226c9e1201..ef65ab56b094 100644
--- a/drivers/hwmon/mc13783-adc.c
+++ b/drivers/hwmon/mc13783-adc.c
@@ -31,7 +31,7 @@
31#define MC13783_ADC_NAME "mc13783-adc" 31#define MC13783_ADC_NAME "mc13783-adc"
32 32
33struct mc13783_adc_priv { 33struct mc13783_adc_priv {
34 struct mc13783 *mc13783; 34 struct mc13xxx *mc13xxx;
35 struct device *hwmon_dev; 35 struct device *hwmon_dev;
36}; 36};
37 37
@@ -51,8 +51,8 @@ static int mc13783_adc_read(struct device *dev,
51 unsigned int sample[4]; 51 unsigned int sample[4];
52 int ret; 52 int ret;
53 53
54 ret = mc13783_adc_do_conversion(priv->mc13783, 54 ret = mc13xxx_adc_do_conversion(priv->mc13xxx,
55 MC13783_ADC_MODE_MULT_CHAN, 55 MC13XXX_ADC_MODE_MULT_CHAN,
56 channel, sample); 56 channel, sample);
57 if (ret) 57 if (ret)
58 return ret; 58 return ret;
@@ -147,9 +147,9 @@ static const struct attribute_group mc13783_group_ts = {
147static int mc13783_adc_use_touchscreen(struct platform_device *pdev) 147static int mc13783_adc_use_touchscreen(struct platform_device *pdev)
148{ 148{
149 struct mc13783_adc_priv *priv = platform_get_drvdata(pdev); 149 struct mc13783_adc_priv *priv = platform_get_drvdata(pdev);
150 unsigned flags = mc13783_get_flags(priv->mc13783); 150 unsigned flags = mc13xxx_get_flags(priv->mc13xxx);
151 151
152 return flags & MC13783_USE_TOUCHSCREEN; 152 return flags & MC13XXX_USE_TOUCHSCREEN;
153} 153}
154 154
155static int __init mc13783_adc_probe(struct platform_device *pdev) 155static int __init mc13783_adc_probe(struct platform_device *pdev)
@@ -161,7 +161,7 @@ static int __init mc13783_adc_probe(struct platform_device *pdev)
161 if (!priv) 161 if (!priv)
162 return -ENOMEM; 162 return -ENOMEM;
163 163
164 priv->mc13783 = dev_get_drvdata(pdev->dev.parent); 164 priv->mc13xxx = dev_get_drvdata(pdev->dev.parent);
165 165
166 platform_set_drvdata(pdev, priv); 166 platform_set_drvdata(pdev, priv);
167 167
diff --git a/drivers/hwmon/sht21.c b/drivers/hwmon/sht21.c
index 1c8c9812f244..15398780cc00 100644
--- a/drivers/hwmon/sht21.c
+++ b/drivers/hwmon/sht21.c
@@ -83,25 +83,6 @@ static inline int sht21_rh_ticks_to_per_cent_mille(int ticks)
83} 83}
84 84
85/** 85/**
86 * sht21_read_word_data() - read word from register
87 * @client: I2C client device
88 * @reg: I2C command byte
89 *
90 * Returns value, negative errno on error.
91 */
92static inline int sht21_read_word_data(struct i2c_client *client, u8 reg)
93{
94 int ret = i2c_smbus_read_word_data(client, reg);
95 if (ret < 0)
96 return ret;
97 /*
98 * SMBus specifies low byte first, but the SHT21 returns MSB
99 * first, so we have to swab16 the values
100 */
101 return swab16(ret);
102}
103
104/**
105 * sht21_update_measurements() - get updated measurements from device 86 * sht21_update_measurements() - get updated measurements from device
106 * @client: I2C client device 87 * @client: I2C client device
107 * 88 *
@@ -119,12 +100,13 @@ static int sht21_update_measurements(struct i2c_client *client)
119 * maximum two measurements per second at 12bit accuracy shall be made. 100 * maximum two measurements per second at 12bit accuracy shall be made.
120 */ 101 */
121 if (time_after(jiffies, sht21->last_update + HZ / 2) || !sht21->valid) { 102 if (time_after(jiffies, sht21->last_update + HZ / 2) || !sht21->valid) {
122 ret = sht21_read_word_data(client, SHT21_TRIG_T_MEASUREMENT_HM); 103 ret = i2c_smbus_read_word_swapped(client,
104 SHT21_TRIG_T_MEASUREMENT_HM);
123 if (ret < 0) 105 if (ret < 0)
124 goto out; 106 goto out;
125 sht21->temperature = sht21_temp_ticks_to_millicelsius(ret); 107 sht21->temperature = sht21_temp_ticks_to_millicelsius(ret);
126 ret = sht21_read_word_data(client, 108 ret = i2c_smbus_read_word_swapped(client,
127 SHT21_TRIG_RH_MEASUREMENT_HM); 109 SHT21_TRIG_RH_MEASUREMENT_HM);
128 if (ret < 0) 110 if (ret < 0)
129 goto out; 111 goto out;
130 sht21->humidity = sht21_rh_ticks_to_per_cent_mille(ret); 112 sht21->humidity = sht21_rh_ticks_to_per_cent_mille(ret);
diff --git a/drivers/hwmon/smm665.c b/drivers/hwmon/smm665.c
index 425df5bccd45..411638181fd8 100644
--- a/drivers/hwmon/smm665.c
+++ b/drivers/hwmon/smm665.c
@@ -214,33 +214,26 @@ static int smm665_read_adc(struct smm665_data *data, int adc)
214 * 214 *
215 * Neither i2c_smbus_read_byte() nor 215 * Neither i2c_smbus_read_byte() nor
216 * i2c_smbus_read_block_data() worked here, 216 * i2c_smbus_read_block_data() worked here,
217 * so use i2c_smbus_read_word_data() instead. 217 * so use i2c_smbus_read_word_swapped() instead.
218 * We could also try to use i2c_master_recv(), 218 * We could also try to use i2c_master_recv(),
219 * but that is not always supported. 219 * but that is not always supported.
220 */ 220 */
221 rv = i2c_smbus_read_word_data(client, 0); 221 rv = i2c_smbus_read_word_swapped(client, 0);
222 if (rv < 0) { 222 if (rv < 0) {
223 dev_dbg(&client->dev, "Failed to read ADC value: error %d", rv); 223 dev_dbg(&client->dev, "Failed to read ADC value: error %d", rv);
224 return -1; 224 return -1;
225 } 225 }
226 /* 226 /*
227 * Validate/verify readback adc channel (in bit 11..14). 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 */ 228 */
230 radc = (rv >> 3) & 0x0f; 229 radc = (rv >> 11) & 0x0f;
231 if (radc != adc) { 230 if (radc != adc) {
232 dev_dbg(&client->dev, "Unexpected RADC: Expected %d got %d", 231 dev_dbg(&client->dev, "Unexpected RADC: Expected %d got %d",
233 adc, radc); 232 adc, radc);
234 return -EIO; 233 return -EIO;
235 } 234 }
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 235
243 return rv; 236 return rv & SMM665_ADC_MASK;
244} 237}
245 238
246static struct smm665_data *smm665_update_device(struct device *dev) 239static struct smm665_data *smm665_update_device(struct device *dev)
diff --git a/drivers/hwmon/smsc47b397.c b/drivers/hwmon/smsc47b397.c
index 9fb7516e6f45..65c88ff5645a 100644
--- a/drivers/hwmon/smsc47b397.c
+++ b/drivers/hwmon/smsc47b397.c
@@ -113,7 +113,7 @@ struct smsc47b397_data {
113 u8 temp[4]; 113 u8 temp[4];
114}; 114};
115 115
116static int smsc47b397_read_value(struct smsc47b397_data* data, u8 reg) 116static int smsc47b397_read_value(struct smsc47b397_data *data, u8 reg)
117{ 117{
118 int res; 118 int res;
119 119
@@ -265,7 +265,8 @@ static int __devinit smsc47b397_probe(struct platform_device *pdev)
265 return -EBUSY; 265 return -EBUSY;
266 } 266 }
267 267
268 if (!(data = kzalloc(sizeof(struct smsc47b397_data), GFP_KERNEL))) { 268 data = kzalloc(sizeof(struct smsc47b397_data), GFP_KERNEL);
269 if (!data) {
269 err = -ENOMEM; 270 err = -ENOMEM;
270 goto error_release; 271 goto error_release;
271 } 272 }
@@ -276,7 +277,8 @@ static int __devinit smsc47b397_probe(struct platform_device *pdev)
276 mutex_init(&data->update_lock); 277 mutex_init(&data->update_lock);
277 platform_set_drvdata(pdev, data); 278 platform_set_drvdata(pdev, data);
278 279
279 if ((err = sysfs_create_group(&dev->kobj, &smsc47b397_group))) 280 err = sysfs_create_group(&dev->kobj, &smsc47b397_group);
281 if (err)
280 goto error_free; 282 goto error_free;
281 283
282 data->hwmon_dev = hwmon_device_register(dev); 284 data->hwmon_dev = hwmon_device_register(dev);
@@ -345,7 +347,7 @@ static int __init smsc47b397_find(unsigned short *addr)
345 superio_enter(); 347 superio_enter();
346 id = force_id ? force_id : superio_inb(SUPERIO_REG_DEVID); 348 id = force_id ? force_id : superio_inb(SUPERIO_REG_DEVID);
347 349
348 switch(id) { 350 switch (id) {
349 case 0x81: 351 case 0x81:
350 name = "SCH5307-NS"; 352 name = "SCH5307-NS";
351 break; 353 break;
@@ -379,7 +381,8 @@ static int __init smsc47b397_init(void)
379 unsigned short address; 381 unsigned short address;
380 int ret; 382 int ret;
381 383
382 if ((ret = smsc47b397_find(&address))) 384 ret = smsc47b397_find(&address);
385 if (ret)
383 return ret; 386 return ret;
384 387
385 ret = platform_driver_register(&smsc47b397_driver); 388 ret = platform_driver_register(&smsc47b397_driver);
diff --git a/drivers/hwmon/tmp102.c b/drivers/hwmon/tmp102.c
index 5bd194968801..643aa8c94535 100644
--- a/drivers/hwmon/tmp102.c
+++ b/drivers/hwmon/tmp102.c
@@ -55,19 +55,6 @@ struct tmp102 {
55 int temp[3]; 55 int temp[3];
56}; 56};
57 57
58/* SMBus specifies low byte first, but the TMP102 returns high byte first,
59 * so we have to swab16 the values */
60static inline int tmp102_read_reg(struct i2c_client *client, u8 reg)
61{
62 int result = i2c_smbus_read_word_data(client, reg);
63 return result < 0 ? result : swab16(result);
64}
65
66static inline int tmp102_write_reg(struct i2c_client *client, u8 reg, u16 val)
67{
68 return i2c_smbus_write_word_data(client, reg, swab16(val));
69}
70
71/* convert left adjusted 13-bit TMP102 register value to milliCelsius */ 58/* convert left adjusted 13-bit TMP102 register value to milliCelsius */
72static inline int tmp102_reg_to_mC(s16 val) 59static inline int tmp102_reg_to_mC(s16 val)
73{ 60{
@@ -94,7 +81,8 @@ static struct tmp102 *tmp102_update_device(struct i2c_client *client)
94 if (time_after(jiffies, tmp102->last_update + HZ / 3)) { 81 if (time_after(jiffies, tmp102->last_update + HZ / 3)) {
95 int i; 82 int i;
96 for (i = 0; i < ARRAY_SIZE(tmp102->temp); ++i) { 83 for (i = 0; i < ARRAY_SIZE(tmp102->temp); ++i) {
97 int status = tmp102_read_reg(client, tmp102_reg[i]); 84 int status = i2c_smbus_read_word_swapped(client,
85 tmp102_reg[i]);
98 if (status > -1) 86 if (status > -1)
99 tmp102->temp[i] = tmp102_reg_to_mC(status); 87 tmp102->temp[i] = tmp102_reg_to_mC(status);
100 } 88 }
@@ -130,8 +118,8 @@ static ssize_t tmp102_set_temp(struct device *dev,
130 118
131 mutex_lock(&tmp102->lock); 119 mutex_lock(&tmp102->lock);
132 tmp102->temp[sda->index] = val; 120 tmp102->temp[sda->index] = val;
133 status = tmp102_write_reg(client, tmp102_reg[sda->index], 121 status = i2c_smbus_write_word_swapped(client, tmp102_reg[sda->index],
134 tmp102_mC_to_reg(val)); 122 tmp102_mC_to_reg(val));
135 mutex_unlock(&tmp102->lock); 123 mutex_unlock(&tmp102->lock);
136 return status ? : count; 124 return status ? : count;
137} 125}
@@ -178,18 +166,19 @@ static int __devinit tmp102_probe(struct i2c_client *client,
178 } 166 }
179 i2c_set_clientdata(client, tmp102); 167 i2c_set_clientdata(client, tmp102);
180 168
181 status = tmp102_read_reg(client, TMP102_CONF_REG); 169 status = i2c_smbus_read_word_swapped(client, TMP102_CONF_REG);
182 if (status < 0) { 170 if (status < 0) {
183 dev_err(&client->dev, "error reading config register\n"); 171 dev_err(&client->dev, "error reading config register\n");
184 goto fail_free; 172 goto fail_free;
185 } 173 }
186 tmp102->config_orig = status; 174 tmp102->config_orig = status;
187 status = tmp102_write_reg(client, TMP102_CONF_REG, TMP102_CONFIG); 175 status = i2c_smbus_write_word_swapped(client, TMP102_CONF_REG,
176 TMP102_CONFIG);
188 if (status < 0) { 177 if (status < 0) {
189 dev_err(&client->dev, "error writing config register\n"); 178 dev_err(&client->dev, "error writing config register\n");
190 goto fail_restore_config; 179 goto fail_restore_config;
191 } 180 }
192 status = tmp102_read_reg(client, TMP102_CONF_REG); 181 status = i2c_smbus_read_word_swapped(client, TMP102_CONF_REG);
193 if (status < 0) { 182 if (status < 0) {
194 dev_err(&client->dev, "error reading config register\n"); 183 dev_err(&client->dev, "error reading config register\n");
195 goto fail_restore_config; 184 goto fail_restore_config;
@@ -222,7 +211,8 @@ static int __devinit tmp102_probe(struct i2c_client *client,
222fail_remove_sysfs: 211fail_remove_sysfs:
223 sysfs_remove_group(&client->dev.kobj, &tmp102_attr_group); 212 sysfs_remove_group(&client->dev.kobj, &tmp102_attr_group);
224fail_restore_config: 213fail_restore_config:
225 tmp102_write_reg(client, TMP102_CONF_REG, tmp102->config_orig); 214 i2c_smbus_write_word_swapped(client, TMP102_CONF_REG,
215 tmp102->config_orig);
226fail_free: 216fail_free:
227 kfree(tmp102); 217 kfree(tmp102);
228 218
@@ -240,10 +230,10 @@ static int __devexit tmp102_remove(struct i2c_client *client)
240 if (tmp102->config_orig & TMP102_CONF_SD) { 230 if (tmp102->config_orig & TMP102_CONF_SD) {
241 int config; 231 int config;
242 232
243 config = tmp102_read_reg(client, TMP102_CONF_REG); 233 config = i2c_smbus_read_word_swapped(client, TMP102_CONF_REG);
244 if (config >= 0) 234 if (config >= 0)
245 tmp102_write_reg(client, TMP102_CONF_REG, 235 i2c_smbus_write_word_swapped(client, TMP102_CONF_REG,
246 config | TMP102_CONF_SD); 236 config | TMP102_CONF_SD);
247 } 237 }
248 238
249 kfree(tmp102); 239 kfree(tmp102);
@@ -257,12 +247,12 @@ static int tmp102_suspend(struct device *dev)
257 struct i2c_client *client = to_i2c_client(dev); 247 struct i2c_client *client = to_i2c_client(dev);
258 int config; 248 int config;
259 249
260 config = tmp102_read_reg(client, TMP102_CONF_REG); 250 config = i2c_smbus_read_word_swapped(client, TMP102_CONF_REG);
261 if (config < 0) 251 if (config < 0)
262 return config; 252 return config;
263 253
264 config |= TMP102_CONF_SD; 254 config |= TMP102_CONF_SD;
265 return tmp102_write_reg(client, TMP102_CONF_REG, config); 255 return i2c_smbus_write_word_swapped(client, TMP102_CONF_REG, config);
266} 256}
267 257
268static int tmp102_resume(struct device *dev) 258static int tmp102_resume(struct device *dev)
@@ -270,12 +260,12 @@ static int tmp102_resume(struct device *dev)
270 struct i2c_client *client = to_i2c_client(dev); 260 struct i2c_client *client = to_i2c_client(dev);
271 int config; 261 int config;
272 262
273 config = tmp102_read_reg(client, TMP102_CONF_REG); 263 config = i2c_smbus_read_word_swapped(client, TMP102_CONF_REG);
274 if (config < 0) 264 if (config < 0)
275 return config; 265 return config;
276 266
277 config &= ~TMP102_CONF_SD; 267 config &= ~TMP102_CONF_SD;
278 return tmp102_write_reg(client, TMP102_CONF_REG, config); 268 return i2c_smbus_write_word_swapped(client, TMP102_CONF_REG, config);
279} 269}
280 270
281static const struct dev_pm_ops tmp102_dev_pm_ops = { 271static const struct dev_pm_ops tmp102_dev_pm_ops = {
diff --git a/drivers/hwmon/ultra45_env.c b/drivers/hwmon/ultra45_env.c
index 27a62711e0a6..3cd07bf42dca 100644
--- a/drivers/hwmon/ultra45_env.c
+++ b/drivers/hwmon/ultra45_env.c
@@ -6,6 +6,7 @@
6#include <linux/kernel.h> 6#include <linux/kernel.h>
7#include <linux/types.h> 7#include <linux/types.h>
8#include <linux/slab.h> 8#include <linux/slab.h>
9#include <linux/module.h>
9#include <linux/of_device.h> 10#include <linux/of_device.h>
10#include <linux/io.h> 11#include <linux/io.h>
11#include <linux/hwmon.h> 12#include <linux/hwmon.h>
diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index 98aab4bea342..93f5fc7d6059 100644
--- a/drivers/hwmon/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
@@ -1,7 +1,7 @@
1/* 1/*
2 w83627ehf - Driver for the hardware monitoring functionality of 2 w83627ehf - Driver for the hardware monitoring functionality of
3 the Winbond W83627EHF Super-I/O chip 3 the Winbond W83627EHF Super-I/O chip
4 Copyright (C) 2005 Jean Delvare <khali@linux-fr.org> 4 Copyright (C) 2005-2011 Jean Delvare <khali@linux-fr.org>
5 Copyright (C) 2006 Yuan Mu (Winbond), 5 Copyright (C) 2006 Yuan Mu (Winbond),
6 Rudolf Marek <r.marek@assembler.cz> 6 Rudolf Marek <r.marek@assembler.cz>
7 David Hubbard <david.c.hubbard@gmail.com> 7 David Hubbard <david.c.hubbard@gmail.com>
@@ -39,6 +39,7 @@
39 0x8860 0xa1 39 0x8860 0xa1
40 w83627dhg 9 5 4 3 0xa020 0xc1 0x5ca3 40 w83627dhg 9 5 4 3 0xa020 0xc1 0x5ca3
41 w83627dhg-p 9 5 4 3 0xb070 0xc1 0x5ca3 41 w83627dhg-p 9 5 4 3 0xb070 0xc1 0x5ca3
42 w83627uhg 8 2 2 2 0xa230 0xc1 0x5ca3
42 w83667hg 9 5 3 3 0xa510 0xc1 0x5ca3 43 w83667hg 9 5 3 3 0xa510 0xc1 0x5ca3
43 w83667hg-b 9 5 3 4 0xb350 0xc1 0x5ca3 44 w83667hg-b 9 5 3 4 0xb350 0xc1 0x5ca3
44 nct6775f 9 4 3 9 0xb470 0xc1 0x5ca3 45 nct6775f 9 4 3 9 0xb470 0xc1 0x5ca3
@@ -61,14 +62,17 @@
61#include <linux/io.h> 62#include <linux/io.h>
62#include "lm75.h" 63#include "lm75.h"
63 64
64enum kinds { w83627ehf, w83627dhg, w83627dhg_p, w83667hg, w83667hg_b, nct6775, 65enum kinds {
65 nct6776 }; 66 w83627ehf, w83627dhg, w83627dhg_p, w83627uhg,
67 w83667hg, w83667hg_b, nct6775, nct6776,
68};
66 69
67/* used to set data->name = w83627ehf_device_names[data->sio_kind] */ 70/* used to set data->name = w83627ehf_device_names[data->sio_kind] */
68static const char * const w83627ehf_device_names[] = { 71static const char * const w83627ehf_device_names[] = {
69 "w83627ehf", 72 "w83627ehf",
70 "w83627dhg", 73 "w83627dhg",
71 "w83627dhg", 74 "w83627dhg",
75 "w83627uhg",
72 "w83667hg", 76 "w83667hg",
73 "w83667hg", 77 "w83667hg",
74 "nct6775", 78 "nct6775",
@@ -104,6 +108,7 @@ MODULE_PARM_DESC(fan_debounce, "Enable debouncing for fan RPM signal");
104#define SIO_W83627EHG_ID 0x8860 108#define SIO_W83627EHG_ID 0x8860
105#define SIO_W83627DHG_ID 0xa020 109#define SIO_W83627DHG_ID 0xa020
106#define SIO_W83627DHG_P_ID 0xb070 110#define SIO_W83627DHG_P_ID 0xb070
111#define SIO_W83627UHG_ID 0xa230
107#define SIO_W83667HG_ID 0xa510 112#define SIO_W83667HG_ID 0xa510
108#define SIO_W83667HG_B_ID 0xb350 113#define SIO_W83667HG_B_ID 0xb350
109#define SIO_NCT6775_ID 0xb470 114#define SIO_NCT6775_ID 0xb470
@@ -388,18 +393,23 @@ div_from_reg(u8 reg)
388 return 1 << reg; 393 return 1 << reg;
389} 394}
390 395
391/* Some of analog inputs have internal scaling (2x), 8mV is ADC LSB */ 396/* Some of the voltage inputs have internal scaling, the tables below
392 397 * contain 8 (the ADC LSB in mV) * scaling factor * 100 */
393static u8 scale_in[10] = { 8, 8, 16, 16, 8, 8, 8, 16, 16, 8 }; 398static const u16 scale_in_common[10] = {
399 800, 800, 1600, 1600, 800, 800, 800, 1600, 1600, 800
400};
401static const u16 scale_in_w83627uhg[9] = {
402 800, 800, 3328, 3424, 800, 800, 0, 3328, 3400
403};
394 404
395static inline long in_from_reg(u8 reg, u8 nr) 405static inline long in_from_reg(u8 reg, u8 nr, const u16 *scale_in)
396{ 406{
397 return reg * scale_in[nr]; 407 return DIV_ROUND_CLOSEST(reg * scale_in[nr], 100);
398} 408}
399 409
400static inline u8 in_to_reg(u32 val, u8 nr) 410static inline u8 in_to_reg(u32 val, u8 nr, const u16 *scale_in)
401{ 411{
402 return SENSORS_LIMIT(((val + (scale_in[nr] / 2)) / scale_in[nr]), 0, 412 return SENSORS_LIMIT(DIV_ROUND_CLOSEST(val * 100, scale_in[nr]), 0,
403 255); 413 255);
404} 414}
405 415
@@ -430,6 +440,7 @@ struct w83627ehf_data {
430 const u16 *REG_FAN_STOP_TIME; 440 const u16 *REG_FAN_STOP_TIME;
431 const u16 *REG_FAN_MAX_OUTPUT; 441 const u16 *REG_FAN_MAX_OUTPUT;
432 const u16 *REG_FAN_STEP_OUTPUT; 442 const u16 *REG_FAN_STEP_OUTPUT;
443 const u16 *scale_in;
433 444
434 unsigned int (*fan_from_reg)(u16 reg, unsigned int divreg); 445 unsigned int (*fan_from_reg)(u16 reg, unsigned int divreg);
435 unsigned int (*fan_from_reg_min)(u16 reg, unsigned int divreg); 446 unsigned int (*fan_from_reg_min)(u16 reg, unsigned int divreg);
@@ -481,7 +492,8 @@ struct w83627ehf_data {
481 u8 vrm; 492 u8 vrm;
482 493
483 u16 have_temp; 494 u16 have_temp;
484 u8 in6_skip; 495 u8 in6_skip:1;
496 u8 temp3_val_only:1;
485}; 497};
486 498
487struct w83627ehf_sio_data { 499struct w83627ehf_sio_data {
@@ -907,7 +919,8 @@ show_##reg(struct device *dev, struct device_attribute *attr, \
907 struct sensor_device_attribute *sensor_attr = \ 919 struct sensor_device_attribute *sensor_attr = \
908 to_sensor_dev_attr(attr); \ 920 to_sensor_dev_attr(attr); \
909 int nr = sensor_attr->index; \ 921 int nr = sensor_attr->index; \
910 return sprintf(buf, "%ld\n", in_from_reg(data->reg[nr], nr)); \ 922 return sprintf(buf, "%ld\n", in_from_reg(data->reg[nr], nr, \
923 data->scale_in)); \
911} 924}
912show_in_reg(in) 925show_in_reg(in)
913show_in_reg(in_min) 926show_in_reg(in_min)
@@ -928,7 +941,7 @@ store_in_##reg(struct device *dev, struct device_attribute *attr, \
928 if (err < 0) \ 941 if (err < 0) \
929 return err; \ 942 return err; \
930 mutex_lock(&data->update_lock); \ 943 mutex_lock(&data->update_lock); \
931 data->in_##reg[nr] = in_to_reg(val, nr); \ 944 data->in_##reg[nr] = in_to_reg(val, nr, data->scale_in); \
932 w83627ehf_write_value(data, W83627EHF_REG_IN_##REG(nr), \ 945 w83627ehf_write_value(data, W83627EHF_REG_IN_##REG(nr), \
933 data->in_##reg[nr]); \ 946 data->in_##reg[nr]); \
934 mutex_unlock(&data->update_lock); \ 947 mutex_unlock(&data->update_lock); \
@@ -1617,25 +1630,28 @@ static struct sensor_device_attribute sda_sf3_arrays_fan4[] = {
1617 store_fan_step_output, 3), 1630 store_fan_step_output, 3),
1618}; 1631};
1619 1632
1633static struct sensor_device_attribute sda_sf3_arrays_fan3[] = {
1634 SENSOR_ATTR(pwm3_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time,
1635 store_fan_stop_time, 2),
1636 SENSOR_ATTR(pwm3_start_output, S_IWUSR | S_IRUGO, show_fan_start_output,
1637 store_fan_start_output, 2),
1638 SENSOR_ATTR(pwm3_stop_output, S_IWUSR | S_IRUGO, show_fan_stop_output,
1639 store_fan_stop_output, 2),
1640};
1641
1620static struct sensor_device_attribute sda_sf3_arrays[] = { 1642static struct sensor_device_attribute sda_sf3_arrays[] = {
1621 SENSOR_ATTR(pwm1_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time, 1643 SENSOR_ATTR(pwm1_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time,
1622 store_fan_stop_time, 0), 1644 store_fan_stop_time, 0),
1623 SENSOR_ATTR(pwm2_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time, 1645 SENSOR_ATTR(pwm2_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time,
1624 store_fan_stop_time, 1), 1646 store_fan_stop_time, 1),
1625 SENSOR_ATTR(pwm3_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time,
1626 store_fan_stop_time, 2),
1627 SENSOR_ATTR(pwm1_start_output, S_IWUSR | S_IRUGO, show_fan_start_output, 1647 SENSOR_ATTR(pwm1_start_output, S_IWUSR | S_IRUGO, show_fan_start_output,
1628 store_fan_start_output, 0), 1648 store_fan_start_output, 0),
1629 SENSOR_ATTR(pwm2_start_output, S_IWUSR | S_IRUGO, show_fan_start_output, 1649 SENSOR_ATTR(pwm2_start_output, S_IWUSR | S_IRUGO, show_fan_start_output,
1630 store_fan_start_output, 1), 1650 store_fan_start_output, 1),
1631 SENSOR_ATTR(pwm3_start_output, S_IWUSR | S_IRUGO, show_fan_start_output,
1632 store_fan_start_output, 2),
1633 SENSOR_ATTR(pwm1_stop_output, S_IWUSR | S_IRUGO, show_fan_stop_output, 1651 SENSOR_ATTR(pwm1_stop_output, S_IWUSR | S_IRUGO, show_fan_stop_output,
1634 store_fan_stop_output, 0), 1652 store_fan_stop_output, 0),
1635 SENSOR_ATTR(pwm2_stop_output, S_IWUSR | S_IRUGO, show_fan_stop_output, 1653 SENSOR_ATTR(pwm2_stop_output, S_IWUSR | S_IRUGO, show_fan_stop_output,
1636 store_fan_stop_output, 1), 1654 store_fan_stop_output, 1),
1637 SENSOR_ATTR(pwm3_stop_output, S_IWUSR | S_IRUGO, show_fan_stop_output,
1638 store_fan_stop_output, 2),
1639}; 1655};
1640 1656
1641 1657
@@ -1728,6 +1744,8 @@ static void w83627ehf_device_remove_files(struct device *dev)
1728 data->REG_FAN_STEP_OUTPUT[attr->index] != 0xff) 1744 data->REG_FAN_STEP_OUTPUT[attr->index] != 0xff)
1729 device_remove_file(dev, &attr->dev_attr); 1745 device_remove_file(dev, &attr->dev_attr);
1730 } 1746 }
1747 for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan3); i++)
1748 device_remove_file(dev, &sda_sf3_arrays_fan3[i].dev_attr);
1731 for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan4); i++) 1749 for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan4); i++)
1732 device_remove_file(dev, &sda_sf3_arrays_fan4[i].dev_attr); 1750 device_remove_file(dev, &sda_sf3_arrays_fan4[i].dev_attr);
1733 for (i = 0; i < data->in_num; i++) { 1751 for (i = 0; i < data->in_num; i++) {
@@ -1756,6 +1774,8 @@ static void w83627ehf_device_remove_files(struct device *dev)
1756 continue; 1774 continue;
1757 device_remove_file(dev, &sda_temp_input[i].dev_attr); 1775 device_remove_file(dev, &sda_temp_input[i].dev_attr);
1758 device_remove_file(dev, &sda_temp_label[i].dev_attr); 1776 device_remove_file(dev, &sda_temp_label[i].dev_attr);
1777 if (i == 2 && data->temp3_val_only)
1778 continue;
1759 device_remove_file(dev, &sda_temp_max[i].dev_attr); 1779 device_remove_file(dev, &sda_temp_max[i].dev_attr);
1760 device_remove_file(dev, &sda_temp_max_hyst[i].dev_attr); 1780 device_remove_file(dev, &sda_temp_max_hyst[i].dev_attr);
1761 if (i > 2) 1781 if (i > 2)
@@ -1808,11 +1828,24 @@ static inline void __devinit w83627ehf_init_device(struct w83627ehf_data *data,
1808 case w83627ehf: 1828 case w83627ehf:
1809 diode = w83627ehf_read_value(data, W83627EHF_REG_DIODE); 1829 diode = w83627ehf_read_value(data, W83627EHF_REG_DIODE);
1810 break; 1830 break;
1831 case w83627uhg:
1832 diode = 0x00;
1833 break;
1811 default: 1834 default:
1812 diode = 0x70; 1835 diode = 0x70;
1813 } 1836 }
1814 for (i = 0; i < 3; i++) { 1837 for (i = 0; i < 3; i++) {
1815 if ((tmp & (0x02 << i))) 1838 const char *label = NULL;
1839
1840 if (data->temp_label)
1841 label = data->temp_label[data->temp_src[i]];
1842
1843 /* Digital source overrides analog type */
1844 if (label && strncmp(label, "PECI", 4) == 0)
1845 data->temp_type[i] = 6;
1846 else if (label && strncmp(label, "AMD", 3) == 0)
1847 data->temp_type[i] = 5;
1848 else if ((tmp & (0x02 << i)))
1816 data->temp_type[i] = (diode & (0x10 << i)) ? 1 : 3; 1849 data->temp_type[i] = (diode & (0x10 << i)) ? 1 : 3;
1817 else 1850 else
1818 data->temp_type[i] = 4; /* thermistor */ 1851 data->temp_type[i] = 4; /* thermistor */
@@ -1846,11 +1879,31 @@ static void w82627ehf_swap_tempreg(struct w83627ehf_data *data,
1846} 1879}
1847 1880
1848static void __devinit 1881static void __devinit
1882w83627ehf_set_temp_reg_ehf(struct w83627ehf_data *data, int n_temp)
1883{
1884 int i;
1885
1886 for (i = 0; i < n_temp; i++) {
1887 data->reg_temp[i] = W83627EHF_REG_TEMP[i];
1888 data->reg_temp_over[i] = W83627EHF_REG_TEMP_OVER[i];
1889 data->reg_temp_hyst[i] = W83627EHF_REG_TEMP_HYST[i];
1890 data->reg_temp_config[i] = W83627EHF_REG_TEMP_CONFIG[i];
1891 }
1892}
1893
1894static void __devinit
1849w83627ehf_check_fan_inputs(const struct w83627ehf_sio_data *sio_data, 1895w83627ehf_check_fan_inputs(const struct w83627ehf_sio_data *sio_data,
1850 struct w83627ehf_data *data) 1896 struct w83627ehf_data *data)
1851{ 1897{
1852 int fan3pin, fan4pin, fan4min, fan5pin, regval; 1898 int fan3pin, fan4pin, fan4min, fan5pin, regval;
1853 1899
1900 /* The W83627UHG is simple, only two fan inputs, no config */
1901 if (sio_data->kind == w83627uhg) {
1902 data->has_fan = 0x03; /* fan1 and fan2 */
1903 data->has_fan_min = 0x03;
1904 return;
1905 }
1906
1854 superio_enter(sio_data->sioreg); 1907 superio_enter(sio_data->sioreg);
1855 1908
1856 /* fan4 and fan5 share some pins with the GPIO and serial flash */ 1909 /* fan4 and fan5 share some pins with the GPIO and serial flash */
@@ -1942,23 +1995,24 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev)
1942 1995
1943 /* 627EHG and 627EHF have 10 voltage inputs; 627DHG and 667HG have 9 */ 1996 /* 627EHG and 627EHF have 10 voltage inputs; 627DHG and 667HG have 9 */
1944 data->in_num = (sio_data->kind == w83627ehf) ? 10 : 9; 1997 data->in_num = (sio_data->kind == w83627ehf) ? 10 : 9;
1945 /* 667HG, NCT6775F, and NCT6776F have 3 pwms */ 1998 /* 667HG, NCT6775F, and NCT6776F have 3 pwms, and 627UHG has only 2 */
1946 data->pwm_num = (sio_data->kind == w83667hg 1999 switch (sio_data->kind) {
1947 || sio_data->kind == w83667hg_b 2000 default:
1948 || sio_data->kind == nct6775 2001 data->pwm_num = 4;
1949 || sio_data->kind == nct6776) ? 3 : 4; 2002 break;
2003 case w83667hg:
2004 case w83667hg_b:
2005 case nct6775:
2006 case nct6776:
2007 data->pwm_num = 3;
2008 break;
2009 case w83627uhg:
2010 data->pwm_num = 2;
2011 break;
2012 }
1950 2013
2014 /* Default to 3 temperature inputs, code below will adjust as needed */
1951 data->have_temp = 0x07; 2015 data->have_temp = 0x07;
1952 /* Check temp3 configuration bit for 667HG */
1953 if (sio_data->kind == w83667hg) {
1954 u8 reg;
1955
1956 reg = w83627ehf_read_value(data, W83627EHF_REG_TEMP_CONFIG[2]);
1957 if (reg & 0x01)
1958 data->have_temp &= ~(1 << 2);
1959 else
1960 data->in6_skip = 1; /* either temp3 or in6 */
1961 }
1962 2016
1963 /* Deal with temperature register setup first. */ 2017 /* Deal with temperature register setup first. */
1964 if (sio_data->kind == nct6775 || sio_data->kind == nct6776) { 2018 if (sio_data->kind == nct6775 || sio_data->kind == nct6776) {
@@ -2035,16 +2089,12 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev)
2035 } else if (sio_data->kind == w83667hg_b) { 2089 } else if (sio_data->kind == w83667hg_b) {
2036 u8 reg; 2090 u8 reg;
2037 2091
2092 w83627ehf_set_temp_reg_ehf(data, 4);
2093
2038 /* 2094 /*
2039 * Temperature sources are selected with bank 0, registers 0x49 2095 * Temperature sources are selected with bank 0, registers 0x49
2040 * and 0x4a. 2096 * and 0x4a.
2041 */ 2097 */
2042 for (i = 0; i < ARRAY_SIZE(W83627EHF_REG_TEMP); i++) {
2043 data->reg_temp[i] = W83627EHF_REG_TEMP[i];
2044 data->reg_temp_over[i] = W83627EHF_REG_TEMP_OVER[i];
2045 data->reg_temp_hyst[i] = W83627EHF_REG_TEMP_HYST[i];
2046 data->reg_temp_config[i] = W83627EHF_REG_TEMP_CONFIG[i];
2047 }
2048 reg = w83627ehf_read_value(data, 0x4a); 2098 reg = w83627ehf_read_value(data, 0x4a);
2049 data->temp_src[0] = reg >> 5; 2099 data->temp_src[0] = reg >> 5;
2050 reg = w83627ehf_read_value(data, 0x49); 2100 reg = w83627ehf_read_value(data, 0x49);
@@ -2078,13 +2128,60 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev)
2078 data->in6_skip = 1; 2128 data->in6_skip = 1;
2079 2129
2080 data->temp_label = w83667hg_b_temp_label; 2130 data->temp_label = w83667hg_b_temp_label;
2131 } else if (sio_data->kind == w83627uhg) {
2132 u8 reg;
2133
2134 w83627ehf_set_temp_reg_ehf(data, 3);
2135
2136 /*
2137 * Temperature sources for temp1 and temp2 are selected with
2138 * bank 0, registers 0x49 and 0x4a.
2139 */
2140 data->temp_src[0] = 0; /* SYSTIN */
2141 reg = w83627ehf_read_value(data, 0x49) & 0x07;
2142 /* Adjust to have the same mapping as other source registers */
2143 if (reg == 0)
2144 data->temp_src[1]++;
2145 else if (reg >= 2 && reg <= 5)
2146 data->temp_src[1] += 2;
2147 else /* should never happen */
2148 data->have_temp &= ~(1 << 1);
2149 reg = w83627ehf_read_value(data, 0x4a);
2150 data->temp_src[2] = reg >> 5;
2151
2152 /*
2153 * Skip temp3 if source is invalid or the same as temp1
2154 * or temp2.
2155 */
2156 if (data->temp_src[2] == 2 || data->temp_src[2] == 3 ||
2157 data->temp_src[2] == data->temp_src[0] ||
2158 ((data->have_temp & (1 << 1)) &&
2159 data->temp_src[2] == data->temp_src[1]))
2160 data->have_temp &= ~(1 << 2);
2161 else
2162 data->temp3_val_only = 1; /* No limit regs */
2163
2164 data->in6_skip = 1; /* No VIN3 */
2165
2166 data->temp_label = w83667hg_b_temp_label;
2081 } else { 2167 } else {
2168 w83627ehf_set_temp_reg_ehf(data, 3);
2169
2082 /* Temperature sources are fixed */ 2170 /* Temperature sources are fixed */
2083 for (i = 0; i < 3; i++) { 2171
2084 data->reg_temp[i] = W83627EHF_REG_TEMP[i]; 2172 if (sio_data->kind == w83667hg) {
2085 data->reg_temp_over[i] = W83627EHF_REG_TEMP_OVER[i]; 2173 u8 reg;
2086 data->reg_temp_hyst[i] = W83627EHF_REG_TEMP_HYST[i]; 2174
2087 data->reg_temp_config[i] = W83627EHF_REG_TEMP_CONFIG[i]; 2175 /*
2176 * Chip supports either AUXTIN or VIN3. Try to find
2177 * out which one.
2178 */
2179 reg = w83627ehf_read_value(data,
2180 W83627EHF_REG_TEMP_CONFIG[2]);
2181 if (reg & 0x01)
2182 data->have_temp &= ~(1 << 2);
2183 else
2184 data->in6_skip = 1;
2088 } 2185 }
2089 } 2186 }
2090 2187
@@ -2144,6 +2241,12 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev)
2144 W83627EHF_REG_FAN_STEP_OUTPUT_COMMON; 2241 W83627EHF_REG_FAN_STEP_OUTPUT_COMMON;
2145 } 2242 }
2146 2243
2244 /* Setup input voltage scaling factors */
2245 if (sio_data->kind == w83627uhg)
2246 data->scale_in = scale_in_w83627uhg;
2247 else
2248 data->scale_in = scale_in_common;
2249
2147 /* Initialize the chip */ 2250 /* Initialize the chip */
2148 w83627ehf_init_device(data, sio_data->kind); 2251 w83627ehf_init_device(data, sio_data->kind);
2149 2252
@@ -2160,7 +2263,7 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev)
2160 err = device_create_file(dev, &dev_attr_cpu0_vid); 2263 err = device_create_file(dev, &dev_attr_cpu0_vid);
2161 if (err) 2264 if (err)
2162 goto exit_release; 2265 goto exit_release;
2163 } else { 2266 } else if (sio_data->kind != w83627uhg) {
2164 superio_select(sio_data->sioreg, W83627EHF_LD_HWM); 2267 superio_select(sio_data->sioreg, W83627EHF_LD_HWM);
2165 if (superio_inb(sio_data->sioreg, SIO_REG_VID_CTRL) & 0x80) { 2268 if (superio_inb(sio_data->sioreg, SIO_REG_VID_CTRL) & 0x80) {
2166 /* Set VID input sensibility if needed. In theory the 2269 /* Set VID input sensibility if needed. In theory the
@@ -2250,7 +2353,14 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev)
2250 goto exit_remove; 2353 goto exit_remove;
2251 } 2354 }
2252 } 2355 }
2253 /* if fan4 is enabled create the sf3 files for it */ 2356 /* if fan3 and fan4 are enabled create the sf3 files for them */
2357 if ((data->has_fan & (1 << 2)) && data->pwm_num >= 3)
2358 for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan3); i++) {
2359 err = device_create_file(dev,
2360 &sda_sf3_arrays_fan3[i].dev_attr);
2361 if (err)
2362 goto exit_remove;
2363 }
2254 if ((data->has_fan & (1 << 3)) && data->pwm_num >= 4) 2364 if ((data->has_fan & (1 << 3)) && data->pwm_num >= 4)
2255 for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan4); i++) { 2365 for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan4); i++) {
2256 err = device_create_file(dev, 2366 err = device_create_file(dev,
@@ -2318,6 +2428,8 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev)
2318 if (err) 2428 if (err)
2319 goto exit_remove; 2429 goto exit_remove;
2320 } 2430 }
2431 if (i == 2 && data->temp3_val_only)
2432 continue;
2321 if (data->reg_temp_over[i]) { 2433 if (data->reg_temp_over[i]) {
2322 err = device_create_file(dev, 2434 err = device_create_file(dev,
2323 &sda_temp_max[i].dev_attr); 2435 &sda_temp_max[i].dev_attr);
@@ -2401,6 +2513,7 @@ static int __init w83627ehf_find(int sioaddr, unsigned short *addr,
2401 static const char __initdata sio_name_W83627EHG[] = "W83627EHG"; 2513 static const char __initdata sio_name_W83627EHG[] = "W83627EHG";
2402 static const char __initdata sio_name_W83627DHG[] = "W83627DHG"; 2514 static const char __initdata sio_name_W83627DHG[] = "W83627DHG";
2403 static const char __initdata sio_name_W83627DHG_P[] = "W83627DHG-P"; 2515 static const char __initdata sio_name_W83627DHG_P[] = "W83627DHG-P";
2516 static const char __initdata sio_name_W83627UHG[] = "W83627UHG";
2404 static const char __initdata sio_name_W83667HG[] = "W83667HG"; 2517 static const char __initdata sio_name_W83667HG[] = "W83667HG";
2405 static const char __initdata sio_name_W83667HG_B[] = "W83667HG-B"; 2518 static const char __initdata sio_name_W83667HG_B[] = "W83667HG-B";
2406 static const char __initdata sio_name_NCT6775[] = "NCT6775F"; 2519 static const char __initdata sio_name_NCT6775[] = "NCT6775F";
@@ -2433,6 +2546,10 @@ static int __init w83627ehf_find(int sioaddr, unsigned short *addr,
2433 sio_data->kind = w83627dhg_p; 2546 sio_data->kind = w83627dhg_p;
2434 sio_name = sio_name_W83627DHG_P; 2547 sio_name = sio_name_W83627DHG_P;
2435 break; 2548 break;
2549 case SIO_W83627UHG_ID:
2550 sio_data->kind = w83627uhg;
2551 sio_name = sio_name_W83627UHG;
2552 break;
2436 case SIO_W83667HG_ID: 2553 case SIO_W83667HG_ID:
2437 sio_data->kind = w83667hg; 2554 sio_data->kind = w83667hg;
2438 sio_name = sio_name_W83667HG; 2555 sio_name = sio_name_W83667HG;
diff --git a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c
index eed43a008be1..65b685e2c7b7 100644
--- a/drivers/hwmon/w83781d.c
+++ b/drivers/hwmon/w83781d.c
@@ -1245,17 +1245,17 @@ w83781d_read_value_i2c(struct w83781d_data *data, u16 reg)
1245 /* convert from ISA to LM75 I2C addresses */ 1245 /* convert from ISA to LM75 I2C addresses */
1246 switch (reg & 0xff) { 1246 switch (reg & 0xff) {
1247 case 0x50: /* TEMP */ 1247 case 0x50: /* TEMP */
1248 res = swab16(i2c_smbus_read_word_data(cl, 0)); 1248 res = i2c_smbus_read_word_swapped(cl, 0);
1249 break; 1249 break;
1250 case 0x52: /* CONFIG */ 1250 case 0x52: /* CONFIG */
1251 res = i2c_smbus_read_byte_data(cl, 1); 1251 res = i2c_smbus_read_byte_data(cl, 1);
1252 break; 1252 break;
1253 case 0x53: /* HYST */ 1253 case 0x53: /* HYST */
1254 res = swab16(i2c_smbus_read_word_data(cl, 2)); 1254 res = i2c_smbus_read_word_swapped(cl, 2);
1255 break; 1255 break;
1256 case 0x55: /* OVER */ 1256 case 0x55: /* OVER */
1257 default: 1257 default:
1258 res = swab16(i2c_smbus_read_word_data(cl, 3)); 1258 res = i2c_smbus_read_word_swapped(cl, 3);
1259 break; 1259 break;
1260 } 1260 }
1261 } 1261 }
@@ -1289,10 +1289,10 @@ w83781d_write_value_i2c(struct w83781d_data *data, u16 reg, u16 value)
1289 i2c_smbus_write_byte_data(cl, 1, value & 0xff); 1289 i2c_smbus_write_byte_data(cl, 1, value & 0xff);
1290 break; 1290 break;
1291 case 0x53: /* HYST */ 1291 case 0x53: /* HYST */
1292 i2c_smbus_write_word_data(cl, 2, swab16(value)); 1292 i2c_smbus_write_word_swapped(cl, 2, value);
1293 break; 1293 break;
1294 case 0x55: /* OVER */ 1294 case 0x55: /* OVER */
1295 i2c_smbus_write_word_data(cl, 3, swab16(value)); 1295 i2c_smbus_write_word_swapped(cl, 3, value);
1296 break; 1296 break;
1297 } 1297 }
1298 } 1298 }
diff --git a/drivers/hwspinlock/Kconfig b/drivers/hwspinlock/Kconfig
index 1f29bab6b3e5..c7c3128393d1 100644
--- a/drivers/hwspinlock/Kconfig
+++ b/drivers/hwspinlock/Kconfig
@@ -2,22 +2,31 @@
2# Generic HWSPINLOCK framework 2# Generic HWSPINLOCK framework
3# 3#
4 4
5# HWSPINLOCK always gets selected by whoever wants it.
5config HWSPINLOCK 6config HWSPINLOCK
6 tristate "Generic Hardware Spinlock framework" 7 tristate
7 depends on ARCH_OMAP4
8 help
9 Say y here to support the generic hardware spinlock framework.
10 You only need to enable this if you have hardware spinlock module
11 on your system (usually only relevant if your system has remote slave
12 coprocessors).
13 8
14 If unsure, say N. 9menu "Hardware Spinlock drivers"
15 10
16config HWSPINLOCK_OMAP 11config HWSPINLOCK_OMAP
17 tristate "OMAP Hardware Spinlock device" 12 tristate "OMAP Hardware Spinlock device"
18 depends on HWSPINLOCK && ARCH_OMAP4 13 depends on ARCH_OMAP4
14 select HWSPINLOCK
19 help 15 help
20 Say y here to support the OMAP Hardware Spinlock device (firstly 16 Say y here to support the OMAP Hardware Spinlock device (firstly
21 introduced in OMAP4). 17 introduced in OMAP4).
22 18
23 If unsure, say N. 19 If unsure, say N.
20
21config HSEM_U8500
22 tristate "STE Hardware Semaphore functionality"
23 depends on ARCH_U8500
24 select HWSPINLOCK
25 help
26 Say y here to support the STE Hardware Semaphore functionality, which
27 provides a synchronisation mechanism for the various processor on the
28 SoC.
29
30 If unsure, say N.
31
32endmenu
diff --git a/drivers/hwspinlock/Makefile b/drivers/hwspinlock/Makefile
index 5729a3f7ed3d..93eb64b66486 100644
--- a/drivers/hwspinlock/Makefile
+++ b/drivers/hwspinlock/Makefile
@@ -4,3 +4,4 @@
4 4
5obj-$(CONFIG_HWSPINLOCK) += hwspinlock_core.o 5obj-$(CONFIG_HWSPINLOCK) += hwspinlock_core.o
6obj-$(CONFIG_HWSPINLOCK_OMAP) += omap_hwspinlock.o 6obj-$(CONFIG_HWSPINLOCK_OMAP) += omap_hwspinlock.o
7obj-$(CONFIG_HSEM_U8500) += u8500_hsem.o
diff --git a/drivers/hwspinlock/hwspinlock_core.c b/drivers/hwspinlock/hwspinlock_core.c
index 43a62714b4fb..61c9cf15fa52 100644
--- a/drivers/hwspinlock/hwspinlock_core.c
+++ b/drivers/hwspinlock/hwspinlock_core.c
@@ -26,6 +26,7 @@
26#include <linux/radix-tree.h> 26#include <linux/radix-tree.h>
27#include <linux/hwspinlock.h> 27#include <linux/hwspinlock.h>
28#include <linux/pm_runtime.h> 28#include <linux/pm_runtime.h>
29#include <linux/mutex.h>
29 30
30#include "hwspinlock_internal.h" 31#include "hwspinlock_internal.h"
31 32
@@ -52,10 +53,12 @@
52static RADIX_TREE(hwspinlock_tree, GFP_KERNEL); 53static RADIX_TREE(hwspinlock_tree, GFP_KERNEL);
53 54
54/* 55/*
55 * Synchronization of access to the tree is achieved using this spinlock, 56 * Synchronization of access to the tree is achieved using this mutex,
56 * as the radix-tree API requires that users provide all synchronisation. 57 * as the radix-tree API requires that users provide all synchronisation.
58 * A mutex is needed because we're using non-atomic radix tree allocations.
57 */ 59 */
58static DEFINE_SPINLOCK(hwspinlock_tree_lock); 60static DEFINE_MUTEX(hwspinlock_tree_lock);
61
59 62
60/** 63/**
61 * __hwspin_trylock() - attempt to lock a specific hwspinlock 64 * __hwspin_trylock() - attempt to lock a specific hwspinlock
@@ -114,7 +117,7 @@ int __hwspin_trylock(struct hwspinlock *hwlock, int mode, unsigned long *flags)
114 return -EBUSY; 117 return -EBUSY;
115 118
116 /* try to take the hwspinlock device */ 119 /* try to take the hwspinlock device */
117 ret = hwlock->ops->trylock(hwlock); 120 ret = hwlock->bank->ops->trylock(hwlock);
118 121
119 /* if hwlock is already taken, undo spin_trylock_* and exit */ 122 /* if hwlock is already taken, undo spin_trylock_* and exit */
120 if (!ret) { 123 if (!ret) {
@@ -196,8 +199,8 @@ int __hwspin_lock_timeout(struct hwspinlock *hwlock, unsigned int to,
196 * Allow platform-specific relax handlers to prevent 199 * Allow platform-specific relax handlers to prevent
197 * hogging the interconnect (no sleeping, though) 200 * hogging the interconnect (no sleeping, though)
198 */ 201 */
199 if (hwlock->ops->relax) 202 if (hwlock->bank->ops->relax)
200 hwlock->ops->relax(hwlock); 203 hwlock->bank->ops->relax(hwlock);
201 } 204 }
202 205
203 return ret; 206 return ret;
@@ -242,7 +245,7 @@ void __hwspin_unlock(struct hwspinlock *hwlock, int mode, unsigned long *flags)
242 */ 245 */
243 mb(); 246 mb();
244 247
245 hwlock->ops->unlock(hwlock); 248 hwlock->bank->ops->unlock(hwlock);
246 249
247 /* Undo the spin_trylock{_irq, _irqsave} called while locking */ 250 /* Undo the spin_trylock{_irq, _irqsave} called while locking */
248 if (mode == HWLOCK_IRQSTATE) 251 if (mode == HWLOCK_IRQSTATE)
@@ -254,68 +257,37 @@ void __hwspin_unlock(struct hwspinlock *hwlock, int mode, unsigned long *flags)
254} 257}
255EXPORT_SYMBOL_GPL(__hwspin_unlock); 258EXPORT_SYMBOL_GPL(__hwspin_unlock);
256 259
257/** 260static int hwspin_lock_register_single(struct hwspinlock *hwlock, int id)
258 * hwspin_lock_register() - register a new hw spinlock
259 * @hwlock: hwspinlock to register.
260 *
261 * This function should be called from the underlying platform-specific
262 * implementation, to register a new hwspinlock instance.
263 *
264 * Can be called from an atomic context (will not sleep) but not from
265 * within interrupt context.
266 *
267 * Returns 0 on success, or an appropriate error code on failure
268 */
269int hwspin_lock_register(struct hwspinlock *hwlock)
270{ 261{
271 struct hwspinlock *tmp; 262 struct hwspinlock *tmp;
272 int ret; 263 int ret;
273 264
274 if (!hwlock || !hwlock->ops || 265 mutex_lock(&hwspinlock_tree_lock);
275 !hwlock->ops->trylock || !hwlock->ops->unlock) {
276 pr_err("invalid parameters\n");
277 return -EINVAL;
278 }
279
280 spin_lock_init(&hwlock->lock);
281
282 spin_lock(&hwspinlock_tree_lock);
283 266
284 ret = radix_tree_insert(&hwspinlock_tree, hwlock->id, hwlock); 267 ret = radix_tree_insert(&hwspinlock_tree, id, hwlock);
285 if (ret) 268 if (ret) {
269 if (ret == -EEXIST)
270 pr_err("hwspinlock id %d already exists!\n", id);
286 goto out; 271 goto out;
272 }
287 273
288 /* mark this hwspinlock as available */ 274 /* mark this hwspinlock as available */
289 tmp = radix_tree_tag_set(&hwspinlock_tree, hwlock->id, 275 tmp = radix_tree_tag_set(&hwspinlock_tree, id, HWSPINLOCK_UNUSED);
290 HWSPINLOCK_UNUSED);
291 276
292 /* self-sanity check which should never fail */ 277 /* self-sanity check which should never fail */
293 WARN_ON(tmp != hwlock); 278 WARN_ON(tmp != hwlock);
294 279
295out: 280out:
296 spin_unlock(&hwspinlock_tree_lock); 281 mutex_unlock(&hwspinlock_tree_lock);
297 return ret; 282 return 0;
298} 283}
299EXPORT_SYMBOL_GPL(hwspin_lock_register);
300 284
301/** 285static struct hwspinlock *hwspin_lock_unregister_single(unsigned int id)
302 * hwspin_lock_unregister() - unregister an hw spinlock
303 * @id: index of the specific hwspinlock to unregister
304 *
305 * This function should be called from the underlying platform-specific
306 * implementation, to unregister an existing (and unused) hwspinlock.
307 *
308 * Can be called from an atomic context (will not sleep) but not from
309 * within interrupt context.
310 *
311 * Returns the address of hwspinlock @id on success, or NULL on failure
312 */
313struct hwspinlock *hwspin_lock_unregister(unsigned int id)
314{ 286{
315 struct hwspinlock *hwlock = NULL; 287 struct hwspinlock *hwlock = NULL;
316 int ret; 288 int ret;
317 289
318 spin_lock(&hwspinlock_tree_lock); 290 mutex_lock(&hwspinlock_tree_lock);
319 291
320 /* make sure the hwspinlock is not in use (tag is set) */ 292 /* make sure the hwspinlock is not in use (tag is set) */
321 ret = radix_tree_tag_get(&hwspinlock_tree, id, HWSPINLOCK_UNUSED); 293 ret = radix_tree_tag_get(&hwspinlock_tree, id, HWSPINLOCK_UNUSED);
@@ -331,9 +303,91 @@ struct hwspinlock *hwspin_lock_unregister(unsigned int id)
331 } 303 }
332 304
333out: 305out:
334 spin_unlock(&hwspinlock_tree_lock); 306 mutex_unlock(&hwspinlock_tree_lock);
335 return hwlock; 307 return hwlock;
336} 308}
309
310/**
311 * hwspin_lock_register() - register a new hw spinlock device
312 * @bank: the hwspinlock device, which usually provides numerous hw locks
313 * @dev: the backing device
314 * @ops: hwspinlock handlers for this device
315 * @base_id: id of the first hardware spinlock in this bank
316 * @num_locks: number of hwspinlocks provided by this device
317 *
318 * This function should be called from the underlying platform-specific
319 * implementation, to register a new hwspinlock device instance.
320 *
321 * Should be called from a process context (might sleep)
322 *
323 * Returns 0 on success, or an appropriate error code on failure
324 */
325int hwspin_lock_register(struct hwspinlock_device *bank, struct device *dev,
326 const struct hwspinlock_ops *ops, int base_id, int num_locks)
327{
328 struct hwspinlock *hwlock;
329 int ret = 0, i;
330
331 if (!bank || !ops || !dev || !num_locks || !ops->trylock ||
332 !ops->unlock) {
333 pr_err("invalid parameters\n");
334 return -EINVAL;
335 }
336
337 bank->dev = dev;
338 bank->ops = ops;
339 bank->base_id = base_id;
340 bank->num_locks = num_locks;
341
342 for (i = 0; i < num_locks; i++) {
343 hwlock = &bank->lock[i];
344
345 spin_lock_init(&hwlock->lock);
346 hwlock->bank = bank;
347
348 ret = hwspin_lock_register_single(hwlock, i);
349 if (ret)
350 goto reg_failed;
351 }
352
353 return 0;
354
355reg_failed:
356 while (--i >= 0)
357 hwspin_lock_unregister_single(i);
358 return ret;
359}
360EXPORT_SYMBOL_GPL(hwspin_lock_register);
361
362/**
363 * hwspin_lock_unregister() - unregister an hw spinlock device
364 * @bank: the hwspinlock device, which usually provides numerous hw locks
365 *
366 * This function should be called from the underlying platform-specific
367 * implementation, to unregister an existing (and unused) hwspinlock.
368 *
369 * Should be called from a process context (might sleep)
370 *
371 * Returns 0 on success, or an appropriate error code on failure
372 */
373int hwspin_lock_unregister(struct hwspinlock_device *bank)
374{
375 struct hwspinlock *hwlock, *tmp;
376 int i;
377
378 for (i = 0; i < bank->num_locks; i++) {
379 hwlock = &bank->lock[i];
380
381 tmp = hwspin_lock_unregister_single(bank->base_id + i);
382 if (!tmp)
383 return -EBUSY;
384
385 /* self-sanity check that should never fail */
386 WARN_ON(tmp != hwlock);
387 }
388
389 return 0;
390}
337EXPORT_SYMBOL_GPL(hwspin_lock_unregister); 391EXPORT_SYMBOL_GPL(hwspin_lock_unregister);
338 392
339/** 393/**
@@ -348,24 +402,25 @@ EXPORT_SYMBOL_GPL(hwspin_lock_unregister);
348 */ 402 */
349static int __hwspin_lock_request(struct hwspinlock *hwlock) 403static int __hwspin_lock_request(struct hwspinlock *hwlock)
350{ 404{
405 struct device *dev = hwlock->bank->dev;
351 struct hwspinlock *tmp; 406 struct hwspinlock *tmp;
352 int ret; 407 int ret;
353 408
354 /* prevent underlying implementation from being removed */ 409 /* prevent underlying implementation from being removed */
355 if (!try_module_get(hwlock->owner)) { 410 if (!try_module_get(dev->driver->owner)) {
356 dev_err(hwlock->dev, "%s: can't get owner\n", __func__); 411 dev_err(dev, "%s: can't get owner\n", __func__);
357 return -EINVAL; 412 return -EINVAL;
358 } 413 }
359 414
360 /* notify PM core that power is now needed */ 415 /* notify PM core that power is now needed */
361 ret = pm_runtime_get_sync(hwlock->dev); 416 ret = pm_runtime_get_sync(dev);
362 if (ret < 0) { 417 if (ret < 0) {
363 dev_err(hwlock->dev, "%s: can't power on device\n", __func__); 418 dev_err(dev, "%s: can't power on device\n", __func__);
364 return ret; 419 return ret;
365 } 420 }
366 421
367 /* mark hwspinlock as used, should not fail */ 422 /* mark hwspinlock as used, should not fail */
368 tmp = radix_tree_tag_clear(&hwspinlock_tree, hwlock->id, 423 tmp = radix_tree_tag_clear(&hwspinlock_tree, hwlock_to_id(hwlock),
369 HWSPINLOCK_UNUSED); 424 HWSPINLOCK_UNUSED);
370 425
371 /* self-sanity check that should never fail */ 426 /* self-sanity check that should never fail */
@@ -387,7 +442,7 @@ int hwspin_lock_get_id(struct hwspinlock *hwlock)
387 return -EINVAL; 442 return -EINVAL;
388 } 443 }
389 444
390 return hwlock->id; 445 return hwlock_to_id(hwlock);
391} 446}
392EXPORT_SYMBOL_GPL(hwspin_lock_get_id); 447EXPORT_SYMBOL_GPL(hwspin_lock_get_id);
393 448
@@ -400,9 +455,7 @@ EXPORT_SYMBOL_GPL(hwspin_lock_get_id);
400 * to the remote core before it can be used for synchronization (to get the 455 * to the remote core before it can be used for synchronization (to get the
401 * id of a given hwlock, use hwspin_lock_get_id()). 456 * id of a given hwlock, use hwspin_lock_get_id()).
402 * 457 *
403 * Can be called from an atomic context (will not sleep) but not from 458 * Should be called from a process context (might sleep)
404 * within interrupt context (simply because there is no use case for
405 * that yet).
406 * 459 *
407 * Returns the address of the assigned hwspinlock, or NULL on error 460 * Returns the address of the assigned hwspinlock, or NULL on error
408 */ 461 */
@@ -411,7 +464,7 @@ struct hwspinlock *hwspin_lock_request(void)
411 struct hwspinlock *hwlock; 464 struct hwspinlock *hwlock;
412 int ret; 465 int ret;
413 466
414 spin_lock(&hwspinlock_tree_lock); 467 mutex_lock(&hwspinlock_tree_lock);
415 468
416 /* look for an unused lock */ 469 /* look for an unused lock */
417 ret = radix_tree_gang_lookup_tag(&hwspinlock_tree, (void **)&hwlock, 470 ret = radix_tree_gang_lookup_tag(&hwspinlock_tree, (void **)&hwlock,
@@ -431,7 +484,7 @@ struct hwspinlock *hwspin_lock_request(void)
431 hwlock = NULL; 484 hwlock = NULL;
432 485
433out: 486out:
434 spin_unlock(&hwspinlock_tree_lock); 487 mutex_unlock(&hwspinlock_tree_lock);
435 return hwlock; 488 return hwlock;
436} 489}
437EXPORT_SYMBOL_GPL(hwspin_lock_request); 490EXPORT_SYMBOL_GPL(hwspin_lock_request);
@@ -445,9 +498,7 @@ EXPORT_SYMBOL_GPL(hwspin_lock_request);
445 * Usually early board code will be calling this function in order to 498 * Usually early board code will be calling this function in order to
446 * reserve specific hwspinlock ids for predefined purposes. 499 * reserve specific hwspinlock ids for predefined purposes.
447 * 500 *
448 * Can be called from an atomic context (will not sleep) but not from 501 * Should be called from a process context (might sleep)
449 * within interrupt context (simply because there is no use case for
450 * that yet).
451 * 502 *
452 * Returns the address of the assigned hwspinlock, or NULL on error 503 * Returns the address of the assigned hwspinlock, or NULL on error
453 */ 504 */
@@ -456,7 +507,7 @@ struct hwspinlock *hwspin_lock_request_specific(unsigned int id)
456 struct hwspinlock *hwlock; 507 struct hwspinlock *hwlock;
457 int ret; 508 int ret;
458 509
459 spin_lock(&hwspinlock_tree_lock); 510 mutex_lock(&hwspinlock_tree_lock);
460 511
461 /* make sure this hwspinlock exists */ 512 /* make sure this hwspinlock exists */
462 hwlock = radix_tree_lookup(&hwspinlock_tree, id); 513 hwlock = radix_tree_lookup(&hwspinlock_tree, id);
@@ -466,7 +517,7 @@ struct hwspinlock *hwspin_lock_request_specific(unsigned int id)
466 } 517 }
467 518
468 /* sanity check (this shouldn't happen) */ 519 /* sanity check (this shouldn't happen) */
469 WARN_ON(hwlock->id != id); 520 WARN_ON(hwlock_to_id(hwlock) != id);
470 521
471 /* make sure this hwspinlock is unused */ 522 /* make sure this hwspinlock is unused */
472 ret = radix_tree_tag_get(&hwspinlock_tree, id, HWSPINLOCK_UNUSED); 523 ret = radix_tree_tag_get(&hwspinlock_tree, id, HWSPINLOCK_UNUSED);
@@ -482,7 +533,7 @@ struct hwspinlock *hwspin_lock_request_specific(unsigned int id)
482 hwlock = NULL; 533 hwlock = NULL;
483 534
484out: 535out:
485 spin_unlock(&hwspinlock_tree_lock); 536 mutex_unlock(&hwspinlock_tree_lock);
486 return hwlock; 537 return hwlock;
487} 538}
488EXPORT_SYMBOL_GPL(hwspin_lock_request_specific); 539EXPORT_SYMBOL_GPL(hwspin_lock_request_specific);
@@ -495,14 +546,13 @@ EXPORT_SYMBOL_GPL(hwspin_lock_request_specific);
495 * Should only be called with an @hwlock that was retrieved from 546 * Should only be called with an @hwlock that was retrieved from
496 * an earlier call to omap_hwspin_lock_request{_specific}. 547 * an earlier call to omap_hwspin_lock_request{_specific}.
497 * 548 *
498 * Can be called from an atomic context (will not sleep) but not from 549 * Should be called from a process context (might sleep)
499 * within interrupt context (simply because there is no use case for
500 * that yet).
501 * 550 *
502 * Returns 0 on success, or an appropriate error code on failure 551 * Returns 0 on success, or an appropriate error code on failure
503 */ 552 */
504int hwspin_lock_free(struct hwspinlock *hwlock) 553int hwspin_lock_free(struct hwspinlock *hwlock)
505{ 554{
555 struct device *dev = hwlock->bank->dev;
506 struct hwspinlock *tmp; 556 struct hwspinlock *tmp;
507 int ret; 557 int ret;
508 558
@@ -511,34 +561,34 @@ int hwspin_lock_free(struct hwspinlock *hwlock)
511 return -EINVAL; 561 return -EINVAL;
512 } 562 }
513 563
514 spin_lock(&hwspinlock_tree_lock); 564 mutex_lock(&hwspinlock_tree_lock);
515 565
516 /* make sure the hwspinlock is used */ 566 /* make sure the hwspinlock is used */
517 ret = radix_tree_tag_get(&hwspinlock_tree, hwlock->id, 567 ret = radix_tree_tag_get(&hwspinlock_tree, hwlock_to_id(hwlock),
518 HWSPINLOCK_UNUSED); 568 HWSPINLOCK_UNUSED);
519 if (ret == 1) { 569 if (ret == 1) {
520 dev_err(hwlock->dev, "%s: hwlock is already free\n", __func__); 570 dev_err(dev, "%s: hwlock is already free\n", __func__);
521 dump_stack(); 571 dump_stack();
522 ret = -EINVAL; 572 ret = -EINVAL;
523 goto out; 573 goto out;
524 } 574 }
525 575
526 /* notify the underlying device that power is not needed */ 576 /* notify the underlying device that power is not needed */
527 ret = pm_runtime_put(hwlock->dev); 577 ret = pm_runtime_put(dev);
528 if (ret < 0) 578 if (ret < 0)
529 goto out; 579 goto out;
530 580
531 /* mark this hwspinlock as available */ 581 /* mark this hwspinlock as available */
532 tmp = radix_tree_tag_set(&hwspinlock_tree, hwlock->id, 582 tmp = radix_tree_tag_set(&hwspinlock_tree, hwlock_to_id(hwlock),
533 HWSPINLOCK_UNUSED); 583 HWSPINLOCK_UNUSED);
534 584
535 /* sanity check (this shouldn't happen) */ 585 /* sanity check (this shouldn't happen) */
536 WARN_ON(tmp != hwlock); 586 WARN_ON(tmp != hwlock);
537 587
538 module_put(hwlock->owner); 588 module_put(dev->driver->owner);
539 589
540out: 590out:
541 spin_unlock(&hwspinlock_tree_lock); 591 mutex_unlock(&hwspinlock_tree_lock);
542 return ret; 592 return ret;
543} 593}
544EXPORT_SYMBOL_GPL(hwspin_lock_free); 594EXPORT_SYMBOL_GPL(hwspin_lock_free);
diff --git a/drivers/hwspinlock/hwspinlock_internal.h b/drivers/hwspinlock/hwspinlock_internal.h
index 69935e6b93e5..d26f78b8f214 100644
--- a/drivers/hwspinlock/hwspinlock_internal.h
+++ b/drivers/hwspinlock/hwspinlock_internal.h
@@ -21,6 +21,8 @@
21#include <linux/spinlock.h> 21#include <linux/spinlock.h>
22#include <linux/device.h> 22#include <linux/device.h>
23 23
24struct hwspinlock_device;
25
24/** 26/**
25 * struct hwspinlock_ops - platform-specific hwspinlock handlers 27 * struct hwspinlock_ops - platform-specific hwspinlock handlers
26 * 28 *
@@ -39,23 +41,37 @@ struct hwspinlock_ops {
39 41
40/** 42/**
41 * struct hwspinlock - this struct represents a single hwspinlock instance 43 * struct hwspinlock - this struct represents a single hwspinlock instance
42 * 44 * @bank: the hwspinlock_device structure which owns this lock
43 * @dev: underlying device, will be used to invoke runtime PM api
44 * @ops: platform-specific hwspinlock handlers
45 * @id: a global, unique, system-wide, index of the lock.
46 * @lock: initialized and used by hwspinlock core 45 * @lock: initialized and used by hwspinlock core
47 * @owner: underlying implementation module, used to maintain module ref count 46 * @priv: private data, owned by the underlying platform-specific hwspinlock drv
48 *
49 * Note: currently simplicity was opted for, but later we can squeeze some
50 * memory bytes by grouping the dev, ops and owner members in a single
51 * per-platform struct, and have all hwspinlocks point at it.
52 */ 47 */
53struct hwspinlock { 48struct hwspinlock {
49 struct hwspinlock_device *bank;
50 spinlock_t lock;
51 void *priv;
52};
53
54/**
55 * struct hwspinlock_device - a device which usually spans numerous hwspinlocks
56 * @dev: underlying device, will be used to invoke runtime PM api
57 * @ops: platform-specific hwspinlock handlers
58 * @base_id: id index of the first lock in this device
59 * @num_locks: number of locks in this device
60 * @lock: dynamically allocated array of 'struct hwspinlock'
61 */
62struct hwspinlock_device {
54 struct device *dev; 63 struct device *dev;
55 const struct hwspinlock_ops *ops; 64 const struct hwspinlock_ops *ops;
56 int id; 65 int base_id;
57 spinlock_t lock; 66 int num_locks;
58 struct module *owner; 67 struct hwspinlock lock[0];
59}; 68};
60 69
70static inline int hwlock_to_id(struct hwspinlock *hwlock)
71{
72 int local_id = hwlock - &hwlock->bank->lock[0];
73
74 return hwlock->bank->base_id + local_id;
75}
76
61#endif /* __HWSPINLOCK_HWSPINLOCK_H */ 77#endif /* __HWSPINLOCK_HWSPINLOCK_H */
diff --git a/drivers/hwspinlock/omap_hwspinlock.c b/drivers/hwspinlock/omap_hwspinlock.c
index a8f02734c026..887d34effb3a 100644
--- a/drivers/hwspinlock/omap_hwspinlock.c
+++ b/drivers/hwspinlock/omap_hwspinlock.c
@@ -41,33 +41,20 @@
41#define SPINLOCK_NOTTAKEN (0) /* free */ 41#define SPINLOCK_NOTTAKEN (0) /* free */
42#define SPINLOCK_TAKEN (1) /* locked */ 42#define SPINLOCK_TAKEN (1) /* locked */
43 43
44#define to_omap_hwspinlock(lock) \
45 container_of(lock, struct omap_hwspinlock, lock)
46
47struct omap_hwspinlock {
48 struct hwspinlock lock;
49 void __iomem *addr;
50};
51
52struct omap_hwspinlock_state {
53 int num_locks; /* Total number of locks in system */
54 void __iomem *io_base; /* Mapped base address */
55};
56
57static int omap_hwspinlock_trylock(struct hwspinlock *lock) 44static int omap_hwspinlock_trylock(struct hwspinlock *lock)
58{ 45{
59 struct omap_hwspinlock *omap_lock = to_omap_hwspinlock(lock); 46 void __iomem *lock_addr = lock->priv;
60 47
61 /* attempt to acquire the lock by reading its value */ 48 /* attempt to acquire the lock by reading its value */
62 return (SPINLOCK_NOTTAKEN == readl(omap_lock->addr)); 49 return (SPINLOCK_NOTTAKEN == readl(lock_addr));
63} 50}
64 51
65static void omap_hwspinlock_unlock(struct hwspinlock *lock) 52static void omap_hwspinlock_unlock(struct hwspinlock *lock)
66{ 53{
67 struct omap_hwspinlock *omap_lock = to_omap_hwspinlock(lock); 54 void __iomem *lock_addr = lock->priv;
68 55
69 /* release the lock by writing 0 to it */ 56 /* release the lock by writing 0 to it */
70 writel(SPINLOCK_NOTTAKEN, omap_lock->addr); 57 writel(SPINLOCK_NOTTAKEN, lock_addr);
71} 58}
72 59
73/* 60/*
@@ -93,26 +80,23 @@ static const struct hwspinlock_ops omap_hwspinlock_ops = {
93 80
94static int __devinit omap_hwspinlock_probe(struct platform_device *pdev) 81static int __devinit omap_hwspinlock_probe(struct platform_device *pdev)
95{ 82{
96 struct omap_hwspinlock *omap_lock; 83 struct hwspinlock_pdata *pdata = pdev->dev.platform_data;
97 struct omap_hwspinlock_state *state; 84 struct hwspinlock_device *bank;
98 struct hwspinlock *lock; 85 struct hwspinlock *hwlock;
99 struct resource *res; 86 struct resource *res;
100 void __iomem *io_base; 87 void __iomem *io_base;
101 int i, ret; 88 int num_locks, i, ret;
89
90 if (!pdata)
91 return -ENODEV;
102 92
103 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 93 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
104 if (!res) 94 if (!res)
105 return -ENODEV; 95 return -ENODEV;
106 96
107 state = kzalloc(sizeof(*state), GFP_KERNEL);
108 if (!state)
109 return -ENOMEM;
110
111 io_base = ioremap(res->start, resource_size(res)); 97 io_base = ioremap(res->start, resource_size(res));
112 if (!io_base) { 98 if (!io_base)
113 ret = -ENOMEM; 99 return -ENOMEM;
114 goto free_state;
115 }
116 100
117 /* Determine number of locks */ 101 /* Determine number of locks */
118 i = readl(io_base + SYSSTATUS_OFFSET); 102 i = readl(io_base + SYSSTATUS_OFFSET);
@@ -124,10 +108,18 @@ static int __devinit omap_hwspinlock_probe(struct platform_device *pdev)
124 goto iounmap_base; 108 goto iounmap_base;
125 } 109 }
126 110
127 state->num_locks = i * 32; 111 num_locks = i * 32; /* actual number of locks in this device */
128 state->io_base = io_base; 112
113 bank = kzalloc(sizeof(*bank) + num_locks * sizeof(*hwlock), GFP_KERNEL);
114 if (!bank) {
115 ret = -ENOMEM;
116 goto iounmap_base;
117 }
118
119 platform_set_drvdata(pdev, bank);
129 120
130 platform_set_drvdata(pdev, state); 121 for (i = 0, hwlock = &bank->lock[0]; i < num_locks; i++, hwlock++)
122 hwlock->priv = io_base + LOCK_BASE_OFFSET + sizeof(u32) * i;
131 123
132 /* 124 /*
133 * runtime PM will make sure the clock of this module is 125 * runtime PM will make sure the clock of this module is
@@ -135,79 +127,46 @@ static int __devinit omap_hwspinlock_probe(struct platform_device *pdev)
135 */ 127 */
136 pm_runtime_enable(&pdev->dev); 128 pm_runtime_enable(&pdev->dev);
137 129
138 for (i = 0; i < state->num_locks; i++) { 130 ret = hwspin_lock_register(bank, &pdev->dev, &omap_hwspinlock_ops,
139 omap_lock = kzalloc(sizeof(*omap_lock), GFP_KERNEL); 131 pdata->base_id, num_locks);
140 if (!omap_lock) { 132 if (ret)
141 ret = -ENOMEM; 133 goto reg_fail;
142 goto free_locks;
143 }
144
145 omap_lock->lock.dev = &pdev->dev;
146 omap_lock->lock.owner = THIS_MODULE;
147 omap_lock->lock.id = i;
148 omap_lock->lock.ops = &omap_hwspinlock_ops;
149 omap_lock->addr = io_base + LOCK_BASE_OFFSET + sizeof(u32) * i;
150
151 ret = hwspin_lock_register(&omap_lock->lock);
152 if (ret) {
153 kfree(omap_lock);
154 goto free_locks;
155 }
156 }
157 134
158 return 0; 135 return 0;
159 136
160free_locks: 137reg_fail:
161 while (--i >= 0) {
162 lock = hwspin_lock_unregister(i);
163 /* this should't happen, but let's give our best effort */
164 if (!lock) {
165 dev_err(&pdev->dev, "%s: cleanups failed\n", __func__);
166 continue;
167 }
168 omap_lock = to_omap_hwspinlock(lock);
169 kfree(omap_lock);
170 }
171 pm_runtime_disable(&pdev->dev); 138 pm_runtime_disable(&pdev->dev);
139 kfree(bank);
172iounmap_base: 140iounmap_base:
173 iounmap(io_base); 141 iounmap(io_base);
174free_state:
175 kfree(state);
176 return ret; 142 return ret;
177} 143}
178 144
179static int omap_hwspinlock_remove(struct platform_device *pdev) 145static int __devexit omap_hwspinlock_remove(struct platform_device *pdev)
180{ 146{
181 struct omap_hwspinlock_state *state = platform_get_drvdata(pdev); 147 struct hwspinlock_device *bank = platform_get_drvdata(pdev);
182 struct hwspinlock *lock; 148 void __iomem *io_base = bank->lock[0].priv - LOCK_BASE_OFFSET;
183 struct omap_hwspinlock *omap_lock; 149 int ret;
184 int i; 150
185 151 ret = hwspin_lock_unregister(bank);
186 for (i = 0; i < state->num_locks; i++) { 152 if (ret) {
187 lock = hwspin_lock_unregister(i); 153 dev_err(&pdev->dev, "%s failed: %d\n", __func__, ret);
188 /* this shouldn't happen at this point. if it does, at least 154 return ret;
189 * don't continue with the remove */
190 if (!lock) {
191 dev_err(&pdev->dev, "%s: failed on %d\n", __func__, i);
192 return -EBUSY;
193 }
194
195 omap_lock = to_omap_hwspinlock(lock);
196 kfree(omap_lock);
197 } 155 }
198 156
199 pm_runtime_disable(&pdev->dev); 157 pm_runtime_disable(&pdev->dev);
200 iounmap(state->io_base); 158 iounmap(io_base);
201 kfree(state); 159 kfree(bank);
202 160
203 return 0; 161 return 0;
204} 162}
205 163
206static struct platform_driver omap_hwspinlock_driver = { 164static struct platform_driver omap_hwspinlock_driver = {
207 .probe = omap_hwspinlock_probe, 165 .probe = omap_hwspinlock_probe,
208 .remove = omap_hwspinlock_remove, 166 .remove = __devexit_p(omap_hwspinlock_remove),
209 .driver = { 167 .driver = {
210 .name = "omap_hwspinlock", 168 .name = "omap_hwspinlock",
169 .owner = THIS_MODULE,
211 }, 170 },
212}; 171};
213 172
diff --git a/drivers/hwspinlock/u8500_hsem.c b/drivers/hwspinlock/u8500_hsem.c
new file mode 100644
index 000000000000..143461a95ae4
--- /dev/null
+++ b/drivers/hwspinlock/u8500_hsem.c
@@ -0,0 +1,198 @@
1/*
2 * u8500 HWSEM driver
3 *
4 * Copyright (C) 2010-2011 ST-Ericsson
5 *
6 * Implements u8500 semaphore handling for protocol 1, no interrupts.
7 *
8 * Author: Mathieu Poirier <mathieu.poirier@linaro.org>
9 * Heavily borrowed from the work of :
10 * Simon Que <sque@ti.com>
11 * Hari Kanigeri <h-kanigeri2@ti.com>
12 * Ohad Ben-Cohen <ohad@wizery.com>
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * version 2 as published by the Free Software Foundation.
17 *
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * General Public License for more details.
22 */
23
24#include <linux/delay.h>
25#include <linux/io.h>
26#include <linux/pm_runtime.h>
27#include <linux/slab.h>
28#include <linux/spinlock.h>
29#include <linux/hwspinlock.h>
30#include <linux/platform_device.h>
31
32#include "hwspinlock_internal.h"
33
34/*
35 * Implementation of STE's HSem protocol 1 without interrutps.
36 * The only masterID we allow is '0x01' to force people to use
37 * HSems for synchronisation between processors rather than processes
38 * on the ARM core.
39 */
40
41#define U8500_MAX_SEMAPHORE 32 /* a total of 32 semaphore */
42#define RESET_SEMAPHORE (0) /* free */
43
44/*
45 * CPU ID for master running u8500 kernel.
46 * Hswpinlocks should only be used to synchonise operations
47 * between the Cortex A9 core and the other CPUs. Hence
48 * forcing the masterID to a preset value.
49 */
50#define HSEM_MASTER_ID 0x01
51
52#define HSEM_REGISTER_OFFSET 0x08
53
54#define HSEM_CTRL_REG 0x00
55#define HSEM_ICRALL 0x90
56#define HSEM_PROTOCOL_1 0x01
57
58static int u8500_hsem_trylock(struct hwspinlock *lock)
59{
60 void __iomem *lock_addr = lock->priv;
61
62 writel(HSEM_MASTER_ID, lock_addr);
63
64 /* get only first 4 bit and compare to masterID.
65 * if equal, we have the semaphore, otherwise
66 * someone else has it.
67 */
68 return (HSEM_MASTER_ID == (0x0F & readl(lock_addr)));
69}
70
71static void u8500_hsem_unlock(struct hwspinlock *lock)
72{
73 void __iomem *lock_addr = lock->priv;
74
75 /* release the lock by writing 0 to it */
76 writel(RESET_SEMAPHORE, lock_addr);
77}
78
79/*
80 * u8500: what value is recommended here ?
81 */
82static void u8500_hsem_relax(struct hwspinlock *lock)
83{
84 ndelay(50);
85}
86
87static const struct hwspinlock_ops u8500_hwspinlock_ops = {
88 .trylock = u8500_hsem_trylock,
89 .unlock = u8500_hsem_unlock,
90 .relax = u8500_hsem_relax,
91};
92
93static int __devinit u8500_hsem_probe(struct platform_device *pdev)
94{
95 struct hwspinlock_pdata *pdata = pdev->dev.platform_data;
96 struct hwspinlock_device *bank;
97 struct hwspinlock *hwlock;
98 struct resource *res;
99 void __iomem *io_base;
100 int i, ret, num_locks = U8500_MAX_SEMAPHORE;
101 ulong val;
102
103 if (!pdata)
104 return -ENODEV;
105
106 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
107 if (!res)
108 return -ENODEV;
109
110 io_base = ioremap(res->start, resource_size(res));
111 if (!io_base) {
112 ret = -ENOMEM;
113 goto free_state;
114 }
115
116 /* make sure protocol 1 is selected */
117 val = readl(io_base + HSEM_CTRL_REG);
118 writel((val & ~HSEM_PROTOCOL_1), io_base + HSEM_CTRL_REG);
119
120 /* clear all interrupts */
121 writel(0xFFFF, io_base + HSEM_ICRALL);
122
123 bank = kzalloc(sizeof(*bank) + num_locks * sizeof(*hwlock), GFP_KERNEL);
124 if (!bank) {
125 ret = -ENOMEM;
126 goto iounmap_base;
127 }
128
129 platform_set_drvdata(pdev, bank);
130
131 for (i = 0, hwlock = &bank->lock[0]; i < num_locks; i++, hwlock++)
132 hwlock->priv = io_base + HSEM_REGISTER_OFFSET + sizeof(u32) * i;
133
134 /* no pm needed for HSem but required to comply with hwspilock core */
135 pm_runtime_enable(&pdev->dev);
136
137 ret = hwspin_lock_register(bank, &pdev->dev, &u8500_hwspinlock_ops,
138 pdata->base_id, num_locks);
139 if (ret)
140 goto reg_fail;
141
142 return 0;
143
144reg_fail:
145 pm_runtime_disable(&pdev->dev);
146 kfree(bank);
147iounmap_base:
148 iounmap(io_base);
149 return ret;
150}
151
152static int __devexit u8500_hsem_remove(struct platform_device *pdev)
153{
154 struct hwspinlock_device *bank = platform_get_drvdata(pdev);
155 void __iomem *io_base = bank->lock[0].priv - HSEM_REGISTER_OFFSET;
156 int ret;
157
158 /* clear all interrupts */
159 writel(0xFFFF, io_base + HSEM_ICRALL);
160
161 ret = hwspin_lock_unregister(bank);
162 if (ret) {
163 dev_err(&pdev->dev, "%s failed: %d\n", __func__, ret);
164 return ret;
165 }
166
167 pm_runtime_disable(&pdev->dev);
168 iounmap(io_base);
169 kfree(bank);
170
171 return 0;
172}
173
174static struct platform_driver u8500_hsem_driver = {
175 .probe = u8500_hsem_probe,
176 .remove = __devexit_p(u8500_hsem_remove),
177 .driver = {
178 .name = "u8500_hsem",
179 .owner = THIS_MODULE,
180 },
181};
182
183static int __init u8500_hsem_init(void)
184{
185 return platform_driver_register(&u8500_hsem_driver);
186}
187/* board init code might need to reserve hwspinlocks for predefined purposes */
188postcore_initcall(u8500_hsem_init);
189
190static void __exit u8500_hsem_exit(void)
191{
192 platform_driver_unregister(&u8500_hsem_driver);
193}
194module_exit(u8500_hsem_exit);
195
196MODULE_LICENSE("GPL v2");
197MODULE_DESCRIPTION("Hardware Spinlock driver for u8500");
198MODULE_AUTHOR("Mathieu Poirier <mathieu.poirier@linaro.org>");
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index b2b85629d074..a3afac4be734 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -110,7 +110,6 @@ config I2C_I801
110config I2C_ISCH 110config I2C_ISCH
111 tristate "Intel SCH SMBus 1.0" 111 tristate "Intel SCH SMBus 1.0"
112 depends on PCI 112 depends on PCI
113 select MFD_CORE
114 select LPC_SCH 113 select LPC_SCH
115 help 114 help
116 Say Y here if you want to use SMBus controller on the Intel SCH 115 Say Y here if you want to use SMBus controller on the Intel SCH
@@ -301,7 +300,7 @@ config I2C_AT91
301 300
302config I2C_AU1550 301config I2C_AU1550
303 tristate "Au1550/Au1200 SMBus interface" 302 tristate "Au1550/Au1200 SMBus interface"
304 depends on SOC_AU1550 || SOC_AU1200 303 depends on MIPS_ALCHEMY
305 help 304 help
306 If you say yes to this option, support will be included for the 305 If you say yes to this option, support will be included for the
307 Au1550 and Au1200 SMBus interface. 306 Au1550 and Au1200 SMBus interface.
diff --git a/drivers/i2c/busses/i2c-au1550.c b/drivers/i2c/busses/i2c-au1550.c
index 4f757a2da8cc..f314d7f433d3 100644
--- a/drivers/i2c/busses/i2c-au1550.c
+++ b/drivers/i2c/busses/i2c-au1550.c
@@ -36,7 +36,7 @@
36#include <linux/i2c.h> 36#include <linux/i2c.h>
37#include <linux/slab.h> 37#include <linux/slab.h>
38 38
39#include <asm/mach-au1x00/au1xxx.h> 39#include <asm/mach-au1x00/au1000.h>
40#include <asm/mach-au1x00/au1xxx_psc.h> 40#include <asm/mach-au1x00/au1xxx_psc.h>
41 41
42#define PSC_SEL 0x00 42#define PSC_SEL 0x00
diff --git a/drivers/i2c/busses/i2c-pxa-pci.c b/drivers/i2c/busses/i2c-pxa-pci.c
index b73da6cd6f91..632e088760a3 100644
--- a/drivers/i2c/busses/i2c-pxa-pci.c
+++ b/drivers/i2c/busses/i2c-pxa-pci.c
@@ -3,6 +3,7 @@
3 * It does not support slave mode, the register slightly moved. This PCI 3 * It does not support slave mode, the register slightly moved. This PCI
4 * device provides three bars, every contains a single I2C controller. 4 * device provides three bars, every contains a single I2C controller.
5 */ 5 */
6#include <linux/module.h>
6#include <linux/pci.h> 7#include <linux/pci.h>
7#include <linux/platform_device.h> 8#include <linux/platform_device.h>
8#include <linux/i2c/pxa-i2c.h> 9#include <linux/i2c/pxa-i2c.h>
diff --git a/drivers/i2c/busses/i2c-sh7760.c b/drivers/i2c/busses/i2c-sh7760.c
index c418c41eff3d..a67132b2e092 100644
--- a/drivers/i2c/busses/i2c-sh7760.c
+++ b/drivers/i2c/busses/i2c-sh7760.c
@@ -17,6 +17,7 @@
17#include <linux/platform_device.h> 17#include <linux/platform_device.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/io.h> 19#include <linux/io.h>
20#include <linux/module.h>
20 21
21#include <asm/clock.h> 22#include <asm/clock.h>
22#include <asm/i2c-sh7760.h> 23#include <asm/i2c-sh7760.h>
diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c
index b0505309faa7..46b6500c5478 100644
--- a/drivers/i2c/busses/i2c-tegra.c
+++ b/drivers/i2c/busses/i2c-tegra.c
@@ -27,6 +27,7 @@
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/i2c-tegra.h> 28#include <linux/i2c-tegra.h>
29#include <linux/of_i2c.h> 29#include <linux/of_i2c.h>
30#include <linux/module.h>
30 31
31#include <asm/unaligned.h> 32#include <asm/unaligned.h>
32 33
diff --git a/drivers/i2c/i2c-boardinfo.c b/drivers/i2c/i2c-boardinfo.c
index 3ca2e012e789..10274ffb66d7 100644
--- a/drivers/i2c/i2c-boardinfo.c
+++ b/drivers/i2c/i2c-boardinfo.c
@@ -19,6 +19,7 @@
19#include <linux/kernel.h> 19#include <linux/kernel.h>
20#include <linux/i2c.h> 20#include <linux/i2c.h>
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/export.h>
22#include <linux/rwsem.h> 23#include <linux/rwsem.h>
23 24
24#include "i2c-core.h" 25#include "i2c-core.h"
diff --git a/drivers/ide/Kconfig b/drivers/ide/Kconfig
index 76b6d98bd295..5a26584934ca 100644
--- a/drivers/ide/Kconfig
+++ b/drivers/ide/Kconfig
@@ -677,19 +677,19 @@ config BLK_DEV_IDE_PMAC_ATA100FIRST
677 677
678config BLK_DEV_IDE_AU1XXX 678config BLK_DEV_IDE_AU1XXX
679 bool "IDE for AMD Alchemy Au1200" 679 bool "IDE for AMD Alchemy Au1200"
680 depends on SOC_AU1200 680 depends on MIPS_ALCHEMY
681 select IDE_XFER_MODE 681 select IDE_XFER_MODE
682choice 682choice
683 prompt "IDE Mode for AMD Alchemy Au1200" 683 prompt "IDE Mode for AMD Alchemy Au1200"
684 default BLK_DEV_IDE_AU1XXX_PIO_DBDMA 684 default BLK_DEV_IDE_AU1XXX_PIO_DBDMA
685 depends on SOC_AU1200 && BLK_DEV_IDE_AU1XXX 685 depends on BLK_DEV_IDE_AU1XXX
686 686
687config BLK_DEV_IDE_AU1XXX_PIO_DBDMA 687config BLK_DEV_IDE_AU1XXX_PIO_DBDMA
688 bool "PIO+DbDMA IDE for AMD Alchemy Au1200" 688 bool "PIO+DbDMA IDE for AMD Alchemy Au1200"
689 689
690config BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA 690config BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
691 bool "MDMA2+DbDMA IDE for AMD Alchemy Au1200" 691 bool "MDMA2+DbDMA IDE for AMD Alchemy Au1200"
692 depends on SOC_AU1200 && BLK_DEV_IDE_AU1XXX 692 depends on BLK_DEV_IDE_AU1XXX
693endchoice 693endchoice
694 694
695config BLK_DEV_IDE_TX4938 695config BLK_DEV_IDE_TX4938
diff --git a/drivers/ide/au1xxx-ide.c b/drivers/ide/au1xxx-ide.c
index b26c23416fa7..259786ca8b75 100644
--- a/drivers/ide/au1xxx-ide.c
+++ b/drivers/ide/au1xxx-ide.c
@@ -36,13 +36,17 @@
36#include <linux/ide.h> 36#include <linux/ide.h>
37#include <linux/scatterlist.h> 37#include <linux/scatterlist.h>
38 38
39#include <asm/mach-au1x00/au1xxx.h> 39#include <asm/mach-au1x00/au1000.h>
40#include <asm/mach-au1x00/au1xxx_dbdma.h> 40#include <asm/mach-au1x00/au1xxx_dbdma.h>
41#include <asm/mach-au1x00/au1xxx_ide.h> 41#include <asm/mach-au1x00/au1xxx_ide.h>
42 42
43#define DRV_NAME "au1200-ide" 43#define DRV_NAME "au1200-ide"
44#define DRV_AUTHOR "Enrico Walther <enrico.walther@amd.com> / Pete Popov <ppopov@embeddedalley.com>" 44#define DRV_AUTHOR "Enrico Walther <enrico.walther@amd.com> / Pete Popov <ppopov@embeddedalley.com>"
45 45
46#ifndef IDE_REG_SHIFT
47#define IDE_REG_SHIFT 5
48#endif
49
46/* enable the burstmode in the dbdma */ 50/* enable the burstmode in the dbdma */
47#define IDE_AU1XXX_BURSTMODE 1 51#define IDE_AU1XXX_BURSTMODE 1
48 52
@@ -317,10 +321,11 @@ static void auide_ddma_rx_callback(int irq, void *param)
317} 321}
318#endif /* end CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA */ 322#endif /* end CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA */
319 323
320static void auide_init_dbdma_dev(dbdev_tab_t *dev, u32 dev_id, u32 tsize, u32 devwidth, u32 flags) 324static void auide_init_dbdma_dev(dbdev_tab_t *dev, u32 dev_id, u32 tsize,
325 u32 devwidth, u32 flags, u32 regbase)
321{ 326{
322 dev->dev_id = dev_id; 327 dev->dev_id = dev_id;
323 dev->dev_physaddr = (u32)IDE_PHYS_ADDR; 328 dev->dev_physaddr = CPHYSADDR(regbase);
324 dev->dev_intlevel = 0; 329 dev->dev_intlevel = 0;
325 dev->dev_intpolarity = 0; 330 dev->dev_intpolarity = 0;
326 dev->dev_tsize = tsize; 331 dev->dev_tsize = tsize;
@@ -344,7 +349,7 @@ static int auide_ddma_init(ide_hwif_t *hwif, const struct ide_port_info *d)
344 dbdev_tab_t source_dev_tab, target_dev_tab; 349 dbdev_tab_t source_dev_tab, target_dev_tab;
345 u32 dev_id, tsize, devwidth, flags; 350 u32 dev_id, tsize, devwidth, flags;
346 351
347 dev_id = IDE_DDMA_REQ; 352 dev_id = hwif->ddma_id;
348 353
349 tsize = 8; /* 1 */ 354 tsize = 8; /* 1 */
350 devwidth = 32; /* 16 */ 355 devwidth = 32; /* 16 */
@@ -356,20 +361,17 @@ static int auide_ddma_init(ide_hwif_t *hwif, const struct ide_port_info *d)
356#endif 361#endif
357 362
358 /* setup dev_tab for tx channel */ 363 /* setup dev_tab for tx channel */
359 auide_init_dbdma_dev( &source_dev_tab, 364 auide_init_dbdma_dev(&source_dev_tab, dev_id, tsize, devwidth,
360 dev_id, 365 DEV_FLAGS_OUT | flags, auide->regbase);
361 tsize, devwidth, DEV_FLAGS_OUT | flags);
362 auide->tx_dev_id = au1xxx_ddma_add_device( &source_dev_tab ); 366 auide->tx_dev_id = au1xxx_ddma_add_device( &source_dev_tab );
363 367
364 auide_init_dbdma_dev( &source_dev_tab, 368 auide_init_dbdma_dev(&source_dev_tab, dev_id, tsize, devwidth,
365 dev_id, 369 DEV_FLAGS_IN | flags, auide->regbase);
366 tsize, devwidth, DEV_FLAGS_IN | flags);
367 auide->rx_dev_id = au1xxx_ddma_add_device( &source_dev_tab ); 370 auide->rx_dev_id = au1xxx_ddma_add_device( &source_dev_tab );
368 371
369 /* We also need to add a target device for the DMA */ 372 /* We also need to add a target device for the DMA */
370 auide_init_dbdma_dev( &target_dev_tab, 373 auide_init_dbdma_dev(&target_dev_tab, (u32)DSCR_CMD0_ALWAYS, tsize,
371 (u32)DSCR_CMD0_ALWAYS, 374 devwidth, DEV_FLAGS_ANYUSE, auide->regbase);
372 tsize, devwidth, DEV_FLAGS_ANYUSE);
373 auide->target_dev_id = au1xxx_ddma_add_device(&target_dev_tab); 375 auide->target_dev_id = au1xxx_ddma_add_device(&target_dev_tab);
374 376
375 /* Get a channel for TX */ 377 /* Get a channel for TX */
@@ -411,14 +413,12 @@ static int auide_ddma_init(ide_hwif_t *hwif, const struct ide_port_info *d)
411#endif 413#endif
412 414
413 /* setup dev_tab for tx channel */ 415 /* setup dev_tab for tx channel */
414 auide_init_dbdma_dev( &source_dev_tab, 416 auide_init_dbdma_dev(&source_dev_tab, (u32)DSCR_CMD0_ALWAYS, 8, 32,
415 (u32)DSCR_CMD0_ALWAYS, 417 DEV_FLAGS_OUT | flags, auide->regbase);
416 8, 32, DEV_FLAGS_OUT | flags);
417 auide->tx_dev_id = au1xxx_ddma_add_device( &source_dev_tab ); 418 auide->tx_dev_id = au1xxx_ddma_add_device( &source_dev_tab );
418 419
419 auide_init_dbdma_dev( &source_dev_tab, 420 auide_init_dbdma_dev(&source_dev_tab, (u32)DSCR_CMD0_ALWAYS, 8, 32,
420 (u32)DSCR_CMD0_ALWAYS, 421 DEV_FLAGS_IN | flags, auide->regbase);
421 8, 32, DEV_FLAGS_IN | flags);
422 auide->rx_dev_id = au1xxx_ddma_add_device( &source_dev_tab ); 422 auide->rx_dev_id = au1xxx_ddma_add_device( &source_dev_tab );
423 423
424 /* Get a channel for TX */ 424 /* Get a channel for TX */
@@ -540,6 +540,14 @@ static int au_ide_probe(struct platform_device *dev)
540 goto out; 540 goto out;
541 } 541 }
542 542
543 res = platform_get_resource(dev, IORESOURCE_DMA, 0);
544 if (!res) {
545 pr_debug("%s: no DDMA ID resource\n", DRV_NAME);
546 ret = -ENODEV;
547 goto out;
548 }
549 ahwif->ddma_id = res->start;
550
543 memset(&hw, 0, sizeof(hw)); 551 memset(&hw, 0, sizeof(hw));
544 auide_setup_ports(&hw, ahwif); 552 auide_setup_ports(&hw, ahwif);
545 hw.irq = ahwif->irq; 553 hw.irq = ahwif->irq;
diff --git a/drivers/ide/buddha.c b/drivers/ide/buddha.c
index ab4f169d0837..b1d38590ac01 100644
--- a/drivers/ide/buddha.c
+++ b/drivers/ide/buddha.c
@@ -23,6 +23,7 @@
23#include <linux/zorro.h> 23#include <linux/zorro.h>
24#include <linux/ide.h> 24#include <linux/ide.h>
25#include <linux/init.h> 25#include <linux/init.h>
26#include <linux/module.h>
26 27
27#include <asm/amigahw.h> 28#include <asm/amigahw.h>
28#include <asm/amigaints.h> 29#include <asm/amigaints.h>
diff --git a/drivers/ide/cmd640.c b/drivers/ide/cmd640.c
index cb10201a15ed..a81bd7575792 100644
--- a/drivers/ide/cmd640.c
+++ b/drivers/ide/cmd640.c
@@ -105,6 +105,7 @@
105#include <linux/delay.h> 105#include <linux/delay.h>
106#include <linux/ide.h> 106#include <linux/ide.h>
107#include <linux/init.h> 107#include <linux/init.h>
108#include <linux/module.h>
108 109
109#include <asm/io.h> 110#include <asm/io.h>
110 111
diff --git a/drivers/ide/ide-acpi.c b/drivers/ide/ide-acpi.c
index 2af8cb460a3b..f22edc66b030 100644
--- a/drivers/ide/ide-acpi.c
+++ b/drivers/ide/ide-acpi.c
@@ -17,6 +17,7 @@
17#include <linux/ide.h> 17#include <linux/ide.h>
18#include <linux/pci.h> 18#include <linux/pci.h>
19#include <linux/dmi.h> 19#include <linux/dmi.h>
20#include <linux/module.h>
20 21
21#include <acpi/acpi_bus.h> 22#include <acpi/acpi_bus.h>
22 23
diff --git a/drivers/ide/ide-atapi.c b/drivers/ide/ide-atapi.c
index 6f218e014e99..fac3d9da2e07 100644
--- a/drivers/ide/ide-atapi.c
+++ b/drivers/ide/ide-atapi.c
@@ -5,6 +5,7 @@
5#include <linux/kernel.h> 5#include <linux/kernel.h>
6#include <linux/cdrom.h> 6#include <linux/cdrom.h>
7#include <linux/delay.h> 7#include <linux/delay.h>
8#include <linux/export.h>
8#include <linux/ide.h> 9#include <linux/ide.h>
9#include <linux/scatterlist.h> 10#include <linux/scatterlist.h>
10#include <linux/gfp.h> 11#include <linux/gfp.h>
diff --git a/drivers/ide/ide-disk_proc.c b/drivers/ide/ide-disk_proc.c
index f9bbd904eae7..8b570a17bcd9 100644
--- a/drivers/ide/ide-disk_proc.c
+++ b/drivers/ide/ide-disk_proc.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/slab.h> 3#include <linux/slab.h>
4#include <linux/export.h>
4#include <linux/seq_file.h> 5#include <linux/seq_file.h>
5 6
6#include "ide-disk.h" 7#include "ide-disk.h"
diff --git a/drivers/ide/ide-dma-sff.c b/drivers/ide/ide-dma-sff.c
index e4cdf78cc3e9..289d16c87b8f 100644
--- a/drivers/ide/ide-dma-sff.c
+++ b/drivers/ide/ide-dma-sff.c
@@ -1,5 +1,6 @@
1#include <linux/types.h> 1#include <linux/types.h>
2#include <linux/kernel.h> 2#include <linux/kernel.h>
3#include <linux/export.h>
3#include <linux/ide.h> 4#include <linux/ide.h>
4#include <linux/scatterlist.h> 5#include <linux/scatterlist.h>
5#include <linux/dma-mapping.h> 6#include <linux/dma-mapping.h>
diff --git a/drivers/ide/ide-dma.c b/drivers/ide/ide-dma.c
index d4136908f916..17a65ac56491 100644
--- a/drivers/ide/ide-dma.c
+++ b/drivers/ide/ide-dma.c
@@ -31,6 +31,7 @@
31#include <linux/types.h> 31#include <linux/types.h>
32#include <linux/gfp.h> 32#include <linux/gfp.h>
33#include <linux/kernel.h> 33#include <linux/kernel.h>
34#include <linux/export.h>
34#include <linux/ide.h> 35#include <linux/ide.h>
35#include <linux/scatterlist.h> 36#include <linux/scatterlist.h>
36#include <linux/dma-mapping.h> 37#include <linux/dma-mapping.h>
diff --git a/drivers/ide/ide-eh.c b/drivers/ide/ide-eh.c
index c0aa93fb7a60..32970664c275 100644
--- a/drivers/ide/ide-eh.c
+++ b/drivers/ide/ide-eh.c
@@ -1,5 +1,6 @@
1 1
2#include <linux/kernel.h> 2#include <linux/kernel.h>
3#include <linux/export.h>
3#include <linux/ide.h> 4#include <linux/ide.h>
4#include <linux/delay.h> 5#include <linux/delay.h>
5 6
diff --git a/drivers/ide/ide-floppy_proc.c b/drivers/ide/ide-floppy_proc.c
index d711d9b883de..1600720f3e86 100644
--- a/drivers/ide/ide-floppy_proc.c
+++ b/drivers/ide/ide-floppy_proc.c
@@ -1,4 +1,5 @@
1#include <linux/kernel.h> 1#include <linux/kernel.h>
2#include <linux/export.h>
2#include <linux/ide.h> 3#include <linux/ide.h>
3#include <linux/seq_file.h> 4#include <linux/seq_file.h>
4 5
diff --git a/drivers/ide/ide-io-std.c b/drivers/ide/ide-io-std.c
index 46721c454518..19763977568c 100644
--- a/drivers/ide/ide-io-std.c
+++ b/drivers/ide/ide-io-std.c
@@ -1,5 +1,6 @@
1 1
2#include <linux/kernel.h> 2#include <linux/kernel.h>
3#include <linux/export.h>
3#include <linux/ide.h> 4#include <linux/ide.h>
4 5
5#if defined(CONFIG_ARM) || defined(CONFIG_M68K) || defined(CONFIG_MIPS) || \ 6#if defined(CONFIG_ARM) || defined(CONFIG_M68K) || defined(CONFIG_MIPS) || \
diff --git a/drivers/ide/ide-ioctls.c b/drivers/ide/ide-ioctls.c
index 9965ecd5078c..4d19eb9772a1 100644
--- a/drivers/ide/ide-ioctls.c
+++ b/drivers/ide/ide-ioctls.c
@@ -2,6 +2,7 @@
2 * IDE ioctls handling. 2 * IDE ioctls handling.
3 */ 3 */
4 4
5#include <linux/export.h>
5#include <linux/hdreg.h> 6#include <linux/hdreg.h>
6#include <linux/ide.h> 7#include <linux/ide.h>
7#include <linux/slab.h> 8#include <linux/slab.h>
diff --git a/drivers/ide/ide-legacy.c b/drivers/ide/ide-legacy.c
index b9654a7bb7be..30fe3630734f 100644
--- a/drivers/ide/ide-legacy.c
+++ b/drivers/ide/ide-legacy.c
@@ -1,4 +1,5 @@
1#include <linux/kernel.h> 1#include <linux/kernel.h>
2#include <linux/export.h>
2#include <linux/ide.h> 3#include <linux/ide.h>
3 4
4static void ide_legacy_init_one(struct ide_hw **hws, struct ide_hw *hw, 5static void ide_legacy_init_one(struct ide_hw **hws, struct ide_hw *hw,
diff --git a/drivers/ide/ide-lib.c b/drivers/ide/ide-lib.c
index e386a32dc9ba..d9c9829c8b20 100644
--- a/drivers/ide/ide-lib.c
+++ b/drivers/ide/ide-lib.c
@@ -1,6 +1,7 @@
1#include <linux/types.h> 1#include <linux/types.h>
2#include <linux/string.h> 2#include <linux/string.h>
3#include <linux/kernel.h> 3#include <linux/kernel.h>
4#include <linux/export.h>
4#include <linux/interrupt.h> 5#include <linux/interrupt.h>
5#include <linux/ide.h> 6#include <linux/ide.h>
6#include <linux/bitops.h> 7#include <linux/bitops.h>
diff --git a/drivers/ide/ide-pnp.c b/drivers/ide/ide-pnp.c
index 017b1df3b805..e5f3db831373 100644
--- a/drivers/ide/ide-pnp.c
+++ b/drivers/ide/ide-pnp.c
@@ -17,6 +17,7 @@
17#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/pnp.h> 18#include <linux/pnp.h>
19#include <linux/ide.h> 19#include <linux/ide.h>
20#include <linux/module.h>
20 21
21#define DRV_NAME "ide-pnp" 22#define DRV_NAME "ide-pnp"
22 23
diff --git a/drivers/ide/ide-taskfile.c b/drivers/ide/ide-taskfile.c
index 600c89a3d137..5bc2839ebcfd 100644
--- a/drivers/ide/ide-taskfile.c
+++ b/drivers/ide/ide-taskfile.c
@@ -11,6 +11,7 @@
11#include <linux/types.h> 11#include <linux/types.h>
12#include <linux/string.h> 12#include <linux/string.h>
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/export.h>
14#include <linux/sched.h> 15#include <linux/sched.h>
15#include <linux/interrupt.h> 16#include <linux/interrupt.h>
16#include <linux/errno.h> 17#include <linux/errno.h>
diff --git a/drivers/ide/ide-xfer-mode.c b/drivers/ide/ide-xfer-mode.c
index 5fc8d5c17de9..eb421883c16d 100644
--- a/drivers/ide/ide-xfer-mode.c
+++ b/drivers/ide/ide-xfer-mode.c
@@ -1,6 +1,7 @@
1#include <linux/types.h> 1#include <linux/types.h>
2#include <linux/string.h> 2#include <linux/string.h>
3#include <linux/kernel.h> 3#include <linux/kernel.h>
4#include <linux/export.h>
4#include <linux/interrupt.h> 5#include <linux/interrupt.h>
5#include <linux/ide.h> 6#include <linux/ide.h>
6#include <linux/bitops.h> 7#include <linux/bitops.h>
diff --git a/drivers/ide/macide.c b/drivers/ide/macide.c
index 505ec43e5606..adc5fe9daafc 100644
--- a/drivers/ide/macide.c
+++ b/drivers/ide/macide.c
@@ -17,6 +17,7 @@
17#include <linux/blkdev.h> 17#include <linux/blkdev.h>
18#include <linux/delay.h> 18#include <linux/delay.h>
19#include <linux/ide.h> 19#include <linux/ide.h>
20#include <linux/module.h>
20 21
21#include <asm/macintosh.h> 22#include <asm/macintosh.h>
22#include <asm/macints.h> 23#include <asm/macints.h>
diff --git a/drivers/ide/pmac.c b/drivers/ide/pmac.c
index 1db7c4368dbf..e944c7f705f7 100644
--- a/drivers/ide/pmac.c
+++ b/drivers/ide/pmac.c
@@ -28,6 +28,7 @@
28#include <linux/delay.h> 28#include <linux/delay.h>
29#include <linux/ide.h> 29#include <linux/ide.h>
30#include <linux/notifier.h> 30#include <linux/notifier.h>
31#include <linux/module.h>
31#include <linux/reboot.h> 32#include <linux/reboot.h>
32#include <linux/pci.h> 33#include <linux/pci.h>
33#include <linux/adb.h> 34#include <linux/adb.h>
diff --git a/drivers/ide/q40ide.c b/drivers/ide/q40ide.c
index 90786083b439..ecd0a69245f6 100644
--- a/drivers/ide/q40ide.c
+++ b/drivers/ide/q40ide.c
@@ -15,6 +15,7 @@
15#include <linux/interrupt.h> 15#include <linux/interrupt.h>
16#include <linux/blkdev.h> 16#include <linux/blkdev.h>
17#include <linux/ide.h> 17#include <linux/ide.h>
18#include <linux/module.h>
18 19
19#include <asm/ide.h> 20#include <asm/ide.h>
20 21
diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c
index ab3db61d2ba0..34a5e5223d50 100644
--- a/drivers/ide/setup-pci.c
+++ b/drivers/ide/setup-pci.c
@@ -8,6 +8,7 @@
8 8
9#include <linux/types.h> 9#include <linux/types.h>
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <linux/export.h>
11#include <linux/pci.h> 12#include <linux/pci.h>
12#include <linux/init.h> 13#include <linux/init.h>
13#include <linux/interrupt.h> 14#include <linux/interrupt.h>
diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
index e444d24934b3..4799d5c384e7 100644
--- a/drivers/ide/tc86c001.c
+++ b/drivers/ide/tc86c001.c
@@ -10,6 +10,7 @@
10#include <linux/types.h> 10#include <linux/types.h>
11#include <linux/pci.h> 11#include <linux/pci.h>
12#include <linux/ide.h> 12#include <linux/ide.h>
13#include <linux/module.h>
13 14
14#define DRV_NAME "tc86c001" 15#define DRV_NAME "tc86c001"
15 16
diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c
index a46dddf61078..18767f8ab090 100644
--- a/drivers/idle/intel_idle.c
+++ b/drivers/idle/intel_idle.c
@@ -61,6 +61,7 @@
61#include <linux/sched.h> 61#include <linux/sched.h>
62#include <linux/notifier.h> 62#include <linux/notifier.h>
63#include <linux/cpu.h> 63#include <linux/cpu.h>
64#include <linux/module.h>
64#include <asm/mwait.h> 65#include <asm/mwait.h>
65#include <asm/msr.h> 66#include <asm/msr.h>
66 67
diff --git a/drivers/infiniband/core/addr.c b/drivers/infiniband/core/addr.c
index 236ad9a89c0a..691276bafd78 100644
--- a/drivers/infiniband/core/addr.c
+++ b/drivers/infiniband/core/addr.c
@@ -37,6 +37,7 @@
37#include <linux/inetdevice.h> 37#include <linux/inetdevice.h>
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/workqueue.h> 39#include <linux/workqueue.h>
40#include <linux/module.h>
40#include <net/arp.h> 41#include <net/arp.h>
41#include <net/neighbour.h> 42#include <net/neighbour.h>
42#include <net/route.h> 43#include <net/route.h>
diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
index 4104ea2427c2..8b72f39202fb 100644
--- a/drivers/infiniband/core/cm.c
+++ b/drivers/infiniband/core/cm.c
@@ -36,6 +36,7 @@
36#include <linux/completion.h> 36#include <linux/completion.h>
37#include <linux/dma-mapping.h> 37#include <linux/dma-mapping.h>
38#include <linux/device.h> 38#include <linux/device.h>
39#include <linux/module.h>
39#include <linux/err.h> 40#include <linux/err.h>
40#include <linux/idr.h> 41#include <linux/idr.h>
41#include <linux/interrupt.h> 42#include <linux/interrupt.h>
diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index 872b1842598a..75ff821c0af0 100644
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -41,6 +41,7 @@
41#include <linux/idr.h> 41#include <linux/idr.h>
42#include <linux/inetdevice.h> 42#include <linux/inetdevice.h>
43#include <linux/slab.h> 43#include <linux/slab.h>
44#include <linux/module.h>
44 45
45#include <net/tcp.h> 46#include <net/tcp.h>
46#include <net/ipv6.h> 47#include <net/ipv6.h>
diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
index 4507043d24c8..176c8f90f2bb 100644
--- a/drivers/infiniband/core/fmr_pool.c
+++ b/drivers/infiniband/core/fmr_pool.c
@@ -33,6 +33,7 @@
33 33
34#include <linux/errno.h> 34#include <linux/errno.h>
35#include <linux/spinlock.h> 35#include <linux/spinlock.h>
36#include <linux/export.h>
36#include <linux/slab.h> 37#include <linux/slab.h>
37#include <linux/jhash.h> 38#include <linux/jhash.h>
38#include <linux/kthread.h> 39#include <linux/kthread.h>
diff --git a/drivers/infiniband/core/iwcm.c b/drivers/infiniband/core/iwcm.c
index a9c042345c6f..1a696f76b616 100644
--- a/drivers/infiniband/core/iwcm.c
+++ b/drivers/infiniband/core/iwcm.c
@@ -45,6 +45,7 @@
45#include <linux/workqueue.h> 45#include <linux/workqueue.h>
46#include <linux/completion.h> 46#include <linux/completion.h>
47#include <linux/slab.h> 47#include <linux/slab.h>
48#include <linux/module.h>
48 49
49#include <rdma/iw_cm.h> 50#include <rdma/iw_cm.h>
50#include <rdma/ib_addr.h> 51#include <rdma/ib_addr.h>
diff --git a/drivers/infiniband/core/mad.c b/drivers/infiniband/core/mad.c
index 056389229ea7..2fe428bba54c 100644
--- a/drivers/infiniband/core/mad.c
+++ b/drivers/infiniband/core/mad.c
@@ -35,6 +35,7 @@
35 */ 35 */
36#include <linux/dma-mapping.h> 36#include <linux/dma-mapping.h>
37#include <linux/slab.h> 37#include <linux/slab.h>
38#include <linux/module.h>
38#include <rdma/ib_cache.h> 39#include <rdma/ib_cache.h>
39 40
40#include "mad_priv.h" 41#include "mad_priv.h"
diff --git a/drivers/infiniband/core/multicast.c b/drivers/infiniband/core/multicast.c
index 68b4162fd9d2..d2360a8ef0b2 100644
--- a/drivers/infiniband/core/multicast.c
+++ b/drivers/infiniband/core/multicast.c
@@ -34,6 +34,7 @@
34#include <linux/dma-mapping.h> 34#include <linux/dma-mapping.h>
35#include <linux/err.h> 35#include <linux/err.h>
36#include <linux/interrupt.h> 36#include <linux/interrupt.h>
37#include <linux/export.h>
37#include <linux/slab.h> 38#include <linux/slab.h>
38#include <linux/bitops.h> 39#include <linux/bitops.h>
39#include <linux/random.h> 40#include <linux/random.h>
diff --git a/drivers/infiniband/core/netlink.c b/drivers/infiniband/core/netlink.c
index 9227f4acd79c..d1c8196d15d7 100644
--- a/drivers/infiniband/core/netlink.c
+++ b/drivers/infiniband/core/netlink.c
@@ -32,6 +32,7 @@
32 32
33#define pr_fmt(fmt) "%s:%s: " fmt, KBUILD_MODNAME, __func__ 33#define pr_fmt(fmt) "%s:%s: " fmt, KBUILD_MODNAME, __func__
34 34
35#include <linux/export.h>
35#include <net/netlink.h> 36#include <net/netlink.h>
36#include <net/net_namespace.h> 37#include <net/net_namespace.h>
37#include <net/sock.h> 38#include <net/sock.h>
diff --git a/drivers/infiniband/core/packer.c b/drivers/infiniband/core/packer.c
index 019bd4b0863e..1b65986c0be3 100644
--- a/drivers/infiniband/core/packer.c
+++ b/drivers/infiniband/core/packer.c
@@ -31,6 +31,7 @@
31 * SOFTWARE. 31 * SOFTWARE.
32 */ 32 */
33 33
34#include <linux/export.h>
34#include <linux/string.h> 35#include <linux/string.h>
35 36
36#include <rdma/ib_pack.h> 37#include <rdma/ib_pack.h>
diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
index 2b59b72b57f9..c61bca30fd2d 100644
--- a/drivers/infiniband/core/sysfs.c
+++ b/drivers/infiniband/core/sysfs.c
@@ -35,6 +35,7 @@
35#include "core_priv.h" 35#include "core_priv.h"
36 36
37#include <linux/slab.h> 37#include <linux/slab.h>
38#include <linux/stat.h>
38#include <linux/string.h> 39#include <linux/string.h>
39 40
40#include <rdma/ib_mad.h> 41#include <rdma/ib_mad.h>
diff --git a/drivers/infiniband/core/ucma.c b/drivers/infiniband/core/ucma.c
index b69307f4f6d0..b37b0c02a7b9 100644
--- a/drivers/infiniband/core/ucma.c
+++ b/drivers/infiniband/core/ucma.c
@@ -41,6 +41,7 @@
41#include <linux/miscdevice.h> 41#include <linux/miscdevice.h>
42#include <linux/slab.h> 42#include <linux/slab.h>
43#include <linux/sysctl.h> 43#include <linux/sysctl.h>
44#include <linux/module.h>
44 45
45#include <rdma/rdma_user_cm.h> 46#include <rdma/rdma_user_cm.h>
46#include <rdma/ib_marshall.h> 47#include <rdma/ib_marshall.h>
diff --git a/drivers/infiniband/core/ud_header.c b/drivers/infiniband/core/ud_header.c
index 9b737ff133e2..72feee620ebf 100644
--- a/drivers/infiniband/core/ud_header.c
+++ b/drivers/infiniband/core/ud_header.c
@@ -33,6 +33,7 @@
33 33
34#include <linux/errno.h> 34#include <linux/errno.h>
35#include <linux/string.h> 35#include <linux/string.h>
36#include <linux/export.h>
36#include <linux/if_ether.h> 37#include <linux/if_ether.h>
37 38
38#include <rdma/ib_pack.h> 39#include <rdma/ib_pack.h>
diff --git a/drivers/infiniband/core/umem.c b/drivers/infiniband/core/umem.c
index 9155f91d66bf..71f0c0f7df94 100644
--- a/drivers/infiniband/core/umem.c
+++ b/drivers/infiniband/core/umem.c
@@ -35,6 +35,7 @@
35#include <linux/mm.h> 35#include <linux/mm.h>
36#include <linux/dma-mapping.h> 36#include <linux/dma-mapping.h>
37#include <linux/sched.h> 37#include <linux/sched.h>
38#include <linux/export.h>
38#include <linux/hugetlb.h> 39#include <linux/hugetlb.h>
39#include <linux/dma-attrs.h> 40#include <linux/dma-attrs.h>
40#include <linux/slab.h> 41#include <linux/slab.h>
diff --git a/drivers/infiniband/core/uverbs_marshall.c b/drivers/infiniband/core/uverbs_marshall.c
index 1b1146f87124..e7bee46868d1 100644
--- a/drivers/infiniband/core/uverbs_marshall.c
+++ b/drivers/infiniband/core/uverbs_marshall.c
@@ -30,6 +30,7 @@
30 * SOFTWARE. 30 * SOFTWARE.
31 */ 31 */
32 32
33#include <linux/export.h>
33#include <rdma/ib_marshall.h> 34#include <rdma/ib_marshall.h>
34 35
35void ib_copy_ah_attr_to_user(struct ib_uverbs_ah_attr *dst, 36void ib_copy_ah_attr_to_user(struct ib_uverbs_ah_attr *dst,
diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c
index 42517500b223..602b1bd723a9 100644
--- a/drivers/infiniband/core/verbs.c
+++ b/drivers/infiniband/core/verbs.c
@@ -38,6 +38,7 @@
38 38
39#include <linux/errno.h> 39#include <linux/errno.h>
40#include <linux/err.h> 40#include <linux/err.h>
41#include <linux/export.h>
41#include <linux/string.h> 42#include <linux/string.h>
42#include <linux/slab.h> 43#include <linux/slab.h>
43 44
diff --git a/drivers/infiniband/hw/cxgb4/qp.c b/drivers/infiniband/hw/cxgb4/qp.c
index d6ccc7e84802..5f940aeaab1e 100644
--- a/drivers/infiniband/hw/cxgb4/qp.c
+++ b/drivers/infiniband/hw/cxgb4/qp.c
@@ -29,6 +29,9 @@
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE. 30 * SOFTWARE.
31 */ 31 */
32
33#include <linux/module.h>
34
32#include "iw_cxgb4.h" 35#include "iw_cxgb4.h"
33 36
34static int ocqp_support = 1; 37static int ocqp_support = 1;
diff --git a/drivers/infiniband/hw/ipath/ipath_diag.c b/drivers/infiniband/hw/ipath/ipath_diag.c
index daef61d5e5bb..714293b78518 100644
--- a/drivers/infiniband/hw/ipath/ipath_diag.c
+++ b/drivers/infiniband/hw/ipath/ipath_diag.c
@@ -45,6 +45,7 @@
45#include <linux/pci.h> 45#include <linux/pci.h>
46#include <linux/vmalloc.h> 46#include <linux/vmalloc.h>
47#include <linux/fs.h> 47#include <linux/fs.h>
48#include <linux/export.h>
48#include <asm/uaccess.h> 49#include <asm/uaccess.h>
49 50
50#include "ipath_kernel.h" 51#include "ipath_kernel.h"
diff --git a/drivers/infiniband/hw/ipath/ipath_driver.c b/drivers/infiniband/hw/ipath/ipath_driver.c
index be24ac726114..bfca37b2432f 100644
--- a/drivers/infiniband/hw/ipath/ipath_driver.c
+++ b/drivers/infiniband/hw/ipath/ipath_driver.c
@@ -41,6 +41,7 @@
41#include <linux/vmalloc.h> 41#include <linux/vmalloc.h>
42#include <linux/bitmap.h> 42#include <linux/bitmap.h>
43#include <linux/slab.h> 43#include <linux/slab.h>
44#include <linux/module.h>
44 45
45#include "ipath_kernel.h" 46#include "ipath_kernel.h"
46#include "ipath_verbs.h" 47#include "ipath_verbs.h"
diff --git a/drivers/infiniband/hw/ipath/ipath_file_ops.c b/drivers/infiniband/hw/ipath/ipath_file_ops.c
index 8697eca14356..736d9edbdbe7 100644
--- a/drivers/infiniband/hw/ipath/ipath_file_ops.c
+++ b/drivers/infiniband/hw/ipath/ipath_file_ops.c
@@ -35,6 +35,7 @@
35#include <linux/poll.h> 35#include <linux/poll.h>
36#include <linux/cdev.h> 36#include <linux/cdev.h>
37#include <linux/swap.h> 37#include <linux/swap.h>
38#include <linux/export.h>
38#include <linux/vmalloc.h> 39#include <linux/vmalloc.h>
39#include <linux/slab.h> 40#include <linux/slab.h>
40#include <linux/highmem.h> 41#include <linux/highmem.h>
diff --git a/drivers/infiniband/hw/ipath/ipath_init_chip.c b/drivers/infiniband/hw/ipath/ipath_init_chip.c
index 824a4d508836..49b09c697c7c 100644
--- a/drivers/infiniband/hw/ipath/ipath_init_chip.c
+++ b/drivers/infiniband/hw/ipath/ipath_init_chip.c
@@ -33,6 +33,7 @@
33 33
34#include <linux/pci.h> 34#include <linux/pci.h>
35#include <linux/netdevice.h> 35#include <linux/netdevice.h>
36#include <linux/moduleparam.h>
36#include <linux/slab.h> 37#include <linux/slab.h>
37#include <linux/stat.h> 38#include <linux/stat.h>
38#include <linux/vmalloc.h> 39#include <linux/vmalloc.h>
diff --git a/drivers/infiniband/hw/ipath/ipath_sysfs.c b/drivers/infiniband/hw/ipath/ipath_sysfs.c
index 8991677e9a08..75558f33f1cb 100644
--- a/drivers/infiniband/hw/ipath/ipath_sysfs.c
+++ b/drivers/infiniband/hw/ipath/ipath_sysfs.c
@@ -32,6 +32,7 @@
32 */ 32 */
33 33
34#include <linux/ctype.h> 34#include <linux/ctype.h>
35#include <linux/stat.h>
35 36
36#include "ipath_kernel.h" 37#include "ipath_kernel.h"
37#include "ipath_verbs.h" 38#include "ipath_verbs.h"
diff --git a/drivers/infiniband/hw/ipath/ipath_verbs.c b/drivers/infiniband/hw/ipath/ipath_verbs.c
index dd7f26d04d46..439c35d4a669 100644
--- a/drivers/infiniband/hw/ipath/ipath_verbs.c
+++ b/drivers/infiniband/hw/ipath/ipath_verbs.c
@@ -35,6 +35,7 @@
35#include <rdma/ib_user_verbs.h> 35#include <rdma/ib_user_verbs.h>
36#include <linux/io.h> 36#include <linux/io.h>
37#include <linux/slab.h> 37#include <linux/slab.h>
38#include <linux/module.h>
38#include <linux/utsname.h> 39#include <linux/utsname.h>
39#include <linux/rculist.h> 40#include <linux/rculist.h>
40 41
diff --git a/drivers/infiniband/hw/mthca/mthca_catas.c b/drivers/infiniband/hw/mthca/mthca_catas.c
index e4a08c2819e4..712d2a30fbe5 100644
--- a/drivers/infiniband/hw/mthca/mthca_catas.c
+++ b/drivers/infiniband/hw/mthca/mthca_catas.c
@@ -31,6 +31,7 @@
31 */ 31 */
32 32
33#include <linux/jiffies.h> 33#include <linux/jiffies.h>
34#include <linux/module.h>
34#include <linux/timer.h> 35#include <linux/timer.h>
35#include <linux/workqueue.h> 36#include <linux/workqueue.h>
36 37
diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
index 3082b3b3d620..9d3e5c1ac60e 100644
--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
@@ -36,6 +36,7 @@
36#include <linux/pci.h> 36#include <linux/pci.h>
37#include <linux/errno.h> 37#include <linux/errno.h>
38#include <linux/sched.h> 38#include <linux/sched.h>
39#include <linux/module.h>
39#include <linux/slab.h> 40#include <linux/slab.h>
40#include <asm/io.h> 41#include <asm/io.h>
41#include <rdma/ib_mad.h> 42#include <rdma/ib_mad.h>
diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
index ab876f928a1b..ed9a989e501b 100644
--- a/drivers/infiniband/hw/mthca/mthca_mr.c
+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
@@ -146,7 +146,7 @@ static int mthca_buddy_init(struct mthca_buddy *buddy, int max_order)
146 146
147 buddy->bits = kzalloc((buddy->max_order + 1) * sizeof (long *), 147 buddy->bits = kzalloc((buddy->max_order + 1) * sizeof (long *),
148 GFP_KERNEL); 148 GFP_KERNEL);
149 buddy->num_free = kzalloc((buddy->max_order + 1) * sizeof (int *), 149 buddy->num_free = kcalloc((buddy->max_order + 1), sizeof *buddy->num_free,
150 GFP_KERNEL); 150 GFP_KERNEL);
151 if (!buddy->bits || !buddy->num_free) 151 if (!buddy->bits || !buddy->num_free)
152 goto err_out; 152 goto err_out;
diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
index cb9a0b976804..5b71d43bd89c 100644
--- a/drivers/infiniband/hw/mthca/mthca_provider.c
+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
@@ -40,7 +40,9 @@
40 40
41#include <linux/sched.h> 41#include <linux/sched.h>
42#include <linux/slab.h> 42#include <linux/slab.h>
43#include <linux/stat.h>
43#include <linux/mm.h> 44#include <linux/mm.h>
45#include <linux/export.h>
44 46
45#include "mthca_dev.h" 47#include "mthca_dev.h"
46#include "mthca_cmd.h" 48#include "mthca_cmd.h"
diff --git a/drivers/infiniband/hw/qib/qib_diag.c b/drivers/infiniband/hw/qib/qib_diag.c
index 204c4dd9dce0..9892456a4348 100644
--- a/drivers/infiniband/hw/qib/qib_diag.c
+++ b/drivers/infiniband/hw/qib/qib_diag.c
@@ -46,6 +46,7 @@
46#include <linux/pci.h> 46#include <linux/pci.h>
47#include <linux/poll.h> 47#include <linux/poll.h>
48#include <linux/vmalloc.h> 48#include <linux/vmalloc.h>
49#include <linux/export.h>
49#include <linux/fs.h> 50#include <linux/fs.h>
50#include <linux/uaccess.h> 51#include <linux/uaccess.h>
51 52
diff --git a/drivers/infiniband/hw/qib/qib_driver.c b/drivers/infiniband/hw/qib/qib_driver.c
index 9a9047f385ae..c90a55f4120f 100644
--- a/drivers/infiniband/hw/qib/qib_driver.c
+++ b/drivers/infiniband/hw/qib/qib_driver.c
@@ -37,6 +37,7 @@
37#include <linux/delay.h> 37#include <linux/delay.h>
38#include <linux/netdevice.h> 38#include <linux/netdevice.h>
39#include <linux/vmalloc.h> 39#include <linux/vmalloc.h>
40#include <linux/module.h>
40 41
41#include "qib.h" 42#include "qib.h"
42 43
diff --git a/drivers/infiniband/hw/qib/qib_file_ops.c b/drivers/infiniband/hw/qib/qib_file_ops.c
index 77633666f81c..574600ef5b42 100644
--- a/drivers/infiniband/hw/qib/qib_file_ops.c
+++ b/drivers/infiniband/hw/qib/qib_file_ops.c
@@ -43,6 +43,7 @@
43#include <linux/jiffies.h> 43#include <linux/jiffies.h>
44#include <asm/pgtable.h> 44#include <asm/pgtable.h>
45#include <linux/delay.h> 45#include <linux/delay.h>
46#include <linux/export.h>
46 47
47#include "qib.h" 48#include "qib.h"
48#include "qib_common.h" 49#include "qib_common.h"
diff --git a/drivers/infiniband/hw/qib/qib_iba7220.c b/drivers/infiniband/hw/qib/qib_iba7220.c
index 3f1d562ba898..439d3c503cd5 100644
--- a/drivers/infiniband/hw/qib/qib_iba7220.c
+++ b/drivers/infiniband/hw/qib/qib_iba7220.c
@@ -39,6 +39,7 @@
39#include <linux/interrupt.h> 39#include <linux/interrupt.h>
40#include <linux/pci.h> 40#include <linux/pci.h>
41#include <linux/delay.h> 41#include <linux/delay.h>
42#include <linux/module.h>
42#include <linux/io.h> 43#include <linux/io.h>
43#include <rdma/ib_verbs.h> 44#include <rdma/ib_verbs.h>
44 45
diff --git a/drivers/infiniband/hw/qib/qib_iba7322.c b/drivers/infiniband/hw/qib/qib_iba7322.c
index efd0a110091f..5bd2162b95dc 100644
--- a/drivers/infiniband/hw/qib/qib_iba7322.c
+++ b/drivers/infiniband/hw/qib/qib_iba7322.c
@@ -40,6 +40,7 @@
40#include <linux/delay.h> 40#include <linux/delay.h>
41#include <linux/io.h> 41#include <linux/io.h>
42#include <linux/jiffies.h> 42#include <linux/jiffies.h>
43#include <linux/module.h>
43#include <rdma/ib_verbs.h> 44#include <rdma/ib_verbs.h>
44#include <rdma/ib_smi.h> 45#include <rdma/ib_smi.h>
45 46
diff --git a/drivers/infiniband/hw/qib/qib_init.c b/drivers/infiniband/hw/qib/qib_init.c
index b093a0b53b2f..58b0f8ad4a29 100644
--- a/drivers/infiniband/hw/qib/qib_init.c
+++ b/drivers/infiniband/hw/qib/qib_init.c
@@ -37,6 +37,7 @@
37#include <linux/vmalloc.h> 37#include <linux/vmalloc.h>
38#include <linux/delay.h> 38#include <linux/delay.h>
39#include <linux/idr.h> 39#include <linux/idr.h>
40#include <linux/module.h>
40 41
41#include "qib.h" 42#include "qib.h"
42#include "qib_common.h" 43#include "qib_common.h"
diff --git a/drivers/infiniband/hw/qib/qib_pcie.c b/drivers/infiniband/hw/qib/qib_pcie.c
index 4426782ad288..97a8bdf68e60 100644
--- a/drivers/infiniband/hw/qib/qib_pcie.c
+++ b/drivers/infiniband/hw/qib/qib_pcie.c
@@ -35,6 +35,7 @@
35#include <linux/delay.h> 35#include <linux/delay.h>
36#include <linux/vmalloc.h> 36#include <linux/vmalloc.h>
37#include <linux/aer.h> 37#include <linux/aer.h>
38#include <linux/module.h>
38 39
39#include "qib.h" 40#include "qib.h"
40 41
diff --git a/drivers/infiniband/hw/qib/qib_rc.c b/drivers/infiniband/hw/qib/qib_rc.c
index afaf4ac79f42..894afac26f3b 100644
--- a/drivers/infiniband/hw/qib/qib_rc.c
+++ b/drivers/infiniband/hw/qib/qib_rc.c
@@ -271,13 +271,9 @@ int qib_make_rc_req(struct qib_qp *qp)
271 goto bail; 271 goto bail;
272 } 272 }
273 wqe = get_swqe_ptr(qp, qp->s_last); 273 wqe = get_swqe_ptr(qp, qp->s_last);
274 while (qp->s_last != qp->s_acked) { 274 qib_send_complete(qp, wqe, qp->s_last != qp->s_acked ?
275 qib_send_complete(qp, wqe, IB_WC_SUCCESS); 275 IB_WC_SUCCESS : IB_WC_WR_FLUSH_ERR);
276 if (++qp->s_last >= qp->s_size) 276 /* will get called again */
277 qp->s_last = 0;
278 wqe = get_swqe_ptr(qp, qp->s_last);
279 }
280 qib_send_complete(qp, wqe, IB_WC_WR_FLUSH_ERR);
281 goto done; 277 goto done;
282 } 278 }
283 279
diff --git a/drivers/infiniband/hw/qib/qib_sd7220.c b/drivers/infiniband/hw/qib/qib_sd7220.c
index e9f9f8bc3204..de1a4b2f33c0 100644
--- a/drivers/infiniband/hw/qib/qib_sd7220.c
+++ b/drivers/infiniband/hw/qib/qib_sd7220.c
@@ -38,6 +38,7 @@
38 38
39#include <linux/pci.h> 39#include <linux/pci.h>
40#include <linux/delay.h> 40#include <linux/delay.h>
41#include <linux/module.h>
41#include <linux/firmware.h> 42#include <linux/firmware.h>
42 43
43#include "qib.h" 44#include "qib.h"
diff --git a/drivers/infiniband/hw/qib/qib_sdma.c b/drivers/infiniband/hw/qib/qib_sdma.c
index cad44491320b..12a9604310d7 100644
--- a/drivers/infiniband/hw/qib/qib_sdma.c
+++ b/drivers/infiniband/hw/qib/qib_sdma.c
@@ -32,6 +32,7 @@
32 32
33#include <linux/spinlock.h> 33#include <linux/spinlock.h>
34#include <linux/netdevice.h> 34#include <linux/netdevice.h>
35#include <linux/moduleparam.h>
35 36
36#include "qib.h" 37#include "qib.h"
37#include "qib_common.h" 38#include "qib_common.h"
diff --git a/drivers/infiniband/hw/qib/qib_tx.c b/drivers/infiniband/hw/qib/qib_tx.c
index 7f36454c225e..1bf626c40172 100644
--- a/drivers/infiniband/hw/qib/qib_tx.c
+++ b/drivers/infiniband/hw/qib/qib_tx.c
@@ -36,6 +36,7 @@
36#include <linux/delay.h> 36#include <linux/delay.h>
37#include <linux/netdevice.h> 37#include <linux/netdevice.h>
38#include <linux/vmalloc.h> 38#include <linux/vmalloc.h>
39#include <linux/moduleparam.h>
39 40
40#include "qib.h" 41#include "qib.h"
41 42
diff --git a/drivers/infiniband/hw/qib/qib_verbs.c b/drivers/infiniband/hw/qib/qib_verbs.c
index 9627cb737125..a894762da462 100644
--- a/drivers/infiniband/hw/qib/qib_verbs.c
+++ b/drivers/infiniband/hw/qib/qib_verbs.c
@@ -35,6 +35,7 @@
35#include <rdma/ib_mad.h> 35#include <rdma/ib_mad.h>
36#include <rdma/ib_user_verbs.h> 36#include <rdma/ib_user_verbs.h>
37#include <linux/io.h> 37#include <linux/io.h>
38#include <linux/module.h>
38#include <linux/utsname.h> 39#include <linux/utsname.h>
39#include <linux/rculist.h> 40#include <linux/rculist.h>
40#include <linux/mm.h> 41#include <linux/mm.h>
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_cm.c b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
index 231c2f2f52f8..014504d8e43c 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_cm.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
@@ -37,6 +37,7 @@
37#include <linux/delay.h> 37#include <linux/delay.h>
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/vmalloc.h> 39#include <linux/vmalloc.h>
40#include <linux/moduleparam.h>
40 41
41#include "ipoib.h" 42#include "ipoib.h"
42 43
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_fs.c b/drivers/infiniband/ulp/ipoib/ipoib_fs.c
index 0e2fe4631ba8..50061854616e 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_fs.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_fs.c
@@ -37,6 +37,7 @@
37struct file_operations; 37struct file_operations;
38 38
39#include <linux/debugfs.h> 39#include <linux/debugfs.h>
40#include <linux/export.h>
40 41
41#include "ipoib.h" 42#include "ipoib.h"
42 43
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_ib.c b/drivers/infiniband/ulp/ipoib/ipoib_ib.c
index 2b060f45bec3..0ef9af94997d 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_ib.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_ib.c
@@ -34,6 +34,7 @@
34 */ 34 */
35 35
36#include <linux/delay.h> 36#include <linux/delay.h>
37#include <linux/moduleparam.h>
37#include <linux/dma-mapping.h> 38#include <linux/dma-mapping.h>
38#include <linux/slab.h> 39#include <linux/slab.h>
39 40
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
index ecea4fe1ed00..1b7a97686356 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
@@ -34,6 +34,7 @@
34 34
35#include <linux/skbuff.h> 35#include <linux/skbuff.h>
36#include <linux/rtnetlink.h> 36#include <linux/rtnetlink.h>
37#include <linux/moduleparam.h>
37#include <linux/ip.h> 38#include <linux/ip.h>
38#include <linux/in.h> 39#include <linux/in.h>
39#include <linux/igmp.h> 40#include <linux/igmp.h>
diff --git a/drivers/infiniband/ulp/iser/iscsi_iser.c b/drivers/infiniband/ulp/iser/iscsi_iser.c
index 84e8c293a715..7e7373a700e6 100644
--- a/drivers/infiniband/ulp/iser/iscsi_iser.c
+++ b/drivers/infiniband/ulp/iser/iscsi_iser.c
@@ -57,6 +57,7 @@
57#include <linux/scatterlist.h> 57#include <linux/scatterlist.h>
58#include <linux/delay.h> 58#include <linux/delay.h>
59#include <linux/slab.h> 59#include <linux/slab.h>
60#include <linux/module.h>
60 61
61#include <net/sock.h> 62#include <net/sock.h>
62 63
@@ -151,7 +152,6 @@ int iser_initialize_task_headers(struct iscsi_task *task,
151 tx_desc->tx_sg[0].length = ISER_HEADERS_LEN; 152 tx_desc->tx_sg[0].length = ISER_HEADERS_LEN;
152 tx_desc->tx_sg[0].lkey = device->mr->lkey; 153 tx_desc->tx_sg[0].lkey = device->mr->lkey;
153 154
154 iser_task->headers_initialized = 1;
155 iser_task->iser_conn = iser_conn; 155 iser_task->iser_conn = iser_conn;
156 return 0; 156 return 0;
157} 157}
@@ -166,8 +166,7 @@ iscsi_iser_task_init(struct iscsi_task *task)
166{ 166{
167 struct iscsi_iser_task *iser_task = task->dd_data; 167 struct iscsi_iser_task *iser_task = task->dd_data;
168 168
169 if (!iser_task->headers_initialized) 169 if (iser_initialize_task_headers(task, &iser_task->desc))
170 if (iser_initialize_task_headers(task, &iser_task->desc))
171 return -ENOMEM; 170 return -ENOMEM;
172 171
173 /* mgmt task */ 172 /* mgmt task */
@@ -278,6 +277,13 @@ iscsi_iser_task_xmit(struct iscsi_task *task)
278static void iscsi_iser_cleanup_task(struct iscsi_task *task) 277static void iscsi_iser_cleanup_task(struct iscsi_task *task)
279{ 278{
280 struct iscsi_iser_task *iser_task = task->dd_data; 279 struct iscsi_iser_task *iser_task = task->dd_data;
280 struct iser_tx_desc *tx_desc = &iser_task->desc;
281
282 struct iscsi_iser_conn *iser_conn = task->conn->dd_data;
283 struct iser_device *device = iser_conn->ib_conn->device;
284
285 ib_dma_unmap_single(device->ib_device,
286 tx_desc->dma_addr, ISER_HEADERS_LEN, DMA_TO_DEVICE);
281 287
282 /* mgmt tasks do not need special cleanup */ 288 /* mgmt tasks do not need special cleanup */
283 if (!task->sc) 289 if (!task->sc)
diff --git a/drivers/infiniband/ulp/iser/iscsi_iser.h b/drivers/infiniband/ulp/iser/iscsi_iser.h
index db6f3ce9f3bf..db7ea3704da7 100644
--- a/drivers/infiniband/ulp/iser/iscsi_iser.h
+++ b/drivers/infiniband/ulp/iser/iscsi_iser.h
@@ -257,7 +257,8 @@ struct iser_conn {
257 struct list_head conn_list; /* entry in ig conn list */ 257 struct list_head conn_list; /* entry in ig conn list */
258 258
259 char *login_buf; 259 char *login_buf;
260 u64 login_dma; 260 char *login_req_buf, *login_resp_buf;
261 u64 login_req_dma, login_resp_dma;
261 unsigned int rx_desc_head; 262 unsigned int rx_desc_head;
262 struct iser_rx_desc *rx_descs; 263 struct iser_rx_desc *rx_descs;
263 struct ib_recv_wr rx_wr[ISER_MIN_POSTED_RX]; 264 struct ib_recv_wr rx_wr[ISER_MIN_POSTED_RX];
@@ -277,7 +278,6 @@ struct iscsi_iser_task {
277 struct iser_regd_buf rdma_regd[ISER_DIRS_NUM];/* regd rdma buf */ 278 struct iser_regd_buf rdma_regd[ISER_DIRS_NUM];/* regd rdma buf */
278 struct iser_data_buf data[ISER_DIRS_NUM]; /* orig. data des*/ 279 struct iser_data_buf data[ISER_DIRS_NUM]; /* orig. data des*/
279 struct iser_data_buf data_copy[ISER_DIRS_NUM];/* contig. copy */ 280 struct iser_data_buf data_copy[ISER_DIRS_NUM];/* contig. copy */
280 int headers_initialized;
281}; 281};
282 282
283struct iser_page_vec { 283struct iser_page_vec {
diff --git a/drivers/infiniband/ulp/iser/iser_initiator.c b/drivers/infiniband/ulp/iser/iser_initiator.c
index f299de6b419b..a607542fc796 100644
--- a/drivers/infiniband/ulp/iser/iser_initiator.c
+++ b/drivers/infiniband/ulp/iser/iser_initiator.c
@@ -221,8 +221,14 @@ void iser_free_rx_descriptors(struct iser_conn *ib_conn)
221 struct iser_device *device = ib_conn->device; 221 struct iser_device *device = ib_conn->device;
222 222
223 if (ib_conn->login_buf) { 223 if (ib_conn->login_buf) {
224 ib_dma_unmap_single(device->ib_device, ib_conn->login_dma, 224 if (ib_conn->login_req_dma)
225 ISER_RX_LOGIN_SIZE, DMA_FROM_DEVICE); 225 ib_dma_unmap_single(device->ib_device,
226 ib_conn->login_req_dma,
227 ISCSI_DEF_MAX_RECV_SEG_LEN, DMA_TO_DEVICE);
228 if (ib_conn->login_resp_dma)
229 ib_dma_unmap_single(device->ib_device,
230 ib_conn->login_resp_dma,
231 ISER_RX_LOGIN_SIZE, DMA_FROM_DEVICE);
226 kfree(ib_conn->login_buf); 232 kfree(ib_conn->login_buf);
227 } 233 }
228 234
@@ -394,6 +400,7 @@ int iser_send_control(struct iscsi_conn *conn,
394 unsigned long data_seg_len; 400 unsigned long data_seg_len;
395 int err = 0; 401 int err = 0;
396 struct iser_device *device; 402 struct iser_device *device;
403 struct iser_conn *ib_conn = iser_conn->ib_conn;
397 404
398 /* build the tx desc regd header and add it to the tx desc dto */ 405 /* build the tx desc regd header and add it to the tx desc dto */
399 mdesc->type = ISCSI_TX_CONTROL; 406 mdesc->type = ISCSI_TX_CONTROL;
@@ -409,9 +416,19 @@ int iser_send_control(struct iscsi_conn *conn,
409 iser_err("data present on non login task!!!\n"); 416 iser_err("data present on non login task!!!\n");
410 goto send_control_error; 417 goto send_control_error;
411 } 418 }
412 memcpy(iser_conn->ib_conn->login_buf, task->data, 419
420 ib_dma_sync_single_for_cpu(device->ib_device,
421 ib_conn->login_req_dma, task->data_count,
422 DMA_TO_DEVICE);
423
424 memcpy(iser_conn->ib_conn->login_req_buf, task->data,
413 task->data_count); 425 task->data_count);
414 tx_dsg->addr = iser_conn->ib_conn->login_dma; 426
427 ib_dma_sync_single_for_device(device->ib_device,
428 ib_conn->login_req_dma, task->data_count,
429 DMA_TO_DEVICE);
430
431 tx_dsg->addr = iser_conn->ib_conn->login_req_dma;
415 tx_dsg->length = task->data_count; 432 tx_dsg->length = task->data_count;
416 tx_dsg->lkey = device->mr->lkey; 433 tx_dsg->lkey = device->mr->lkey;
417 mdesc->num_sge = 2; 434 mdesc->num_sge = 2;
@@ -445,8 +462,8 @@ void iser_rcv_completion(struct iser_rx_desc *rx_desc,
445 int rx_buflen, outstanding, count, err; 462 int rx_buflen, outstanding, count, err;
446 463
447 /* differentiate between login to all other PDUs */ 464 /* differentiate between login to all other PDUs */
448 if ((char *)rx_desc == ib_conn->login_buf) { 465 if ((char *)rx_desc == ib_conn->login_resp_buf) {
449 rx_dma = ib_conn->login_dma; 466 rx_dma = ib_conn->login_resp_dma;
450 rx_buflen = ISER_RX_LOGIN_SIZE; 467 rx_buflen = ISER_RX_LOGIN_SIZE;
451 } else { 468 } else {
452 rx_dma = rx_desc->dma_addr; 469 rx_dma = rx_desc->dma_addr;
@@ -473,7 +490,7 @@ void iser_rcv_completion(struct iser_rx_desc *rx_desc,
473 * for the posted rx bufs refcount to become zero handles everything */ 490 * for the posted rx bufs refcount to become zero handles everything */
474 conn->ib_conn->post_recv_buf_count--; 491 conn->ib_conn->post_recv_buf_count--;
475 492
476 if (rx_dma == ib_conn->login_dma) 493 if (rx_dma == ib_conn->login_resp_dma)
477 return; 494 return;
478 495
479 outstanding = ib_conn->post_recv_buf_count; 496 outstanding = ib_conn->post_recv_buf_count;
diff --git a/drivers/infiniband/ulp/iser/iser_verbs.c b/drivers/infiniband/ulp/iser/iser_verbs.c
index ede1475bee09..e28877c4ce15 100644
--- a/drivers/infiniband/ulp/iser/iser_verbs.c
+++ b/drivers/infiniband/ulp/iser/iser_verbs.c
@@ -155,20 +155,39 @@ static int iser_create_ib_conn_res(struct iser_conn *ib_conn)
155{ 155{
156 struct iser_device *device; 156 struct iser_device *device;
157 struct ib_qp_init_attr init_attr; 157 struct ib_qp_init_attr init_attr;
158 int ret = -ENOMEM; 158 int req_err, resp_err, ret = -ENOMEM;
159 struct ib_fmr_pool_param params; 159 struct ib_fmr_pool_param params;
160 160
161 BUG_ON(ib_conn->device == NULL); 161 BUG_ON(ib_conn->device == NULL);
162 162
163 device = ib_conn->device; 163 device = ib_conn->device;
164 164
165 ib_conn->login_buf = kmalloc(ISER_RX_LOGIN_SIZE, GFP_KERNEL); 165 ib_conn->login_buf = kmalloc(ISCSI_DEF_MAX_RECV_SEG_LEN +
166 ISER_RX_LOGIN_SIZE, GFP_KERNEL);
166 if (!ib_conn->login_buf) 167 if (!ib_conn->login_buf)
167 goto out_err; 168 goto out_err;
168 169
169 ib_conn->login_dma = ib_dma_map_single(ib_conn->device->ib_device, 170 ib_conn->login_req_buf = ib_conn->login_buf;
170 (void *)ib_conn->login_buf, ISER_RX_LOGIN_SIZE, 171 ib_conn->login_resp_buf = ib_conn->login_buf + ISCSI_DEF_MAX_RECV_SEG_LEN;
171 DMA_FROM_DEVICE); 172
173 ib_conn->login_req_dma = ib_dma_map_single(ib_conn->device->ib_device,
174 (void *)ib_conn->login_req_buf,
175 ISCSI_DEF_MAX_RECV_SEG_LEN, DMA_TO_DEVICE);
176
177 ib_conn->login_resp_dma = ib_dma_map_single(ib_conn->device->ib_device,
178 (void *)ib_conn->login_resp_buf,
179 ISER_RX_LOGIN_SIZE, DMA_FROM_DEVICE);
180
181 req_err = ib_dma_mapping_error(device->ib_device, ib_conn->login_req_dma);
182 resp_err = ib_dma_mapping_error(device->ib_device, ib_conn->login_resp_dma);
183
184 if (req_err || resp_err) {
185 if (req_err)
186 ib_conn->login_req_dma = 0;
187 if (resp_err)
188 ib_conn->login_resp_dma = 0;
189 goto out_err;
190 }
172 191
173 ib_conn->page_vec = kmalloc(sizeof(struct iser_page_vec) + 192 ib_conn->page_vec = kmalloc(sizeof(struct iser_page_vec) +
174 (sizeof(u64) * (ISCSI_ISER_SG_TABLESIZE +1)), 193 (sizeof(u64) * (ISCSI_ISER_SG_TABLESIZE +1)),
@@ -658,11 +677,11 @@ int iser_post_recvl(struct iser_conn *ib_conn)
658 struct ib_sge sge; 677 struct ib_sge sge;
659 int ib_ret; 678 int ib_ret;
660 679
661 sge.addr = ib_conn->login_dma; 680 sge.addr = ib_conn->login_resp_dma;
662 sge.length = ISER_RX_LOGIN_SIZE; 681 sge.length = ISER_RX_LOGIN_SIZE;
663 sge.lkey = ib_conn->device->mr->lkey; 682 sge.lkey = ib_conn->device->mr->lkey;
664 683
665 rx_wr.wr_id = (unsigned long)ib_conn->login_buf; 684 rx_wr.wr_id = (unsigned long)ib_conn->login_resp_buf;
666 rx_wr.sg_list = &sge; 685 rx_wr.sg_list = &sge;
667 rx_wr.num_sge = 1; 686 rx_wr.num_sge = 1;
668 rx_wr.next = NULL; 687 rx_wr.next = NULL;
diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig
index 23e82e46656d..001b147c7f95 100644
--- a/drivers/input/Kconfig
+++ b/drivers/input/Kconfig
@@ -3,7 +3,7 @@
3# 3#
4 4
5menu "Input device support" 5menu "Input device support"
6 depends on !S390 6 depends on !S390 && !UML
7 7
8config INPUT 8config INPUT
9 tristate "Generic input layer (needed for keyboard, mouse, ...)" if EXPERT 9 tristate "Generic input layer (needed for keyboard, mouse, ...)" if EXPERT
diff --git a/drivers/input/input-compat.c b/drivers/input/input-compat.c
index 1accb89ae66f..e46a86776a6b 100644
--- a/drivers/input/input-compat.c
+++ b/drivers/input/input-compat.c
@@ -8,6 +8,7 @@
8 * the Free Software Foundation. 8 * the Free Software Foundation.
9 */ 9 */
10 10
11#include <linux/export.h>
11#include <asm/uaccess.h> 12#include <asm/uaccess.h>
12#include "input-compat.h" 13#include "input-compat.h"
13 14
diff --git a/drivers/input/input-mt.c b/drivers/input/input-mt.c
index 9150ee78e00a..f658086fbbe0 100644
--- a/drivers/input/input-mt.c
+++ b/drivers/input/input-mt.c
@@ -9,6 +9,7 @@
9 */ 9 */
10 10
11#include <linux/input/mt.h> 11#include <linux/input/mt.h>
12#include <linux/export.h>
12#include <linux/slab.h> 13#include <linux/slab.h>
13 14
14#define TRKID_SGN ((TRKID_MAX + 1) >> 1) 15#define TRKID_SGN ((TRKID_MAX + 1) >> 1)
diff --git a/drivers/input/input-polldev.c b/drivers/input/input-polldev.c
index b253973881b8..7dfe1009fae0 100644
--- a/drivers/input/input-polldev.c
+++ b/drivers/input/input-polldev.c
@@ -14,6 +14,7 @@
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/mutex.h> 15#include <linux/mutex.h>
16#include <linux/workqueue.h> 16#include <linux/workqueue.h>
17#include <linux/module.h>
17#include <linux/input-polldev.h> 18#include <linux/input-polldev.h>
18 19
19MODULE_AUTHOR("Dmitry Torokhov <dtor@mail.ru>"); 20MODULE_AUTHOR("Dmitry Torokhov <dtor@mail.ru>");
diff --git a/drivers/input/joystick/as5011.c b/drivers/input/joystick/as5011.c
index f6732b57ca07..6d6e7418dc21 100644
--- a/drivers/input/joystick/as5011.c
+++ b/drivers/input/joystick/as5011.c
@@ -30,6 +30,7 @@
30#include <linux/delay.h> 30#include <linux/delay.h>
31#include <linux/input/as5011.h> 31#include <linux/input/as5011.h>
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/module.h>
33 34
34#define DRIVER_DESC "Driver for Austria Microsystems AS5011 joystick" 35#define DRIVER_DESC "Driver for Austria Microsystems AS5011 joystick"
35#define MODULE_DEVICE_ALIAS "as5011" 36#define MODULE_DEVICE_ALIAS "as5011"
diff --git a/drivers/input/keyboard/nomadik-ske-keypad.c b/drivers/input/keyboard/nomadik-ske-keypad.c
index 6e0f23091360..fcdec5e2b297 100644
--- a/drivers/input/keyboard/nomadik-ske-keypad.c
+++ b/drivers/input/keyboard/nomadik-ske-keypad.c
@@ -18,6 +18,7 @@
18#include <linux/input.h> 18#include <linux/input.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/clk.h> 20#include <linux/clk.h>
21#include <linux/module.h>
21 22
22#include <plat/ske.h> 23#include <plat/ske.h>
23 24
diff --git a/drivers/input/keyboard/tnetv107x-keypad.c b/drivers/input/keyboard/tnetv107x-keypad.c
index 1c58681de81f..66e55e5cfdd6 100644
--- a/drivers/input/keyboard/tnetv107x-keypad.c
+++ b/drivers/input/keyboard/tnetv107x-keypad.c
@@ -24,6 +24,7 @@
24#include <linux/io.h> 24#include <linux/io.h>
25#include <linux/clk.h> 25#include <linux/clk.h>
26#include <linux/input/matrix_keypad.h> 26#include <linux/input/matrix_keypad.h>
27#include <linux/module.h>
27 28
28#define BITS(x) (BIT(x) - 1) 29#define BITS(x) (BIT(x) - 1)
29 30
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 56aa465d1b99..22d875fde53a 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -134,6 +134,16 @@ config INPUT_MAX8925_ONKEY
134 To compile this driver as a module, choose M here: the module 134 To compile this driver as a module, choose M here: the module
135 will be called max8925_onkey. 135 will be called max8925_onkey.
136 136
137config INPUT_MC13783_PWRBUTTON
138 tristate "MC13783 ON buttons"
139 depends on MFD_MC13783
140 help
141 Support the ON buttons of MC13783 PMIC as an input device
142 reporting power button status.
143
144 To compile this driver as a module, choose M here: the module
145 will be called mc13783-pwrbutton.
146
137config INPUT_MMA8450 147config INPUT_MMA8450
138 tristate "MMA8450 - Freescale's 3-Axis, 8/12-bit Digital Accelerometer" 148 tristate "MMA8450 - Freescale's 3-Axis, 8/12-bit Digital Accelerometer"
139 depends on I2C 149 depends on I2C
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 62dcd79d548f..a244fc6a781c 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -28,6 +28,7 @@ obj-$(CONFIG_INPUT_KEYSPAN_REMOTE) += keyspan_remote.o
28obj-$(CONFIG_INPUT_KXTJ9) += kxtj9.o 28obj-$(CONFIG_INPUT_KXTJ9) += kxtj9.o
29obj-$(CONFIG_INPUT_M68K_BEEP) += m68kspkr.o 29obj-$(CONFIG_INPUT_M68K_BEEP) += m68kspkr.o
30obj-$(CONFIG_INPUT_MAX8925_ONKEY) += max8925_onkey.o 30obj-$(CONFIG_INPUT_MAX8925_ONKEY) += max8925_onkey.o
31obj-$(CONFIG_INPUT_MC13783_PWRBUTTON) += mc13783-pwrbutton.o
31obj-$(CONFIG_INPUT_MMA8450) += mma8450.o 32obj-$(CONFIG_INPUT_MMA8450) += mma8450.o
32obj-$(CONFIG_INPUT_MPU3050) += mpu3050.o 33obj-$(CONFIG_INPUT_MPU3050) += mpu3050.o
33obj-$(CONFIG_INPUT_PCAP) += pcap_keys.o 34obj-$(CONFIG_INPUT_PCAP) += pcap_keys.o
diff --git a/drivers/input/misc/ad714x.c b/drivers/input/misc/ad714x.c
index ca42c7d2a3c7..0ac75bbad4d6 100644
--- a/drivers/input/misc/ad714x.c
+++ b/drivers/input/misc/ad714x.c
@@ -12,6 +12,7 @@
12#include <linux/interrupt.h> 12#include <linux/interrupt.h>
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/input/ad714x.h> 14#include <linux/input/ad714x.h>
15#include <linux/module.h>
15#include "ad714x.h" 16#include "ad714x.h"
16 17
17#define AD714X_PWR_CTRL 0x0 18#define AD714X_PWR_CTRL 0x0
diff --git a/drivers/input/misc/adxl34x.c b/drivers/input/misc/adxl34x.c
index 144ddbdeb9b3..09244804fb97 100644
--- a/drivers/input/misc/adxl34x.c
+++ b/drivers/input/misc/adxl34x.c
@@ -16,6 +16,7 @@
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <linux/workqueue.h> 17#include <linux/workqueue.h>
18#include <linux/input/adxl34x.h> 18#include <linux/input/adxl34x.h>
19#include <linux/module.h>
19 20
20#include "adxl34x.h" 21#include "adxl34x.h"
21 22
diff --git a/drivers/input/misc/ati_remote2.c b/drivers/input/misc/ati_remote2.c
index 1de58e8a1b71..8d345e87075e 100644
--- a/drivers/input/misc/ati_remote2.c
+++ b/drivers/input/misc/ati_remote2.c
@@ -11,6 +11,7 @@
11 11
12#include <linux/usb/input.h> 12#include <linux/usb/input.h>
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/module.h>
14 15
15#define DRIVER_DESC "ATI/Philips USB RF remote driver" 16#define DRIVER_DESC "ATI/Philips USB RF remote driver"
16#define DRIVER_VERSION "0.3" 17#define DRIVER_VERSION "0.3"
diff --git a/drivers/input/misc/cma3000_d0x.c b/drivers/input/misc/cma3000_d0x.c
index 1633b6342267..80793f1608eb 100644
--- a/drivers/input/misc/cma3000_d0x.c
+++ b/drivers/input/misc/cma3000_d0x.c
@@ -23,6 +23,7 @@
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/input.h> 24#include <linux/input.h>
25#include <linux/input/cma3000.h> 25#include <linux/input/cma3000.h>
26#include <linux/module.h>
26 27
27#include "cma3000_d0x.h" 28#include "cma3000_d0x.h"
28 29
diff --git a/drivers/input/misc/dm355evm_keys.c b/drivers/input/misc/dm355evm_keys.c
index 19af682c24fb..7283dd2a1ad3 100644
--- a/drivers/input/misc/dm355evm_keys.c
+++ b/drivers/input/misc/dm355evm_keys.c
@@ -17,6 +17,7 @@
17#include <linux/interrupt.h> 17#include <linux/interrupt.h>
18 18
19#include <linux/i2c/dm355evm_msp.h> 19#include <linux/i2c/dm355evm_msp.h>
20#include <linux/module.h>
20 21
21 22
22/* 23/*
diff --git a/drivers/input/misc/mc13783-pwrbutton.c b/drivers/input/misc/mc13783-pwrbutton.c
new file mode 100644
index 000000000000..09b052288657
--- /dev/null
+++ b/drivers/input/misc/mc13783-pwrbutton.c
@@ -0,0 +1,282 @@
1/**
2 * Copyright (C) 2011 Philippe Rétornaz
3 *
4 * Based on twl4030-pwrbutton driver by:
5 * Peter De Schrijver <peter.de-schrijver@nokia.com>
6 * Felipe Balbi <felipe.balbi@nokia.com>
7 *
8 * This file is subject to the terms and conditions of the GNU General
9 * Public License. See the file "COPYING" in the main directory of this
10 * archive for more details.
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, Suite 500, Boston, MA 02110-1335 USA
20 */
21
22#include <linux/module.h>
23#include <linux/init.h>
24#include <linux/kernel.h>
25#include <linux/errno.h>
26#include <linux/input.h>
27#include <linux/interrupt.h>
28#include <linux/platform_device.h>
29#include <linux/mfd/mc13783.h>
30#include <linux/sched.h>
31#include <linux/slab.h>
32
33struct mc13783_pwrb {
34 struct input_dev *pwr;
35 struct mc13xxx *mc13783;
36#define MC13783_PWRB_B1_POL_INVERT (1 << 0)
37#define MC13783_PWRB_B2_POL_INVERT (1 << 1)
38#define MC13783_PWRB_B3_POL_INVERT (1 << 2)
39 int flags;
40 unsigned short keymap[3];
41};
42
43#define MC13783_REG_INTERRUPT_SENSE_1 5
44#define MC13783_IRQSENSE1_ONOFD1S (1 << 3)
45#define MC13783_IRQSENSE1_ONOFD2S (1 << 4)
46#define MC13783_IRQSENSE1_ONOFD3S (1 << 5)
47
48#define MC13783_REG_POWER_CONTROL_2 15
49#define MC13783_POWER_CONTROL_2_ON1BDBNC 4
50#define MC13783_POWER_CONTROL_2_ON2BDBNC 6
51#define MC13783_POWER_CONTROL_2_ON3BDBNC 8
52#define MC13783_POWER_CONTROL_2_ON1BRSTEN (1 << 1)
53#define MC13783_POWER_CONTROL_2_ON2BRSTEN (1 << 2)
54#define MC13783_POWER_CONTROL_2_ON3BRSTEN (1 << 3)
55
56static irqreturn_t button_irq(int irq, void *_priv)
57{
58 struct mc13783_pwrb *priv = _priv;
59 int val;
60
61 mc13xxx_irq_ack(priv->mc13783, irq);
62 mc13xxx_reg_read(priv->mc13783, MC13783_REG_INTERRUPT_SENSE_1, &val);
63
64 switch (irq) {
65 case MC13783_IRQ_ONOFD1:
66 val = val & MC13783_IRQSENSE1_ONOFD1S ? 1 : 0;
67 if (priv->flags & MC13783_PWRB_B1_POL_INVERT)
68 val ^= 1;
69 input_report_key(priv->pwr, priv->keymap[0], val);
70 break;
71
72 case MC13783_IRQ_ONOFD2:
73 val = val & MC13783_IRQSENSE1_ONOFD2S ? 1 : 0;
74 if (priv->flags & MC13783_PWRB_B2_POL_INVERT)
75 val ^= 1;
76 input_report_key(priv->pwr, priv->keymap[1], val);
77 break;
78
79 case MC13783_IRQ_ONOFD3:
80 val = val & MC13783_IRQSENSE1_ONOFD3S ? 1 : 0;
81 if (priv->flags & MC13783_PWRB_B3_POL_INVERT)
82 val ^= 1;
83 input_report_key(priv->pwr, priv->keymap[2], val);
84 break;
85 }
86
87 input_sync(priv->pwr);
88
89 return IRQ_HANDLED;
90}
91
92static int __devinit mc13783_pwrbutton_probe(struct platform_device *pdev)
93{
94 const struct mc13xxx_buttons_platform_data *pdata;
95 struct mc13xxx *mc13783 = dev_get_drvdata(pdev->dev.parent);
96 struct input_dev *pwr;
97 struct mc13783_pwrb *priv;
98 int err = 0;
99 int reg = 0;
100
101 pdata = dev_get_platdata(&pdev->dev);
102 if (!pdata) {
103 dev_err(&pdev->dev, "missing platform data\n");
104 return -ENODEV;
105 }
106
107 pwr = input_allocate_device();
108 if (!pwr) {
109 dev_dbg(&pdev->dev, "Can't allocate power button\n");
110 return -ENOMEM;
111 }
112
113 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
114 if (!priv) {
115 err = -ENOMEM;
116 dev_dbg(&pdev->dev, "Can't allocate power button\n");
117 goto free_input_dev;
118 }
119
120 reg |= (pdata->b1on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON1BDBNC;
121 reg |= (pdata->b2on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON2BDBNC;
122 reg |= (pdata->b3on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON3BDBNC;
123
124 priv->pwr = pwr;
125 priv->mc13783 = mc13783;
126
127 mc13xxx_lock(mc13783);
128
129 if (pdata->b1on_flags & MC13783_BUTTON_ENABLE) {
130 priv->keymap[0] = pdata->b1on_key;
131 if (pdata->b1on_key != KEY_RESERVED)
132 __set_bit(pdata->b1on_key, pwr->keybit);
133
134 if (pdata->b1on_flags & MC13783_BUTTON_POL_INVERT)
135 priv->flags |= MC13783_PWRB_B1_POL_INVERT;
136
137 if (pdata->b1on_flags & MC13783_BUTTON_RESET_EN)
138 reg |= MC13783_POWER_CONTROL_2_ON1BRSTEN;
139
140 err = mc13xxx_irq_request(mc13783, MC13783_IRQ_ONOFD1,
141 button_irq, "b1on", priv);
142 if (err) {
143 dev_dbg(&pdev->dev, "Can't request irq\n");
144 goto free_priv;
145 }
146 }
147
148 if (pdata->b2on_flags & MC13783_BUTTON_ENABLE) {
149 priv->keymap[1] = pdata->b2on_key;
150 if (pdata->b2on_key != KEY_RESERVED)
151 __set_bit(pdata->b2on_key, pwr->keybit);
152
153 if (pdata->b2on_flags & MC13783_BUTTON_POL_INVERT)
154 priv->flags |= MC13783_PWRB_B2_POL_INVERT;
155
156 if (pdata->b2on_flags & MC13783_BUTTON_RESET_EN)
157 reg |= MC13783_POWER_CONTROL_2_ON2BRSTEN;
158
159 err = mc13xxx_irq_request(mc13783, MC13783_IRQ_ONOFD2,
160 button_irq, "b2on", priv);
161 if (err) {
162 dev_dbg(&pdev->dev, "Can't request irq\n");
163 goto free_irq_b1;
164 }
165 }
166
167 if (pdata->b3on_flags & MC13783_BUTTON_ENABLE) {
168 priv->keymap[2] = pdata->b3on_key;
169 if (pdata->b3on_key != KEY_RESERVED)
170 __set_bit(pdata->b3on_key, pwr->keybit);
171
172 if (pdata->b3on_flags & MC13783_BUTTON_POL_INVERT)
173 priv->flags |= MC13783_PWRB_B3_POL_INVERT;
174
175 if (pdata->b3on_flags & MC13783_BUTTON_RESET_EN)
176 reg |= MC13783_POWER_CONTROL_2_ON3BRSTEN;
177
178 err = mc13xxx_irq_request(mc13783, MC13783_IRQ_ONOFD3,
179 button_irq, "b3on", priv);
180 if (err) {
181 dev_dbg(&pdev->dev, "Can't request irq: %d\n", err);
182 goto free_irq_b2;
183 }
184 }
185
186 mc13xxx_reg_rmw(mc13783, MC13783_REG_POWER_CONTROL_2, 0x3FE, reg);
187
188 mc13xxx_unlock(mc13783);
189
190 pwr->name = "mc13783_pwrbutton";
191 pwr->phys = "mc13783_pwrbutton/input0";
192 pwr->dev.parent = &pdev->dev;
193
194 pwr->keycode = priv->keymap;
195 pwr->keycodemax = ARRAY_SIZE(priv->keymap);
196 pwr->keycodesize = sizeof(priv->keymap[0]);
197 __set_bit(EV_KEY, pwr->evbit);
198
199 err = input_register_device(pwr);
200 if (err) {
201 dev_dbg(&pdev->dev, "Can't register power button: %d\n", err);
202 goto free_irq;
203 }
204
205 platform_set_drvdata(pdev, priv);
206
207 return 0;
208
209free_irq:
210 mc13xxx_lock(mc13783);
211
212 if (pdata->b3on_flags & MC13783_BUTTON_ENABLE)
213 mc13xxx_irq_free(mc13783, MC13783_IRQ_ONOFD3, priv);
214
215free_irq_b2:
216 if (pdata->b2on_flags & MC13783_BUTTON_ENABLE)
217 mc13xxx_irq_free(mc13783, MC13783_IRQ_ONOFD2, priv);
218
219free_irq_b1:
220 if (pdata->b1on_flags & MC13783_BUTTON_ENABLE)
221 mc13xxx_irq_free(mc13783, MC13783_IRQ_ONOFD1, priv);
222
223free_priv:
224 mc13xxx_unlock(mc13783);
225 kfree(priv);
226
227free_input_dev:
228 input_free_device(pwr);
229
230 return err;
231}
232
233static int __devexit mc13783_pwrbutton_remove(struct platform_device *pdev)
234{
235 struct mc13783_pwrb *priv = platform_get_drvdata(pdev);
236 const struct mc13xxx_buttons_platform_data *pdata;
237
238 pdata = dev_get_platdata(&pdev->dev);
239
240 mc13xxx_lock(priv->mc13783);
241
242 if (pdata->b3on_flags & MC13783_BUTTON_ENABLE)
243 mc13xxx_irq_free(priv->mc13783, MC13783_IRQ_ONOFD3, priv);
244 if (pdata->b2on_flags & MC13783_BUTTON_ENABLE)
245 mc13xxx_irq_free(priv->mc13783, MC13783_IRQ_ONOFD2, priv);
246 if (pdata->b1on_flags & MC13783_BUTTON_ENABLE)
247 mc13xxx_irq_free(priv->mc13783, MC13783_IRQ_ONOFD1, priv);
248
249 mc13xxx_unlock(priv->mc13783);
250
251 input_unregister_device(priv->pwr);
252 kfree(priv);
253 platform_set_drvdata(pdev, NULL);
254
255 return 0;
256}
257
258struct platform_driver mc13783_pwrbutton_driver = {
259 .probe = mc13783_pwrbutton_probe,
260 .remove = __devexit_p(mc13783_pwrbutton_remove),
261 .driver = {
262 .name = "mc13783-pwrbutton",
263 .owner = THIS_MODULE,
264 },
265};
266
267static int __init mc13783_pwrbutton_init(void)
268{
269 return platform_driver_register(&mc13783_pwrbutton_driver);
270}
271module_init(mc13783_pwrbutton_init);
272
273static void __exit mc13783_pwrbutton_exit(void)
274{
275 platform_driver_unregister(&mc13783_pwrbutton_driver);
276}
277module_exit(mc13783_pwrbutton_exit);
278
279MODULE_ALIAS("platform:mc13783-pwrbutton");
280MODULE_DESCRIPTION("MC13783 Power Button");
281MODULE_LICENSE("GPL v2");
282MODULE_AUTHOR("Philippe Retornaz");
diff --git a/drivers/input/sparse-keymap.c b/drivers/input/sparse-keymap.c
index fdb6a3976f94..75fb040a3435 100644
--- a/drivers/input/sparse-keymap.c
+++ b/drivers/input/sparse-keymap.c
@@ -15,6 +15,7 @@
15 15
16#include <linux/input.h> 16#include <linux/input.h>
17#include <linux/input/sparse-keymap.h> 17#include <linux/input/sparse-keymap.h>
18#include <linux/module.h>
18#include <linux/slab.h> 19#include <linux/slab.h>
19 20
20MODULE_AUTHOR("Dmitry Torokhov <dtor@mail.ru>"); 21MODULE_AUTHOR("Dmitry Torokhov <dtor@mail.ru>");
diff --git a/drivers/input/touchscreen/ad7877.c b/drivers/input/touchscreen/ad7877.c
index 714d4e0f9f95..400131df677b 100644
--- a/drivers/input/touchscreen/ad7877.c
+++ b/drivers/input/touchscreen/ad7877.c
@@ -45,6 +45,7 @@
45#include <linux/slab.h> 45#include <linux/slab.h>
46#include <linux/spi/spi.h> 46#include <linux/spi/spi.h>
47#include <linux/spi/ad7877.h> 47#include <linux/spi/ad7877.h>
48#include <linux/module.h>
48#include <asm/irq.h> 49#include <asm/irq.h>
49 50
50#define TS_PEN_UP_TIMEOUT msecs_to_jiffies(100) 51#define TS_PEN_UP_TIMEOUT msecs_to_jiffies(100)
diff --git a/drivers/input/touchscreen/ad7879-spi.c b/drivers/input/touchscreen/ad7879-spi.c
index ddf732f3cafc..b1643c8fa7c9 100644
--- a/drivers/input/touchscreen/ad7879-spi.c
+++ b/drivers/input/touchscreen/ad7879-spi.c
@@ -9,6 +9,7 @@
9#include <linux/input.h> /* BUS_SPI */ 9#include <linux/input.h> /* BUS_SPI */
10#include <linux/pm.h> 10#include <linux/pm.h>
11#include <linux/spi/spi.h> 11#include <linux/spi/spi.h>
12#include <linux/module.h>
12 13
13#include "ad7879.h" 14#include "ad7879.h"
14 15
diff --git a/drivers/input/touchscreen/ad7879.c b/drivers/input/touchscreen/ad7879.c
index 131f9d1c921b..3b2e9ed2aeec 100644
--- a/drivers/input/touchscreen/ad7879.c
+++ b/drivers/input/touchscreen/ad7879.c
@@ -33,6 +33,7 @@
33#include <linux/gpio.h> 33#include <linux/gpio.h>
34 34
35#include <linux/spi/ad7879.h> 35#include <linux/spi/ad7879.h>
36#include <linux/module.h>
36#include "ad7879.h" 37#include "ad7879.h"
37 38
38#define AD7879_REG_ZEROS 0 39#define AD7879_REG_ZEROS 0
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index d507b9b67806..de31ec6fe9e4 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -31,6 +31,7 @@
31#include <linux/spi/spi.h> 31#include <linux/spi/spi.h>
32#include <linux/spi/ads7846.h> 32#include <linux/spi/ads7846.h>
33#include <linux/regulator/consumer.h> 33#include <linux/regulator/consumer.h>
34#include <linux/module.h>
34#include <asm/irq.h> 35#include <asm/irq.h>
35 36
36/* 37/*
diff --git a/drivers/input/touchscreen/bu21013_ts.c b/drivers/input/touchscreen/bu21013_ts.c
index 1507ce108d5b..902c7214e887 100644
--- a/drivers/input/touchscreen/bu21013_ts.c
+++ b/drivers/input/touchscreen/bu21013_ts.c
@@ -13,6 +13,7 @@
13#include <linux/input/bu21013.h> 13#include <linux/input/bu21013.h>
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/regulator/consumer.h> 15#include <linux/regulator/consumer.h>
16#include <linux/module.h>
16 17
17#define PEN_DOWN_INTR 0 18#define PEN_DOWN_INTR 0
18#define MAX_FINGERS 2 19#define MAX_FINGERS 2
diff --git a/drivers/input/touchscreen/mc13783_ts.c b/drivers/input/touchscreen/mc13783_ts.c
index c5bc62d85bb6..ede02743eac1 100644
--- a/drivers/input/touchscreen/mc13783_ts.c
+++ b/drivers/input/touchscreen/mc13783_ts.c
@@ -35,7 +35,7 @@ MODULE_PARM_DESC(sample_tolerance,
35 35
36struct mc13783_ts_priv { 36struct mc13783_ts_priv {
37 struct input_dev *idev; 37 struct input_dev *idev;
38 struct mc13783 *mc13783; 38 struct mc13xxx *mc13xxx;
39 struct delayed_work work; 39 struct delayed_work work;
40 struct workqueue_struct *workq; 40 struct workqueue_struct *workq;
41 unsigned int sample[4]; 41 unsigned int sample[4];
@@ -45,7 +45,7 @@ static irqreturn_t mc13783_ts_handler(int irq, void *data)
45{ 45{
46 struct mc13783_ts_priv *priv = data; 46 struct mc13783_ts_priv *priv = data;
47 47
48 mc13783_irq_ack(priv->mc13783, irq); 48 mc13xxx_irq_ack(priv->mc13xxx, irq);
49 49
50 /* 50 /*
51 * Kick off reading coordinates. Note that if work happens already 51 * Kick off reading coordinates. Note that if work happens already
@@ -121,10 +121,10 @@ static void mc13783_ts_work(struct work_struct *work)
121{ 121{
122 struct mc13783_ts_priv *priv = 122 struct mc13783_ts_priv *priv =
123 container_of(work, struct mc13783_ts_priv, work.work); 123 container_of(work, struct mc13783_ts_priv, work.work);
124 unsigned int mode = MC13783_ADC_MODE_TS; 124 unsigned int mode = MC13XXX_ADC_MODE_TS;
125 unsigned int channel = 12; 125 unsigned int channel = 12;
126 126
127 if (mc13783_adc_do_conversion(priv->mc13783, 127 if (mc13xxx_adc_do_conversion(priv->mc13xxx,
128 mode, channel, priv->sample) == 0) 128 mode, channel, priv->sample) == 0)
129 mc13783_ts_report_sample(priv); 129 mc13783_ts_report_sample(priv);
130} 130}
@@ -134,21 +134,21 @@ static int mc13783_ts_open(struct input_dev *dev)
134 struct mc13783_ts_priv *priv = input_get_drvdata(dev); 134 struct mc13783_ts_priv *priv = input_get_drvdata(dev);
135 int ret; 135 int ret;
136 136
137 mc13783_lock(priv->mc13783); 137 mc13xxx_lock(priv->mc13xxx);
138 138
139 mc13783_irq_ack(priv->mc13783, MC13783_IRQ_TS); 139 mc13xxx_irq_ack(priv->mc13xxx, MC13XXX_IRQ_TS);
140 140
141 ret = mc13783_irq_request(priv->mc13783, MC13783_IRQ_TS, 141 ret = mc13xxx_irq_request(priv->mc13xxx, MC13XXX_IRQ_TS,
142 mc13783_ts_handler, MC13783_TS_NAME, priv); 142 mc13783_ts_handler, MC13783_TS_NAME, priv);
143 if (ret) 143 if (ret)
144 goto out; 144 goto out;
145 145
146 ret = mc13783_reg_rmw(priv->mc13783, MC13783_ADC0, 146 ret = mc13xxx_reg_rmw(priv->mc13xxx, MC13XXX_ADC0,
147 MC13783_ADC0_TSMOD_MASK, MC13783_ADC0_TSMOD0); 147 MC13XXX_ADC0_TSMOD_MASK, MC13XXX_ADC0_TSMOD0);
148 if (ret) 148 if (ret)
149 mc13783_irq_free(priv->mc13783, MC13783_IRQ_TS, priv); 149 mc13xxx_irq_free(priv->mc13xxx, MC13XXX_IRQ_TS, priv);
150out: 150out:
151 mc13783_unlock(priv->mc13783); 151 mc13xxx_unlock(priv->mc13xxx);
152 return ret; 152 return ret;
153} 153}
154 154
@@ -156,11 +156,11 @@ static void mc13783_ts_close(struct input_dev *dev)
156{ 156{
157 struct mc13783_ts_priv *priv = input_get_drvdata(dev); 157 struct mc13783_ts_priv *priv = input_get_drvdata(dev);
158 158
159 mc13783_lock(priv->mc13783); 159 mc13xxx_lock(priv->mc13xxx);
160 mc13783_reg_rmw(priv->mc13783, MC13783_ADC0, 160 mc13xxx_reg_rmw(priv->mc13xxx, MC13XXX_ADC0,
161 MC13783_ADC0_TSMOD_MASK, 0); 161 MC13XXX_ADC0_TSMOD_MASK, 0);
162 mc13783_irq_free(priv->mc13783, MC13783_IRQ_TS, priv); 162 mc13xxx_irq_free(priv->mc13xxx, MC13XXX_IRQ_TS, priv);
163 mc13783_unlock(priv->mc13783); 163 mc13xxx_unlock(priv->mc13xxx);
164 164
165 cancel_delayed_work_sync(&priv->work); 165 cancel_delayed_work_sync(&priv->work);
166} 166}
@@ -177,7 +177,7 @@ static int __init mc13783_ts_probe(struct platform_device *pdev)
177 goto err_free_mem; 177 goto err_free_mem;
178 178
179 INIT_DELAYED_WORK(&priv->work, mc13783_ts_work); 179 INIT_DELAYED_WORK(&priv->work, mc13783_ts_work);
180 priv->mc13783 = dev_get_drvdata(pdev->dev.parent); 180 priv->mc13xxx = dev_get_drvdata(pdev->dev.parent);
181 priv->idev = idev; 181 priv->idev = idev;
182 182
183 /* 183 /*
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index bb161d2fa03c..c0c7820d4c46 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -24,6 +24,7 @@
24#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/bitmap.h> 25#include <linux/bitmap.h>
26#include <linux/debugfs.h> 26#include <linux/debugfs.h>
27#include <linux/export.h>
27#include <linux/slab.h> 28#include <linux/slab.h>
28#include <linux/irq.h> 29#include <linux/irq.h>
29#include <linux/interrupt.h> 30#include <linux/interrupt.h>
diff --git a/drivers/isdn/Kconfig b/drivers/isdn/Kconfig
index 4fb601670de3..a233ed53913a 100644
--- a/drivers/isdn/Kconfig
+++ b/drivers/isdn/Kconfig
@@ -5,7 +5,7 @@
5menuconfig ISDN 5menuconfig ISDN
6 bool "ISDN support" 6 bool "ISDN support"
7 depends on NET 7 depends on NET
8 depends on !S390 8 depends on !S390 && !UML
9 ---help--- 9 ---help---
10 ISDN ("Integrated Services Digital Network", called RNIS in France) 10 ISDN ("Integrated Services Digital Network", called RNIS in France)
11 is a fully digital telephone service that can be used for voice and 11 is a fully digital telephone service that can be used for voice and
diff --git a/drivers/isdn/capi/kcapi_proc.c b/drivers/isdn/capi/kcapi_proc.c
index ea2dff602e49..8d51cd1bf674 100644
--- a/drivers/isdn/capi/kcapi_proc.c
+++ b/drivers/isdn/capi/kcapi_proc.c
@@ -14,6 +14,7 @@
14#include <linux/proc_fs.h> 14#include <linux/proc_fs.h>
15#include <linux/seq_file.h> 15#include <linux/seq_file.h>
16#include <linux/init.h> 16#include <linux/init.h>
17#include <linux/export.h>
17 18
18static char *state2str(unsigned short state) 19static char *state2str(unsigned short state)
19{ 20{
diff --git a/drivers/isdn/gigaset/asyncdata.c b/drivers/isdn/gigaset/asyncdata.c
index c3b1dc3a13a0..fddae72e3f98 100644
--- a/drivers/isdn/gigaset/asyncdata.c
+++ b/drivers/isdn/gigaset/asyncdata.c
@@ -16,6 +16,7 @@
16#include "gigaset.h" 16#include "gigaset.h"
17#include <linux/crc-ccitt.h> 17#include <linux/crc-ccitt.h>
18#include <linux/bitrev.h> 18#include <linux/bitrev.h>
19#include <linux/export.h>
19 20
20/* check if byte must be stuffed/escaped 21/* check if byte must be stuffed/escaped
21 * I'm not sure which data should be encoded. 22 * I'm not sure which data should be encoded.
diff --git a/drivers/isdn/gigaset/capi.c b/drivers/isdn/gigaset/capi.c
index 658e75f18d05..6d5ceeece9f2 100644
--- a/drivers/isdn/gigaset/capi.c
+++ b/drivers/isdn/gigaset/capi.c
@@ -17,6 +17,7 @@
17#include <linux/isdn/capilli.h> 17#include <linux/isdn/capilli.h>
18#include <linux/isdn/capicmd.h> 18#include <linux/isdn/capicmd.h>
19#include <linux/isdn/capiutil.h> 19#include <linux/isdn/capiutil.h>
20#include <linux/export.h>
20 21
21/* missing from kernelcapi.h */ 22/* missing from kernelcapi.h */
22#define CapiNcpiNotSupportedByProtocol 0x0001 23#define CapiNcpiNotSupportedByProtocol 0x0001
diff --git a/drivers/isdn/gigaset/dummyll.c b/drivers/isdn/gigaset/dummyll.c
index bd0b1eaa7572..19b1c779d50f 100644
--- a/drivers/isdn/gigaset/dummyll.c
+++ b/drivers/isdn/gigaset/dummyll.c
@@ -11,6 +11,7 @@
11 * ===================================================================== 11 * =====================================================================
12 */ 12 */
13 13
14#include <linux/export.h>
14#include "gigaset.h" 15#include "gigaset.h"
15 16
16void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb) 17void gigaset_skb_sent(struct bc_state *bcs, struct sk_buff *skb)
diff --git a/drivers/isdn/gigaset/ev-layer.c b/drivers/isdn/gigaset/ev-layer.c
index ba74646cf0e4..6d12623c1db0 100644
--- a/drivers/isdn/gigaset/ev-layer.c
+++ b/drivers/isdn/gigaset/ev-layer.c
@@ -13,6 +13,7 @@
13 * ===================================================================== 13 * =====================================================================
14 */ 14 */
15 15
16#include <linux/export.h>
16#include "gigaset.h" 17#include "gigaset.h"
17 18
18/* ========================================================== */ 19/* ========================================================== */
diff --git a/drivers/isdn/gigaset/i4l.c b/drivers/isdn/gigaset/i4l.c
index 9bec8b969964..04231cb2f031 100644
--- a/drivers/isdn/gigaset/i4l.c
+++ b/drivers/isdn/gigaset/i4l.c
@@ -15,6 +15,7 @@
15 15
16#include "gigaset.h" 16#include "gigaset.h"
17#include <linux/isdnif.h> 17#include <linux/isdnif.h>
18#include <linux/export.h>
18 19
19#define SBUFSIZE 4096 /* sk_buff payload size */ 20#define SBUFSIZE 4096 /* sk_buff payload size */
20#define TRANSBUFSIZE 768 /* bytes per skb for transparent receive */ 21#define TRANSBUFSIZE 768 /* bytes per skb for transparent receive */
diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
index e35058bcd7b9..ee0a549a933a 100644
--- a/drivers/isdn/gigaset/interface.c
+++ b/drivers/isdn/gigaset/interface.c
@@ -14,6 +14,7 @@
14#include "gigaset.h" 14#include "gigaset.h"
15#include <linux/gigaset_dev.h> 15#include <linux/gigaset_dev.h>
16#include <linux/tty_flip.h> 16#include <linux/tty_flip.h>
17#include <linux/module.h>
17 18
18/*** our ioctls ***/ 19/*** our ioctls ***/
19 20
diff --git a/drivers/isdn/hardware/mISDN/mISDNisar.c b/drivers/isdn/hardware/mISDN/mISDNisar.c
index d13fa5b119f5..7034af28d464 100644
--- a/drivers/isdn/hardware/mISDN/mISDNisar.c
+++ b/drivers/isdn/hardware/mISDN/mISDNisar.c
@@ -29,6 +29,7 @@
29#include <linux/delay.h> 29#include <linux/delay.h>
30#include <linux/vmalloc.h> 30#include <linux/vmalloc.h>
31#include <linux/mISDNhw.h> 31#include <linux/mISDNhw.h>
32#include <linux/module.h>
32#include "isar.h" 33#include "isar.h"
33 34
34#define ISAR_REV "2.1" 35#define ISAR_REV "2.1"
diff --git a/drivers/isdn/hisax/l3dss1.c b/drivers/isdn/hisax/l3dss1.c
index b0d9ab1f21c0..6a8acf65777d 100644
--- a/drivers/isdn/hisax/l3dss1.c
+++ b/drivers/isdn/hisax/l3dss1.c
@@ -353,7 +353,7 @@ l3dss1_parse_facility(struct PStack *st, struct l3_process *pc,
353 { l3dss1_dummy_invoke(st, cr, id, ident, p, nlen); 353 { l3dss1_dummy_invoke(st, cr, id, ident, p, nlen);
354 return; 354 return;
355 } 355 }
356#ifdef HISAX_DE_AOC 356#ifdef CONFIG_DE_AOC
357 { 357 {
358 358
359#define FOO1(s,a,b) \ 359#define FOO1(s,a,b) \
@@ -422,9 +422,9 @@ l3dss1_parse_facility(struct PStack *st, struct l3_process *pc,
422#undef FOO1 422#undef FOO1
423 423
424 } 424 }
425#else /* not HISAX_DE_AOC */ 425#else /* not CONFIG_DE_AOC */
426 l3_debug(st, "invoke break"); 426 l3_debug(st, "invoke break");
427#endif /* not HISAX_DE_AOC */ 427#endif /* not CONFIG_DE_AOC */
428 break; 428 break;
429 case 2: /* return result */ 429 case 2: /* return result */
430 /* if no process available handle separately */ 430 /* if no process available handle separately */
diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
index e5546cb3ac69..2c26b64ebbea 100644
--- a/drivers/isdn/i4l/isdn_tty.c
+++ b/drivers/isdn/i4l/isdn_tty.c
@@ -750,6 +750,7 @@ isdn_tty_modem_hup(modem_info * info, int local)
750 * supplementary service (CAPI 2.0 part III) 750 * supplementary service (CAPI 2.0 part III)
751 */ 751 */
752#include <linux/isdn/capicmd.h> 752#include <linux/isdn/capicmd.h>
753#include <linux/module.h>
753 754
754int 755int
755isdn_tty_capi_facility(capi_msg *cm) { 756isdn_tty_capi_facility(capi_msg *cm) {
diff --git a/drivers/isdn/mISDN/clock.c b/drivers/isdn/mISDN/clock.c
index 1fa629b3b940..7418f2d811d8 100644
--- a/drivers/isdn/mISDN/clock.c
+++ b/drivers/isdn/mISDN/clock.c
@@ -38,6 +38,7 @@
38#include <linux/stddef.h> 38#include <linux/stddef.h>
39#include <linux/spinlock.h> 39#include <linux/spinlock.h>
40#include <linux/mISDNif.h> 40#include <linux/mISDNif.h>
41#include <linux/export.h>
41#include "core.h" 42#include "core.h"
42 43
43static u_int *debug; 44static u_int *debug;
diff --git a/drivers/isdn/mISDN/dsp_audio.c b/drivers/isdn/mISDN/dsp_audio.c
index 9c7c6451bf3d..b8f18bd09e43 100644
--- a/drivers/isdn/mISDN/dsp_audio.c
+++ b/drivers/isdn/mISDN/dsp_audio.c
@@ -12,6 +12,7 @@
12#include <linux/delay.h> 12#include <linux/delay.h>
13#include <linux/mISDNif.h> 13#include <linux/mISDNif.h>
14#include <linux/mISDNdsp.h> 14#include <linux/mISDNdsp.h>
15#include <linux/export.h>
15#include "core.h" 16#include "core.h"
16#include "dsp.h" 17#include "dsp.h"
17 18
diff --git a/drivers/isdn/mISDN/dsp_pipeline.c b/drivers/isdn/mISDN/dsp_pipeline.c
index 621f31007095..b6c9a5889346 100644
--- a/drivers/isdn/mISDN/dsp_pipeline.c
+++ b/drivers/isdn/mISDN/dsp_pipeline.c
@@ -30,6 +30,7 @@
30#include <linux/string.h> 30#include <linux/string.h>
31#include <linux/mISDNif.h> 31#include <linux/mISDNif.h>
32#include <linux/mISDNdsp.h> 32#include <linux/mISDNdsp.h>
33#include <linux/export.h>
33#include "dsp.h" 34#include "dsp.h"
34#include "dsp_hwec.h" 35#include "dsp_hwec.h"
35 36
diff --git a/drivers/isdn/mISDN/socket.c b/drivers/isdn/mISDN/socket.c
index 8e325227b4c0..738ea8dd0adf 100644
--- a/drivers/isdn/mISDN/socket.c
+++ b/drivers/isdn/mISDN/socket.c
@@ -17,6 +17,7 @@
17 17
18#include <linux/mISDNif.h> 18#include <linux/mISDNif.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/export.h>
20#include "core.h" 21#include "core.h"
21 22
22static u_int *debug; 23static u_int *debug;
diff --git a/drivers/leds/dell-led.c b/drivers/leds/dell-led.c
index 52590296af33..e5c57389efd6 100644
--- a/drivers/leds/dell-led.c
+++ b/drivers/leds/dell-led.c
@@ -14,6 +14,7 @@
14#include <linux/acpi.h> 14#include <linux/acpi.h>
15#include <linux/leds.h> 15#include <linux/leds.h>
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <linux/module.h>
17 18
18MODULE_AUTHOR("Louis Davis/Jim Dailey"); 19MODULE_AUTHOR("Louis Davis/Jim Dailey");
19MODULE_DESCRIPTION("Dell LED Control Driver"); 20MODULE_DESCRIPTION("Dell LED Control Driver");
diff --git a/drivers/leds/leds-88pm860x.c b/drivers/leds/leds-88pm860x.c
index 0d4c16678ace..0810604dc701 100644
--- a/drivers/leds/leds-88pm860x.c
+++ b/drivers/leds/leds-88pm860x.c
@@ -18,6 +18,7 @@
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/workqueue.h> 19#include <linux/workqueue.h>
20#include <linux/mfd/88pm860x.h> 20#include <linux/mfd/88pm860x.h>
21#include <linux/module.h>
21 22
22#define LED_PWM_SHIFT (3) 23#define LED_PWM_SHIFT (3)
23#define LED_PWM_MASK (0x1F) 24#define LED_PWM_MASK (0x1F)
diff --git a/drivers/leds/leds-asic3.c b/drivers/leds/leds-asic3.c
index 22f847c890c9..48d9fe61bdfc 100644
--- a/drivers/leds/leds-asic3.c
+++ b/drivers/leds/leds-asic3.c
@@ -14,6 +14,7 @@
14 14
15#include <linux/mfd/asic3.h> 15#include <linux/mfd/asic3.h>
16#include <linux/mfd/core.h> 16#include <linux/mfd/core.h>
17#include <linux/module.h>
17 18
18/* 19/*
19 * The HTC ASIC3 LED GPIOs are inputs, not outputs. 20 * The HTC ASIC3 LED GPIOs are inputs, not outputs.
@@ -107,9 +108,10 @@ static int __devinit asic3_led_probe(struct platform_device *pdev)
107 } 108 }
108 109
109 led->cdev->name = led->name; 110 led->cdev->name = led->name;
110 led->cdev->default_trigger = led->default_trigger; 111 led->cdev->flags = LED_CORE_SUSPENDRESUME;
111 led->cdev->brightness_set = brightness_set; 112 led->cdev->brightness_set = brightness_set;
112 led->cdev->blink_set = blink_set; 113 led->cdev->blink_set = blink_set;
114 led->cdev->default_trigger = led->default_trigger;
113 115
114 ret = led_classdev_register(&pdev->dev, led->cdev); 116 ret = led_classdev_register(&pdev->dev, led->cdev);
115 if (ret < 0) 117 if (ret < 0)
@@ -136,12 +138,44 @@ static int __devexit asic3_led_remove(struct platform_device *pdev)
136 return mfd_cell_disable(pdev); 138 return mfd_cell_disable(pdev);
137} 139}
138 140
141static int asic3_led_suspend(struct device *dev)
142{
143 struct platform_device *pdev = to_platform_device(dev);
144 const struct mfd_cell *cell = mfd_get_cell(pdev);
145 int ret;
146
147 ret = 0;
148 if (cell->suspend)
149 ret = (*cell->suspend)(pdev);
150
151 return ret;
152}
153
154static int asic3_led_resume(struct device *dev)
155{
156 struct platform_device *pdev = to_platform_device(dev);
157 const struct mfd_cell *cell = mfd_get_cell(pdev);
158 int ret;
159
160 ret = 0;
161 if (cell->resume)
162 ret = (*cell->resume)(pdev);
163
164 return ret;
165}
166
167static const struct dev_pm_ops asic3_led_pm_ops = {
168 .suspend = asic3_led_suspend,
169 .resume = asic3_led_resume,
170};
171
139static struct platform_driver asic3_led_driver = { 172static struct platform_driver asic3_led_driver = {
140 .probe = asic3_led_probe, 173 .probe = asic3_led_probe,
141 .remove = __devexit_p(asic3_led_remove), 174 .remove = __devexit_p(asic3_led_remove),
142 .driver = { 175 .driver = {
143 .name = "leds-asic3", 176 .name = "leds-asic3",
144 .owner = THIS_MODULE, 177 .owner = THIS_MODULE,
178 .pm = &asic3_led_pm_ops,
145 }, 179 },
146}; 180};
147 181
diff --git a/drivers/leds/leds-atmel-pwm.c b/drivers/leds/leds-atmel-pwm.c
index c941d906bba6..109c875ea233 100644
--- a/drivers/leds/leds-atmel-pwm.c
+++ b/drivers/leds/leds-atmel-pwm.c
@@ -4,6 +4,7 @@
4#include <linux/io.h> 4#include <linux/io.h>
5#include <linux/atmel_pwm.h> 5#include <linux/atmel_pwm.h>
6#include <linux/slab.h> 6#include <linux/slab.h>
7#include <linux/module.h>
7 8
8 9
9struct pwmled { 10struct pwmled {
diff --git a/drivers/leds/leds-cobalt-raq.c b/drivers/leds/leds-cobalt-raq.c
index 438d48384636..aac1c073fe7b 100644
--- a/drivers/leds/leds-cobalt-raq.c
+++ b/drivers/leds/leds-cobalt-raq.c
@@ -24,6 +24,7 @@
24#include <linux/platform_device.h> 24#include <linux/platform_device.h>
25#include <linux/spinlock.h> 25#include <linux/spinlock.h>
26#include <linux/types.h> 26#include <linux/types.h>
27#include <linux/export.h>
27 28
28#define LED_WEB 0x04 29#define LED_WEB 0x04
29#define LED_POWER_OFF 0x08 30#define LED_POWER_OFF 0x08
diff --git a/drivers/leds/leds-fsg.c b/drivers/leds/leds-fsg.c
index d11d05be0dee..49aceffaa5b6 100644
--- a/drivers/leds/leds-fsg.c
+++ b/drivers/leds/leds-fsg.c
@@ -19,6 +19,7 @@
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/leds.h> 21#include <linux/leds.h>
22#include <linux/module.h>
22#include <mach/hardware.h> 23#include <mach/hardware.h>
23#include <asm/io.h> 24#include <asm/io.h>
24 25
diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
index 504cc26c7e4b..399a86f2013a 100644
--- a/drivers/leds/leds-gpio.c
+++ b/drivers/leds/leds-gpio.c
@@ -18,6 +18,7 @@
18#include <linux/of_gpio.h> 18#include <linux/of_gpio.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/workqueue.h> 20#include <linux/workqueue.h>
21#include <linux/module.h>
21 22
22#include <asm/gpio.h> 23#include <asm/gpio.h>
23 24
diff --git a/drivers/leds/leds-lm3530.c b/drivers/leds/leds-lm3530.c
index 4dc510fdfa06..0630e4f4b286 100644
--- a/drivers/leds/leds-lm3530.c
+++ b/drivers/leds/leds-lm3530.c
@@ -18,6 +18,7 @@
18#include <linux/led-lm3530.h> 18#include <linux/led-lm3530.h>
19#include <linux/types.h> 19#include <linux/types.h>
20#include <linux/regulator/consumer.h> 20#include <linux/regulator/consumer.h>
21#include <linux/module.h>
21 22
22#define LM3530_LED_DEV "lcd-backlight" 23#define LM3530_LED_DEV "lcd-backlight"
23#define LM3530_NAME "lm3530-led" 24#define LM3530_NAME "lm3530-led"
diff --git a/drivers/leds/leds-locomo.c b/drivers/leds/leds-locomo.c
index 1f7c10f6b7f2..80ba048889d6 100644
--- a/drivers/leds/leds-locomo.c
+++ b/drivers/leds/leds-locomo.c
@@ -10,6 +10,7 @@
10 10
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/module.h>
13#include <linux/device.h> 14#include <linux/device.h>
14#include <linux/leds.h> 15#include <linux/leds.h>
15 16
diff --git a/drivers/leds/leds-lt3593.c b/drivers/leds/leds-lt3593.c
index 2579678f97a6..53f67b8ce55d 100644
--- a/drivers/leds/leds-lt3593.c
+++ b/drivers/leds/leds-lt3593.c
@@ -24,6 +24,7 @@
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <linux/gpio.h> 25#include <linux/gpio.h>
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/module.h>
27 28
28struct lt3593_led_data { 29struct lt3593_led_data {
29 struct led_classdev cdev; 30 struct led_classdev cdev;
diff --git a/drivers/leds/leds-mc13783.c b/drivers/leds/leds-mc13783.c
index f369e56d6547..b3393a9f2139 100644
--- a/drivers/leds/leds-mc13783.c
+++ b/drivers/leds/leds-mc13783.c
@@ -21,13 +21,13 @@
21#include <linux/platform_device.h> 21#include <linux/platform_device.h>
22#include <linux/leds.h> 22#include <linux/leds.h>
23#include <linux/workqueue.h> 23#include <linux/workqueue.h>
24#include <linux/mfd/mc13783.h> 24#include <linux/mfd/mc13xxx.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26 26
27struct mc13783_led { 27struct mc13783_led {
28 struct led_classdev cdev; 28 struct led_classdev cdev;
29 struct work_struct work; 29 struct work_struct work;
30 struct mc13783 *master; 30 struct mc13xxx *master;
31 enum led_brightness new_brightness; 31 enum led_brightness new_brightness;
32 int id; 32 int id;
33}; 33};
@@ -111,11 +111,11 @@ static void mc13783_led_work(struct work_struct *work)
111 break; 111 break;
112 } 112 }
113 113
114 mc13783_lock(led->master); 114 mc13xxx_lock(led->master);
115 115
116 mc13783_reg_rmw(led->master, reg, mask, value); 116 mc13xxx_reg_rmw(led->master, reg, mask, value);
117 117
118 mc13783_unlock(led->master); 118 mc13xxx_unlock(led->master);
119} 119}
120 120
121static void mc13783_led_set(struct led_classdev *led_cdev, 121static void mc13783_led_set(struct led_classdev *led_cdev,
@@ -172,23 +172,23 @@ static int __devinit mc13783_led_setup(struct mc13783_led *led, int max_current)
172 break; 172 break;
173 } 173 }
174 174
175 mc13783_lock(led->master); 175 mc13xxx_lock(led->master);
176 176
177 ret = mc13783_reg_rmw(led->master, reg, mask << shift, 177 ret = mc13xxx_reg_rmw(led->master, reg, mask << shift,
178 value << shift); 178 value << shift);
179 179
180 mc13783_unlock(led->master); 180 mc13xxx_unlock(led->master);
181 return ret; 181 return ret;
182} 182}
183 183
184static int __devinit mc13783_leds_prepare(struct platform_device *pdev) 184static int __devinit mc13783_leds_prepare(struct platform_device *pdev)
185{ 185{
186 struct mc13783_leds_platform_data *pdata = dev_get_platdata(&pdev->dev); 186 struct mc13xxx_leds_platform_data *pdata = dev_get_platdata(&pdev->dev);
187 struct mc13783 *dev = dev_get_drvdata(pdev->dev.parent); 187 struct mc13xxx *dev = dev_get_drvdata(pdev->dev.parent);
188 int ret = 0; 188 int ret = 0;
189 int reg = 0; 189 int reg = 0;
190 190
191 mc13783_lock(dev); 191 mc13xxx_lock(dev);
192 192
193 if (pdata->flags & MC13783_LED_TC1HALF) 193 if (pdata->flags & MC13783_LED_TC1HALF)
194 reg |= MC13783_LED_C1_TC1HALF_BIT; 194 reg |= MC13783_LED_C1_TC1HALF_BIT;
@@ -196,7 +196,7 @@ static int __devinit mc13783_leds_prepare(struct platform_device *pdev)
196 if (pdata->flags & MC13783_LED_SLEWLIMTC) 196 if (pdata->flags & MC13783_LED_SLEWLIMTC)
197 reg |= MC13783_LED_Cx_SLEWLIM_BIT; 197 reg |= MC13783_LED_Cx_SLEWLIM_BIT;
198 198
199 ret = mc13783_reg_write(dev, MC13783_REG_LED_CONTROL_1, reg); 199 ret = mc13xxx_reg_write(dev, MC13783_REG_LED_CONTROL_1, reg);
200 if (ret) 200 if (ret)
201 goto out; 201 goto out;
202 202
@@ -206,7 +206,7 @@ static int __devinit mc13783_leds_prepare(struct platform_device *pdev)
206 if (pdata->flags & MC13783_LED_SLEWLIMBL) 206 if (pdata->flags & MC13783_LED_SLEWLIMBL)
207 reg |= MC13783_LED_Cx_SLEWLIM_BIT; 207 reg |= MC13783_LED_Cx_SLEWLIM_BIT;
208 208
209 ret = mc13783_reg_write(dev, MC13783_REG_LED_CONTROL_2, reg); 209 ret = mc13xxx_reg_write(dev, MC13783_REG_LED_CONTROL_2, reg);
210 if (ret) 210 if (ret)
211 goto out; 211 goto out;
212 212
@@ -216,7 +216,7 @@ static int __devinit mc13783_leds_prepare(struct platform_device *pdev)
216 if (pdata->flags & MC13783_LED_TRIODE_TC1) 216 if (pdata->flags & MC13783_LED_TRIODE_TC1)
217 reg |= MC13783_LED_Cx_TRIODE_TC_BIT; 217 reg |= MC13783_LED_Cx_TRIODE_TC_BIT;
218 218
219 ret = mc13783_reg_write(dev, MC13783_REG_LED_CONTROL_3, reg); 219 ret = mc13xxx_reg_write(dev, MC13783_REG_LED_CONTROL_3, reg);
220 if (ret) 220 if (ret)
221 goto out; 221 goto out;
222 222
@@ -226,7 +226,7 @@ static int __devinit mc13783_leds_prepare(struct platform_device *pdev)
226 if (pdata->flags & MC13783_LED_TRIODE_TC2) 226 if (pdata->flags & MC13783_LED_TRIODE_TC2)
227 reg |= MC13783_LED_Cx_TRIODE_TC_BIT; 227 reg |= MC13783_LED_Cx_TRIODE_TC_BIT;
228 228
229 ret = mc13783_reg_write(dev, MC13783_REG_LED_CONTROL_4, reg); 229 ret = mc13xxx_reg_write(dev, MC13783_REG_LED_CONTROL_4, reg);
230 if (ret) 230 if (ret)
231 goto out; 231 goto out;
232 232
@@ -236,7 +236,7 @@ static int __devinit mc13783_leds_prepare(struct platform_device *pdev)
236 if (pdata->flags & MC13783_LED_TRIODE_TC3) 236 if (pdata->flags & MC13783_LED_TRIODE_TC3)
237 reg |= MC13783_LED_Cx_TRIODE_TC_BIT; 237 reg |= MC13783_LED_Cx_TRIODE_TC_BIT;
238 238
239 ret = mc13783_reg_write(dev, MC13783_REG_LED_CONTROL_5, reg); 239 ret = mc13xxx_reg_write(dev, MC13783_REG_LED_CONTROL_5, reg);
240 if (ret) 240 if (ret)
241 goto out; 241 goto out;
242 242
@@ -255,17 +255,17 @@ static int __devinit mc13783_leds_prepare(struct platform_device *pdev)
255 reg |= (pdata->abref & MC13783_LED_C0_ABREF_MASK) << 255 reg |= (pdata->abref & MC13783_LED_C0_ABREF_MASK) <<
256 MC13783_LED_C0_ABREF; 256 MC13783_LED_C0_ABREF;
257 257
258 ret = mc13783_reg_write(dev, MC13783_REG_LED_CONTROL_0, reg); 258 ret = mc13xxx_reg_write(dev, MC13783_REG_LED_CONTROL_0, reg);
259 259
260out: 260out:
261 mc13783_unlock(dev); 261 mc13xxx_unlock(dev);
262 return ret; 262 return ret;
263} 263}
264 264
265static int __devinit mc13783_led_probe(struct platform_device *pdev) 265static int __devinit mc13783_led_probe(struct platform_device *pdev)
266{ 266{
267 struct mc13783_leds_platform_data *pdata = dev_get_platdata(&pdev->dev); 267 struct mc13xxx_leds_platform_data *pdata = dev_get_platdata(&pdev->dev);
268 struct mc13783_led_platform_data *led_cur; 268 struct mc13xxx_led_platform_data *led_cur;
269 struct mc13783_led *led, *led_dat; 269 struct mc13783_led *led, *led_dat;
270 int ret, i; 270 int ret, i;
271 int init_led = 0; 271 int init_led = 0;
@@ -351,9 +351,9 @@ err_free:
351 351
352static int __devexit mc13783_led_remove(struct platform_device *pdev) 352static int __devexit mc13783_led_remove(struct platform_device *pdev)
353{ 353{
354 struct mc13783_leds_platform_data *pdata = dev_get_platdata(&pdev->dev); 354 struct mc13xxx_leds_platform_data *pdata = dev_get_platdata(&pdev->dev);
355 struct mc13783_led *led = platform_get_drvdata(pdev); 355 struct mc13783_led *led = platform_get_drvdata(pdev);
356 struct mc13783 *dev = dev_get_drvdata(pdev->dev.parent); 356 struct mc13xxx *dev = dev_get_drvdata(pdev->dev.parent);
357 int i; 357 int i;
358 358
359 for (i = 0; i < pdata->num_leds; i++) { 359 for (i = 0; i < pdata->num_leds; i++) {
@@ -361,16 +361,16 @@ static int __devexit mc13783_led_remove(struct platform_device *pdev)
361 cancel_work_sync(&led[i].work); 361 cancel_work_sync(&led[i].work);
362 } 362 }
363 363
364 mc13783_lock(dev); 364 mc13xxx_lock(dev);
365 365
366 mc13783_reg_write(dev, MC13783_REG_LED_CONTROL_0, 0); 366 mc13xxx_reg_write(dev, MC13783_REG_LED_CONTROL_0, 0);
367 mc13783_reg_write(dev, MC13783_REG_LED_CONTROL_1, 0); 367 mc13xxx_reg_write(dev, MC13783_REG_LED_CONTROL_1, 0);
368 mc13783_reg_write(dev, MC13783_REG_LED_CONTROL_2, 0); 368 mc13xxx_reg_write(dev, MC13783_REG_LED_CONTROL_2, 0);
369 mc13783_reg_write(dev, MC13783_REG_LED_CONTROL_3, 0); 369 mc13xxx_reg_write(dev, MC13783_REG_LED_CONTROL_3, 0);
370 mc13783_reg_write(dev, MC13783_REG_LED_CONTROL_4, 0); 370 mc13xxx_reg_write(dev, MC13783_REG_LED_CONTROL_4, 0);
371 mc13783_reg_write(dev, MC13783_REG_LED_CONTROL_5, 0); 371 mc13xxx_reg_write(dev, MC13783_REG_LED_CONTROL_5, 0);
372 372
373 mc13783_unlock(dev); 373 mc13xxx_unlock(dev);
374 374
375 kfree(led); 375 kfree(led);
376 return 0; 376 return 0;
diff --git a/drivers/leds/leds-net48xx.c b/drivers/leds/leds-net48xx.c
index 93987a12da49..f117f7326c5b 100644
--- a/drivers/leds/leds-net48xx.c
+++ b/drivers/leds/leds-net48xx.c
@@ -18,6 +18,7 @@
18#include <asm/io.h> 18#include <asm/io.h>
19#include <linux/nsc_gpio.h> 19#include <linux/nsc_gpio.h>
20#include <linux/scx200_gpio.h> 20#include <linux/scx200_gpio.h>
21#include <linux/module.h>
21 22
22#define DRVNAME "net48xx-led" 23#define DRVNAME "net48xx-led"
23#define NET48XX_ERROR_LED_GPIO 20 24#define NET48XX_ERROR_LED_GPIO 20
diff --git a/drivers/leds/leds-net5501.c b/drivers/leds/leds-net5501.c
index 7e764b8365e6..0555d4709a7c 100644
--- a/drivers/leds/leds-net5501.c
+++ b/drivers/leds/leds-net5501.c
@@ -16,6 +16,7 @@
16#include <linux/leds.h> 16#include <linux/leds.h>
17#include <linux/platform_device.h> 17#include <linux/platform_device.h>
18#include <linux/gpio.h> 18#include <linux/gpio.h>
19#include <linux/module.h>
19 20
20#include <asm/geode.h> 21#include <asm/geode.h>
21 22
diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c
index f77d48d0b3e4..37b7d0cfe586 100644
--- a/drivers/leds/leds-ns2.c
+++ b/drivers/leds/leds-ns2.c
@@ -28,6 +28,7 @@
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/gpio.h> 29#include <linux/gpio.h>
30#include <linux/leds.h> 30#include <linux/leds.h>
31#include <linux/module.h>
31#include <mach/leds-ns2.h> 32#include <mach/leds-ns2.h>
32 33
33/* 34/*
diff --git a/drivers/leds/leds-s3c24xx.c b/drivers/leds/leds-s3c24xx.c
index a77771dc2e95..29f8b0f0e2c6 100644
--- a/drivers/leds/leds-s3c24xx.c
+++ b/drivers/leds/leds-s3c24xx.c
@@ -17,6 +17,7 @@
17#include <linux/leds.h> 17#include <linux/leds.h>
18#include <linux/gpio.h> 18#include <linux/gpio.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/module.h>
20 21
21#include <mach/hardware.h> 22#include <mach/hardware.h>
22#include <mach/regs-gpio.h> 23#include <mach/regs-gpio.h>
diff --git a/drivers/leds/leds-wm831x-status.c b/drivers/leds/leds-wm831x-status.c
index ef5c24140a44..b1eb34c3e81f 100644
--- a/drivers/leds/leds-wm831x-status.c
+++ b/drivers/leds/leds-wm831x-status.c
@@ -18,6 +18,7 @@
18#include <linux/mfd/wm831x/core.h> 18#include <linux/mfd/wm831x/core.h>
19#include <linux/mfd/wm831x/pdata.h> 19#include <linux/mfd/wm831x/pdata.h>
20#include <linux/mfd/wm831x/status.h> 20#include <linux/mfd/wm831x/status.h>
21#include <linux/module.h>
21 22
22 23
23struct wm831x_status { 24struct wm831x_status {
diff --git a/drivers/leds/leds-wm8350.c b/drivers/leds/leds-wm8350.c
index f14edd82cb00..4a1276578352 100644
--- a/drivers/leds/leds-wm8350.c
+++ b/drivers/leds/leds-wm8350.c
@@ -17,6 +17,7 @@
17#include <linux/mfd/wm8350/pmic.h> 17#include <linux/mfd/wm8350/pmic.h>
18#include <linux/regulator/consumer.h> 18#include <linux/regulator/consumer.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/module.h>
20 21
21/* Microamps */ 22/* Microamps */
22static const int isink_cur[] = { 23static const int isink_cur[] = {
diff --git a/drivers/leds/leds-wrap.c b/drivers/leds/leds-wrap.c
index 2982c86ac4cf..6e21e654bb02 100644
--- a/drivers/leds/leds-wrap.c
+++ b/drivers/leds/leds-wrap.c
@@ -17,6 +17,7 @@
17#include <linux/err.h> 17#include <linux/err.h>
18#include <asm/io.h> 18#include <asm/io.h>
19#include <linux/scx200_gpio.h> 19#include <linux/scx200_gpio.h>
20#include <linux/module.h>
20 21
21#define DRVNAME "wrap-led" 22#define DRVNAME "wrap-led"
22#define WRAP_POWER_LED_GPIO 2 23#define WRAP_POWER_LED_GPIO 2
diff --git a/drivers/lguest/lguest_device.c b/drivers/lguest/lguest_device.c
index 5289ffa2e500..0dc30ffde5ad 100644
--- a/drivers/lguest/lguest_device.c
+++ b/drivers/lguest/lguest_device.c
@@ -15,6 +15,7 @@
15#include <linux/interrupt.h> 15#include <linux/interrupt.h>
16#include <linux/virtio_ring.h> 16#include <linux/virtio_ring.h>
17#include <linux/err.h> 17#include <linux/err.h>
18#include <linux/export.h>
18#include <linux/slab.h> 19#include <linux/slab.h>
19#include <asm/io.h> 20#include <asm/io.h>
20#include <asm/paravirt.h> 21#include <asm/paravirt.h>
diff --git a/drivers/lguest/lguest_user.c b/drivers/lguest/lguest_user.c
index f97e625241ad..ff4a0bc9904d 100644
--- a/drivers/lguest/lguest_user.c
+++ b/drivers/lguest/lguest_user.c
@@ -13,6 +13,7 @@
13#include <linux/eventfd.h> 13#include <linux/eventfd.h>
14#include <linux/file.h> 14#include <linux/file.h>
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/export.h>
16#include "lg.h" 17#include "lg.h"
17 18
18/*L:056 19/*L:056
diff --git a/drivers/md/Kconfig b/drivers/md/Kconfig
index f75a66e7d312..faa4741df6d3 100644
--- a/drivers/md/Kconfig
+++ b/drivers/md/Kconfig
@@ -208,6 +208,16 @@ config DM_DEBUG
208 208
209 If unsure, say N. 209 If unsure, say N.
210 210
211config DM_BUFIO
212 tristate
213 depends on BLK_DEV_DM && EXPERIMENTAL
214 ---help---
215 This interface allows you to do buffered I/O on a device and acts
216 as a cache, holding recently-read blocks in memory and performing
217 delayed writes.
218
219source "drivers/md/persistent-data/Kconfig"
220
211config DM_CRYPT 221config DM_CRYPT
212 tristate "Crypt target support" 222 tristate "Crypt target support"
213 depends on BLK_DEV_DM 223 depends on BLK_DEV_DM
@@ -233,6 +243,32 @@ config DM_SNAPSHOT
233 ---help--- 243 ---help---
234 Allow volume managers to take writable snapshots of a device. 244 Allow volume managers to take writable snapshots of a device.
235 245
246config DM_THIN_PROVISIONING
247 tristate "Thin provisioning target (EXPERIMENTAL)"
248 depends on BLK_DEV_DM && EXPERIMENTAL
249 select DM_PERSISTENT_DATA
250 ---help---
251 Provides thin provisioning and snapshots that share a data store.
252
253config DM_DEBUG_BLOCK_STACK_TRACING
254 boolean "Keep stack trace of thin provisioning block lock holders"
255 depends on STACKTRACE_SUPPORT && DM_THIN_PROVISIONING
256 select STACKTRACE
257 ---help---
258 Enable this for messages that may help debug problems with the
259 block manager locking used by thin provisioning.
260
261 If unsure, say N.
262
263config DM_DEBUG_SPACE_MAPS
264 boolean "Extra validation for thin provisioning space maps"
265 depends on DM_THIN_PROVISIONING
266 ---help---
267 Enable this for messages that may help debug problems with the
268 space maps used by thin provisioning.
269
270 If unsure, say N.
271
236config DM_MIRROR 272config DM_MIRROR
237 tristate "Mirror target" 273 tristate "Mirror target"
238 depends on BLK_DEV_DM 274 depends on BLK_DEV_DM
diff --git a/drivers/md/Makefile b/drivers/md/Makefile
index 448838b1f92a..046860c7a166 100644
--- a/drivers/md/Makefile
+++ b/drivers/md/Makefile
@@ -10,6 +10,7 @@ dm-snapshot-y += dm-snap.o dm-exception-store.o dm-snap-transient.o \
10dm-mirror-y += dm-raid1.o 10dm-mirror-y += dm-raid1.o
11dm-log-userspace-y \ 11dm-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
13dm-thin-pool-y += dm-thin.o dm-thin-metadata.o
13md-mod-y += md.o bitmap.o 14md-mod-y += md.o bitmap.o
14raid456-y += raid5.o 15raid456-y += raid5.o
15 16
@@ -27,6 +28,7 @@ obj-$(CONFIG_MD_MULTIPATH) += multipath.o
27obj-$(CONFIG_MD_FAULTY) += faulty.o 28obj-$(CONFIG_MD_FAULTY) += faulty.o
28obj-$(CONFIG_BLK_DEV_MD) += md-mod.o 29obj-$(CONFIG_BLK_DEV_MD) += md-mod.o
29obj-$(CONFIG_BLK_DEV_DM) += dm-mod.o 30obj-$(CONFIG_BLK_DEV_DM) += dm-mod.o
31obj-$(CONFIG_DM_BUFIO) += dm-bufio.o
30obj-$(CONFIG_DM_CRYPT) += dm-crypt.o 32obj-$(CONFIG_DM_CRYPT) += dm-crypt.o
31obj-$(CONFIG_DM_DELAY) += dm-delay.o 33obj-$(CONFIG_DM_DELAY) += dm-delay.o
32obj-$(CONFIG_DM_FLAKEY) += dm-flakey.o 34obj-$(CONFIG_DM_FLAKEY) += dm-flakey.o
@@ -34,10 +36,12 @@ obj-$(CONFIG_DM_MULTIPATH) += dm-multipath.o dm-round-robin.o
34obj-$(CONFIG_DM_MULTIPATH_QL) += dm-queue-length.o 36obj-$(CONFIG_DM_MULTIPATH_QL) += dm-queue-length.o
35obj-$(CONFIG_DM_MULTIPATH_ST) += dm-service-time.o 37obj-$(CONFIG_DM_MULTIPATH_ST) += dm-service-time.o
36obj-$(CONFIG_DM_SNAPSHOT) += dm-snapshot.o 38obj-$(CONFIG_DM_SNAPSHOT) += dm-snapshot.o
39obj-$(CONFIG_DM_PERSISTENT_DATA) += persistent-data/
37obj-$(CONFIG_DM_MIRROR) += dm-mirror.o dm-log.o dm-region-hash.o 40obj-$(CONFIG_DM_MIRROR) += dm-mirror.o dm-log.o dm-region-hash.o
38obj-$(CONFIG_DM_LOG_USERSPACE) += dm-log-userspace.o 41obj-$(CONFIG_DM_LOG_USERSPACE) += dm-log-userspace.o
39obj-$(CONFIG_DM_ZERO) += dm-zero.o 42obj-$(CONFIG_DM_ZERO) += dm-zero.o
40obj-$(CONFIG_DM_RAID) += dm-raid.o 43obj-$(CONFIG_DM_RAID) += dm-raid.o
44obj-$(CONFIG_DM_THIN_PROVISIONING) += dm-thin-pool.o
41 45
42ifeq ($(CONFIG_DM_UEVENT),y) 46ifeq ($(CONFIG_DM_UEVENT),y)
43dm-mod-objs += dm-uevent.o 47dm-mod-objs += dm-uevent.o
diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
new file mode 100644
index 000000000000..cb246667dd52
--- /dev/null
+++ b/drivers/md/dm-bufio.c
@@ -0,0 +1,1699 @@
1/*
2 * Copyright (C) 2009-2011 Red Hat, Inc.
3 *
4 * Author: Mikulas Patocka <mpatocka@redhat.com>
5 *
6 * This file is released under the GPL.
7 */
8
9#include "dm-bufio.h"
10
11#include <linux/device-mapper.h>
12#include <linux/dm-io.h>
13#include <linux/slab.h>
14#include <linux/vmalloc.h>
15#include <linux/version.h>
16#include <linux/shrinker.h>
17
18#define DM_MSG_PREFIX "bufio"
19
20/*
21 * Memory management policy:
22 * Limit the number of buffers to DM_BUFIO_MEMORY_PERCENT of main memory
23 * or DM_BUFIO_VMALLOC_PERCENT of vmalloc memory (whichever is lower).
24 * Always allocate at least DM_BUFIO_MIN_BUFFERS buffers.
25 * Start background writeback when there are DM_BUFIO_WRITEBACK_PERCENT
26 * dirty buffers.
27 */
28#define DM_BUFIO_MIN_BUFFERS 8
29
30#define DM_BUFIO_MEMORY_PERCENT 2
31#define DM_BUFIO_VMALLOC_PERCENT 25
32#define DM_BUFIO_WRITEBACK_PERCENT 75
33
34/*
35 * Check buffer ages in this interval (seconds)
36 */
37#define DM_BUFIO_WORK_TIMER_SECS 10
38
39/*
40 * Free buffers when they are older than this (seconds)
41 */
42#define DM_BUFIO_DEFAULT_AGE_SECS 60
43
44/*
45 * The number of bvec entries that are embedded directly in the buffer.
46 * If the chunk size is larger, dm-io is used to do the io.
47 */
48#define DM_BUFIO_INLINE_VECS 16
49
50/*
51 * Buffer hash
52 */
53#define DM_BUFIO_HASH_BITS 20
54#define DM_BUFIO_HASH(block) \
55 ((((block) >> DM_BUFIO_HASH_BITS) ^ (block)) & \
56 ((1 << DM_BUFIO_HASH_BITS) - 1))
57
58/*
59 * Don't try to use kmem_cache_alloc for blocks larger than this.
60 * For explanation, see alloc_buffer_data below.
61 */
62#define DM_BUFIO_BLOCK_SIZE_SLAB_LIMIT (PAGE_SIZE >> 1)
63#define DM_BUFIO_BLOCK_SIZE_GFP_LIMIT (PAGE_SIZE << (MAX_ORDER - 1))
64
65/*
66 * dm_buffer->list_mode
67 */
68#define LIST_CLEAN 0
69#define LIST_DIRTY 1
70#define LIST_SIZE 2
71
72/*
73 * Linking of buffers:
74 * All buffers are linked to cache_hash with their hash_list field.
75 *
76 * Clean buffers that are not being written (B_WRITING not set)
77 * are linked to lru[LIST_CLEAN] with their lru_list field.
78 *
79 * Dirty and clean buffers that are being written are linked to
80 * lru[LIST_DIRTY] with their lru_list field. When the write
81 * finishes, the buffer cannot be relinked immediately (because we
82 * are in an interrupt context and relinking requires process
83 * context), so some clean-not-writing buffers can be held on
84 * dirty_lru too. They are later added to lru in the process
85 * context.
86 */
87struct dm_bufio_client {
88 struct mutex lock;
89
90 struct list_head lru[LIST_SIZE];
91 unsigned long n_buffers[LIST_SIZE];
92
93 struct block_device *bdev;
94 unsigned block_size;
95 unsigned char sectors_per_block_bits;
96 unsigned char pages_per_block_bits;
97 unsigned char blocks_per_page_bits;
98 unsigned aux_size;
99 void (*alloc_callback)(struct dm_buffer *);
100 void (*write_callback)(struct dm_buffer *);
101
102 struct dm_io_client *dm_io;
103
104 struct list_head reserved_buffers;
105 unsigned need_reserved_buffers;
106
107 struct hlist_head *cache_hash;
108 wait_queue_head_t free_buffer_wait;
109
110 int async_write_error;
111
112 struct list_head client_list;
113 struct shrinker shrinker;
114};
115
116/*
117 * Buffer state bits.
118 */
119#define B_READING 0
120#define B_WRITING 1
121#define B_DIRTY 2
122
123/*
124 * Describes how the block was allocated:
125 * kmem_cache_alloc(), __get_free_pages() or vmalloc().
126 * See the comment at alloc_buffer_data.
127 */
128enum data_mode {
129 DATA_MODE_SLAB = 0,
130 DATA_MODE_GET_FREE_PAGES = 1,
131 DATA_MODE_VMALLOC = 2,
132 DATA_MODE_LIMIT = 3
133};
134
135struct dm_buffer {
136 struct hlist_node hash_list;
137 struct list_head lru_list;
138 sector_t block;
139 void *data;
140 enum data_mode data_mode;
141 unsigned char list_mode; /* LIST_* */
142 unsigned hold_count;
143 int read_error;
144 int write_error;
145 unsigned long state;
146 unsigned long last_accessed;
147 struct dm_bufio_client *c;
148 struct bio bio;
149 struct bio_vec bio_vec[DM_BUFIO_INLINE_VECS];
150};
151
152/*----------------------------------------------------------------*/
153
154static struct kmem_cache *dm_bufio_caches[PAGE_SHIFT - SECTOR_SHIFT];
155static char *dm_bufio_cache_names[PAGE_SHIFT - SECTOR_SHIFT];
156
157static inline int dm_bufio_cache_index(struct dm_bufio_client *c)
158{
159 unsigned ret = c->blocks_per_page_bits - 1;
160
161 BUG_ON(ret >= ARRAY_SIZE(dm_bufio_caches));
162
163 return ret;
164}
165
166#define DM_BUFIO_CACHE(c) (dm_bufio_caches[dm_bufio_cache_index(c)])
167#define DM_BUFIO_CACHE_NAME(c) (dm_bufio_cache_names[dm_bufio_cache_index(c)])
168
169#define dm_bufio_in_request() (!!current->bio_list)
170
171static void dm_bufio_lock(struct dm_bufio_client *c)
172{
173 mutex_lock_nested(&c->lock, dm_bufio_in_request());
174}
175
176static int dm_bufio_trylock(struct dm_bufio_client *c)
177{
178 return mutex_trylock(&c->lock);
179}
180
181static void dm_bufio_unlock(struct dm_bufio_client *c)
182{
183 mutex_unlock(&c->lock);
184}
185
186/*
187 * FIXME Move to sched.h?
188 */
189#ifdef CONFIG_PREEMPT_VOLUNTARY
190# define dm_bufio_cond_resched() \
191do { \
192 if (unlikely(need_resched())) \
193 _cond_resched(); \
194} while (0)
195#else
196# define dm_bufio_cond_resched() do { } while (0)
197#endif
198
199/*----------------------------------------------------------------*/
200
201/*
202 * Default cache size: available memory divided by the ratio.
203 */
204static unsigned long dm_bufio_default_cache_size;
205
206/*
207 * Total cache size set by the user.
208 */
209static unsigned long dm_bufio_cache_size;
210
211/*
212 * A copy of dm_bufio_cache_size because dm_bufio_cache_size can change
213 * at any time. If it disagrees, the user has changed cache size.
214 */
215static unsigned long dm_bufio_cache_size_latch;
216
217static DEFINE_SPINLOCK(param_spinlock);
218
219/*
220 * Buffers are freed after this timeout
221 */
222static unsigned dm_bufio_max_age = DM_BUFIO_DEFAULT_AGE_SECS;
223
224static unsigned long dm_bufio_peak_allocated;
225static unsigned long dm_bufio_allocated_kmem_cache;
226static unsigned long dm_bufio_allocated_get_free_pages;
227static unsigned long dm_bufio_allocated_vmalloc;
228static unsigned long dm_bufio_current_allocated;
229
230/*----------------------------------------------------------------*/
231
232/*
233 * Per-client cache: dm_bufio_cache_size / dm_bufio_client_count
234 */
235static unsigned long dm_bufio_cache_size_per_client;
236
237/*
238 * The current number of clients.
239 */
240static int dm_bufio_client_count;
241
242/*
243 * The list of all clients.
244 */
245static LIST_HEAD(dm_bufio_all_clients);
246
247/*
248 * This mutex protects dm_bufio_cache_size_latch,
249 * dm_bufio_cache_size_per_client and dm_bufio_client_count
250 */
251static DEFINE_MUTEX(dm_bufio_clients_lock);
252
253/*----------------------------------------------------------------*/
254
255static void adjust_total_allocated(enum data_mode data_mode, long diff)
256{
257 static unsigned long * const class_ptr[DATA_MODE_LIMIT] = {
258 &dm_bufio_allocated_kmem_cache,
259 &dm_bufio_allocated_get_free_pages,
260 &dm_bufio_allocated_vmalloc,
261 };
262
263 spin_lock(&param_spinlock);
264
265 *class_ptr[data_mode] += diff;
266
267 dm_bufio_current_allocated += diff;
268
269 if (dm_bufio_current_allocated > dm_bufio_peak_allocated)
270 dm_bufio_peak_allocated = dm_bufio_current_allocated;
271
272 spin_unlock(&param_spinlock);
273}
274
275/*
276 * Change the number of clients and recalculate per-client limit.
277 */
278static void __cache_size_refresh(void)
279{
280 BUG_ON(!mutex_is_locked(&dm_bufio_clients_lock));
281 BUG_ON(dm_bufio_client_count < 0);
282
283 dm_bufio_cache_size_latch = dm_bufio_cache_size;
284
285 barrier();
286
287 /*
288 * Use default if set to 0 and report the actual cache size used.
289 */
290 if (!dm_bufio_cache_size_latch) {
291 (void)cmpxchg(&dm_bufio_cache_size, 0,
292 dm_bufio_default_cache_size);
293 dm_bufio_cache_size_latch = dm_bufio_default_cache_size;
294 }
295
296 dm_bufio_cache_size_per_client = dm_bufio_cache_size_latch /
297 (dm_bufio_client_count ? : 1);
298}
299
300/*
301 * Allocating buffer data.
302 *
303 * Small buffers are allocated with kmem_cache, to use space optimally.
304 *
305 * For large buffers, we choose between get_free_pages and vmalloc.
306 * Each has advantages and disadvantages.
307 *
308 * __get_free_pages can randomly fail if the memory is fragmented.
309 * __vmalloc won't randomly fail, but vmalloc space is limited (it may be
310 * as low as 128M) so using it for caching is not appropriate.
311 *
312 * If the allocation may fail we use __get_free_pages. Memory fragmentation
313 * won't have a fatal effect here, but it just causes flushes of some other
314 * buffers and more I/O will be performed. Don't use __get_free_pages if it
315 * always fails (i.e. order >= MAX_ORDER).
316 *
317 * If the allocation shouldn't fail we use __vmalloc. This is only for the
318 * initial reserve allocation, so there's no risk of wasting all vmalloc
319 * space.
320 */
321static void *alloc_buffer_data(struct dm_bufio_client *c, gfp_t gfp_mask,
322 enum data_mode *data_mode)
323{
324 if (c->block_size <= DM_BUFIO_BLOCK_SIZE_SLAB_LIMIT) {
325 *data_mode = DATA_MODE_SLAB;
326 return kmem_cache_alloc(DM_BUFIO_CACHE(c), gfp_mask);
327 }
328
329 if (c->block_size <= DM_BUFIO_BLOCK_SIZE_GFP_LIMIT &&
330 gfp_mask & __GFP_NORETRY) {
331 *data_mode = DATA_MODE_GET_FREE_PAGES;
332 return (void *)__get_free_pages(gfp_mask,
333 c->pages_per_block_bits);
334 }
335
336 *data_mode = DATA_MODE_VMALLOC;
337 return __vmalloc(c->block_size, gfp_mask, PAGE_KERNEL);
338}
339
340/*
341 * Free buffer's data.
342 */
343static void free_buffer_data(struct dm_bufio_client *c,
344 void *data, enum data_mode data_mode)
345{
346 switch (data_mode) {
347 case DATA_MODE_SLAB:
348 kmem_cache_free(DM_BUFIO_CACHE(c), data);
349 break;
350
351 case DATA_MODE_GET_FREE_PAGES:
352 free_pages((unsigned long)data, c->pages_per_block_bits);
353 break;
354
355 case DATA_MODE_VMALLOC:
356 vfree(data);
357 break;
358
359 default:
360 DMCRIT("dm_bufio_free_buffer_data: bad data mode: %d",
361 data_mode);
362 BUG();
363 }
364}
365
366/*
367 * Allocate buffer and its data.
368 */
369static struct dm_buffer *alloc_buffer(struct dm_bufio_client *c, gfp_t gfp_mask)
370{
371 struct dm_buffer *b = kmalloc(sizeof(struct dm_buffer) + c->aux_size,
372 gfp_mask);
373
374 if (!b)
375 return NULL;
376
377 b->c = c;
378
379 b->data = alloc_buffer_data(c, gfp_mask, &b->data_mode);
380 if (!b->data) {
381 kfree(b);
382 return NULL;
383 }
384
385 adjust_total_allocated(b->data_mode, (long)c->block_size);
386
387 return b;
388}
389
390/*
391 * Free buffer and its data.
392 */
393static void free_buffer(struct dm_buffer *b)
394{
395 struct dm_bufio_client *c = b->c;
396
397 adjust_total_allocated(b->data_mode, -(long)c->block_size);
398
399 free_buffer_data(c, b->data, b->data_mode);
400 kfree(b);
401}
402
403/*
404 * Link buffer to the hash list and clean or dirty queue.
405 */
406static void __link_buffer(struct dm_buffer *b, sector_t block, int dirty)
407{
408 struct dm_bufio_client *c = b->c;
409
410 c->n_buffers[dirty]++;
411 b->block = block;
412 b->list_mode = dirty;
413 list_add(&b->lru_list, &c->lru[dirty]);
414 hlist_add_head(&b->hash_list, &c->cache_hash[DM_BUFIO_HASH(block)]);
415 b->last_accessed = jiffies;
416}
417
418/*
419 * Unlink buffer from the hash list and dirty or clean queue.
420 */
421static void __unlink_buffer(struct dm_buffer *b)
422{
423 struct dm_bufio_client *c = b->c;
424
425 BUG_ON(!c->n_buffers[b->list_mode]);
426
427 c->n_buffers[b->list_mode]--;
428 hlist_del(&b->hash_list);
429 list_del(&b->lru_list);
430}
431
432/*
433 * Place the buffer to the head of dirty or clean LRU queue.
434 */
435static void __relink_lru(struct dm_buffer *b, int dirty)
436{
437 struct dm_bufio_client *c = b->c;
438
439 BUG_ON(!c->n_buffers[b->list_mode]);
440
441 c->n_buffers[b->list_mode]--;
442 c->n_buffers[dirty]++;
443 b->list_mode = dirty;
444 list_del(&b->lru_list);
445 list_add(&b->lru_list, &c->lru[dirty]);
446}
447
448/*----------------------------------------------------------------
449 * Submit I/O on the buffer.
450 *
451 * Bio interface is faster but it has some problems:
452 * the vector list is limited (increasing this limit increases
453 * memory-consumption per buffer, so it is not viable);
454 *
455 * the memory must be direct-mapped, not vmalloced;
456 *
457 * the I/O driver can reject requests spuriously if it thinks that
458 * the requests are too big for the device or if they cross a
459 * controller-defined memory boundary.
460 *
461 * If the buffer is small enough (up to DM_BUFIO_INLINE_VECS pages) and
462 * it is not vmalloced, try using the bio interface.
463 *
464 * If the buffer is big, if it is vmalloced or if the underlying device
465 * rejects the bio because it is too large, use dm-io layer to do the I/O.
466 * The dm-io layer splits the I/O into multiple requests, avoiding the above
467 * shortcomings.
468 *--------------------------------------------------------------*/
469
470/*
471 * dm-io completion routine. It just calls b->bio.bi_end_io, pretending
472 * that the request was handled directly with bio interface.
473 */
474static void dmio_complete(unsigned long error, void *context)
475{
476 struct dm_buffer *b = context;
477
478 b->bio.bi_end_io(&b->bio, error ? -EIO : 0);
479}
480
481static void use_dmio(struct dm_buffer *b, int rw, sector_t block,
482 bio_end_io_t *end_io)
483{
484 int r;
485 struct dm_io_request io_req = {
486 .bi_rw = rw,
487 .notify.fn = dmio_complete,
488 .notify.context = b,
489 .client = b->c->dm_io,
490 };
491 struct dm_io_region region = {
492 .bdev = b->c->bdev,
493 .sector = block << b->c->sectors_per_block_bits,
494 .count = b->c->block_size >> SECTOR_SHIFT,
495 };
496
497 if (b->data_mode != DATA_MODE_VMALLOC) {
498 io_req.mem.type = DM_IO_KMEM;
499 io_req.mem.ptr.addr = b->data;
500 } else {
501 io_req.mem.type = DM_IO_VMA;
502 io_req.mem.ptr.vma = b->data;
503 }
504
505 b->bio.bi_end_io = end_io;
506
507 r = dm_io(&io_req, 1, &region, NULL);
508 if (r)
509 end_io(&b->bio, r);
510}
511
512static void use_inline_bio(struct dm_buffer *b, int rw, sector_t block,
513 bio_end_io_t *end_io)
514{
515 char *ptr;
516 int len;
517
518 bio_init(&b->bio);
519 b->bio.bi_io_vec = b->bio_vec;
520 b->bio.bi_max_vecs = DM_BUFIO_INLINE_VECS;
521 b->bio.bi_sector = block << b->c->sectors_per_block_bits;
522 b->bio.bi_bdev = b->c->bdev;
523 b->bio.bi_end_io = end_io;
524
525 /*
526 * We assume that if len >= PAGE_SIZE ptr is page-aligned.
527 * If len < PAGE_SIZE the buffer doesn't cross page boundary.
528 */
529 ptr = b->data;
530 len = b->c->block_size;
531
532 if (len >= PAGE_SIZE)
533 BUG_ON((unsigned long)ptr & (PAGE_SIZE - 1));
534 else
535 BUG_ON((unsigned long)ptr & (len - 1));
536
537 do {
538 if (!bio_add_page(&b->bio, virt_to_page(ptr),
539 len < PAGE_SIZE ? len : PAGE_SIZE,
540 virt_to_phys(ptr) & (PAGE_SIZE - 1))) {
541 BUG_ON(b->c->block_size <= PAGE_SIZE);
542 use_dmio(b, rw, block, end_io);
543 return;
544 }
545
546 len -= PAGE_SIZE;
547 ptr += PAGE_SIZE;
548 } while (len > 0);
549
550 submit_bio(rw, &b->bio);
551}
552
553static void submit_io(struct dm_buffer *b, int rw, sector_t block,
554 bio_end_io_t *end_io)
555{
556 if (rw == WRITE && b->c->write_callback)
557 b->c->write_callback(b);
558
559 if (b->c->block_size <= DM_BUFIO_INLINE_VECS * PAGE_SIZE &&
560 b->data_mode != DATA_MODE_VMALLOC)
561 use_inline_bio(b, rw, block, end_io);
562 else
563 use_dmio(b, rw, block, end_io);
564}
565
566/*----------------------------------------------------------------
567 * Writing dirty buffers
568 *--------------------------------------------------------------*/
569
570/*
571 * The endio routine for write.
572 *
573 * Set the error, clear B_WRITING bit and wake anyone who was waiting on
574 * it.
575 */
576static void write_endio(struct bio *bio, int error)
577{
578 struct dm_buffer *b = container_of(bio, struct dm_buffer, bio);
579
580 b->write_error = error;
581 if (error) {
582 struct dm_bufio_client *c = b->c;
583 (void)cmpxchg(&c->async_write_error, 0, error);
584 }
585
586 BUG_ON(!test_bit(B_WRITING, &b->state));
587
588 smp_mb__before_clear_bit();
589 clear_bit(B_WRITING, &b->state);
590 smp_mb__after_clear_bit();
591
592 wake_up_bit(&b->state, B_WRITING);
593}
594
595/*
596 * This function is called when wait_on_bit is actually waiting.
597 */
598static int do_io_schedule(void *word)
599{
600 io_schedule();
601
602 return 0;
603}
604
605/*
606 * Initiate a write on a dirty buffer, but don't wait for it.
607 *
608 * - If the buffer is not dirty, exit.
609 * - If there some previous write going on, wait for it to finish (we can't
610 * have two writes on the same buffer simultaneously).
611 * - Submit our write and don't wait on it. We set B_WRITING indicating
612 * that there is a write in progress.
613 */
614static void __write_dirty_buffer(struct dm_buffer *b)
615{
616 if (!test_bit(B_DIRTY, &b->state))
617 return;
618
619 clear_bit(B_DIRTY, &b->state);
620 wait_on_bit_lock(&b->state, B_WRITING,
621 do_io_schedule, TASK_UNINTERRUPTIBLE);
622
623 submit_io(b, WRITE, b->block, write_endio);
624}
625
626/*
627 * Wait until any activity on the buffer finishes. Possibly write the
628 * buffer if it is dirty. When this function finishes, there is no I/O
629 * running on the buffer and the buffer is not dirty.
630 */
631static void __make_buffer_clean(struct dm_buffer *b)
632{
633 BUG_ON(b->hold_count);
634
635 if (!b->state) /* fast case */
636 return;
637
638 wait_on_bit(&b->state, B_READING, do_io_schedule, TASK_UNINTERRUPTIBLE);
639 __write_dirty_buffer(b);
640 wait_on_bit(&b->state, B_WRITING, do_io_schedule, TASK_UNINTERRUPTIBLE);
641}
642
643/*
644 * Find some buffer that is not held by anybody, clean it, unlink it and
645 * return it.
646 */
647static struct dm_buffer *__get_unclaimed_buffer(struct dm_bufio_client *c)
648{
649 struct dm_buffer *b;
650
651 list_for_each_entry_reverse(b, &c->lru[LIST_CLEAN], lru_list) {
652 BUG_ON(test_bit(B_WRITING, &b->state));
653 BUG_ON(test_bit(B_DIRTY, &b->state));
654
655 if (!b->hold_count) {
656 __make_buffer_clean(b);
657 __unlink_buffer(b);
658 return b;
659 }
660 dm_bufio_cond_resched();
661 }
662
663 list_for_each_entry_reverse(b, &c->lru[LIST_DIRTY], lru_list) {
664 BUG_ON(test_bit(B_READING, &b->state));
665
666 if (!b->hold_count) {
667 __make_buffer_clean(b);
668 __unlink_buffer(b);
669 return b;
670 }
671 dm_bufio_cond_resched();
672 }
673
674 return NULL;
675}
676
677/*
678 * Wait until some other threads free some buffer or release hold count on
679 * some buffer.
680 *
681 * This function is entered with c->lock held, drops it and regains it
682 * before exiting.
683 */
684static void __wait_for_free_buffer(struct dm_bufio_client *c)
685{
686 DECLARE_WAITQUEUE(wait, current);
687
688 add_wait_queue(&c->free_buffer_wait, &wait);
689 set_task_state(current, TASK_UNINTERRUPTIBLE);
690 dm_bufio_unlock(c);
691
692 io_schedule();
693
694 set_task_state(current, TASK_RUNNING);
695 remove_wait_queue(&c->free_buffer_wait, &wait);
696
697 dm_bufio_lock(c);
698}
699
700/*
701 * Allocate a new buffer. If the allocation is not possible, wait until
702 * some other thread frees a buffer.
703 *
704 * May drop the lock and regain it.
705 */
706static struct dm_buffer *__alloc_buffer_wait_no_callback(struct dm_bufio_client *c)
707{
708 struct dm_buffer *b;
709
710 /*
711 * dm-bufio is resistant to allocation failures (it just keeps
712 * one buffer reserved in cases all the allocations fail).
713 * So set flags to not try too hard:
714 * GFP_NOIO: don't recurse into the I/O layer
715 * __GFP_NORETRY: don't retry and rather return failure
716 * __GFP_NOMEMALLOC: don't use emergency reserves
717 * __GFP_NOWARN: don't print a warning in case of failure
718 *
719 * For debugging, if we set the cache size to 1, no new buffers will
720 * be allocated.
721 */
722 while (1) {
723 if (dm_bufio_cache_size_latch != 1) {
724 b = alloc_buffer(c, GFP_NOIO | __GFP_NORETRY | __GFP_NOMEMALLOC | __GFP_NOWARN);
725 if (b)
726 return b;
727 }
728
729 if (!list_empty(&c->reserved_buffers)) {
730 b = list_entry(c->reserved_buffers.next,
731 struct dm_buffer, lru_list);
732 list_del(&b->lru_list);
733 c->need_reserved_buffers++;
734
735 return b;
736 }
737
738 b = __get_unclaimed_buffer(c);
739 if (b)
740 return b;
741
742 __wait_for_free_buffer(c);
743 }
744}
745
746static struct dm_buffer *__alloc_buffer_wait(struct dm_bufio_client *c)
747{
748 struct dm_buffer *b = __alloc_buffer_wait_no_callback(c);
749
750 if (c->alloc_callback)
751 c->alloc_callback(b);
752
753 return b;
754}
755
756/*
757 * Free a buffer and wake other threads waiting for free buffers.
758 */
759static void __free_buffer_wake(struct dm_buffer *b)
760{
761 struct dm_bufio_client *c = b->c;
762
763 if (!c->need_reserved_buffers)
764 free_buffer(b);
765 else {
766 list_add(&b->lru_list, &c->reserved_buffers);
767 c->need_reserved_buffers--;
768 }
769
770 wake_up(&c->free_buffer_wait);
771}
772
773static void __write_dirty_buffers_async(struct dm_bufio_client *c, int no_wait)
774{
775 struct dm_buffer *b, *tmp;
776
777 list_for_each_entry_safe_reverse(b, tmp, &c->lru[LIST_DIRTY], lru_list) {
778 BUG_ON(test_bit(B_READING, &b->state));
779
780 if (!test_bit(B_DIRTY, &b->state) &&
781 !test_bit(B_WRITING, &b->state)) {
782 __relink_lru(b, LIST_CLEAN);
783 continue;
784 }
785
786 if (no_wait && test_bit(B_WRITING, &b->state))
787 return;
788
789 __write_dirty_buffer(b);
790 dm_bufio_cond_resched();
791 }
792}
793
794/*
795 * Get writeback threshold and buffer limit for a given client.
796 */
797static void __get_memory_limit(struct dm_bufio_client *c,
798 unsigned long *threshold_buffers,
799 unsigned long *limit_buffers)
800{
801 unsigned long buffers;
802
803 if (dm_bufio_cache_size != dm_bufio_cache_size_latch) {
804 mutex_lock(&dm_bufio_clients_lock);
805 __cache_size_refresh();
806 mutex_unlock(&dm_bufio_clients_lock);
807 }
808
809 buffers = dm_bufio_cache_size_per_client >>
810 (c->sectors_per_block_bits + SECTOR_SHIFT);
811
812 if (buffers < DM_BUFIO_MIN_BUFFERS)
813 buffers = DM_BUFIO_MIN_BUFFERS;
814
815 *limit_buffers = buffers;
816 *threshold_buffers = buffers * DM_BUFIO_WRITEBACK_PERCENT / 100;
817}
818
819/*
820 * Check if we're over watermark.
821 * If we are over threshold_buffers, start freeing buffers.
822 * If we're over "limit_buffers", block until we get under the limit.
823 */
824static void __check_watermark(struct dm_bufio_client *c)
825{
826 unsigned long threshold_buffers, limit_buffers;
827
828 __get_memory_limit(c, &threshold_buffers, &limit_buffers);
829
830 while (c->n_buffers[LIST_CLEAN] + c->n_buffers[LIST_DIRTY] >
831 limit_buffers) {
832
833 struct dm_buffer *b = __get_unclaimed_buffer(c);
834
835 if (!b)
836 return;
837
838 __free_buffer_wake(b);
839 dm_bufio_cond_resched();
840 }
841
842 if (c->n_buffers[LIST_DIRTY] > threshold_buffers)
843 __write_dirty_buffers_async(c, 1);
844}
845
846/*
847 * Find a buffer in the hash.
848 */
849static struct dm_buffer *__find(struct dm_bufio_client *c, sector_t block)
850{
851 struct dm_buffer *b;
852 struct hlist_node *hn;
853
854 hlist_for_each_entry(b, hn, &c->cache_hash[DM_BUFIO_HASH(block)],
855 hash_list) {
856 dm_bufio_cond_resched();
857 if (b->block == block)
858 return b;
859 }
860
861 return NULL;
862}
863
864/*----------------------------------------------------------------
865 * Getting a buffer
866 *--------------------------------------------------------------*/
867
868enum new_flag {
869 NF_FRESH = 0,
870 NF_READ = 1,
871 NF_GET = 2
872};
873
874static struct dm_buffer *__bufio_new(struct dm_bufio_client *c, sector_t block,
875 enum new_flag nf, struct dm_buffer **bp,
876 int *need_submit)
877{
878 struct dm_buffer *b, *new_b = NULL;
879
880 *need_submit = 0;
881
882 b = __find(c, block);
883 if (b) {
884 b->hold_count++;
885 __relink_lru(b, test_bit(B_DIRTY, &b->state) ||
886 test_bit(B_WRITING, &b->state));
887 return b;
888 }
889
890 if (nf == NF_GET)
891 return NULL;
892
893 new_b = __alloc_buffer_wait(c);
894
895 /*
896 * We've had a period where the mutex was unlocked, so need to
897 * recheck the hash table.
898 */
899 b = __find(c, block);
900 if (b) {
901 __free_buffer_wake(new_b);
902 b->hold_count++;
903 __relink_lru(b, test_bit(B_DIRTY, &b->state) ||
904 test_bit(B_WRITING, &b->state));
905 return b;
906 }
907
908 __check_watermark(c);
909
910 b = new_b;
911 b->hold_count = 1;
912 b->read_error = 0;
913 b->write_error = 0;
914 __link_buffer(b, block, LIST_CLEAN);
915
916 if (nf == NF_FRESH) {
917 b->state = 0;
918 return b;
919 }
920
921 b->state = 1 << B_READING;
922 *need_submit = 1;
923
924 return b;
925}
926
927/*
928 * The endio routine for reading: set the error, clear the bit and wake up
929 * anyone waiting on the buffer.
930 */
931static void read_endio(struct bio *bio, int error)
932{
933 struct dm_buffer *b = container_of(bio, struct dm_buffer, bio);
934
935 b->read_error = error;
936
937 BUG_ON(!test_bit(B_READING, &b->state));
938
939 smp_mb__before_clear_bit();
940 clear_bit(B_READING, &b->state);
941 smp_mb__after_clear_bit();
942
943 wake_up_bit(&b->state, B_READING);
944}
945
946/*
947 * A common routine for dm_bufio_new and dm_bufio_read. Operation of these
948 * functions is similar except that dm_bufio_new doesn't read the
949 * buffer from the disk (assuming that the caller overwrites all the data
950 * and uses dm_bufio_mark_buffer_dirty to write new data back).
951 */
952static void *new_read(struct dm_bufio_client *c, sector_t block,
953 enum new_flag nf, struct dm_buffer **bp)
954{
955 int need_submit;
956 struct dm_buffer *b;
957
958 dm_bufio_lock(c);
959 b = __bufio_new(c, block, nf, bp, &need_submit);
960 dm_bufio_unlock(c);
961
962 if (!b || IS_ERR(b))
963 return b;
964
965 if (need_submit)
966 submit_io(b, READ, b->block, read_endio);
967
968 wait_on_bit(&b->state, B_READING, do_io_schedule, TASK_UNINTERRUPTIBLE);
969
970 if (b->read_error) {
971 int error = b->read_error;
972
973 dm_bufio_release(b);
974
975 return ERR_PTR(error);
976 }
977
978 *bp = b;
979
980 return b->data;
981}
982
983void *dm_bufio_get(struct dm_bufio_client *c, sector_t block,
984 struct dm_buffer **bp)
985{
986 return new_read(c, block, NF_GET, bp);
987}
988EXPORT_SYMBOL_GPL(dm_bufio_get);
989
990void *dm_bufio_read(struct dm_bufio_client *c, sector_t block,
991 struct dm_buffer **bp)
992{
993 BUG_ON(dm_bufio_in_request());
994
995 return new_read(c, block, NF_READ, bp);
996}
997EXPORT_SYMBOL_GPL(dm_bufio_read);
998
999void *dm_bufio_new(struct dm_bufio_client *c, sector_t block,
1000 struct dm_buffer **bp)
1001{
1002 BUG_ON(dm_bufio_in_request());
1003
1004 return new_read(c, block, NF_FRESH, bp);
1005}
1006EXPORT_SYMBOL_GPL(dm_bufio_new);
1007
1008void dm_bufio_release(struct dm_buffer *b)
1009{
1010 struct dm_bufio_client *c = b->c;
1011
1012 dm_bufio_lock(c);
1013
1014 BUG_ON(test_bit(B_READING, &b->state));
1015 BUG_ON(!b->hold_count);
1016
1017 b->hold_count--;
1018 if (!b->hold_count) {
1019 wake_up(&c->free_buffer_wait);
1020
1021 /*
1022 * If there were errors on the buffer, and the buffer is not
1023 * to be written, free the buffer. There is no point in caching
1024 * invalid buffer.
1025 */
1026 if ((b->read_error || b->write_error) &&
1027 !test_bit(B_WRITING, &b->state) &&
1028 !test_bit(B_DIRTY, &b->state)) {
1029 __unlink_buffer(b);
1030 __free_buffer_wake(b);
1031 }
1032 }
1033
1034 dm_bufio_unlock(c);
1035}
1036EXPORT_SYMBOL_GPL(dm_bufio_release);
1037
1038void dm_bufio_mark_buffer_dirty(struct dm_buffer *b)
1039{
1040 struct dm_bufio_client *c = b->c;
1041
1042 dm_bufio_lock(c);
1043
1044 if (!test_and_set_bit(B_DIRTY, &b->state))
1045 __relink_lru(b, LIST_DIRTY);
1046
1047 dm_bufio_unlock(c);
1048}
1049EXPORT_SYMBOL_GPL(dm_bufio_mark_buffer_dirty);
1050
1051void dm_bufio_write_dirty_buffers_async(struct dm_bufio_client *c)
1052{
1053 BUG_ON(dm_bufio_in_request());
1054
1055 dm_bufio_lock(c);
1056 __write_dirty_buffers_async(c, 0);
1057 dm_bufio_unlock(c);
1058}
1059EXPORT_SYMBOL_GPL(dm_bufio_write_dirty_buffers_async);
1060
1061/*
1062 * For performance, it is essential that the buffers are written asynchronously
1063 * and simultaneously (so that the block layer can merge the writes) and then
1064 * waited upon.
1065 *
1066 * Finally, we flush hardware disk cache.
1067 */
1068int dm_bufio_write_dirty_buffers(struct dm_bufio_client *c)
1069{
1070 int a, f;
1071 unsigned long buffers_processed = 0;
1072 struct dm_buffer *b, *tmp;
1073
1074 dm_bufio_lock(c);
1075 __write_dirty_buffers_async(c, 0);
1076
1077again:
1078 list_for_each_entry_safe_reverse(b, tmp, &c->lru[LIST_DIRTY], lru_list) {
1079 int dropped_lock = 0;
1080
1081 if (buffers_processed < c->n_buffers[LIST_DIRTY])
1082 buffers_processed++;
1083
1084 BUG_ON(test_bit(B_READING, &b->state));
1085
1086 if (test_bit(B_WRITING, &b->state)) {
1087 if (buffers_processed < c->n_buffers[LIST_DIRTY]) {
1088 dropped_lock = 1;
1089 b->hold_count++;
1090 dm_bufio_unlock(c);
1091 wait_on_bit(&b->state, B_WRITING,
1092 do_io_schedule,
1093 TASK_UNINTERRUPTIBLE);
1094 dm_bufio_lock(c);
1095 b->hold_count--;
1096 } else
1097 wait_on_bit(&b->state, B_WRITING,
1098 do_io_schedule,
1099 TASK_UNINTERRUPTIBLE);
1100 }
1101
1102 if (!test_bit(B_DIRTY, &b->state) &&
1103 !test_bit(B_WRITING, &b->state))
1104 __relink_lru(b, LIST_CLEAN);
1105
1106 dm_bufio_cond_resched();
1107
1108 /*
1109 * If we dropped the lock, the list is no longer consistent,
1110 * so we must restart the search.
1111 *
1112 * In the most common case, the buffer just processed is
1113 * relinked to the clean list, so we won't loop scanning the
1114 * same buffer again and again.
1115 *
1116 * This may livelock if there is another thread simultaneously
1117 * dirtying buffers, so we count the number of buffers walked
1118 * and if it exceeds the total number of buffers, it means that
1119 * someone is doing some writes simultaneously with us. In
1120 * this case, stop, dropping the lock.
1121 */
1122 if (dropped_lock)
1123 goto again;
1124 }
1125 wake_up(&c->free_buffer_wait);
1126 dm_bufio_unlock(c);
1127
1128 a = xchg(&c->async_write_error, 0);
1129 f = dm_bufio_issue_flush(c);
1130 if (a)
1131 return a;
1132
1133 return f;
1134}
1135EXPORT_SYMBOL_GPL(dm_bufio_write_dirty_buffers);
1136
1137/*
1138 * Use dm-io to send and empty barrier flush the device.
1139 */
1140int dm_bufio_issue_flush(struct dm_bufio_client *c)
1141{
1142 struct dm_io_request io_req = {
1143 .bi_rw = REQ_FLUSH,
1144 .mem.type = DM_IO_KMEM,
1145 .mem.ptr.addr = NULL,
1146 .client = c->dm_io,
1147 };
1148 struct dm_io_region io_reg = {
1149 .bdev = c->bdev,
1150 .sector = 0,
1151 .count = 0,
1152 };
1153
1154 BUG_ON(dm_bufio_in_request());
1155
1156 return dm_io(&io_req, 1, &io_reg, NULL);
1157}
1158EXPORT_SYMBOL_GPL(dm_bufio_issue_flush);
1159
1160/*
1161 * We first delete any other buffer that may be at that new location.
1162 *
1163 * Then, we write the buffer to the original location if it was dirty.
1164 *
1165 * Then, if we are the only one who is holding the buffer, relink the buffer
1166 * in the hash queue for the new location.
1167 *
1168 * If there was someone else holding the buffer, we write it to the new
1169 * location but not relink it, because that other user needs to have the buffer
1170 * at the same place.
1171 */
1172void dm_bufio_release_move(struct dm_buffer *b, sector_t new_block)
1173{
1174 struct dm_bufio_client *c = b->c;
1175 struct dm_buffer *new;
1176
1177 BUG_ON(dm_bufio_in_request());
1178
1179 dm_bufio_lock(c);
1180
1181retry:
1182 new = __find(c, new_block);
1183 if (new) {
1184 if (new->hold_count) {
1185 __wait_for_free_buffer(c);
1186 goto retry;
1187 }
1188
1189 /*
1190 * FIXME: Is there any point waiting for a write that's going
1191 * to be overwritten in a bit?
1192 */
1193 __make_buffer_clean(new);
1194 __unlink_buffer(new);
1195 __free_buffer_wake(new);
1196 }
1197
1198 BUG_ON(!b->hold_count);
1199 BUG_ON(test_bit(B_READING, &b->state));
1200
1201 __write_dirty_buffer(b);
1202 if (b->hold_count == 1) {
1203 wait_on_bit(&b->state, B_WRITING,
1204 do_io_schedule, TASK_UNINTERRUPTIBLE);
1205 set_bit(B_DIRTY, &b->state);
1206 __unlink_buffer(b);
1207 __link_buffer(b, new_block, LIST_DIRTY);
1208 } else {
1209 sector_t old_block;
1210 wait_on_bit_lock(&b->state, B_WRITING,
1211 do_io_schedule, TASK_UNINTERRUPTIBLE);
1212 /*
1213 * Relink buffer to "new_block" so that write_callback
1214 * sees "new_block" as a block number.
1215 * After the write, link the buffer back to old_block.
1216 * All this must be done in bufio lock, so that block number
1217 * change isn't visible to other threads.
1218 */
1219 old_block = b->block;
1220 __unlink_buffer(b);
1221 __link_buffer(b, new_block, b->list_mode);
1222 submit_io(b, WRITE, new_block, write_endio);
1223 wait_on_bit(&b->state, B_WRITING,
1224 do_io_schedule, TASK_UNINTERRUPTIBLE);
1225 __unlink_buffer(b);
1226 __link_buffer(b, old_block, b->list_mode);
1227 }
1228
1229 dm_bufio_unlock(c);
1230 dm_bufio_release(b);
1231}
1232EXPORT_SYMBOL_GPL(dm_bufio_release_move);
1233
1234unsigned dm_bufio_get_block_size(struct dm_bufio_client *c)
1235{
1236 return c->block_size;
1237}
1238EXPORT_SYMBOL_GPL(dm_bufio_get_block_size);
1239
1240sector_t dm_bufio_get_device_size(struct dm_bufio_client *c)
1241{
1242 return i_size_read(c->bdev->bd_inode) >>
1243 (SECTOR_SHIFT + c->sectors_per_block_bits);
1244}
1245EXPORT_SYMBOL_GPL(dm_bufio_get_device_size);
1246
1247sector_t dm_bufio_get_block_number(struct dm_buffer *b)
1248{
1249 return b->block;
1250}
1251EXPORT_SYMBOL_GPL(dm_bufio_get_block_number);
1252
1253void *dm_bufio_get_block_data(struct dm_buffer *b)
1254{
1255 return b->data;
1256}
1257EXPORT_SYMBOL_GPL(dm_bufio_get_block_data);
1258
1259void *dm_bufio_get_aux_data(struct dm_buffer *b)
1260{
1261 return b + 1;
1262}
1263EXPORT_SYMBOL_GPL(dm_bufio_get_aux_data);
1264
1265struct dm_bufio_client *dm_bufio_get_client(struct dm_buffer *b)
1266{
1267 return b->c;
1268}
1269EXPORT_SYMBOL_GPL(dm_bufio_get_client);
1270
1271static void drop_buffers(struct dm_bufio_client *c)
1272{
1273 struct dm_buffer *b;
1274 int i;
1275
1276 BUG_ON(dm_bufio_in_request());
1277
1278 /*
1279 * An optimization so that the buffers are not written one-by-one.
1280 */
1281 dm_bufio_write_dirty_buffers_async(c);
1282
1283 dm_bufio_lock(c);
1284
1285 while ((b = __get_unclaimed_buffer(c)))
1286 __free_buffer_wake(b);
1287
1288 for (i = 0; i < LIST_SIZE; i++)
1289 list_for_each_entry(b, &c->lru[i], lru_list)
1290 DMERR("leaked buffer %llx, hold count %u, list %d",
1291 (unsigned long long)b->block, b->hold_count, i);
1292
1293 for (i = 0; i < LIST_SIZE; i++)
1294 BUG_ON(!list_empty(&c->lru[i]));
1295
1296 dm_bufio_unlock(c);
1297}
1298
1299/*
1300 * Test if the buffer is unused and too old, and commit it.
1301 * At if noio is set, we must not do any I/O because we hold
1302 * dm_bufio_clients_lock and we would risk deadlock if the I/O gets rerouted to
1303 * different bufio client.
1304 */
1305static int __cleanup_old_buffer(struct dm_buffer *b, gfp_t gfp,
1306 unsigned long max_jiffies)
1307{
1308 if (jiffies - b->last_accessed < max_jiffies)
1309 return 1;
1310
1311 if (!(gfp & __GFP_IO)) {
1312 if (test_bit(B_READING, &b->state) ||
1313 test_bit(B_WRITING, &b->state) ||
1314 test_bit(B_DIRTY, &b->state))
1315 return 1;
1316 }
1317
1318 if (b->hold_count)
1319 return 1;
1320
1321 __make_buffer_clean(b);
1322 __unlink_buffer(b);
1323 __free_buffer_wake(b);
1324
1325 return 0;
1326}
1327
1328static void __scan(struct dm_bufio_client *c, unsigned long nr_to_scan,
1329 struct shrink_control *sc)
1330{
1331 int l;
1332 struct dm_buffer *b, *tmp;
1333
1334 for (l = 0; l < LIST_SIZE; l++) {
1335 list_for_each_entry_safe_reverse(b, tmp, &c->lru[l], lru_list)
1336 if (!__cleanup_old_buffer(b, sc->gfp_mask, 0) &&
1337 !--nr_to_scan)
1338 return;
1339 dm_bufio_cond_resched();
1340 }
1341}
1342
1343static int shrink(struct shrinker *shrinker, struct shrink_control *sc)
1344{
1345 struct dm_bufio_client *c =
1346 container_of(shrinker, struct dm_bufio_client, shrinker);
1347 unsigned long r;
1348 unsigned long nr_to_scan = sc->nr_to_scan;
1349
1350 if (sc->gfp_mask & __GFP_IO)
1351 dm_bufio_lock(c);
1352 else if (!dm_bufio_trylock(c))
1353 return !nr_to_scan ? 0 : -1;
1354
1355 if (nr_to_scan)
1356 __scan(c, nr_to_scan, sc);
1357
1358 r = c->n_buffers[LIST_CLEAN] + c->n_buffers[LIST_DIRTY];
1359 if (r > INT_MAX)
1360 r = INT_MAX;
1361
1362 dm_bufio_unlock(c);
1363
1364 return r;
1365}
1366
1367/*
1368 * Create the buffering interface
1369 */
1370struct dm_bufio_client *dm_bufio_client_create(struct block_device *bdev, unsigned block_size,
1371 unsigned reserved_buffers, unsigned aux_size,
1372 void (*alloc_callback)(struct dm_buffer *),
1373 void (*write_callback)(struct dm_buffer *))
1374{
1375 int r;
1376 struct dm_bufio_client *c;
1377 unsigned i;
1378
1379 BUG_ON(block_size < 1 << SECTOR_SHIFT ||
1380 (block_size & (block_size - 1)));
1381
1382 c = kmalloc(sizeof(*c), GFP_KERNEL);
1383 if (!c) {
1384 r = -ENOMEM;
1385 goto bad_client;
1386 }
1387 c->cache_hash = vmalloc(sizeof(struct hlist_head) << DM_BUFIO_HASH_BITS);
1388 if (!c->cache_hash) {
1389 r = -ENOMEM;
1390 goto bad_hash;
1391 }
1392
1393 c->bdev = bdev;
1394 c->block_size = block_size;
1395 c->sectors_per_block_bits = ffs(block_size) - 1 - SECTOR_SHIFT;
1396 c->pages_per_block_bits = (ffs(block_size) - 1 >= PAGE_SHIFT) ?
1397 ffs(block_size) - 1 - PAGE_SHIFT : 0;
1398 c->blocks_per_page_bits = (ffs(block_size) - 1 < PAGE_SHIFT ?
1399 PAGE_SHIFT - (ffs(block_size) - 1) : 0);
1400
1401 c->aux_size = aux_size;
1402 c->alloc_callback = alloc_callback;
1403 c->write_callback = write_callback;
1404
1405 for (i = 0; i < LIST_SIZE; i++) {
1406 INIT_LIST_HEAD(&c->lru[i]);
1407 c->n_buffers[i] = 0;
1408 }
1409
1410 for (i = 0; i < 1 << DM_BUFIO_HASH_BITS; i++)
1411 INIT_HLIST_HEAD(&c->cache_hash[i]);
1412
1413 mutex_init(&c->lock);
1414 INIT_LIST_HEAD(&c->reserved_buffers);
1415 c->need_reserved_buffers = reserved_buffers;
1416
1417 init_waitqueue_head(&c->free_buffer_wait);
1418 c->async_write_error = 0;
1419
1420 c->dm_io = dm_io_client_create();
1421 if (IS_ERR(c->dm_io)) {
1422 r = PTR_ERR(c->dm_io);
1423 goto bad_dm_io;
1424 }
1425
1426 mutex_lock(&dm_bufio_clients_lock);
1427 if (c->blocks_per_page_bits) {
1428 if (!DM_BUFIO_CACHE_NAME(c)) {
1429 DM_BUFIO_CACHE_NAME(c) = kasprintf(GFP_KERNEL, "dm_bufio_cache-%u", c->block_size);
1430 if (!DM_BUFIO_CACHE_NAME(c)) {
1431 r = -ENOMEM;
1432 mutex_unlock(&dm_bufio_clients_lock);
1433 goto bad_cache;
1434 }
1435 }
1436
1437 if (!DM_BUFIO_CACHE(c)) {
1438 DM_BUFIO_CACHE(c) = kmem_cache_create(DM_BUFIO_CACHE_NAME(c),
1439 c->block_size,
1440 c->block_size, 0, NULL);
1441 if (!DM_BUFIO_CACHE(c)) {
1442 r = -ENOMEM;
1443 mutex_unlock(&dm_bufio_clients_lock);
1444 goto bad_cache;
1445 }
1446 }
1447 }
1448 mutex_unlock(&dm_bufio_clients_lock);
1449
1450 while (c->need_reserved_buffers) {
1451 struct dm_buffer *b = alloc_buffer(c, GFP_KERNEL);
1452
1453 if (!b) {
1454 r = -ENOMEM;
1455 goto bad_buffer;
1456 }
1457 __free_buffer_wake(b);
1458 }
1459
1460 mutex_lock(&dm_bufio_clients_lock);
1461 dm_bufio_client_count++;
1462 list_add(&c->client_list, &dm_bufio_all_clients);
1463 __cache_size_refresh();
1464 mutex_unlock(&dm_bufio_clients_lock);
1465
1466 c->shrinker.shrink = shrink;
1467 c->shrinker.seeks = 1;
1468 c->shrinker.batch = 0;
1469 register_shrinker(&c->shrinker);
1470
1471 return c;
1472
1473bad_buffer:
1474bad_cache:
1475 while (!list_empty(&c->reserved_buffers)) {
1476 struct dm_buffer *b = list_entry(c->reserved_buffers.next,
1477 struct dm_buffer, lru_list);
1478 list_del(&b->lru_list);
1479 free_buffer(b);
1480 }
1481 dm_io_client_destroy(c->dm_io);
1482bad_dm_io:
1483 vfree(c->cache_hash);
1484bad_hash:
1485 kfree(c);
1486bad_client:
1487 return ERR_PTR(r);
1488}
1489EXPORT_SYMBOL_GPL(dm_bufio_client_create);
1490
1491/*
1492 * Free the buffering interface.
1493 * It is required that there are no references on any buffers.
1494 */
1495void dm_bufio_client_destroy(struct dm_bufio_client *c)
1496{
1497 unsigned i;
1498
1499 drop_buffers(c);
1500
1501 unregister_shrinker(&c->shrinker);
1502
1503 mutex_lock(&dm_bufio_clients_lock);
1504
1505 list_del(&c->client_list);
1506 dm_bufio_client_count--;
1507 __cache_size_refresh();
1508
1509 mutex_unlock(&dm_bufio_clients_lock);
1510
1511 for (i = 0; i < 1 << DM_BUFIO_HASH_BITS; i++)
1512 BUG_ON(!hlist_empty(&c->cache_hash[i]));
1513
1514 BUG_ON(c->need_reserved_buffers);
1515
1516 while (!list_empty(&c->reserved_buffers)) {
1517 struct dm_buffer *b = list_entry(c->reserved_buffers.next,
1518 struct dm_buffer, lru_list);
1519 list_del(&b->lru_list);
1520 free_buffer(b);
1521 }
1522
1523 for (i = 0; i < LIST_SIZE; i++)
1524 if (c->n_buffers[i])
1525 DMERR("leaked buffer count %d: %ld", i, c->n_buffers[i]);
1526
1527 for (i = 0; i < LIST_SIZE; i++)
1528 BUG_ON(c->n_buffers[i]);
1529
1530 dm_io_client_destroy(c->dm_io);
1531 vfree(c->cache_hash);
1532 kfree(c);
1533}
1534EXPORT_SYMBOL_GPL(dm_bufio_client_destroy);
1535
1536static void cleanup_old_buffers(void)
1537{
1538 unsigned long max_age = dm_bufio_max_age;
1539 struct dm_bufio_client *c;
1540
1541 barrier();
1542
1543 if (max_age > ULONG_MAX / HZ)
1544 max_age = ULONG_MAX / HZ;
1545
1546 mutex_lock(&dm_bufio_clients_lock);
1547 list_for_each_entry(c, &dm_bufio_all_clients, client_list) {
1548 if (!dm_bufio_trylock(c))
1549 continue;
1550
1551 while (!list_empty(&c->lru[LIST_CLEAN])) {
1552 struct dm_buffer *b;
1553 b = list_entry(c->lru[LIST_CLEAN].prev,
1554 struct dm_buffer, lru_list);
1555 if (__cleanup_old_buffer(b, 0, max_age * HZ))
1556 break;
1557 dm_bufio_cond_resched();
1558 }
1559
1560 dm_bufio_unlock(c);
1561 dm_bufio_cond_resched();
1562 }
1563 mutex_unlock(&dm_bufio_clients_lock);
1564}
1565
1566static struct workqueue_struct *dm_bufio_wq;
1567static struct delayed_work dm_bufio_work;
1568
1569static void work_fn(struct work_struct *w)
1570{
1571 cleanup_old_buffers();
1572
1573 queue_delayed_work(dm_bufio_wq, &dm_bufio_work,
1574 DM_BUFIO_WORK_TIMER_SECS * HZ);
1575}
1576
1577/*----------------------------------------------------------------
1578 * Module setup
1579 *--------------------------------------------------------------*/
1580
1581/*
1582 * This is called only once for the whole dm_bufio module.
1583 * It initializes memory limit.
1584 */
1585static int __init dm_bufio_init(void)
1586{
1587 __u64 mem;
1588
1589 memset(&dm_bufio_caches, 0, sizeof dm_bufio_caches);
1590 memset(&dm_bufio_cache_names, 0, sizeof dm_bufio_cache_names);
1591
1592 mem = (__u64)((totalram_pages - totalhigh_pages) *
1593 DM_BUFIO_MEMORY_PERCENT / 100) << PAGE_SHIFT;
1594
1595 if (mem > ULONG_MAX)
1596 mem = ULONG_MAX;
1597
1598#ifdef CONFIG_MMU
1599 /*
1600 * Get the size of vmalloc space the same way as VMALLOC_TOTAL
1601 * in fs/proc/internal.h
1602 */
1603 if (mem > (VMALLOC_END - VMALLOC_START) * DM_BUFIO_VMALLOC_PERCENT / 100)
1604 mem = (VMALLOC_END - VMALLOC_START) * DM_BUFIO_VMALLOC_PERCENT / 100;
1605#endif
1606
1607 dm_bufio_default_cache_size = mem;
1608
1609 mutex_lock(&dm_bufio_clients_lock);
1610 __cache_size_refresh();
1611 mutex_unlock(&dm_bufio_clients_lock);
1612
1613 dm_bufio_wq = create_singlethread_workqueue("dm_bufio_cache");
1614 if (!dm_bufio_wq)
1615 return -ENOMEM;
1616
1617 INIT_DELAYED_WORK(&dm_bufio_work, work_fn);
1618 queue_delayed_work(dm_bufio_wq, &dm_bufio_work,
1619 DM_BUFIO_WORK_TIMER_SECS * HZ);
1620
1621 return 0;
1622}
1623
1624/*
1625 * This is called once when unloading the dm_bufio module.
1626 */
1627static void __exit dm_bufio_exit(void)
1628{
1629 int bug = 0;
1630 int i;
1631
1632 cancel_delayed_work_sync(&dm_bufio_work);
1633 destroy_workqueue(dm_bufio_wq);
1634
1635 for (i = 0; i < ARRAY_SIZE(dm_bufio_caches); i++) {
1636 struct kmem_cache *kc = dm_bufio_caches[i];
1637
1638 if (kc)
1639 kmem_cache_destroy(kc);
1640 }
1641
1642 for (i = 0; i < ARRAY_SIZE(dm_bufio_cache_names); i++)
1643 kfree(dm_bufio_cache_names[i]);
1644
1645 if (dm_bufio_client_count) {
1646 DMCRIT("%s: dm_bufio_client_count leaked: %d",
1647 __func__, dm_bufio_client_count);
1648 bug = 1;
1649 }
1650
1651 if (dm_bufio_current_allocated) {
1652 DMCRIT("%s: dm_bufio_current_allocated leaked: %lu",
1653 __func__, dm_bufio_current_allocated);
1654 bug = 1;
1655 }
1656
1657 if (dm_bufio_allocated_get_free_pages) {
1658 DMCRIT("%s: dm_bufio_allocated_get_free_pages leaked: %lu",
1659 __func__, dm_bufio_allocated_get_free_pages);
1660 bug = 1;
1661 }
1662
1663 if (dm_bufio_allocated_vmalloc) {
1664 DMCRIT("%s: dm_bufio_vmalloc leaked: %lu",
1665 __func__, dm_bufio_allocated_vmalloc);
1666 bug = 1;
1667 }
1668
1669 if (bug)
1670 BUG();
1671}
1672
1673module_init(dm_bufio_init)
1674module_exit(dm_bufio_exit)
1675
1676module_param_named(max_cache_size_bytes, dm_bufio_cache_size, ulong, S_IRUGO | S_IWUSR);
1677MODULE_PARM_DESC(max_cache_size_bytes, "Size of metadata cache");
1678
1679module_param_named(max_age_seconds, dm_bufio_max_age, uint, S_IRUGO | S_IWUSR);
1680MODULE_PARM_DESC(max_age_seconds, "Max age of a buffer in seconds");
1681
1682module_param_named(peak_allocated_bytes, dm_bufio_peak_allocated, ulong, S_IRUGO | S_IWUSR);
1683MODULE_PARM_DESC(peak_allocated_bytes, "Tracks the maximum allocated memory");
1684
1685module_param_named(allocated_kmem_cache_bytes, dm_bufio_allocated_kmem_cache, ulong, S_IRUGO);
1686MODULE_PARM_DESC(allocated_kmem_cache_bytes, "Memory allocated with kmem_cache_alloc");
1687
1688module_param_named(allocated_get_free_pages_bytes, dm_bufio_allocated_get_free_pages, ulong, S_IRUGO);
1689MODULE_PARM_DESC(allocated_get_free_pages_bytes, "Memory allocated with get_free_pages");
1690
1691module_param_named(allocated_vmalloc_bytes, dm_bufio_allocated_vmalloc, ulong, S_IRUGO);
1692MODULE_PARM_DESC(allocated_vmalloc_bytes, "Memory allocated with vmalloc");
1693
1694module_param_named(current_allocated_bytes, dm_bufio_current_allocated, ulong, S_IRUGO);
1695MODULE_PARM_DESC(current_allocated_bytes, "Memory currently used by the cache");
1696
1697MODULE_AUTHOR("Mikulas Patocka <dm-devel@redhat.com>");
1698MODULE_DESCRIPTION(DM_NAME " buffered I/O library");
1699MODULE_LICENSE("GPL");
diff --git a/drivers/md/dm-bufio.h b/drivers/md/dm-bufio.h
new file mode 100644
index 000000000000..5c4c3a04e381
--- /dev/null
+++ b/drivers/md/dm-bufio.h
@@ -0,0 +1,112 @@
1/*
2 * Copyright (C) 2009-2011 Red Hat, Inc.
3 *
4 * Author: Mikulas Patocka <mpatocka@redhat.com>
5 *
6 * This file is released under the GPL.
7 */
8
9#ifndef DM_BUFIO_H
10#define DM_BUFIO_H
11
12#include <linux/blkdev.h>
13#include <linux/types.h>
14
15/*----------------------------------------------------------------*/
16
17struct dm_bufio_client;
18struct dm_buffer;
19
20/*
21 * Create a buffered IO cache on a given device
22 */
23struct dm_bufio_client *
24dm_bufio_client_create(struct block_device *bdev, unsigned block_size,
25 unsigned reserved_buffers, unsigned aux_size,
26 void (*alloc_callback)(struct dm_buffer *),
27 void (*write_callback)(struct dm_buffer *));
28
29/*
30 * Release a buffered IO cache.
31 */
32void dm_bufio_client_destroy(struct dm_bufio_client *c);
33
34/*
35 * WARNING: to avoid deadlocks, these conditions are observed:
36 *
37 * - At most one thread can hold at most "reserved_buffers" simultaneously.
38 * - Each other threads can hold at most one buffer.
39 * - Threads which call only dm_bufio_get can hold unlimited number of
40 * buffers.
41 */
42
43/*
44 * Read a given block from disk. Returns pointer to data. Returns a
45 * pointer to dm_buffer that can be used to release the buffer or to make
46 * it dirty.
47 */
48void *dm_bufio_read(struct dm_bufio_client *c, sector_t block,
49 struct dm_buffer **bp);
50
51/*
52 * Like dm_bufio_read, but return buffer from cache, don't read
53 * it. If the buffer is not in the cache, return NULL.
54 */
55void *dm_bufio_get(struct dm_bufio_client *c, sector_t block,
56 struct dm_buffer **bp);
57
58/*
59 * Like dm_bufio_read, but don't read anything from the disk. It is
60 * expected that the caller initializes the buffer and marks it dirty.
61 */
62void *dm_bufio_new(struct dm_bufio_client *c, sector_t block,
63 struct dm_buffer **bp);
64
65/*
66 * Release a reference obtained with dm_bufio_{read,get,new}. The data
67 * pointer and dm_buffer pointer is no longer valid after this call.
68 */
69void dm_bufio_release(struct dm_buffer *b);
70
71/*
72 * Mark a buffer dirty. It should be called after the buffer is modified.
73 *
74 * In case of memory pressure, the buffer may be written after
75 * dm_bufio_mark_buffer_dirty, but before dm_bufio_write_dirty_buffers. So
76 * dm_bufio_write_dirty_buffers guarantees that the buffer is on-disk but
77 * the actual writing may occur earlier.
78 */
79void dm_bufio_mark_buffer_dirty(struct dm_buffer *b);
80
81/*
82 * Initiate writing of dirty buffers, without waiting for completion.
83 */
84void dm_bufio_write_dirty_buffers_async(struct dm_bufio_client *c);
85
86/*
87 * Write all dirty buffers. Guarantees that all dirty buffers created prior
88 * to this call are on disk when this call exits.
89 */
90int dm_bufio_write_dirty_buffers(struct dm_bufio_client *c);
91
92/*
93 * Send an empty write barrier to the device to flush hardware disk cache.
94 */
95int dm_bufio_issue_flush(struct dm_bufio_client *c);
96
97/*
98 * Like dm_bufio_release but also move the buffer to the new
99 * block. dm_bufio_write_dirty_buffers is needed to commit the new block.
100 */
101void dm_bufio_release_move(struct dm_buffer *b, sector_t new_block);
102
103unsigned dm_bufio_get_block_size(struct dm_bufio_client *c);
104sector_t dm_bufio_get_device_size(struct dm_bufio_client *c);
105sector_t dm_bufio_get_block_number(struct dm_buffer *b);
106void *dm_bufio_get_block_data(struct dm_buffer *b);
107void *dm_bufio_get_aux_data(struct dm_buffer *b);
108struct dm_bufio_client *dm_bufio_get_client(struct dm_buffer *b);
109
110/*----------------------------------------------------------------*/
111
112#endif
diff --git a/drivers/md/dm-exception-store.c b/drivers/md/dm-exception-store.c
index 0bdb201c2c2a..042e71996569 100644
--- a/drivers/md/dm-exception-store.c
+++ b/drivers/md/dm-exception-store.c
@@ -11,6 +11,7 @@
11#include <linux/mm.h> 11#include <linux/mm.h>
12#include <linux/pagemap.h> 12#include <linux/pagemap.h>
13#include <linux/vmalloc.h> 13#include <linux/vmalloc.h>
14#include <linux/module.h>
14#include <linux/slab.h> 15#include <linux/slab.h>
15 16
16#define DM_MSG_PREFIX "snapshot exception stores" 17#define DM_MSG_PREFIX "snapshot exception stores"
diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
index 2e9a3ca37bdd..31c2dc25886d 100644
--- a/drivers/md/dm-ioctl.c
+++ b/drivers/md/dm-ioctl.c
@@ -1215,6 +1215,7 @@ static int table_load(struct dm_ioctl *param, size_t param_size)
1215 struct hash_cell *hc; 1215 struct hash_cell *hc;
1216 struct dm_table *t; 1216 struct dm_table *t;
1217 struct mapped_device *md; 1217 struct mapped_device *md;
1218 struct target_type *immutable_target_type;
1218 1219
1219 md = find_device(param); 1220 md = find_device(param);
1220 if (!md) 1221 if (!md)
@@ -1230,6 +1231,16 @@ static int table_load(struct dm_ioctl *param, size_t param_size)
1230 goto out; 1231 goto out;
1231 } 1232 }
1232 1233
1234 immutable_target_type = dm_get_immutable_target_type(md);
1235 if (immutable_target_type &&
1236 (immutable_target_type != dm_table_get_immutable_target_type(t))) {
1237 DMWARN("can't replace immutable target type %s",
1238 immutable_target_type->name);
1239 dm_table_destroy(t);
1240 r = -EINVAL;
1241 goto out;
1242 }
1243
1233 /* Protect md->type and md->queue against concurrent table loads. */ 1244 /* Protect md->type and md->queue against concurrent table loads. */
1234 dm_lock_md_type(md); 1245 dm_lock_md_type(md);
1235 if (dm_get_md_type(md) == DM_TYPE_NONE) 1246 if (dm_get_md_type(md) == DM_TYPE_NONE)
diff --git a/drivers/md/dm-kcopyd.c b/drivers/md/dm-kcopyd.c
index 32ac70861d66..bed444c93d8d 100644
--- a/drivers/md/dm-kcopyd.c
+++ b/drivers/md/dm-kcopyd.c
@@ -66,6 +66,8 @@ struct dm_kcopyd_client {
66 struct list_head pages_jobs; 66 struct list_head pages_jobs;
67}; 67};
68 68
69static struct page_list zero_page_list;
70
69static void wake(struct dm_kcopyd_client *kc) 71static void wake(struct dm_kcopyd_client *kc)
70{ 72{
71 queue_work(kc->kcopyd_wq, &kc->kcopyd_work); 73 queue_work(kc->kcopyd_wq, &kc->kcopyd_work);
@@ -254,6 +256,9 @@ int __init dm_kcopyd_init(void)
254 if (!_job_cache) 256 if (!_job_cache)
255 return -ENOMEM; 257 return -ENOMEM;
256 258
259 zero_page_list.next = &zero_page_list;
260 zero_page_list.page = ZERO_PAGE(0);
261
257 return 0; 262 return 0;
258} 263}
259 264
@@ -322,7 +327,7 @@ static int run_complete_job(struct kcopyd_job *job)
322 dm_kcopyd_notify_fn fn = job->fn; 327 dm_kcopyd_notify_fn fn = job->fn;
323 struct dm_kcopyd_client *kc = job->kc; 328 struct dm_kcopyd_client *kc = job->kc;
324 329
325 if (job->pages) 330 if (job->pages && job->pages != &zero_page_list)
326 kcopyd_put_pages(kc, job->pages); 331 kcopyd_put_pages(kc, job->pages);
327 /* 332 /*
328 * If this is the master job, the sub jobs have already 333 * If this is the master job, the sub jobs have already
@@ -484,6 +489,8 @@ static void dispatch_job(struct kcopyd_job *job)
484 atomic_inc(&kc->nr_jobs); 489 atomic_inc(&kc->nr_jobs);
485 if (unlikely(!job->source.count)) 490 if (unlikely(!job->source.count))
486 push(&kc->complete_jobs, job); 491 push(&kc->complete_jobs, job);
492 else if (job->pages == &zero_page_list)
493 push(&kc->io_jobs, job);
487 else 494 else
488 push(&kc->pages_jobs, job); 495 push(&kc->pages_jobs, job);
489 wake(kc); 496 wake(kc);
@@ -592,14 +599,20 @@ int dm_kcopyd_copy(struct dm_kcopyd_client *kc, struct dm_io_region *from,
592 job->flags = flags; 599 job->flags = flags;
593 job->read_err = 0; 600 job->read_err = 0;
594 job->write_err = 0; 601 job->write_err = 0;
595 job->rw = READ;
596
597 job->source = *from;
598 602
599 job->num_dests = num_dests; 603 job->num_dests = num_dests;
600 memcpy(&job->dests, dests, sizeof(*dests) * num_dests); 604 memcpy(&job->dests, dests, sizeof(*dests) * num_dests);
601 605
602 job->pages = NULL; 606 if (from) {
607 job->source = *from;
608 job->pages = NULL;
609 job->rw = READ;
610 } else {
611 memset(&job->source, 0, sizeof job->source);
612 job->source.count = job->dests[0].count;
613 job->pages = &zero_page_list;
614 job->rw = WRITE;
615 }
603 616
604 job->fn = fn; 617 job->fn = fn;
605 job->context = context; 618 job->context = context;
@@ -617,6 +630,14 @@ int dm_kcopyd_copy(struct dm_kcopyd_client *kc, struct dm_io_region *from,
617} 630}
618EXPORT_SYMBOL(dm_kcopyd_copy); 631EXPORT_SYMBOL(dm_kcopyd_copy);
619 632
633int dm_kcopyd_zero(struct dm_kcopyd_client *kc,
634 unsigned num_dests, struct dm_io_region *dests,
635 unsigned flags, dm_kcopyd_notify_fn fn, void *context)
636{
637 return dm_kcopyd_copy(kc, NULL, num_dests, dests, flags, fn, context);
638}
639EXPORT_SYMBOL(dm_kcopyd_zero);
640
620void *dm_kcopyd_prepare_callback(struct dm_kcopyd_client *kc, 641void *dm_kcopyd_prepare_callback(struct dm_kcopyd_client *kc,
621 dm_kcopyd_notify_fn fn, void *context) 642 dm_kcopyd_notify_fn fn, void *context)
622{ 643{
diff --git a/drivers/md/dm-log-userspace-base.c b/drivers/md/dm-log-userspace-base.c
index 1021c8986011..9429159d9ee3 100644
--- a/drivers/md/dm-log-userspace-base.c
+++ b/drivers/md/dm-log-userspace-base.c
@@ -9,6 +9,7 @@
9#include <linux/dm-dirty-log.h> 9#include <linux/dm-dirty-log.h>
10#include <linux/device-mapper.h> 10#include <linux/device-mapper.h>
11#include <linux/dm-log-userspace.h> 11#include <linux/dm-log-userspace.h>
12#include <linux/module.h>
12 13
13#include "dm-log-userspace-transfer.h" 14#include "dm-log-userspace-transfer.h"
14 15
@@ -30,6 +31,7 @@ struct flush_entry {
30 31
31struct log_c { 32struct log_c {
32 struct dm_target *ti; 33 struct dm_target *ti;
34 struct dm_dev *log_dev;
33 uint32_t region_size; 35 uint32_t region_size;
34 region_t region_count; 36 region_t region_count;
35 uint64_t luid; 37 uint64_t luid;
@@ -146,7 +148,7 @@ static int build_constructor_string(struct dm_target *ti,
146 * <UUID> <other args> 148 * <UUID> <other args>
147 * Where 'other args' is the userspace implementation specific log 149 * Where 'other args' is the userspace implementation specific log
148 * arguments. An example might be: 150 * arguments. An example might be:
149 * <UUID> clustered_disk <arg count> <log dev> <region_size> [[no]sync] 151 * <UUID> clustered-disk <arg count> <log dev> <region_size> [[no]sync]
150 * 152 *
151 * So, this module will strip off the <UUID> for identification purposes 153 * So, this module will strip off the <UUID> for identification purposes
152 * when communicating with userspace about a log; but will pass on everything 154 * when communicating with userspace about a log; but will pass on everything
@@ -161,13 +163,15 @@ static int userspace_ctr(struct dm_dirty_log *log, struct dm_target *ti,
161 struct log_c *lc = NULL; 163 struct log_c *lc = NULL;
162 uint64_t rdata; 164 uint64_t rdata;
163 size_t rdata_size = sizeof(rdata); 165 size_t rdata_size = sizeof(rdata);
166 char *devices_rdata = NULL;
167 size_t devices_rdata_size = DM_NAME_LEN;
164 168
165 if (argc < 3) { 169 if (argc < 3) {
166 DMWARN("Too few arguments to userspace dirty log"); 170 DMWARN("Too few arguments to userspace dirty log");
167 return -EINVAL; 171 return -EINVAL;
168 } 172 }
169 173
170 lc = kmalloc(sizeof(*lc), GFP_KERNEL); 174 lc = kzalloc(sizeof(*lc), GFP_KERNEL);
171 if (!lc) { 175 if (!lc) {
172 DMWARN("Unable to allocate userspace log context."); 176 DMWARN("Unable to allocate userspace log context.");
173 return -ENOMEM; 177 return -ENOMEM;
@@ -195,9 +199,19 @@ static int userspace_ctr(struct dm_dirty_log *log, struct dm_target *ti,
195 return str_size; 199 return str_size;
196 } 200 }
197 201
198 /* Send table string */ 202 devices_rdata = kzalloc(devices_rdata_size, GFP_KERNEL);
203 if (!devices_rdata) {
204 DMERR("Failed to allocate memory for device information");
205 r = -ENOMEM;
206 goto out;
207 }
208
209 /*
210 * Send table string and get back any opened device.
211 */
199 r = dm_consult_userspace(lc->uuid, lc->luid, DM_ULOG_CTR, 212 r = dm_consult_userspace(lc->uuid, lc->luid, DM_ULOG_CTR,
200 ctr_str, str_size, NULL, NULL); 213 ctr_str, str_size,
214 devices_rdata, &devices_rdata_size);
201 215
202 if (r < 0) { 216 if (r < 0) {
203 if (r == -ESRCH) 217 if (r == -ESRCH)
@@ -220,7 +234,20 @@ static int userspace_ctr(struct dm_dirty_log *log, struct dm_target *ti,
220 lc->region_size = (uint32_t)rdata; 234 lc->region_size = (uint32_t)rdata;
221 lc->region_count = dm_sector_div_up(ti->len, lc->region_size); 235 lc->region_count = dm_sector_div_up(ti->len, lc->region_size);
222 236
237 if (devices_rdata_size) {
238 if (devices_rdata[devices_rdata_size - 1] != '\0') {
239 DMERR("DM_ULOG_CTR device return string not properly terminated");
240 r = -EINVAL;
241 goto out;
242 }
243 r = dm_get_device(ti, devices_rdata,
244 dm_table_get_mode(ti->table), &lc->log_dev);
245 if (r)
246 DMERR("Failed to register %s with device-mapper",
247 devices_rdata);
248 }
223out: 249out:
250 kfree(devices_rdata);
224 if (r) { 251 if (r) {
225 kfree(lc); 252 kfree(lc);
226 kfree(ctr_str); 253 kfree(ctr_str);
@@ -241,6 +268,9 @@ static void userspace_dtr(struct dm_dirty_log *log)
241 NULL, 0, 268 NULL, 0,
242 NULL, NULL); 269 NULL, NULL);
243 270
271 if (lc->log_dev)
272 dm_put_device(lc->ti, lc->log_dev);
273
244 kfree(lc->usr_argv_str); 274 kfree(lc->usr_argv_str);
245 kfree(lc); 275 kfree(lc);
246 276
diff --git a/drivers/md/dm-path-selector.c b/drivers/md/dm-path-selector.c
index 42c04f04a0c4..fa0ccc585cb4 100644
--- a/drivers/md/dm-path-selector.c
+++ b/drivers/md/dm-path-selector.c
@@ -10,6 +10,7 @@
10 */ 10 */
11 11
12#include <linux/device-mapper.h> 12#include <linux/device-mapper.h>
13#include <linux/module.h>
13 14
14#include "dm-path-selector.h" 15#include "dm-path-selector.h"
15 16
diff --git a/drivers/md/dm-raid.c b/drivers/md/dm-raid.c
index 37a37266a1e3..c2907d836e4e 100644
--- a/drivers/md/dm-raid.c
+++ b/drivers/md/dm-raid.c
@@ -6,6 +6,7 @@
6 */ 6 */
7 7
8#include <linux/slab.h> 8#include <linux/slab.h>
9#include <linux/module.h>
9 10
10#include "md.h" 11#include "md.h"
11#include "raid1.h" 12#include "raid1.h"
@@ -1017,30 +1018,56 @@ static int raid_status(struct dm_target *ti, status_type_t type,
1017 struct raid_set *rs = ti->private; 1018 struct raid_set *rs = ti->private;
1018 unsigned raid_param_cnt = 1; /* at least 1 for chunksize */ 1019 unsigned raid_param_cnt = 1; /* at least 1 for chunksize */
1019 unsigned sz = 0; 1020 unsigned sz = 0;
1020 int i; 1021 int i, array_in_sync = 0;
1021 sector_t sync; 1022 sector_t sync;
1022 1023
1023 switch (type) { 1024 switch (type) {
1024 case STATUSTYPE_INFO: 1025 case STATUSTYPE_INFO:
1025 DMEMIT("%s %d ", rs->raid_type->name, rs->md.raid_disks); 1026 DMEMIT("%s %d ", rs->raid_type->name, rs->md.raid_disks);
1026 1027
1027 for (i = 0; i < rs->md.raid_disks; i++) {
1028 if (test_bit(Faulty, &rs->dev[i].rdev.flags))
1029 DMEMIT("D");
1030 else if (test_bit(In_sync, &rs->dev[i].rdev.flags))
1031 DMEMIT("A");
1032 else
1033 DMEMIT("a");
1034 }
1035
1036 if (test_bit(MD_RECOVERY_RUNNING, &rs->md.recovery)) 1028 if (test_bit(MD_RECOVERY_RUNNING, &rs->md.recovery))
1037 sync = rs->md.curr_resync_completed; 1029 sync = rs->md.curr_resync_completed;
1038 else 1030 else
1039 sync = rs->md.recovery_cp; 1031 sync = rs->md.recovery_cp;
1040 1032
1041 if (sync > rs->md.resync_max_sectors) 1033 if (sync >= rs->md.resync_max_sectors) {
1034 array_in_sync = 1;
1042 sync = rs->md.resync_max_sectors; 1035 sync = rs->md.resync_max_sectors;
1036 } else {
1037 /*
1038 * The array may be doing an initial sync, or it may
1039 * be rebuilding individual components. If all the
1040 * devices are In_sync, then it is the array that is
1041 * being initialized.
1042 */
1043 for (i = 0; i < rs->md.raid_disks; i++)
1044 if (!test_bit(In_sync, &rs->dev[i].rdev.flags))
1045 array_in_sync = 1;
1046 }
1047 /*
1048 * Status characters:
1049 * 'D' = Dead/Failed device
1050 * 'a' = Alive but not in-sync
1051 * 'A' = Alive and in-sync
1052 */
1053 for (i = 0; i < rs->md.raid_disks; i++) {
1054 if (test_bit(Faulty, &rs->dev[i].rdev.flags))
1055 DMEMIT("D");
1056 else if (!array_in_sync ||
1057 !test_bit(In_sync, &rs->dev[i].rdev.flags))
1058 DMEMIT("a");
1059 else
1060 DMEMIT("A");
1061 }
1043 1062
1063 /*
1064 * In-sync ratio:
1065 * The in-sync ratio shows the progress of:
1066 * - Initializing the array
1067 * - Rebuilding a subset of devices of the array
1068 * The user can distinguish between the two by referring
1069 * to the status characters.
1070 */
1044 DMEMIT(" %llu/%llu", 1071 DMEMIT(" %llu/%llu",
1045 (unsigned long long) sync, 1072 (unsigned long long) sync,
1046 (unsigned long long) rs->md.resync_max_sectors); 1073 (unsigned long long) rs->md.resync_max_sectors);
diff --git a/drivers/md/dm-round-robin.c b/drivers/md/dm-round-robin.c
index 24752f449bef..27f1d423b76c 100644
--- a/drivers/md/dm-round-robin.c
+++ b/drivers/md/dm-round-robin.c
@@ -14,6 +14,7 @@
14#include "dm-path-selector.h" 14#include "dm-path-selector.h"
15 15
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <linux/module.h>
17 18
18#define DM_MSG_PREFIX "multipath round-robin" 19#define DM_MSG_PREFIX "multipath round-robin"
19 20
diff --git a/drivers/md/dm-service-time.c b/drivers/md/dm-service-time.c
index 9c6c2e47ad62..59883bd78214 100644
--- a/drivers/md/dm-service-time.c
+++ b/drivers/md/dm-service-time.c
@@ -12,6 +12,7 @@
12#include "dm-path-selector.h" 12#include "dm-path-selector.h"
13 13
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/module.h>
15 16
16#define DM_MSG_PREFIX "multipath service-time" 17#define DM_MSG_PREFIX "multipath service-time"
17#define ST_MIN_IO 1 18#define ST_MIN_IO 1
diff --git a/drivers/md/dm-snap-persistent.c b/drivers/md/dm-snap-persistent.c
index d1f1d7017103..3ac415675b6c 100644
--- a/drivers/md/dm-snap-persistent.c
+++ b/drivers/md/dm-snap-persistent.c
@@ -10,6 +10,7 @@
10#include <linux/mm.h> 10#include <linux/mm.h>
11#include <linux/pagemap.h> 11#include <linux/pagemap.h>
12#include <linux/vmalloc.h> 12#include <linux/vmalloc.h>
13#include <linux/export.h>
13#include <linux/slab.h> 14#include <linux/slab.h>
14#include <linux/dm-io.h> 15#include <linux/dm-io.h>
15 16
diff --git a/drivers/md/dm-snap-transient.c b/drivers/md/dm-snap-transient.c
index a0898a66a2f8..1ce9a2586e41 100644
--- a/drivers/md/dm-snap-transient.c
+++ b/drivers/md/dm-snap-transient.c
@@ -10,6 +10,7 @@
10#include <linux/mm.h> 10#include <linux/mm.h>
11#include <linux/pagemap.h> 11#include <linux/pagemap.h>
12#include <linux/vmalloc.h> 12#include <linux/vmalloc.h>
13#include <linux/export.h>
13#include <linux/slab.h> 14#include <linux/slab.h>
14#include <linux/dm-io.h> 15#include <linux/dm-io.h>
15 16
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index bc04518e9d8b..8e9132130142 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -54,7 +54,9 @@ struct dm_table {
54 sector_t *highs; 54 sector_t *highs;
55 struct dm_target *targets; 55 struct dm_target *targets;
56 56
57 struct target_type *immutable_target_type;
57 unsigned integrity_supported:1; 58 unsigned integrity_supported:1;
59 unsigned singleton:1;
58 60
59 /* 61 /*
60 * Indicates the rw permissions for the new logical 62 * Indicates the rw permissions for the new logical
@@ -740,6 +742,12 @@ int dm_table_add_target(struct dm_table *t, const char *type,
740 char **argv; 742 char **argv;
741 struct dm_target *tgt; 743 struct dm_target *tgt;
742 744
745 if (t->singleton) {
746 DMERR("%s: target type %s must appear alone in table",
747 dm_device_name(t->md), t->targets->type->name);
748 return -EINVAL;
749 }
750
743 if ((r = check_space(t))) 751 if ((r = check_space(t)))
744 return r; 752 return r;
745 753
@@ -758,6 +766,36 @@ int dm_table_add_target(struct dm_table *t, const char *type,
758 return -EINVAL; 766 return -EINVAL;
759 } 767 }
760 768
769 if (dm_target_needs_singleton(tgt->type)) {
770 if (t->num_targets) {
771 DMERR("%s: target type %s must appear alone in table",
772 dm_device_name(t->md), type);
773 return -EINVAL;
774 }
775 t->singleton = 1;
776 }
777
778 if (dm_target_always_writeable(tgt->type) && !(t->mode & FMODE_WRITE)) {
779 DMERR("%s: target type %s may not be included in read-only tables",
780 dm_device_name(t->md), type);
781 return -EINVAL;
782 }
783
784 if (t->immutable_target_type) {
785 if (t->immutable_target_type != tgt->type) {
786 DMERR("%s: immutable target type %s cannot be mixed with other target types",
787 dm_device_name(t->md), t->immutable_target_type->name);
788 return -EINVAL;
789 }
790 } else if (dm_target_is_immutable(tgt->type)) {
791 if (t->num_targets) {
792 DMERR("%s: immutable target type %s cannot be mixed with other target types",
793 dm_device_name(t->md), tgt->type->name);
794 return -EINVAL;
795 }
796 t->immutable_target_type = tgt->type;
797 }
798
761 tgt->table = t; 799 tgt->table = t;
762 tgt->begin = start; 800 tgt->begin = start;
763 tgt->len = len; 801 tgt->len = len;
@@ -915,6 +953,11 @@ unsigned dm_table_get_type(struct dm_table *t)
915 return t->type; 953 return t->type;
916} 954}
917 955
956struct target_type *dm_table_get_immutable_target_type(struct dm_table *t)
957{
958 return t->immutable_target_type;
959}
960
918bool dm_table_request_based(struct dm_table *t) 961bool dm_table_request_based(struct dm_table *t)
919{ 962{
920 return dm_table_get_type(t) == DM_TYPE_REQUEST_BASED; 963 return dm_table_get_type(t) == DM_TYPE_REQUEST_BASED;
@@ -1299,6 +1342,31 @@ static bool dm_table_discard_zeroes_data(struct dm_table *t)
1299 return 1; 1342 return 1;
1300} 1343}
1301 1344
1345static int device_is_nonrot(struct dm_target *ti, struct dm_dev *dev,
1346 sector_t start, sector_t len, void *data)
1347{
1348 struct request_queue *q = bdev_get_queue(dev->bdev);
1349
1350 return q && blk_queue_nonrot(q);
1351}
1352
1353static bool dm_table_is_nonrot(struct dm_table *t)
1354{
1355 struct dm_target *ti;
1356 unsigned i = 0;
1357
1358 /* Ensure that all underlying device are non-rotational. */
1359 while (i < dm_table_get_num_targets(t)) {
1360 ti = dm_table_get_target(t, i++);
1361
1362 if (!ti->type->iterate_devices ||
1363 !ti->type->iterate_devices(ti, device_is_nonrot, NULL))
1364 return 0;
1365 }
1366
1367 return 1;
1368}
1369
1302void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q, 1370void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
1303 struct queue_limits *limits) 1371 struct queue_limits *limits)
1304{ 1372{
@@ -1324,6 +1392,11 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
1324 if (!dm_table_discard_zeroes_data(t)) 1392 if (!dm_table_discard_zeroes_data(t))
1325 q->limits.discard_zeroes_data = 0; 1393 q->limits.discard_zeroes_data = 0;
1326 1394
1395 if (dm_table_is_nonrot(t))
1396 queue_flag_set_unlocked(QUEUE_FLAG_NONROT, q);
1397 else
1398 queue_flag_clear_unlocked(QUEUE_FLAG_NONROT, q);
1399
1327 dm_table_set_integrity(t); 1400 dm_table_set_integrity(t);
1328 1401
1329 /* 1402 /*
diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
new file mode 100644
index 000000000000..59c4f0446ffa
--- /dev/null
+++ b/drivers/md/dm-thin-metadata.c
@@ -0,0 +1,1391 @@
1/*
2 * Copyright (C) 2011 Red Hat, Inc.
3 *
4 * This file is released under the GPL.
5 */
6
7#include "dm-thin-metadata.h"
8#include "persistent-data/dm-btree.h"
9#include "persistent-data/dm-space-map.h"
10#include "persistent-data/dm-space-map-disk.h"
11#include "persistent-data/dm-transaction-manager.h"
12
13#include <linux/list.h>
14#include <linux/device-mapper.h>
15#include <linux/workqueue.h>
16
17/*--------------------------------------------------------------------------
18 * As far as the metadata goes, there is:
19 *
20 * - A superblock in block zero, taking up fewer than 512 bytes for
21 * atomic writes.
22 *
23 * - A space map managing the metadata blocks.
24 *
25 * - A space map managing the data blocks.
26 *
27 * - A btree mapping our internal thin dev ids onto struct disk_device_details.
28 *
29 * - A hierarchical btree, with 2 levels which effectively maps (thin
30 * dev id, virtual block) -> block_time. Block time is a 64-bit
31 * field holding the time in the low 24 bits, and block in the top 48
32 * bits.
33 *
34 * BTrees consist solely of btree_nodes, that fill a block. Some are
35 * internal nodes, as such their values are a __le64 pointing to other
36 * nodes. Leaf nodes can store data of any reasonable size (ie. much
37 * smaller than the block size). The nodes consist of the header,
38 * followed by an array of keys, followed by an array of values. We have
39 * to binary search on the keys so they're all held together to help the
40 * cpu cache.
41 *
42 * Space maps have 2 btrees:
43 *
44 * - One maps a uint64_t onto a struct index_entry. Which points to a
45 * bitmap block, and has some details about how many free entries there
46 * are etc.
47 *
48 * - The bitmap blocks have a header (for the checksum). Then the rest
49 * of the block is pairs of bits. With the meaning being:
50 *
51 * 0 - ref count is 0
52 * 1 - ref count is 1
53 * 2 - ref count is 2
54 * 3 - ref count is higher than 2
55 *
56 * - If the count is higher than 2 then the ref count is entered in a
57 * second btree that directly maps the block_address to a uint32_t ref
58 * count.
59 *
60 * The space map metadata variant doesn't have a bitmaps btree. Instead
61 * it has one single blocks worth of index_entries. This avoids
62 * recursive issues with the bitmap btree needing to allocate space in
63 * order to insert. With a small data block size such as 64k the
64 * metadata support data devices that are hundreds of terrabytes.
65 *
66 * The space maps allocate space linearly from front to back. Space that
67 * is freed in a transaction is never recycled within that transaction.
68 * To try and avoid fragmenting _free_ space the allocator always goes
69 * back and fills in gaps.
70 *
71 * All metadata io is in THIN_METADATA_BLOCK_SIZE sized/aligned chunks
72 * from the block manager.
73 *--------------------------------------------------------------------------*/
74
75#define DM_MSG_PREFIX "thin metadata"
76
77#define THIN_SUPERBLOCK_MAGIC 27022010
78#define THIN_SUPERBLOCK_LOCATION 0
79#define THIN_VERSION 1
80#define THIN_METADATA_CACHE_SIZE 64
81#define SECTOR_TO_BLOCK_SHIFT 3
82
83/* This should be plenty */
84#define SPACE_MAP_ROOT_SIZE 128
85
86/*
87 * Little endian on-disk superblock and device details.
88 */
89struct thin_disk_superblock {
90 __le32 csum; /* Checksum of superblock except for this field. */
91 __le32 flags;
92 __le64 blocknr; /* This block number, dm_block_t. */
93
94 __u8 uuid[16];
95 __le64 magic;
96 __le32 version;
97 __le32 time;
98
99 __le64 trans_id;
100
101 /*
102 * Root held by userspace transactions.
103 */
104 __le64 held_root;
105
106 __u8 data_space_map_root[SPACE_MAP_ROOT_SIZE];
107 __u8 metadata_space_map_root[SPACE_MAP_ROOT_SIZE];
108
109 /*
110 * 2-level btree mapping (dev_id, (dev block, time)) -> data block
111 */
112 __le64 data_mapping_root;
113
114 /*
115 * Device detail root mapping dev_id -> device_details
116 */
117 __le64 device_details_root;
118
119 __le32 data_block_size; /* In 512-byte sectors. */
120
121 __le32 metadata_block_size; /* In 512-byte sectors. */
122 __le64 metadata_nr_blocks;
123
124 __le32 compat_flags;
125 __le32 compat_ro_flags;
126 __le32 incompat_flags;
127} __packed;
128
129struct disk_device_details {
130 __le64 mapped_blocks;
131 __le64 transaction_id; /* When created. */
132 __le32 creation_time;
133 __le32 snapshotted_time;
134} __packed;
135
136struct dm_pool_metadata {
137 struct hlist_node hash;
138
139 struct block_device *bdev;
140 struct dm_block_manager *bm;
141 struct dm_space_map *metadata_sm;
142 struct dm_space_map *data_sm;
143 struct dm_transaction_manager *tm;
144 struct dm_transaction_manager *nb_tm;
145
146 /*
147 * Two-level btree.
148 * First level holds thin_dev_t.
149 * Second level holds mappings.
150 */
151 struct dm_btree_info info;
152
153 /*
154 * Non-blocking version of the above.
155 */
156 struct dm_btree_info nb_info;
157
158 /*
159 * Just the top level for deleting whole devices.
160 */
161 struct dm_btree_info tl_info;
162
163 /*
164 * Just the bottom level for creating new devices.
165 */
166 struct dm_btree_info bl_info;
167
168 /*
169 * Describes the device details btree.
170 */
171 struct dm_btree_info details_info;
172
173 struct rw_semaphore root_lock;
174 uint32_t time;
175 int need_commit;
176 dm_block_t root;
177 dm_block_t details_root;
178 struct list_head thin_devices;
179 uint64_t trans_id;
180 unsigned long flags;
181 sector_t data_block_size;
182};
183
184struct dm_thin_device {
185 struct list_head list;
186 struct dm_pool_metadata *pmd;
187 dm_thin_id id;
188
189 int open_count;
190 int changed;
191 uint64_t mapped_blocks;
192 uint64_t transaction_id;
193 uint32_t creation_time;
194 uint32_t snapshotted_time;
195};
196
197/*----------------------------------------------------------------
198 * superblock validator
199 *--------------------------------------------------------------*/
200
201#define SUPERBLOCK_CSUM_XOR 160774
202
203static void sb_prepare_for_write(struct dm_block_validator *v,
204 struct dm_block *b,
205 size_t block_size)
206{
207 struct thin_disk_superblock *disk_super = dm_block_data(b);
208
209 disk_super->blocknr = cpu_to_le64(dm_block_location(b));
210 disk_super->csum = cpu_to_le32(dm_bm_checksum(&disk_super->flags,
211 block_size - sizeof(__le32),
212 SUPERBLOCK_CSUM_XOR));
213}
214
215static int sb_check(struct dm_block_validator *v,
216 struct dm_block *b,
217 size_t block_size)
218{
219 struct thin_disk_superblock *disk_super = dm_block_data(b);
220 __le32 csum_le;
221
222 if (dm_block_location(b) != le64_to_cpu(disk_super->blocknr)) {
223 DMERR("sb_check failed: blocknr %llu: "
224 "wanted %llu", le64_to_cpu(disk_super->blocknr),
225 (unsigned long long)dm_block_location(b));
226 return -ENOTBLK;
227 }
228
229 if (le64_to_cpu(disk_super->magic) != THIN_SUPERBLOCK_MAGIC) {
230 DMERR("sb_check failed: magic %llu: "
231 "wanted %llu", le64_to_cpu(disk_super->magic),
232 (unsigned long long)THIN_SUPERBLOCK_MAGIC);
233 return -EILSEQ;
234 }
235
236 csum_le = cpu_to_le32(dm_bm_checksum(&disk_super->flags,
237 block_size - sizeof(__le32),
238 SUPERBLOCK_CSUM_XOR));
239 if (csum_le != disk_super->csum) {
240 DMERR("sb_check failed: csum %u: wanted %u",
241 le32_to_cpu(csum_le), le32_to_cpu(disk_super->csum));
242 return -EILSEQ;
243 }
244
245 return 0;
246}
247
248static struct dm_block_validator sb_validator = {
249 .name = "superblock",
250 .prepare_for_write = sb_prepare_for_write,
251 .check = sb_check
252};
253
254/*----------------------------------------------------------------
255 * Methods for the btree value types
256 *--------------------------------------------------------------*/
257
258static uint64_t pack_block_time(dm_block_t b, uint32_t t)
259{
260 return (b << 24) | t;
261}
262
263static void unpack_block_time(uint64_t v, dm_block_t *b, uint32_t *t)
264{
265 *b = v >> 24;
266 *t = v & ((1 << 24) - 1);
267}
268
269static void data_block_inc(void *context, void *value_le)
270{
271 struct dm_space_map *sm = context;
272 __le64 v_le;
273 uint64_t b;
274 uint32_t t;
275
276 memcpy(&v_le, value_le, sizeof(v_le));
277 unpack_block_time(le64_to_cpu(v_le), &b, &t);
278 dm_sm_inc_block(sm, b);
279}
280
281static void data_block_dec(void *context, void *value_le)
282{
283 struct dm_space_map *sm = context;
284 __le64 v_le;
285 uint64_t b;
286 uint32_t t;
287
288 memcpy(&v_le, value_le, sizeof(v_le));
289 unpack_block_time(le64_to_cpu(v_le), &b, &t);
290 dm_sm_dec_block(sm, b);
291}
292
293static int data_block_equal(void *context, void *value1_le, void *value2_le)
294{
295 __le64 v1_le, v2_le;
296 uint64_t b1, b2;
297 uint32_t t;
298
299 memcpy(&v1_le, value1_le, sizeof(v1_le));
300 memcpy(&v2_le, value2_le, sizeof(v2_le));
301 unpack_block_time(le64_to_cpu(v1_le), &b1, &t);
302 unpack_block_time(le64_to_cpu(v2_le), &b2, &t);
303
304 return b1 == b2;
305}
306
307static void subtree_inc(void *context, void *value)
308{
309 struct dm_btree_info *info = context;
310 __le64 root_le;
311 uint64_t root;
312
313 memcpy(&root_le, value, sizeof(root_le));
314 root = le64_to_cpu(root_le);
315 dm_tm_inc(info->tm, root);
316}
317
318static void subtree_dec(void *context, void *value)
319{
320 struct dm_btree_info *info = context;
321 __le64 root_le;
322 uint64_t root;
323
324 memcpy(&root_le, value, sizeof(root_le));
325 root = le64_to_cpu(root_le);
326 if (dm_btree_del(info, root))
327 DMERR("btree delete failed\n");
328}
329
330static int subtree_equal(void *context, void *value1_le, void *value2_le)
331{
332 __le64 v1_le, v2_le;
333 memcpy(&v1_le, value1_le, sizeof(v1_le));
334 memcpy(&v2_le, value2_le, sizeof(v2_le));
335
336 return v1_le == v2_le;
337}
338
339/*----------------------------------------------------------------*/
340
341static int superblock_all_zeroes(struct dm_block_manager *bm, int *result)
342{
343 int r;
344 unsigned i;
345 struct dm_block *b;
346 __le64 *data_le, zero = cpu_to_le64(0);
347 unsigned block_size = dm_bm_block_size(bm) / sizeof(__le64);
348
349 /*
350 * We can't use a validator here - it may be all zeroes.
351 */
352 r = dm_bm_read_lock(bm, THIN_SUPERBLOCK_LOCATION, NULL, &b);
353 if (r)
354 return r;
355
356 data_le = dm_block_data(b);
357 *result = 1;
358 for (i = 0; i < block_size; i++) {
359 if (data_le[i] != zero) {
360 *result = 0;
361 break;
362 }
363 }
364
365 return dm_bm_unlock(b);
366}
367
368static int init_pmd(struct dm_pool_metadata *pmd,
369 struct dm_block_manager *bm,
370 dm_block_t nr_blocks, int create)
371{
372 int r;
373 struct dm_space_map *sm, *data_sm;
374 struct dm_transaction_manager *tm;
375 struct dm_block *sblock;
376
377 if (create) {
378 r = dm_tm_create_with_sm(bm, THIN_SUPERBLOCK_LOCATION,
379 &sb_validator, &tm, &sm, &sblock);
380 if (r < 0) {
381 DMERR("tm_create_with_sm failed");
382 return r;
383 }
384
385 data_sm = dm_sm_disk_create(tm, nr_blocks);
386 if (IS_ERR(data_sm)) {
387 DMERR("sm_disk_create failed");
388 r = PTR_ERR(data_sm);
389 goto bad;
390 }
391 } else {
392 struct thin_disk_superblock *disk_super = NULL;
393 size_t space_map_root_offset =
394 offsetof(struct thin_disk_superblock, metadata_space_map_root);
395
396 r = dm_tm_open_with_sm(bm, THIN_SUPERBLOCK_LOCATION,
397 &sb_validator, space_map_root_offset,
398 SPACE_MAP_ROOT_SIZE, &tm, &sm, &sblock);
399 if (r < 0) {
400 DMERR("tm_open_with_sm failed");
401 return r;
402 }
403
404 disk_super = dm_block_data(sblock);
405 data_sm = dm_sm_disk_open(tm, disk_super->data_space_map_root,
406 sizeof(disk_super->data_space_map_root));
407 if (IS_ERR(data_sm)) {
408 DMERR("sm_disk_open failed");
409 r = PTR_ERR(data_sm);
410 goto bad;
411 }
412 }
413
414
415 r = dm_tm_unlock(tm, sblock);
416 if (r < 0) {
417 DMERR("couldn't unlock superblock");
418 goto bad_data_sm;
419 }
420
421 pmd->bm = bm;
422 pmd->metadata_sm = sm;
423 pmd->data_sm = data_sm;
424 pmd->tm = tm;
425 pmd->nb_tm = dm_tm_create_non_blocking_clone(tm);
426 if (!pmd->nb_tm) {
427 DMERR("could not create clone tm");
428 r = -ENOMEM;
429 goto bad_data_sm;
430 }
431
432 pmd->info.tm = tm;
433 pmd->info.levels = 2;
434 pmd->info.value_type.context = pmd->data_sm;
435 pmd->info.value_type.size = sizeof(__le64);
436 pmd->info.value_type.inc = data_block_inc;
437 pmd->info.value_type.dec = data_block_dec;
438 pmd->info.value_type.equal = data_block_equal;
439
440 memcpy(&pmd->nb_info, &pmd->info, sizeof(pmd->nb_info));
441 pmd->nb_info.tm = pmd->nb_tm;
442
443 pmd->tl_info.tm = tm;
444 pmd->tl_info.levels = 1;
445 pmd->tl_info.value_type.context = &pmd->info;
446 pmd->tl_info.value_type.size = sizeof(__le64);
447 pmd->tl_info.value_type.inc = subtree_inc;
448 pmd->tl_info.value_type.dec = subtree_dec;
449 pmd->tl_info.value_type.equal = subtree_equal;
450
451 pmd->bl_info.tm = tm;
452 pmd->bl_info.levels = 1;
453 pmd->bl_info.value_type.context = pmd->data_sm;
454 pmd->bl_info.value_type.size = sizeof(__le64);
455 pmd->bl_info.value_type.inc = data_block_inc;
456 pmd->bl_info.value_type.dec = data_block_dec;
457 pmd->bl_info.value_type.equal = data_block_equal;
458
459 pmd->details_info.tm = tm;
460 pmd->details_info.levels = 1;
461 pmd->details_info.value_type.context = NULL;
462 pmd->details_info.value_type.size = sizeof(struct disk_device_details);
463 pmd->details_info.value_type.inc = NULL;
464 pmd->details_info.value_type.dec = NULL;
465 pmd->details_info.value_type.equal = NULL;
466
467 pmd->root = 0;
468
469 init_rwsem(&pmd->root_lock);
470 pmd->time = 0;
471 pmd->need_commit = 0;
472 pmd->details_root = 0;
473 pmd->trans_id = 0;
474 pmd->flags = 0;
475 INIT_LIST_HEAD(&pmd->thin_devices);
476
477 return 0;
478
479bad_data_sm:
480 dm_sm_destroy(data_sm);
481bad:
482 dm_tm_destroy(tm);
483 dm_sm_destroy(sm);
484
485 return r;
486}
487
488static int __begin_transaction(struct dm_pool_metadata *pmd)
489{
490 int r;
491 u32 features;
492 struct thin_disk_superblock *disk_super;
493 struct dm_block *sblock;
494
495 /*
496 * __maybe_commit_transaction() resets these
497 */
498 WARN_ON(pmd->need_commit);
499
500 /*
501 * We re-read the superblock every time. Shouldn't need to do this
502 * really.
503 */
504 r = dm_bm_read_lock(pmd->bm, THIN_SUPERBLOCK_LOCATION,
505 &sb_validator, &sblock);
506 if (r)
507 return r;
508
509 disk_super = dm_block_data(sblock);
510 pmd->time = le32_to_cpu(disk_super->time);
511 pmd->root = le64_to_cpu(disk_super->data_mapping_root);
512 pmd->details_root = le64_to_cpu(disk_super->device_details_root);
513 pmd->trans_id = le64_to_cpu(disk_super->trans_id);
514 pmd->flags = le32_to_cpu(disk_super->flags);
515 pmd->data_block_size = le32_to_cpu(disk_super->data_block_size);
516
517 features = le32_to_cpu(disk_super->incompat_flags) & ~THIN_FEATURE_INCOMPAT_SUPP;
518 if (features) {
519 DMERR("could not access metadata due to "
520 "unsupported optional features (%lx).",
521 (unsigned long)features);
522 r = -EINVAL;
523 goto out;
524 }
525
526 /*
527 * Check for read-only metadata to skip the following RDWR checks.
528 */
529 if (get_disk_ro(pmd->bdev->bd_disk))
530 goto out;
531
532 features = le32_to_cpu(disk_super->compat_ro_flags) & ~THIN_FEATURE_COMPAT_RO_SUPP;
533 if (features) {
534 DMERR("could not access metadata RDWR due to "
535 "unsupported optional features (%lx).",
536 (unsigned long)features);
537 r = -EINVAL;
538 }
539
540out:
541 dm_bm_unlock(sblock);
542 return r;
543}
544
545static int __write_changed_details(struct dm_pool_metadata *pmd)
546{
547 int r;
548 struct dm_thin_device *td, *tmp;
549 struct disk_device_details details;
550 uint64_t key;
551
552 list_for_each_entry_safe(td, tmp, &pmd->thin_devices, list) {
553 if (!td->changed)
554 continue;
555
556 key = td->id;
557
558 details.mapped_blocks = cpu_to_le64(td->mapped_blocks);
559 details.transaction_id = cpu_to_le64(td->transaction_id);
560 details.creation_time = cpu_to_le32(td->creation_time);
561 details.snapshotted_time = cpu_to_le32(td->snapshotted_time);
562 __dm_bless_for_disk(&details);
563
564 r = dm_btree_insert(&pmd->details_info, pmd->details_root,
565 &key, &details, &pmd->details_root);
566 if (r)
567 return r;
568
569 if (td->open_count)
570 td->changed = 0;
571 else {
572 list_del(&td->list);
573 kfree(td);
574 }
575
576 pmd->need_commit = 1;
577 }
578
579 return 0;
580}
581
582static int __commit_transaction(struct dm_pool_metadata *pmd)
583{
584 /*
585 * FIXME: Associated pool should be made read-only on failure.
586 */
587 int r;
588 size_t metadata_len, data_len;
589 struct thin_disk_superblock *disk_super;
590 struct dm_block *sblock;
591
592 /*
593 * We need to know if the thin_disk_superblock exceeds a 512-byte sector.
594 */
595 BUILD_BUG_ON(sizeof(struct thin_disk_superblock) > 512);
596
597 r = __write_changed_details(pmd);
598 if (r < 0)
599 goto out;
600
601 if (!pmd->need_commit)
602 goto out;
603
604 r = dm_sm_commit(pmd->data_sm);
605 if (r < 0)
606 goto out;
607
608 r = dm_tm_pre_commit(pmd->tm);
609 if (r < 0)
610 goto out;
611
612 r = dm_sm_root_size(pmd->metadata_sm, &metadata_len);
613 if (r < 0)
614 goto out;
615
616 r = dm_sm_root_size(pmd->metadata_sm, &data_len);
617 if (r < 0)
618 goto out;
619
620 r = dm_bm_write_lock(pmd->bm, THIN_SUPERBLOCK_LOCATION,
621 &sb_validator, &sblock);
622 if (r)
623 goto out;
624
625 disk_super = dm_block_data(sblock);
626 disk_super->time = cpu_to_le32(pmd->time);
627 disk_super->data_mapping_root = cpu_to_le64(pmd->root);
628 disk_super->device_details_root = cpu_to_le64(pmd->details_root);
629 disk_super->trans_id = cpu_to_le64(pmd->trans_id);
630 disk_super->flags = cpu_to_le32(pmd->flags);
631
632 r = dm_sm_copy_root(pmd->metadata_sm, &disk_super->metadata_space_map_root,
633 metadata_len);
634 if (r < 0)
635 goto out_locked;
636
637 r = dm_sm_copy_root(pmd->data_sm, &disk_super->data_space_map_root,
638 data_len);
639 if (r < 0)
640 goto out_locked;
641
642 r = dm_tm_commit(pmd->tm, sblock);
643 if (!r)
644 pmd->need_commit = 0;
645
646out:
647 return r;
648
649out_locked:
650 dm_bm_unlock(sblock);
651 return r;
652}
653
654struct dm_pool_metadata *dm_pool_metadata_open(struct block_device *bdev,
655 sector_t data_block_size)
656{
657 int r;
658 struct thin_disk_superblock *disk_super;
659 struct dm_pool_metadata *pmd;
660 sector_t bdev_size = i_size_read(bdev->bd_inode) >> SECTOR_SHIFT;
661 struct dm_block_manager *bm;
662 int create;
663 struct dm_block *sblock;
664
665 pmd = kmalloc(sizeof(*pmd), GFP_KERNEL);
666 if (!pmd) {
667 DMERR("could not allocate metadata struct");
668 return ERR_PTR(-ENOMEM);
669 }
670
671 /*
672 * Max hex locks:
673 * 3 for btree insert +
674 * 2 for btree lookup used within space map
675 */
676 bm = dm_block_manager_create(bdev, THIN_METADATA_BLOCK_SIZE,
677 THIN_METADATA_CACHE_SIZE, 5);
678 if (!bm) {
679 DMERR("could not create block manager");
680 kfree(pmd);
681 return ERR_PTR(-ENOMEM);
682 }
683
684 r = superblock_all_zeroes(bm, &create);
685 if (r) {
686 dm_block_manager_destroy(bm);
687 kfree(pmd);
688 return ERR_PTR(r);
689 }
690
691
692 r = init_pmd(pmd, bm, 0, create);
693 if (r) {
694 dm_block_manager_destroy(bm);
695 kfree(pmd);
696 return ERR_PTR(r);
697 }
698 pmd->bdev = bdev;
699
700 if (!create) {
701 r = __begin_transaction(pmd);
702 if (r < 0)
703 goto bad;
704 return pmd;
705 }
706
707 /*
708 * Create.
709 */
710 r = dm_bm_write_lock(pmd->bm, THIN_SUPERBLOCK_LOCATION,
711 &sb_validator, &sblock);
712 if (r)
713 goto bad;
714
715 disk_super = dm_block_data(sblock);
716 disk_super->magic = cpu_to_le64(THIN_SUPERBLOCK_MAGIC);
717 disk_super->version = cpu_to_le32(THIN_VERSION);
718 disk_super->time = 0;
719 disk_super->metadata_block_size = cpu_to_le32(THIN_METADATA_BLOCK_SIZE >> SECTOR_SHIFT);
720 disk_super->metadata_nr_blocks = cpu_to_le64(bdev_size >> SECTOR_TO_BLOCK_SHIFT);
721 disk_super->data_block_size = cpu_to_le32(data_block_size);
722
723 r = dm_bm_unlock(sblock);
724 if (r < 0)
725 goto bad;
726
727 r = dm_btree_empty(&pmd->info, &pmd->root);
728 if (r < 0)
729 goto bad;
730
731 r = dm_btree_empty(&pmd->details_info, &pmd->details_root);
732 if (r < 0) {
733 DMERR("couldn't create devices root");
734 goto bad;
735 }
736
737 pmd->flags = 0;
738 pmd->need_commit = 1;
739 r = dm_pool_commit_metadata(pmd);
740 if (r < 0) {
741 DMERR("%s: dm_pool_commit_metadata() failed, error = %d",
742 __func__, r);
743 goto bad;
744 }
745
746 return pmd;
747
748bad:
749 if (dm_pool_metadata_close(pmd) < 0)
750 DMWARN("%s: dm_pool_metadata_close() failed.", __func__);
751 return ERR_PTR(r);
752}
753
754int dm_pool_metadata_close(struct dm_pool_metadata *pmd)
755{
756 int r;
757 unsigned open_devices = 0;
758 struct dm_thin_device *td, *tmp;
759
760 down_read(&pmd->root_lock);
761 list_for_each_entry_safe(td, tmp, &pmd->thin_devices, list) {
762 if (td->open_count)
763 open_devices++;
764 else {
765 list_del(&td->list);
766 kfree(td);
767 }
768 }
769 up_read(&pmd->root_lock);
770
771 if (open_devices) {
772 DMERR("attempt to close pmd when %u device(s) are still open",
773 open_devices);
774 return -EBUSY;
775 }
776
777 r = __commit_transaction(pmd);
778 if (r < 0)
779 DMWARN("%s: __commit_transaction() failed, error = %d",
780 __func__, r);
781
782 dm_tm_destroy(pmd->tm);
783 dm_tm_destroy(pmd->nb_tm);
784 dm_block_manager_destroy(pmd->bm);
785 dm_sm_destroy(pmd->metadata_sm);
786 dm_sm_destroy(pmd->data_sm);
787 kfree(pmd);
788
789 return 0;
790}
791
792static int __open_device(struct dm_pool_metadata *pmd,
793 dm_thin_id dev, int create,
794 struct dm_thin_device **td)
795{
796 int r, changed = 0;
797 struct dm_thin_device *td2;
798 uint64_t key = dev;
799 struct disk_device_details details_le;
800
801 /*
802 * Check the device isn't already open.
803 */
804 list_for_each_entry(td2, &pmd->thin_devices, list)
805 if (td2->id == dev) {
806 td2->open_count++;
807 *td = td2;
808 return 0;
809 }
810
811 /*
812 * Check the device exists.
813 */
814 r = dm_btree_lookup(&pmd->details_info, pmd->details_root,
815 &key, &details_le);
816 if (r) {
817 if (r != -ENODATA || !create)
818 return r;
819
820 changed = 1;
821 details_le.mapped_blocks = 0;
822 details_le.transaction_id = cpu_to_le64(pmd->trans_id);
823 details_le.creation_time = cpu_to_le32(pmd->time);
824 details_le.snapshotted_time = cpu_to_le32(pmd->time);
825 }
826
827 *td = kmalloc(sizeof(**td), GFP_NOIO);
828 if (!*td)
829 return -ENOMEM;
830
831 (*td)->pmd = pmd;
832 (*td)->id = dev;
833 (*td)->open_count = 1;
834 (*td)->changed = changed;
835 (*td)->mapped_blocks = le64_to_cpu(details_le.mapped_blocks);
836 (*td)->transaction_id = le64_to_cpu(details_le.transaction_id);
837 (*td)->creation_time = le32_to_cpu(details_le.creation_time);
838 (*td)->snapshotted_time = le32_to_cpu(details_le.snapshotted_time);
839
840 list_add(&(*td)->list, &pmd->thin_devices);
841
842 return 0;
843}
844
845static void __close_device(struct dm_thin_device *td)
846{
847 --td->open_count;
848}
849
850static int __create_thin(struct dm_pool_metadata *pmd,
851 dm_thin_id dev)
852{
853 int r;
854 dm_block_t dev_root;
855 uint64_t key = dev;
856 struct disk_device_details details_le;
857 struct dm_thin_device *td;
858 __le64 value;
859
860 r = dm_btree_lookup(&pmd->details_info, pmd->details_root,
861 &key, &details_le);
862 if (!r)
863 return -EEXIST;
864
865 /*
866 * Create an empty btree for the mappings.
867 */
868 r = dm_btree_empty(&pmd->bl_info, &dev_root);
869 if (r)
870 return r;
871
872 /*
873 * Insert it into the main mapping tree.
874 */
875 value = cpu_to_le64(dev_root);
876 __dm_bless_for_disk(&value);
877 r = dm_btree_insert(&pmd->tl_info, pmd->root, &key, &value, &pmd->root);
878 if (r) {
879 dm_btree_del(&pmd->bl_info, dev_root);
880 return r;
881 }
882
883 r = __open_device(pmd, dev, 1, &td);
884 if (r) {
885 __close_device(td);
886 dm_btree_remove(&pmd->tl_info, pmd->root, &key, &pmd->root);
887 dm_btree_del(&pmd->bl_info, dev_root);
888 return r;
889 }
890 td->changed = 1;
891 __close_device(td);
892
893 return r;
894}
895
896int dm_pool_create_thin(struct dm_pool_metadata *pmd, dm_thin_id dev)
897{
898 int r;
899
900 down_write(&pmd->root_lock);
901 r = __create_thin(pmd, dev);
902 up_write(&pmd->root_lock);
903
904 return r;
905}
906
907static int __set_snapshot_details(struct dm_pool_metadata *pmd,
908 struct dm_thin_device *snap,
909 dm_thin_id origin, uint32_t time)
910{
911 int r;
912 struct dm_thin_device *td;
913
914 r = __open_device(pmd, origin, 0, &td);
915 if (r)
916 return r;
917
918 td->changed = 1;
919 td->snapshotted_time = time;
920
921 snap->mapped_blocks = td->mapped_blocks;
922 snap->snapshotted_time = time;
923 __close_device(td);
924
925 return 0;
926}
927
928static int __create_snap(struct dm_pool_metadata *pmd,
929 dm_thin_id dev, dm_thin_id origin)
930{
931 int r;
932 dm_block_t origin_root;
933 uint64_t key = origin, dev_key = dev;
934 struct dm_thin_device *td;
935 struct disk_device_details details_le;
936 __le64 value;
937
938 /* check this device is unused */
939 r = dm_btree_lookup(&pmd->details_info, pmd->details_root,
940 &dev_key, &details_le);
941 if (!r)
942 return -EEXIST;
943
944 /* find the mapping tree for the origin */
945 r = dm_btree_lookup(&pmd->tl_info, pmd->root, &key, &value);
946 if (r)
947 return r;
948 origin_root = le64_to_cpu(value);
949
950 /* clone the origin, an inc will do */
951 dm_tm_inc(pmd->tm, origin_root);
952
953 /* insert into the main mapping tree */
954 value = cpu_to_le64(origin_root);
955 __dm_bless_for_disk(&value);
956 key = dev;
957 r = dm_btree_insert(&pmd->tl_info, pmd->root, &key, &value, &pmd->root);
958 if (r) {
959 dm_tm_dec(pmd->tm, origin_root);
960 return r;
961 }
962
963 pmd->time++;
964
965 r = __open_device(pmd, dev, 1, &td);
966 if (r)
967 goto bad;
968
969 r = __set_snapshot_details(pmd, td, origin, pmd->time);
970 if (r)
971 goto bad;
972
973 __close_device(td);
974 return 0;
975
976bad:
977 __close_device(td);
978 dm_btree_remove(&pmd->tl_info, pmd->root, &key, &pmd->root);
979 dm_btree_remove(&pmd->details_info, pmd->details_root,
980 &key, &pmd->details_root);
981 return r;
982}
983
984int dm_pool_create_snap(struct dm_pool_metadata *pmd,
985 dm_thin_id dev,
986 dm_thin_id origin)
987{
988 int r;
989
990 down_write(&pmd->root_lock);
991 r = __create_snap(pmd, dev, origin);
992 up_write(&pmd->root_lock);
993
994 return r;
995}
996
997static int __delete_device(struct dm_pool_metadata *pmd, dm_thin_id dev)
998{
999 int r;
1000 uint64_t key = dev;
1001 struct dm_thin_device *td;
1002
1003 /* TODO: failure should mark the transaction invalid */
1004 r = __open_device(pmd, dev, 0, &td);
1005 if (r)
1006 return r;
1007
1008 if (td->open_count > 1) {
1009 __close_device(td);
1010 return -EBUSY;
1011 }
1012
1013 list_del(&td->list);
1014 kfree(td);
1015 r = dm_btree_remove(&pmd->details_info, pmd->details_root,
1016 &key, &pmd->details_root);
1017 if (r)
1018 return r;
1019
1020 r = dm_btree_remove(&pmd->tl_info, pmd->root, &key, &pmd->root);
1021 if (r)
1022 return r;
1023
1024 pmd->need_commit = 1;
1025
1026 return 0;
1027}
1028
1029int dm_pool_delete_thin_device(struct dm_pool_metadata *pmd,
1030 dm_thin_id dev)
1031{
1032 int r;
1033
1034 down_write(&pmd->root_lock);
1035 r = __delete_device(pmd, dev);
1036 up_write(&pmd->root_lock);
1037
1038 return r;
1039}
1040
1041int dm_pool_set_metadata_transaction_id(struct dm_pool_metadata *pmd,
1042 uint64_t current_id,
1043 uint64_t new_id)
1044{
1045 down_write(&pmd->root_lock);
1046 if (pmd->trans_id != current_id) {
1047 up_write(&pmd->root_lock);
1048 DMERR("mismatched transaction id");
1049 return -EINVAL;
1050 }
1051
1052 pmd->trans_id = new_id;
1053 pmd->need_commit = 1;
1054 up_write(&pmd->root_lock);
1055
1056 return 0;
1057}
1058
1059int dm_pool_get_metadata_transaction_id(struct dm_pool_metadata *pmd,
1060 uint64_t *result)
1061{
1062 down_read(&pmd->root_lock);
1063 *result = pmd->trans_id;
1064 up_read(&pmd->root_lock);
1065
1066 return 0;
1067}
1068
1069static int __get_held_metadata_root(struct dm_pool_metadata *pmd,
1070 dm_block_t *result)
1071{
1072 int r;
1073 struct thin_disk_superblock *disk_super;
1074 struct dm_block *sblock;
1075
1076 r = dm_bm_write_lock(pmd->bm, THIN_SUPERBLOCK_LOCATION,
1077 &sb_validator, &sblock);
1078 if (r)
1079 return r;
1080
1081 disk_super = dm_block_data(sblock);
1082 *result = le64_to_cpu(disk_super->held_root);
1083
1084 return dm_bm_unlock(sblock);
1085}
1086
1087int dm_pool_get_held_metadata_root(struct dm_pool_metadata *pmd,
1088 dm_block_t *result)
1089{
1090 int r;
1091
1092 down_read(&pmd->root_lock);
1093 r = __get_held_metadata_root(pmd, result);
1094 up_read(&pmd->root_lock);
1095
1096 return r;
1097}
1098
1099int dm_pool_open_thin_device(struct dm_pool_metadata *pmd, dm_thin_id dev,
1100 struct dm_thin_device **td)
1101{
1102 int r;
1103
1104 down_write(&pmd->root_lock);
1105 r = __open_device(pmd, dev, 0, td);
1106 up_write(&pmd->root_lock);
1107
1108 return r;
1109}
1110
1111int dm_pool_close_thin_device(struct dm_thin_device *td)
1112{
1113 down_write(&td->pmd->root_lock);
1114 __close_device(td);
1115 up_write(&td->pmd->root_lock);
1116
1117 return 0;
1118}
1119
1120dm_thin_id dm_thin_dev_id(struct dm_thin_device *td)
1121{
1122 return td->id;
1123}
1124
1125static int __snapshotted_since(struct dm_thin_device *td, uint32_t time)
1126{
1127 return td->snapshotted_time > time;
1128}
1129
1130int dm_thin_find_block(struct dm_thin_device *td, dm_block_t block,
1131 int can_block, struct dm_thin_lookup_result *result)
1132{
1133 int r;
1134 uint64_t block_time = 0;
1135 __le64 value;
1136 struct dm_pool_metadata *pmd = td->pmd;
1137 dm_block_t keys[2] = { td->id, block };
1138
1139 if (can_block) {
1140 down_read(&pmd->root_lock);
1141 r = dm_btree_lookup(&pmd->info, pmd->root, keys, &value);
1142 if (!r)
1143 block_time = le64_to_cpu(value);
1144 up_read(&pmd->root_lock);
1145
1146 } else if (down_read_trylock(&pmd->root_lock)) {
1147 r = dm_btree_lookup(&pmd->nb_info, pmd->root, keys, &value);
1148 if (!r)
1149 block_time = le64_to_cpu(value);
1150 up_read(&pmd->root_lock);
1151
1152 } else
1153 return -EWOULDBLOCK;
1154
1155 if (!r) {
1156 dm_block_t exception_block;
1157 uint32_t exception_time;
1158 unpack_block_time(block_time, &exception_block,
1159 &exception_time);
1160 result->block = exception_block;
1161 result->shared = __snapshotted_since(td, exception_time);
1162 }
1163
1164 return r;
1165}
1166
1167static int __insert(struct dm_thin_device *td, dm_block_t block,
1168 dm_block_t data_block)
1169{
1170 int r, inserted;
1171 __le64 value;
1172 struct dm_pool_metadata *pmd = td->pmd;
1173 dm_block_t keys[2] = { td->id, block };
1174
1175 pmd->need_commit = 1;
1176 value = cpu_to_le64(pack_block_time(data_block, pmd->time));
1177 __dm_bless_for_disk(&value);
1178
1179 r = dm_btree_insert_notify(&pmd->info, pmd->root, keys, &value,
1180 &pmd->root, &inserted);
1181 if (r)
1182 return r;
1183
1184 if (inserted) {
1185 td->mapped_blocks++;
1186 td->changed = 1;
1187 }
1188
1189 return 0;
1190}
1191
1192int dm_thin_insert_block(struct dm_thin_device *td, dm_block_t block,
1193 dm_block_t data_block)
1194{
1195 int r;
1196
1197 down_write(&td->pmd->root_lock);
1198 r = __insert(td, block, data_block);
1199 up_write(&td->pmd->root_lock);
1200
1201 return r;
1202}
1203
1204static int __remove(struct dm_thin_device *td, dm_block_t block)
1205{
1206 int r;
1207 struct dm_pool_metadata *pmd = td->pmd;
1208 dm_block_t keys[2] = { td->id, block };
1209
1210 r = dm_btree_remove(&pmd->info, pmd->root, keys, &pmd->root);
1211 if (r)
1212 return r;
1213
1214 pmd->need_commit = 1;
1215
1216 return 0;
1217}
1218
1219int dm_thin_remove_block(struct dm_thin_device *td, dm_block_t block)
1220{
1221 int r;
1222
1223 down_write(&td->pmd->root_lock);
1224 r = __remove(td, block);
1225 up_write(&td->pmd->root_lock);
1226
1227 return r;
1228}
1229
1230int dm_pool_alloc_data_block(struct dm_pool_metadata *pmd, dm_block_t *result)
1231{
1232 int r;
1233
1234 down_write(&pmd->root_lock);
1235
1236 r = dm_sm_new_block(pmd->data_sm, result);
1237 pmd->need_commit = 1;
1238
1239 up_write(&pmd->root_lock);
1240
1241 return r;
1242}
1243
1244int dm_pool_commit_metadata(struct dm_pool_metadata *pmd)
1245{
1246 int r;
1247
1248 down_write(&pmd->root_lock);
1249
1250 r = __commit_transaction(pmd);
1251 if (r <= 0)
1252 goto out;
1253
1254 /*
1255 * Open the next transaction.
1256 */
1257 r = __begin_transaction(pmd);
1258out:
1259 up_write(&pmd->root_lock);
1260 return r;
1261}
1262
1263int dm_pool_get_free_block_count(struct dm_pool_metadata *pmd, dm_block_t *result)
1264{
1265 int r;
1266
1267 down_read(&pmd->root_lock);
1268 r = dm_sm_get_nr_free(pmd->data_sm, result);
1269 up_read(&pmd->root_lock);
1270
1271 return r;
1272}
1273
1274int dm_pool_get_free_metadata_block_count(struct dm_pool_metadata *pmd,
1275 dm_block_t *result)
1276{
1277 int r;
1278
1279 down_read(&pmd->root_lock);
1280 r = dm_sm_get_nr_free(pmd->metadata_sm, result);
1281 up_read(&pmd->root_lock);
1282
1283 return r;
1284}
1285
1286int dm_pool_get_metadata_dev_size(struct dm_pool_metadata *pmd,
1287 dm_block_t *result)
1288{
1289 int r;
1290
1291 down_read(&pmd->root_lock);
1292 r = dm_sm_get_nr_blocks(pmd->metadata_sm, result);
1293 up_read(&pmd->root_lock);
1294
1295 return r;
1296}
1297
1298int dm_pool_get_data_block_size(struct dm_pool_metadata *pmd, sector_t *result)
1299{
1300 down_read(&pmd->root_lock);
1301 *result = pmd->data_block_size;
1302 up_read(&pmd->root_lock);
1303
1304 return 0;
1305}
1306
1307int dm_pool_get_data_dev_size(struct dm_pool_metadata *pmd, dm_block_t *result)
1308{
1309 int r;
1310
1311 down_read(&pmd->root_lock);
1312 r = dm_sm_get_nr_blocks(pmd->data_sm, result);
1313 up_read(&pmd->root_lock);
1314
1315 return r;
1316}
1317
1318int dm_thin_get_mapped_count(struct dm_thin_device *td, dm_block_t *result)
1319{
1320 struct dm_pool_metadata *pmd = td->pmd;
1321
1322 down_read(&pmd->root_lock);
1323 *result = td->mapped_blocks;
1324 up_read(&pmd->root_lock);
1325
1326 return 0;
1327}
1328
1329static int __highest_block(struct dm_thin_device *td, dm_block_t *result)
1330{
1331 int r;
1332 __le64 value_le;
1333 dm_block_t thin_root;
1334 struct dm_pool_metadata *pmd = td->pmd;
1335
1336 r = dm_btree_lookup(&pmd->tl_info, pmd->root, &td->id, &value_le);
1337 if (r)
1338 return r;
1339
1340 thin_root = le64_to_cpu(value_le);
1341
1342 return dm_btree_find_highest_key(&pmd->bl_info, thin_root, result);
1343}
1344
1345int dm_thin_get_highest_mapped_block(struct dm_thin_device *td,
1346 dm_block_t *result)
1347{
1348 int r;
1349 struct dm_pool_metadata *pmd = td->pmd;
1350
1351 down_read(&pmd->root_lock);
1352 r = __highest_block(td, result);
1353 up_read(&pmd->root_lock);
1354
1355 return r;
1356}
1357
1358static int __resize_data_dev(struct dm_pool_metadata *pmd, dm_block_t new_count)
1359{
1360 int r;
1361 dm_block_t old_count;
1362
1363 r = dm_sm_get_nr_blocks(pmd->data_sm, &old_count);
1364 if (r)
1365 return r;
1366
1367 if (new_count == old_count)
1368 return 0;
1369
1370 if (new_count < old_count) {
1371 DMERR("cannot reduce size of data device");
1372 return -EINVAL;
1373 }
1374
1375 r = dm_sm_extend(pmd->data_sm, new_count - old_count);
1376 if (!r)
1377 pmd->need_commit = 1;
1378
1379 return r;
1380}
1381
1382int dm_pool_resize_data_dev(struct dm_pool_metadata *pmd, dm_block_t new_count)
1383{
1384 int r;
1385
1386 down_write(&pmd->root_lock);
1387 r = __resize_data_dev(pmd, new_count);
1388 up_write(&pmd->root_lock);
1389
1390 return r;
1391}
diff --git a/drivers/md/dm-thin-metadata.h b/drivers/md/dm-thin-metadata.h
new file mode 100644
index 000000000000..859c16896877
--- /dev/null
+++ b/drivers/md/dm-thin-metadata.h
@@ -0,0 +1,156 @@
1/*
2 * Copyright (C) 2010-2011 Red Hat, Inc.
3 *
4 * This file is released under the GPL.
5 */
6
7#ifndef DM_THIN_METADATA_H
8#define DM_THIN_METADATA_H
9
10#include "persistent-data/dm-block-manager.h"
11
12#define THIN_METADATA_BLOCK_SIZE 4096
13
14/*----------------------------------------------------------------*/
15
16struct dm_pool_metadata;
17struct dm_thin_device;
18
19/*
20 * Device identifier
21 */
22typedef uint64_t dm_thin_id;
23
24/*
25 * Reopens or creates a new, empty metadata volume.
26 */
27struct dm_pool_metadata *dm_pool_metadata_open(struct block_device *bdev,
28 sector_t data_block_size);
29
30int dm_pool_metadata_close(struct dm_pool_metadata *pmd);
31
32/*
33 * Compat feature flags. Any incompat flags beyond the ones
34 * specified below will prevent use of the thin metadata.
35 */
36#define THIN_FEATURE_COMPAT_SUPP 0UL
37#define THIN_FEATURE_COMPAT_RO_SUPP 0UL
38#define THIN_FEATURE_INCOMPAT_SUPP 0UL
39
40/*
41 * Device creation/deletion.
42 */
43int dm_pool_create_thin(struct dm_pool_metadata *pmd, dm_thin_id dev);
44
45/*
46 * An internal snapshot.
47 *
48 * You can only snapshot a quiesced origin i.e. one that is either
49 * suspended or not instanced at all.
50 */
51int dm_pool_create_snap(struct dm_pool_metadata *pmd, dm_thin_id dev,
52 dm_thin_id origin);
53
54/*
55 * Deletes a virtual device from the metadata. It _is_ safe to call this
56 * when that device is open. Operations on that device will just start
57 * failing. You still need to call close() on the device.
58 */
59int dm_pool_delete_thin_device(struct dm_pool_metadata *pmd,
60 dm_thin_id dev);
61
62/*
63 * Commits _all_ metadata changes: device creation, deletion, mapping
64 * updates.
65 */
66int dm_pool_commit_metadata(struct dm_pool_metadata *pmd);
67
68/*
69 * Set/get userspace transaction id.
70 */
71int dm_pool_set_metadata_transaction_id(struct dm_pool_metadata *pmd,
72 uint64_t current_id,
73 uint64_t new_id);
74
75int dm_pool_get_metadata_transaction_id(struct dm_pool_metadata *pmd,
76 uint64_t *result);
77
78/*
79 * Hold/get root for userspace transaction.
80 */
81int dm_pool_hold_metadata_root(struct dm_pool_metadata *pmd);
82
83int dm_pool_get_held_metadata_root(struct dm_pool_metadata *pmd,
84 dm_block_t *result);
85
86/*
87 * Actions on a single virtual device.
88 */
89
90/*
91 * Opening the same device more than once will fail with -EBUSY.
92 */
93int dm_pool_open_thin_device(struct dm_pool_metadata *pmd, dm_thin_id dev,
94 struct dm_thin_device **td);
95
96int dm_pool_close_thin_device(struct dm_thin_device *td);
97
98dm_thin_id dm_thin_dev_id(struct dm_thin_device *td);
99
100struct dm_thin_lookup_result {
101 dm_block_t block;
102 int shared;
103};
104
105/*
106 * Returns:
107 * -EWOULDBLOCK iff @can_block is set and would block.
108 * -ENODATA iff that mapping is not present.
109 * 0 success
110 */
111int dm_thin_find_block(struct dm_thin_device *td, dm_block_t block,
112 int can_block, struct dm_thin_lookup_result *result);
113
114/*
115 * Obtain an unused block.
116 */
117int dm_pool_alloc_data_block(struct dm_pool_metadata *pmd, dm_block_t *result);
118
119/*
120 * Insert or remove block.
121 */
122int dm_thin_insert_block(struct dm_thin_device *td, dm_block_t block,
123 dm_block_t data_block);
124
125int dm_thin_remove_block(struct dm_thin_device *td, dm_block_t block);
126
127/*
128 * Queries.
129 */
130int dm_thin_get_highest_mapped_block(struct dm_thin_device *td,
131 dm_block_t *highest_mapped);
132
133int dm_thin_get_mapped_count(struct dm_thin_device *td, dm_block_t *result);
134
135int dm_pool_get_free_block_count(struct dm_pool_metadata *pmd,
136 dm_block_t *result);
137
138int dm_pool_get_free_metadata_block_count(struct dm_pool_metadata *pmd,
139 dm_block_t *result);
140
141int dm_pool_get_metadata_dev_size(struct dm_pool_metadata *pmd,
142 dm_block_t *result);
143
144int dm_pool_get_data_block_size(struct dm_pool_metadata *pmd, sector_t *result);
145
146int dm_pool_get_data_dev_size(struct dm_pool_metadata *pmd, dm_block_t *result);
147
148/*
149 * Returns -ENOSPC if the new size is too small and already allocated
150 * blocks would be lost.
151 */
152int dm_pool_resize_data_dev(struct dm_pool_metadata *pmd, dm_block_t new_size);
153
154/*----------------------------------------------------------------*/
155
156#endif
diff --git a/drivers/md/dm-thin.c b/drivers/md/dm-thin.c
new file mode 100644
index 000000000000..c3087575fef0
--- /dev/null
+++ b/drivers/md/dm-thin.c
@@ -0,0 +1,2428 @@
1/*
2 * Copyright (C) 2011 Red Hat UK.
3 *
4 * This file is released under the GPL.
5 */
6
7#include "dm-thin-metadata.h"
8
9#include <linux/device-mapper.h>
10#include <linux/dm-io.h>
11#include <linux/dm-kcopyd.h>
12#include <linux/list.h>
13#include <linux/init.h>
14#include <linux/module.h>
15#include <linux/slab.h>
16
17#define DM_MSG_PREFIX "thin"
18
19/*
20 * Tunable constants
21 */
22#define ENDIO_HOOK_POOL_SIZE 10240
23#define DEFERRED_SET_SIZE 64
24#define MAPPING_POOL_SIZE 1024
25#define PRISON_CELLS 1024
26
27/*
28 * The block size of the device holding pool data must be
29 * between 64KB and 1GB.
30 */
31#define DATA_DEV_BLOCK_SIZE_MIN_SECTORS (64 * 1024 >> SECTOR_SHIFT)
32#define DATA_DEV_BLOCK_SIZE_MAX_SECTORS (1024 * 1024 * 1024 >> SECTOR_SHIFT)
33
34/*
35 * The metadata device is currently limited in size. The limitation is
36 * checked lower down in dm-space-map-metadata, but we also check it here
37 * so we can fail early.
38 *
39 * We have one block of index, which can hold 255 index entries. Each
40 * index entry contains allocation info about 16k metadata blocks.
41 */
42#define METADATA_DEV_MAX_SECTORS (255 * (1 << 14) * (THIN_METADATA_BLOCK_SIZE / (1 << SECTOR_SHIFT)))
43
44/*
45 * Device id is restricted to 24 bits.
46 */
47#define MAX_DEV_ID ((1 << 24) - 1)
48
49/*
50 * How do we handle breaking sharing of data blocks?
51 * =================================================
52 *
53 * We use a standard copy-on-write btree to store the mappings for the
54 * devices (note I'm talking about copy-on-write of the metadata here, not
55 * the data). When you take an internal snapshot you clone the root node
56 * of the origin btree. After this there is no concept of an origin or a
57 * snapshot. They are just two device trees that happen to point to the
58 * same data blocks.
59 *
60 * When we get a write in we decide if it's to a shared data block using
61 * some timestamp magic. If it is, we have to break sharing.
62 *
63 * Let's say we write to a shared block in what was the origin. The
64 * steps are:
65 *
66 * i) plug io further to this physical block. (see bio_prison code).
67 *
68 * ii) quiesce any read io to that shared data block. Obviously
69 * including all devices that share this block. (see deferred_set code)
70 *
71 * iii) copy the data block to a newly allocate block. This step can be
72 * missed out if the io covers the block. (schedule_copy).
73 *
74 * iv) insert the new mapping into the origin's btree
75 * (process_prepared_mappings). This act of inserting breaks some
76 * sharing of btree nodes between the two devices. Breaking sharing only
77 * effects the btree of that specific device. Btrees for the other
78 * devices that share the block never change. The btree for the origin
79 * device as it was after the last commit is untouched, ie. we're using
80 * persistent data structures in the functional programming sense.
81 *
82 * v) unplug io to this physical block, including the io that triggered
83 * the breaking of sharing.
84 *
85 * Steps (ii) and (iii) occur in parallel.
86 *
87 * The metadata _doesn't_ need to be committed before the io continues. We
88 * get away with this because the io is always written to a _new_ block.
89 * If there's a crash, then:
90 *
91 * - The origin mapping will point to the old origin block (the shared
92 * one). This will contain the data as it was before the io that triggered
93 * the breaking of sharing came in.
94 *
95 * - The snap mapping still points to the old block. As it would after
96 * the commit.
97 *
98 * The downside of this scheme is the timestamp magic isn't perfect, and
99 * will continue to think that data block in the snapshot device is shared
100 * even after the write to the origin has broken sharing. I suspect data
101 * blocks will typically be shared by many different devices, so we're
102 * breaking sharing n + 1 times, rather than n, where n is the number of
103 * devices that reference this data block. At the moment I think the
104 * benefits far, far outweigh the disadvantages.
105 */
106
107/*----------------------------------------------------------------*/
108
109/*
110 * Sometimes we can't deal with a bio straight away. We put them in prison
111 * where they can't cause any mischief. Bios are put in a cell identified
112 * by a key, multiple bios can be in the same cell. When the cell is
113 * subsequently unlocked the bios become available.
114 */
115struct bio_prison;
116
117struct cell_key {
118 int virtual;
119 dm_thin_id dev;
120 dm_block_t block;
121};
122
123struct cell {
124 struct hlist_node list;
125 struct bio_prison *prison;
126 struct cell_key key;
127 unsigned count;
128 struct bio_list bios;
129};
130
131struct bio_prison {
132 spinlock_t lock;
133 mempool_t *cell_pool;
134
135 unsigned nr_buckets;
136 unsigned hash_mask;
137 struct hlist_head *cells;
138};
139
140static uint32_t calc_nr_buckets(unsigned nr_cells)
141{
142 uint32_t n = 128;
143
144 nr_cells /= 4;
145 nr_cells = min(nr_cells, 8192u);
146
147 while (n < nr_cells)
148 n <<= 1;
149
150 return n;
151}
152
153/*
154 * @nr_cells should be the number of cells you want in use _concurrently_.
155 * Don't confuse it with the number of distinct keys.
156 */
157static struct bio_prison *prison_create(unsigned nr_cells)
158{
159 unsigned i;
160 uint32_t nr_buckets = calc_nr_buckets(nr_cells);
161 size_t len = sizeof(struct bio_prison) +
162 (sizeof(struct hlist_head) * nr_buckets);
163 struct bio_prison *prison = kmalloc(len, GFP_KERNEL);
164
165 if (!prison)
166 return NULL;
167
168 spin_lock_init(&prison->lock);
169 prison->cell_pool = mempool_create_kmalloc_pool(nr_cells,
170 sizeof(struct cell));
171 if (!prison->cell_pool) {
172 kfree(prison);
173 return NULL;
174 }
175
176 prison->nr_buckets = nr_buckets;
177 prison->hash_mask = nr_buckets - 1;
178 prison->cells = (struct hlist_head *) (prison + 1);
179 for (i = 0; i < nr_buckets; i++)
180 INIT_HLIST_HEAD(prison->cells + i);
181
182 return prison;
183}
184
185static void prison_destroy(struct bio_prison *prison)
186{
187 mempool_destroy(prison->cell_pool);
188 kfree(prison);
189}
190
191static uint32_t hash_key(struct bio_prison *prison, struct cell_key *key)
192{
193 const unsigned long BIG_PRIME = 4294967291UL;
194 uint64_t hash = key->block * BIG_PRIME;
195
196 return (uint32_t) (hash & prison->hash_mask);
197}
198
199static int keys_equal(struct cell_key *lhs, struct cell_key *rhs)
200{
201 return (lhs->virtual == rhs->virtual) &&
202 (lhs->dev == rhs->dev) &&
203 (lhs->block == rhs->block);
204}
205
206static struct cell *__search_bucket(struct hlist_head *bucket,
207 struct cell_key *key)
208{
209 struct cell *cell;
210 struct hlist_node *tmp;
211
212 hlist_for_each_entry(cell, tmp, bucket, list)
213 if (keys_equal(&cell->key, key))
214 return cell;
215
216 return NULL;
217}
218
219/*
220 * This may block if a new cell needs allocating. You must ensure that
221 * cells will be unlocked even if the calling thread is blocked.
222 *
223 * Returns the number of entries in the cell prior to the new addition
224 * or < 0 on failure.
225 */
226static int bio_detain(struct bio_prison *prison, struct cell_key *key,
227 struct bio *inmate, struct cell **ref)
228{
229 int r;
230 unsigned long flags;
231 uint32_t hash = hash_key(prison, key);
232 struct cell *uninitialized_var(cell), *cell2 = NULL;
233
234 BUG_ON(hash > prison->nr_buckets);
235
236 spin_lock_irqsave(&prison->lock, flags);
237 cell = __search_bucket(prison->cells + hash, key);
238
239 if (!cell) {
240 /*
241 * Allocate a new cell
242 */
243 spin_unlock_irqrestore(&prison->lock, flags);
244 cell2 = mempool_alloc(prison->cell_pool, GFP_NOIO);
245 spin_lock_irqsave(&prison->lock, flags);
246
247 /*
248 * We've been unlocked, so we have to double check that
249 * nobody else has inserted this cell in the meantime.
250 */
251 cell = __search_bucket(prison->cells + hash, key);
252
253 if (!cell) {
254 cell = cell2;
255 cell2 = NULL;
256
257 cell->prison = prison;
258 memcpy(&cell->key, key, sizeof(cell->key));
259 cell->count = 0;
260 bio_list_init(&cell->bios);
261 hlist_add_head(&cell->list, prison->cells + hash);
262 }
263 }
264
265 r = cell->count++;
266 bio_list_add(&cell->bios, inmate);
267 spin_unlock_irqrestore(&prison->lock, flags);
268
269 if (cell2)
270 mempool_free(cell2, prison->cell_pool);
271
272 *ref = cell;
273
274 return r;
275}
276
277/*
278 * @inmates must have been initialised prior to this call
279 */
280static void __cell_release(struct cell *cell, struct bio_list *inmates)
281{
282 struct bio_prison *prison = cell->prison;
283
284 hlist_del(&cell->list);
285
286 if (inmates)
287 bio_list_merge(inmates, &cell->bios);
288
289 mempool_free(cell, prison->cell_pool);
290}
291
292static void cell_release(struct cell *cell, struct bio_list *bios)
293{
294 unsigned long flags;
295 struct bio_prison *prison = cell->prison;
296
297 spin_lock_irqsave(&prison->lock, flags);
298 __cell_release(cell, bios);
299 spin_unlock_irqrestore(&prison->lock, flags);
300}
301
302/*
303 * There are a couple of places where we put a bio into a cell briefly
304 * before taking it out again. In these situations we know that no other
305 * bio may be in the cell. This function releases the cell, and also does
306 * a sanity check.
307 */
308static void cell_release_singleton(struct cell *cell, struct bio *bio)
309{
310 struct bio_prison *prison = cell->prison;
311 struct bio_list bios;
312 struct bio *b;
313 unsigned long flags;
314
315 bio_list_init(&bios);
316
317 spin_lock_irqsave(&prison->lock, flags);
318 __cell_release(cell, &bios);
319 spin_unlock_irqrestore(&prison->lock, flags);
320
321 b = bio_list_pop(&bios);
322 BUG_ON(b != bio);
323 BUG_ON(!bio_list_empty(&bios));
324}
325
326static void cell_error(struct cell *cell)
327{
328 struct bio_prison *prison = cell->prison;
329 struct bio_list bios;
330 struct bio *bio;
331 unsigned long flags;
332
333 bio_list_init(&bios);
334
335 spin_lock_irqsave(&prison->lock, flags);
336 __cell_release(cell, &bios);
337 spin_unlock_irqrestore(&prison->lock, flags);
338
339 while ((bio = bio_list_pop(&bios)))
340 bio_io_error(bio);
341}
342
343/*----------------------------------------------------------------*/
344
345/*
346 * We use the deferred set to keep track of pending reads to shared blocks.
347 * We do this to ensure the new mapping caused by a write isn't performed
348 * until these prior reads have completed. Otherwise the insertion of the
349 * new mapping could free the old block that the read bios are mapped to.
350 */
351
352struct deferred_set;
353struct deferred_entry {
354 struct deferred_set *ds;
355 unsigned count;
356 struct list_head work_items;
357};
358
359struct deferred_set {
360 spinlock_t lock;
361 unsigned current_entry;
362 unsigned sweeper;
363 struct deferred_entry entries[DEFERRED_SET_SIZE];
364};
365
366static void ds_init(struct deferred_set *ds)
367{
368 int i;
369
370 spin_lock_init(&ds->lock);
371 ds->current_entry = 0;
372 ds->sweeper = 0;
373 for (i = 0; i < DEFERRED_SET_SIZE; i++) {
374 ds->entries[i].ds = ds;
375 ds->entries[i].count = 0;
376 INIT_LIST_HEAD(&ds->entries[i].work_items);
377 }
378}
379
380static struct deferred_entry *ds_inc(struct deferred_set *ds)
381{
382 unsigned long flags;
383 struct deferred_entry *entry;
384
385 spin_lock_irqsave(&ds->lock, flags);
386 entry = ds->entries + ds->current_entry;
387 entry->count++;
388 spin_unlock_irqrestore(&ds->lock, flags);
389
390 return entry;
391}
392
393static unsigned ds_next(unsigned index)
394{
395 return (index + 1) % DEFERRED_SET_SIZE;
396}
397
398static void __sweep(struct deferred_set *ds, struct list_head *head)
399{
400 while ((ds->sweeper != ds->current_entry) &&
401 !ds->entries[ds->sweeper].count) {
402 list_splice_init(&ds->entries[ds->sweeper].work_items, head);
403 ds->sweeper = ds_next(ds->sweeper);
404 }
405
406 if ((ds->sweeper == ds->current_entry) && !ds->entries[ds->sweeper].count)
407 list_splice_init(&ds->entries[ds->sweeper].work_items, head);
408}
409
410static void ds_dec(struct deferred_entry *entry, struct list_head *head)
411{
412 unsigned long flags;
413
414 spin_lock_irqsave(&entry->ds->lock, flags);
415 BUG_ON(!entry->count);
416 --entry->count;
417 __sweep(entry->ds, head);
418 spin_unlock_irqrestore(&entry->ds->lock, flags);
419}
420
421/*
422 * Returns 1 if deferred or 0 if no pending items to delay job.
423 */
424static int ds_add_work(struct deferred_set *ds, struct list_head *work)
425{
426 int r = 1;
427 unsigned long flags;
428 unsigned next_entry;
429
430 spin_lock_irqsave(&ds->lock, flags);
431 if ((ds->sweeper == ds->current_entry) &&
432 !ds->entries[ds->current_entry].count)
433 r = 0;
434 else {
435 list_add(work, &ds->entries[ds->current_entry].work_items);
436 next_entry = ds_next(ds->current_entry);
437 if (!ds->entries[next_entry].count)
438 ds->current_entry = next_entry;
439 }
440 spin_unlock_irqrestore(&ds->lock, flags);
441
442 return r;
443}
444
445/*----------------------------------------------------------------*/
446
447/*
448 * Key building.
449 */
450static void build_data_key(struct dm_thin_device *td,
451 dm_block_t b, struct cell_key *key)
452{
453 key->virtual = 0;
454 key->dev = dm_thin_dev_id(td);
455 key->block = b;
456}
457
458static void build_virtual_key(struct dm_thin_device *td, dm_block_t b,
459 struct cell_key *key)
460{
461 key->virtual = 1;
462 key->dev = dm_thin_dev_id(td);
463 key->block = b;
464}
465
466/*----------------------------------------------------------------*/
467
468/*
469 * A pool device ties together a metadata device and a data device. It
470 * also provides the interface for creating and destroying internal
471 * devices.
472 */
473struct new_mapping;
474struct pool {
475 struct list_head list;
476 struct dm_target *ti; /* Only set if a pool target is bound */
477
478 struct mapped_device *pool_md;
479 struct block_device *md_dev;
480 struct dm_pool_metadata *pmd;
481
482 uint32_t sectors_per_block;
483 unsigned block_shift;
484 dm_block_t offset_mask;
485 dm_block_t low_water_blocks;
486
487 unsigned zero_new_blocks:1;
488 unsigned low_water_triggered:1; /* A dm event has been sent */
489 unsigned no_free_space:1; /* A -ENOSPC warning has been issued */
490
491 struct bio_prison *prison;
492 struct dm_kcopyd_client *copier;
493
494 struct workqueue_struct *wq;
495 struct work_struct worker;
496
497 unsigned ref_count;
498
499 spinlock_t lock;
500 struct bio_list deferred_bios;
501 struct bio_list deferred_flush_bios;
502 struct list_head prepared_mappings;
503
504 struct bio_list retry_on_resume_list;
505
506 struct deferred_set ds; /* FIXME: move to thin_c */
507
508 struct new_mapping *next_mapping;
509 mempool_t *mapping_pool;
510 mempool_t *endio_hook_pool;
511};
512
513/*
514 * Target context for a pool.
515 */
516struct pool_c {
517 struct dm_target *ti;
518 struct pool *pool;
519 struct dm_dev *data_dev;
520 struct dm_dev *metadata_dev;
521 struct dm_target_callbacks callbacks;
522
523 dm_block_t low_water_blocks;
524 unsigned zero_new_blocks:1;
525};
526
527/*
528 * Target context for a thin.
529 */
530struct thin_c {
531 struct dm_dev *pool_dev;
532 dm_thin_id dev_id;
533
534 struct pool *pool;
535 struct dm_thin_device *td;
536};
537
538/*----------------------------------------------------------------*/
539
540/*
541 * A global list of pools that uses a struct mapped_device as a key.
542 */
543static struct dm_thin_pool_table {
544 struct mutex mutex;
545 struct list_head pools;
546} dm_thin_pool_table;
547
548static void pool_table_init(void)
549{
550 mutex_init(&dm_thin_pool_table.mutex);
551 INIT_LIST_HEAD(&dm_thin_pool_table.pools);
552}
553
554static void __pool_table_insert(struct pool *pool)
555{
556 BUG_ON(!mutex_is_locked(&dm_thin_pool_table.mutex));
557 list_add(&pool->list, &dm_thin_pool_table.pools);
558}
559
560static void __pool_table_remove(struct pool *pool)
561{
562 BUG_ON(!mutex_is_locked(&dm_thin_pool_table.mutex));
563 list_del(&pool->list);
564}
565
566static struct pool *__pool_table_lookup(struct mapped_device *md)
567{
568 struct pool *pool = NULL, *tmp;
569
570 BUG_ON(!mutex_is_locked(&dm_thin_pool_table.mutex));
571
572 list_for_each_entry(tmp, &dm_thin_pool_table.pools, list) {
573 if (tmp->pool_md == md) {
574 pool = tmp;
575 break;
576 }
577 }
578
579 return pool;
580}
581
582static struct pool *__pool_table_lookup_metadata_dev(struct block_device *md_dev)
583{
584 struct pool *pool = NULL, *tmp;
585
586 BUG_ON(!mutex_is_locked(&dm_thin_pool_table.mutex));
587
588 list_for_each_entry(tmp, &dm_thin_pool_table.pools, list) {
589 if (tmp->md_dev == md_dev) {
590 pool = tmp;
591 break;
592 }
593 }
594
595 return pool;
596}
597
598/*----------------------------------------------------------------*/
599
600static void __requeue_bio_list(struct thin_c *tc, struct bio_list *master)
601{
602 struct bio *bio;
603 struct bio_list bios;
604
605 bio_list_init(&bios);
606 bio_list_merge(&bios, master);
607 bio_list_init(master);
608
609 while ((bio = bio_list_pop(&bios))) {
610 if (dm_get_mapinfo(bio)->ptr == tc)
611 bio_endio(bio, DM_ENDIO_REQUEUE);
612 else
613 bio_list_add(master, bio);
614 }
615}
616
617static void requeue_io(struct thin_c *tc)
618{
619 struct pool *pool = tc->pool;
620 unsigned long flags;
621
622 spin_lock_irqsave(&pool->lock, flags);
623 __requeue_bio_list(tc, &pool->deferred_bios);
624 __requeue_bio_list(tc, &pool->retry_on_resume_list);
625 spin_unlock_irqrestore(&pool->lock, flags);
626}
627
628/*
629 * This section of code contains the logic for processing a thin device's IO.
630 * Much of the code depends on pool object resources (lists, workqueues, etc)
631 * but most is exclusively called from the thin target rather than the thin-pool
632 * target.
633 */
634
635static dm_block_t get_bio_block(struct thin_c *tc, struct bio *bio)
636{
637 return bio->bi_sector >> tc->pool->block_shift;
638}
639
640static void remap(struct thin_c *tc, struct bio *bio, dm_block_t block)
641{
642 struct pool *pool = tc->pool;
643
644 bio->bi_bdev = tc->pool_dev->bdev;
645 bio->bi_sector = (block << pool->block_shift) +
646 (bio->bi_sector & pool->offset_mask);
647}
648
649static void remap_and_issue(struct thin_c *tc, struct bio *bio,
650 dm_block_t block)
651{
652 struct pool *pool = tc->pool;
653 unsigned long flags;
654
655 remap(tc, bio, block);
656
657 /*
658 * Batch together any FUA/FLUSH bios we find and then issue
659 * a single commit for them in process_deferred_bios().
660 */
661 if (bio->bi_rw & (REQ_FLUSH | REQ_FUA)) {
662 spin_lock_irqsave(&pool->lock, flags);
663 bio_list_add(&pool->deferred_flush_bios, bio);
664 spin_unlock_irqrestore(&pool->lock, flags);
665 } else
666 generic_make_request(bio);
667}
668
669/*
670 * wake_worker() is used when new work is queued and when pool_resume is
671 * ready to continue deferred IO processing.
672 */
673static void wake_worker(struct pool *pool)
674{
675 queue_work(pool->wq, &pool->worker);
676}
677
678/*----------------------------------------------------------------*/
679
680/*
681 * Bio endio functions.
682 */
683struct endio_hook {
684 struct thin_c *tc;
685 bio_end_io_t *saved_bi_end_io;
686 struct deferred_entry *entry;
687};
688
689struct new_mapping {
690 struct list_head list;
691
692 int prepared;
693
694 struct thin_c *tc;
695 dm_block_t virt_block;
696 dm_block_t data_block;
697 struct cell *cell;
698 int err;
699
700 /*
701 * If the bio covers the whole area of a block then we can avoid
702 * zeroing or copying. Instead this bio is hooked. The bio will
703 * still be in the cell, so care has to be taken to avoid issuing
704 * the bio twice.
705 */
706 struct bio *bio;
707 bio_end_io_t *saved_bi_end_io;
708};
709
710static void __maybe_add_mapping(struct new_mapping *m)
711{
712 struct pool *pool = m->tc->pool;
713
714 if (list_empty(&m->list) && m->prepared) {
715 list_add(&m->list, &pool->prepared_mappings);
716 wake_worker(pool);
717 }
718}
719
720static void copy_complete(int read_err, unsigned long write_err, void *context)
721{
722 unsigned long flags;
723 struct new_mapping *m = context;
724 struct pool *pool = m->tc->pool;
725
726 m->err = read_err || write_err ? -EIO : 0;
727
728 spin_lock_irqsave(&pool->lock, flags);
729 m->prepared = 1;
730 __maybe_add_mapping(m);
731 spin_unlock_irqrestore(&pool->lock, flags);
732}
733
734static void overwrite_endio(struct bio *bio, int err)
735{
736 unsigned long flags;
737 struct new_mapping *m = dm_get_mapinfo(bio)->ptr;
738 struct pool *pool = m->tc->pool;
739
740 m->err = err;
741
742 spin_lock_irqsave(&pool->lock, flags);
743 m->prepared = 1;
744 __maybe_add_mapping(m);
745 spin_unlock_irqrestore(&pool->lock, flags);
746}
747
748static void shared_read_endio(struct bio *bio, int err)
749{
750 struct list_head mappings;
751 struct new_mapping *m, *tmp;
752 struct endio_hook *h = dm_get_mapinfo(bio)->ptr;
753 unsigned long flags;
754 struct pool *pool = h->tc->pool;
755
756 bio->bi_end_io = h->saved_bi_end_io;
757 bio_endio(bio, err);
758
759 INIT_LIST_HEAD(&mappings);
760 ds_dec(h->entry, &mappings);
761
762 spin_lock_irqsave(&pool->lock, flags);
763 list_for_each_entry_safe(m, tmp, &mappings, list) {
764 list_del(&m->list);
765 INIT_LIST_HEAD(&m->list);
766 __maybe_add_mapping(m);
767 }
768 spin_unlock_irqrestore(&pool->lock, flags);
769
770 mempool_free(h, pool->endio_hook_pool);
771}
772
773/*----------------------------------------------------------------*/
774
775/*
776 * Workqueue.
777 */
778
779/*
780 * Prepared mapping jobs.
781 */
782
783/*
784 * This sends the bios in the cell back to the deferred_bios list.
785 */
786static void cell_defer(struct thin_c *tc, struct cell *cell,
787 dm_block_t data_block)
788{
789 struct pool *pool = tc->pool;
790 unsigned long flags;
791
792 spin_lock_irqsave(&pool->lock, flags);
793 cell_release(cell, &pool->deferred_bios);
794 spin_unlock_irqrestore(&tc->pool->lock, flags);
795
796 wake_worker(pool);
797}
798
799/*
800 * Same as cell_defer above, except it omits one particular detainee,
801 * a write bio that covers the block and has already been processed.
802 */
803static void cell_defer_except(struct thin_c *tc, struct cell *cell,
804 struct bio *exception)
805{
806 struct bio_list bios;
807 struct bio *bio;
808 struct pool *pool = tc->pool;
809 unsigned long flags;
810
811 bio_list_init(&bios);
812 cell_release(cell, &bios);
813
814 spin_lock_irqsave(&pool->lock, flags);
815 while ((bio = bio_list_pop(&bios)))
816 if (bio != exception)
817 bio_list_add(&pool->deferred_bios, bio);
818 spin_unlock_irqrestore(&pool->lock, flags);
819
820 wake_worker(pool);
821}
822
823static void process_prepared_mapping(struct new_mapping *m)
824{
825 struct thin_c *tc = m->tc;
826 struct bio *bio;
827 int r;
828
829 bio = m->bio;
830 if (bio)
831 bio->bi_end_io = m->saved_bi_end_io;
832
833 if (m->err) {
834 cell_error(m->cell);
835 return;
836 }
837
838 /*
839 * Commit the prepared block into the mapping btree.
840 * Any I/O for this block arriving after this point will get
841 * remapped to it directly.
842 */
843 r = dm_thin_insert_block(tc->td, m->virt_block, m->data_block);
844 if (r) {
845 DMERR("dm_thin_insert_block() failed");
846 cell_error(m->cell);
847 return;
848 }
849
850 /*
851 * Release any bios held while the block was being provisioned.
852 * If we are processing a write bio that completely covers the block,
853 * we already processed it so can ignore it now when processing
854 * the bios in the cell.
855 */
856 if (bio) {
857 cell_defer_except(tc, m->cell, bio);
858 bio_endio(bio, 0);
859 } else
860 cell_defer(tc, m->cell, m->data_block);
861
862 list_del(&m->list);
863 mempool_free(m, tc->pool->mapping_pool);
864}
865
866static void process_prepared_mappings(struct pool *pool)
867{
868 unsigned long flags;
869 struct list_head maps;
870 struct new_mapping *m, *tmp;
871
872 INIT_LIST_HEAD(&maps);
873 spin_lock_irqsave(&pool->lock, flags);
874 list_splice_init(&pool->prepared_mappings, &maps);
875 spin_unlock_irqrestore(&pool->lock, flags);
876
877 list_for_each_entry_safe(m, tmp, &maps, list)
878 process_prepared_mapping(m);
879}
880
881/*
882 * Deferred bio jobs.
883 */
884static int io_overwrites_block(struct pool *pool, struct bio *bio)
885{
886 return ((bio_data_dir(bio) == WRITE) &&
887 !(bio->bi_sector & pool->offset_mask)) &&
888 (bio->bi_size == (pool->sectors_per_block << SECTOR_SHIFT));
889}
890
891static void save_and_set_endio(struct bio *bio, bio_end_io_t **save,
892 bio_end_io_t *fn)
893{
894 *save = bio->bi_end_io;
895 bio->bi_end_io = fn;
896}
897
898static int ensure_next_mapping(struct pool *pool)
899{
900 if (pool->next_mapping)
901 return 0;
902
903 pool->next_mapping = mempool_alloc(pool->mapping_pool, GFP_ATOMIC);
904
905 return pool->next_mapping ? 0 : -ENOMEM;
906}
907
908static struct new_mapping *get_next_mapping(struct pool *pool)
909{
910 struct new_mapping *r = pool->next_mapping;
911
912 BUG_ON(!pool->next_mapping);
913
914 pool->next_mapping = NULL;
915
916 return r;
917}
918
919static void schedule_copy(struct thin_c *tc, dm_block_t virt_block,
920 dm_block_t data_origin, dm_block_t data_dest,
921 struct cell *cell, struct bio *bio)
922{
923 int r;
924 struct pool *pool = tc->pool;
925 struct new_mapping *m = get_next_mapping(pool);
926
927 INIT_LIST_HEAD(&m->list);
928 m->prepared = 0;
929 m->tc = tc;
930 m->virt_block = virt_block;
931 m->data_block = data_dest;
932 m->cell = cell;
933 m->err = 0;
934 m->bio = NULL;
935
936 ds_add_work(&pool->ds, &m->list);
937
938 /*
939 * IO to pool_dev remaps to the pool target's data_dev.
940 *
941 * If the whole block of data is being overwritten, we can issue the
942 * bio immediately. Otherwise we use kcopyd to clone the data first.
943 */
944 if (io_overwrites_block(pool, bio)) {
945 m->bio = bio;
946 save_and_set_endio(bio, &m->saved_bi_end_io, overwrite_endio);
947 dm_get_mapinfo(bio)->ptr = m;
948 remap_and_issue(tc, bio, data_dest);
949 } else {
950 struct dm_io_region from, to;
951
952 from.bdev = tc->pool_dev->bdev;
953 from.sector = data_origin * pool->sectors_per_block;
954 from.count = pool->sectors_per_block;
955
956 to.bdev = tc->pool_dev->bdev;
957 to.sector = data_dest * pool->sectors_per_block;
958 to.count = pool->sectors_per_block;
959
960 r = dm_kcopyd_copy(pool->copier, &from, 1, &to,
961 0, copy_complete, m);
962 if (r < 0) {
963 mempool_free(m, pool->mapping_pool);
964 DMERR("dm_kcopyd_copy() failed");
965 cell_error(cell);
966 }
967 }
968}
969
970static void schedule_zero(struct thin_c *tc, dm_block_t virt_block,
971 dm_block_t data_block, struct cell *cell,
972 struct bio *bio)
973{
974 struct pool *pool = tc->pool;
975 struct new_mapping *m = get_next_mapping(pool);
976
977 INIT_LIST_HEAD(&m->list);
978 m->prepared = 0;
979 m->tc = tc;
980 m->virt_block = virt_block;
981 m->data_block = data_block;
982 m->cell = cell;
983 m->err = 0;
984 m->bio = NULL;
985
986 /*
987 * If the whole block of data is being overwritten or we are not
988 * zeroing pre-existing data, we can issue the bio immediately.
989 * Otherwise we use kcopyd to zero the data first.
990 */
991 if (!pool->zero_new_blocks)
992 process_prepared_mapping(m);
993
994 else if (io_overwrites_block(pool, bio)) {
995 m->bio = bio;
996 save_and_set_endio(bio, &m->saved_bi_end_io, overwrite_endio);
997 dm_get_mapinfo(bio)->ptr = m;
998 remap_and_issue(tc, bio, data_block);
999
1000 } else {
1001 int r;
1002 struct dm_io_region to;
1003
1004 to.bdev = tc->pool_dev->bdev;
1005 to.sector = data_block * pool->sectors_per_block;
1006 to.count = pool->sectors_per_block;
1007
1008 r = dm_kcopyd_zero(pool->copier, 1, &to, 0, copy_complete, m);
1009 if (r < 0) {
1010 mempool_free(m, pool->mapping_pool);
1011 DMERR("dm_kcopyd_zero() failed");
1012 cell_error(cell);
1013 }
1014 }
1015}
1016
1017static int alloc_data_block(struct thin_c *tc, dm_block_t *result)
1018{
1019 int r;
1020 dm_block_t free_blocks;
1021 unsigned long flags;
1022 struct pool *pool = tc->pool;
1023
1024 r = dm_pool_get_free_block_count(pool->pmd, &free_blocks);
1025 if (r)
1026 return r;
1027
1028 if (free_blocks <= pool->low_water_blocks && !pool->low_water_triggered) {
1029 DMWARN("%s: reached low water mark, sending event.",
1030 dm_device_name(pool->pool_md));
1031 spin_lock_irqsave(&pool->lock, flags);
1032 pool->low_water_triggered = 1;
1033 spin_unlock_irqrestore(&pool->lock, flags);
1034 dm_table_event(pool->ti->table);
1035 }
1036
1037 if (!free_blocks) {
1038 if (pool->no_free_space)
1039 return -ENOSPC;
1040 else {
1041 /*
1042 * Try to commit to see if that will free up some
1043 * more space.
1044 */
1045 r = dm_pool_commit_metadata(pool->pmd);
1046 if (r) {
1047 DMERR("%s: dm_pool_commit_metadata() failed, error = %d",
1048 __func__, r);
1049 return r;
1050 }
1051
1052 r = dm_pool_get_free_block_count(pool->pmd, &free_blocks);
1053 if (r)
1054 return r;
1055
1056 /*
1057 * If we still have no space we set a flag to avoid
1058 * doing all this checking and return -ENOSPC.
1059 */
1060 if (!free_blocks) {
1061 DMWARN("%s: no free space available.",
1062 dm_device_name(pool->pool_md));
1063 spin_lock_irqsave(&pool->lock, flags);
1064 pool->no_free_space = 1;
1065 spin_unlock_irqrestore(&pool->lock, flags);
1066 return -ENOSPC;
1067 }
1068 }
1069 }
1070
1071 r = dm_pool_alloc_data_block(pool->pmd, result);
1072 if (r)
1073 return r;
1074
1075 return 0;
1076}
1077
1078/*
1079 * If we have run out of space, queue bios until the device is
1080 * resumed, presumably after having been reloaded with more space.
1081 */
1082static void retry_on_resume(struct bio *bio)
1083{
1084 struct thin_c *tc = dm_get_mapinfo(bio)->ptr;
1085 struct pool *pool = tc->pool;
1086 unsigned long flags;
1087
1088 spin_lock_irqsave(&pool->lock, flags);
1089 bio_list_add(&pool->retry_on_resume_list, bio);
1090 spin_unlock_irqrestore(&pool->lock, flags);
1091}
1092
1093static void no_space(struct cell *cell)
1094{
1095 struct bio *bio;
1096 struct bio_list bios;
1097
1098 bio_list_init(&bios);
1099 cell_release(cell, &bios);
1100
1101 while ((bio = bio_list_pop(&bios)))
1102 retry_on_resume(bio);
1103}
1104
1105static void break_sharing(struct thin_c *tc, struct bio *bio, dm_block_t block,
1106 struct cell_key *key,
1107 struct dm_thin_lookup_result *lookup_result,
1108 struct cell *cell)
1109{
1110 int r;
1111 dm_block_t data_block;
1112
1113 r = alloc_data_block(tc, &data_block);
1114 switch (r) {
1115 case 0:
1116 schedule_copy(tc, block, lookup_result->block,
1117 data_block, cell, bio);
1118 break;
1119
1120 case -ENOSPC:
1121 no_space(cell);
1122 break;
1123
1124 default:
1125 DMERR("%s: alloc_data_block() failed, error = %d", __func__, r);
1126 cell_error(cell);
1127 break;
1128 }
1129}
1130
1131static void process_shared_bio(struct thin_c *tc, struct bio *bio,
1132 dm_block_t block,
1133 struct dm_thin_lookup_result *lookup_result)
1134{
1135 struct cell *cell;
1136 struct pool *pool = tc->pool;
1137 struct cell_key key;
1138
1139 /*
1140 * If cell is already occupied, then sharing is already in the process
1141 * of being broken so we have nothing further to do here.
1142 */
1143 build_data_key(tc->td, lookup_result->block, &key);
1144 if (bio_detain(pool->prison, &key, bio, &cell))
1145 return;
1146
1147 if (bio_data_dir(bio) == WRITE)
1148 break_sharing(tc, bio, block, &key, lookup_result, cell);
1149 else {
1150 struct endio_hook *h;
1151 h = mempool_alloc(pool->endio_hook_pool, GFP_NOIO);
1152
1153 h->tc = tc;
1154 h->entry = ds_inc(&pool->ds);
1155 save_and_set_endio(bio, &h->saved_bi_end_io, shared_read_endio);
1156 dm_get_mapinfo(bio)->ptr = h;
1157
1158 cell_release_singleton(cell, bio);
1159 remap_and_issue(tc, bio, lookup_result->block);
1160 }
1161}
1162
1163static void provision_block(struct thin_c *tc, struct bio *bio, dm_block_t block,
1164 struct cell *cell)
1165{
1166 int r;
1167 dm_block_t data_block;
1168
1169 /*
1170 * Remap empty bios (flushes) immediately, without provisioning.
1171 */
1172 if (!bio->bi_size) {
1173 cell_release_singleton(cell, bio);
1174 remap_and_issue(tc, bio, 0);
1175 return;
1176 }
1177
1178 /*
1179 * Fill read bios with zeroes and complete them immediately.
1180 */
1181 if (bio_data_dir(bio) == READ) {
1182 zero_fill_bio(bio);
1183 cell_release_singleton(cell, bio);
1184 bio_endio(bio, 0);
1185 return;
1186 }
1187
1188 r = alloc_data_block(tc, &data_block);
1189 switch (r) {
1190 case 0:
1191 schedule_zero(tc, block, data_block, cell, bio);
1192 break;
1193
1194 case -ENOSPC:
1195 no_space(cell);
1196 break;
1197
1198 default:
1199 DMERR("%s: alloc_data_block() failed, error = %d", __func__, r);
1200 cell_error(cell);
1201 break;
1202 }
1203}
1204
1205static void process_bio(struct thin_c *tc, struct bio *bio)
1206{
1207 int r;
1208 dm_block_t block = get_bio_block(tc, bio);
1209 struct cell *cell;
1210 struct cell_key key;
1211 struct dm_thin_lookup_result lookup_result;
1212
1213 /*
1214 * If cell is already occupied, then the block is already
1215 * being provisioned so we have nothing further to do here.
1216 */
1217 build_virtual_key(tc->td, block, &key);
1218 if (bio_detain(tc->pool->prison, &key, bio, &cell))
1219 return;
1220
1221 r = dm_thin_find_block(tc->td, block, 1, &lookup_result);
1222 switch (r) {
1223 case 0:
1224 /*
1225 * We can release this cell now. This thread is the only
1226 * one that puts bios into a cell, and we know there were
1227 * no preceding bios.
1228 */
1229 /*
1230 * TODO: this will probably have to change when discard goes
1231 * back in.
1232 */
1233 cell_release_singleton(cell, bio);
1234
1235 if (lookup_result.shared)
1236 process_shared_bio(tc, bio, block, &lookup_result);
1237 else
1238 remap_and_issue(tc, bio, lookup_result.block);
1239 break;
1240
1241 case -ENODATA:
1242 provision_block(tc, bio, block, cell);
1243 break;
1244
1245 default:
1246 DMERR("dm_thin_find_block() failed, error = %d", r);
1247 bio_io_error(bio);
1248 break;
1249 }
1250}
1251
1252static void process_deferred_bios(struct pool *pool)
1253{
1254 unsigned long flags;
1255 struct bio *bio;
1256 struct bio_list bios;
1257 int r;
1258
1259 bio_list_init(&bios);
1260
1261 spin_lock_irqsave(&pool->lock, flags);
1262 bio_list_merge(&bios, &pool->deferred_bios);
1263 bio_list_init(&pool->deferred_bios);
1264 spin_unlock_irqrestore(&pool->lock, flags);
1265
1266 while ((bio = bio_list_pop(&bios))) {
1267 struct thin_c *tc = dm_get_mapinfo(bio)->ptr;
1268 /*
1269 * If we've got no free new_mapping structs, and processing
1270 * this bio might require one, we pause until there are some
1271 * prepared mappings to process.
1272 */
1273 if (ensure_next_mapping(pool)) {
1274 spin_lock_irqsave(&pool->lock, flags);
1275 bio_list_merge(&pool->deferred_bios, &bios);
1276 spin_unlock_irqrestore(&pool->lock, flags);
1277
1278 break;
1279 }
1280 process_bio(tc, bio);
1281 }
1282
1283 /*
1284 * If there are any deferred flush bios, we must commit
1285 * the metadata before issuing them.
1286 */
1287 bio_list_init(&bios);
1288 spin_lock_irqsave(&pool->lock, flags);
1289 bio_list_merge(&bios, &pool->deferred_flush_bios);
1290 bio_list_init(&pool->deferred_flush_bios);
1291 spin_unlock_irqrestore(&pool->lock, flags);
1292
1293 if (bio_list_empty(&bios))
1294 return;
1295
1296 r = dm_pool_commit_metadata(pool->pmd);
1297 if (r) {
1298 DMERR("%s: dm_pool_commit_metadata() failed, error = %d",
1299 __func__, r);
1300 while ((bio = bio_list_pop(&bios)))
1301 bio_io_error(bio);
1302 return;
1303 }
1304
1305 while ((bio = bio_list_pop(&bios)))
1306 generic_make_request(bio);
1307}
1308
1309static void do_worker(struct work_struct *ws)
1310{
1311 struct pool *pool = container_of(ws, struct pool, worker);
1312
1313 process_prepared_mappings(pool);
1314 process_deferred_bios(pool);
1315}
1316
1317/*----------------------------------------------------------------*/
1318
1319/*
1320 * Mapping functions.
1321 */
1322
1323/*
1324 * Called only while mapping a thin bio to hand it over to the workqueue.
1325 */
1326static void thin_defer_bio(struct thin_c *tc, struct bio *bio)
1327{
1328 unsigned long flags;
1329 struct pool *pool = tc->pool;
1330
1331 spin_lock_irqsave(&pool->lock, flags);
1332 bio_list_add(&pool->deferred_bios, bio);
1333 spin_unlock_irqrestore(&pool->lock, flags);
1334
1335 wake_worker(pool);
1336}
1337
1338/*
1339 * Non-blocking function called from the thin target's map function.
1340 */
1341static int thin_bio_map(struct dm_target *ti, struct bio *bio,
1342 union map_info *map_context)
1343{
1344 int r;
1345 struct thin_c *tc = ti->private;
1346 dm_block_t block = get_bio_block(tc, bio);
1347 struct dm_thin_device *td = tc->td;
1348 struct dm_thin_lookup_result result;
1349
1350 /*
1351 * Save the thin context for easy access from the deferred bio later.
1352 */
1353 map_context->ptr = tc;
1354
1355 if (bio->bi_rw & (REQ_FLUSH | REQ_FUA)) {
1356 thin_defer_bio(tc, bio);
1357 return DM_MAPIO_SUBMITTED;
1358 }
1359
1360 r = dm_thin_find_block(td, block, 0, &result);
1361
1362 /*
1363 * Note that we defer readahead too.
1364 */
1365 switch (r) {
1366 case 0:
1367 if (unlikely(result.shared)) {
1368 /*
1369 * We have a race condition here between the
1370 * result.shared value returned by the lookup and
1371 * snapshot creation, which may cause new
1372 * sharing.
1373 *
1374 * To avoid this always quiesce the origin before
1375 * taking the snap. You want to do this anyway to
1376 * ensure a consistent application view
1377 * (i.e. lockfs).
1378 *
1379 * More distant ancestors are irrelevant. The
1380 * shared flag will be set in their case.
1381 */
1382 thin_defer_bio(tc, bio);
1383 r = DM_MAPIO_SUBMITTED;
1384 } else {
1385 remap(tc, bio, result.block);
1386 r = DM_MAPIO_REMAPPED;
1387 }
1388 break;
1389
1390 case -ENODATA:
1391 /*
1392 * In future, the failed dm_thin_find_block above could
1393 * provide the hint to load the metadata into cache.
1394 */
1395 case -EWOULDBLOCK:
1396 thin_defer_bio(tc, bio);
1397 r = DM_MAPIO_SUBMITTED;
1398 break;
1399 }
1400
1401 return r;
1402}
1403
1404static int pool_is_congested(struct dm_target_callbacks *cb, int bdi_bits)
1405{
1406 int r;
1407 unsigned long flags;
1408 struct pool_c *pt = container_of(cb, struct pool_c, callbacks);
1409
1410 spin_lock_irqsave(&pt->pool->lock, flags);
1411 r = !bio_list_empty(&pt->pool->retry_on_resume_list);
1412 spin_unlock_irqrestore(&pt->pool->lock, flags);
1413
1414 if (!r) {
1415 struct request_queue *q = bdev_get_queue(pt->data_dev->bdev);
1416 r = bdi_congested(&q->backing_dev_info, bdi_bits);
1417 }
1418
1419 return r;
1420}
1421
1422static void __requeue_bios(struct pool *pool)
1423{
1424 bio_list_merge(&pool->deferred_bios, &pool->retry_on_resume_list);
1425 bio_list_init(&pool->retry_on_resume_list);
1426}
1427
1428/*----------------------------------------------------------------
1429 * Binding of control targets to a pool object
1430 *--------------------------------------------------------------*/
1431static int bind_control_target(struct pool *pool, struct dm_target *ti)
1432{
1433 struct pool_c *pt = ti->private;
1434
1435 pool->ti = ti;
1436 pool->low_water_blocks = pt->low_water_blocks;
1437 pool->zero_new_blocks = pt->zero_new_blocks;
1438
1439 return 0;
1440}
1441
1442static void unbind_control_target(struct pool *pool, struct dm_target *ti)
1443{
1444 if (pool->ti == ti)
1445 pool->ti = NULL;
1446}
1447
1448/*----------------------------------------------------------------
1449 * Pool creation
1450 *--------------------------------------------------------------*/
1451static void __pool_destroy(struct pool *pool)
1452{
1453 __pool_table_remove(pool);
1454
1455 if (dm_pool_metadata_close(pool->pmd) < 0)
1456 DMWARN("%s: dm_pool_metadata_close() failed.", __func__);
1457
1458 prison_destroy(pool->prison);
1459 dm_kcopyd_client_destroy(pool->copier);
1460
1461 if (pool->wq)
1462 destroy_workqueue(pool->wq);
1463
1464 if (pool->next_mapping)
1465 mempool_free(pool->next_mapping, pool->mapping_pool);
1466 mempool_destroy(pool->mapping_pool);
1467 mempool_destroy(pool->endio_hook_pool);
1468 kfree(pool);
1469}
1470
1471static struct pool *pool_create(struct mapped_device *pool_md,
1472 struct block_device *metadata_dev,
1473 unsigned long block_size, char **error)
1474{
1475 int r;
1476 void *err_p;
1477 struct pool *pool;
1478 struct dm_pool_metadata *pmd;
1479
1480 pmd = dm_pool_metadata_open(metadata_dev, block_size);
1481 if (IS_ERR(pmd)) {
1482 *error = "Error creating metadata object";
1483 return (struct pool *)pmd;
1484 }
1485
1486 pool = kmalloc(sizeof(*pool), GFP_KERNEL);
1487 if (!pool) {
1488 *error = "Error allocating memory for pool";
1489 err_p = ERR_PTR(-ENOMEM);
1490 goto bad_pool;
1491 }
1492
1493 pool->pmd = pmd;
1494 pool->sectors_per_block = block_size;
1495 pool->block_shift = ffs(block_size) - 1;
1496 pool->offset_mask = block_size - 1;
1497 pool->low_water_blocks = 0;
1498 pool->zero_new_blocks = 1;
1499 pool->prison = prison_create(PRISON_CELLS);
1500 if (!pool->prison) {
1501 *error = "Error creating pool's bio prison";
1502 err_p = ERR_PTR(-ENOMEM);
1503 goto bad_prison;
1504 }
1505
1506 pool->copier = dm_kcopyd_client_create();
1507 if (IS_ERR(pool->copier)) {
1508 r = PTR_ERR(pool->copier);
1509 *error = "Error creating pool's kcopyd client";
1510 err_p = ERR_PTR(r);
1511 goto bad_kcopyd_client;
1512 }
1513
1514 /*
1515 * Create singlethreaded workqueue that will service all devices
1516 * that use this metadata.
1517 */
1518 pool->wq = alloc_ordered_workqueue("dm-" DM_MSG_PREFIX, WQ_MEM_RECLAIM);
1519 if (!pool->wq) {
1520 *error = "Error creating pool's workqueue";
1521 err_p = ERR_PTR(-ENOMEM);
1522 goto bad_wq;
1523 }
1524
1525 INIT_WORK(&pool->worker, do_worker);
1526 spin_lock_init(&pool->lock);
1527 bio_list_init(&pool->deferred_bios);
1528 bio_list_init(&pool->deferred_flush_bios);
1529 INIT_LIST_HEAD(&pool->prepared_mappings);
1530 pool->low_water_triggered = 0;
1531 pool->no_free_space = 0;
1532 bio_list_init(&pool->retry_on_resume_list);
1533 ds_init(&pool->ds);
1534
1535 pool->next_mapping = NULL;
1536 pool->mapping_pool =
1537 mempool_create_kmalloc_pool(MAPPING_POOL_SIZE, sizeof(struct new_mapping));
1538 if (!pool->mapping_pool) {
1539 *error = "Error creating pool's mapping mempool";
1540 err_p = ERR_PTR(-ENOMEM);
1541 goto bad_mapping_pool;
1542 }
1543
1544 pool->endio_hook_pool =
1545 mempool_create_kmalloc_pool(ENDIO_HOOK_POOL_SIZE, sizeof(struct endio_hook));
1546 if (!pool->endio_hook_pool) {
1547 *error = "Error creating pool's endio_hook mempool";
1548 err_p = ERR_PTR(-ENOMEM);
1549 goto bad_endio_hook_pool;
1550 }
1551 pool->ref_count = 1;
1552 pool->pool_md = pool_md;
1553 pool->md_dev = metadata_dev;
1554 __pool_table_insert(pool);
1555
1556 return pool;
1557
1558bad_endio_hook_pool:
1559 mempool_destroy(pool->mapping_pool);
1560bad_mapping_pool:
1561 destroy_workqueue(pool->wq);
1562bad_wq:
1563 dm_kcopyd_client_destroy(pool->copier);
1564bad_kcopyd_client:
1565 prison_destroy(pool->prison);
1566bad_prison:
1567 kfree(pool);
1568bad_pool:
1569 if (dm_pool_metadata_close(pmd))
1570 DMWARN("%s: dm_pool_metadata_close() failed.", __func__);
1571
1572 return err_p;
1573}
1574
1575static void __pool_inc(struct pool *pool)
1576{
1577 BUG_ON(!mutex_is_locked(&dm_thin_pool_table.mutex));
1578 pool->ref_count++;
1579}
1580
1581static void __pool_dec(struct pool *pool)
1582{
1583 BUG_ON(!mutex_is_locked(&dm_thin_pool_table.mutex));
1584 BUG_ON(!pool->ref_count);
1585 if (!--pool->ref_count)
1586 __pool_destroy(pool);
1587}
1588
1589static struct pool *__pool_find(struct mapped_device *pool_md,
1590 struct block_device *metadata_dev,
1591 unsigned long block_size, char **error)
1592{
1593 struct pool *pool = __pool_table_lookup_metadata_dev(metadata_dev);
1594
1595 if (pool) {
1596 if (pool->pool_md != pool_md)
1597 return ERR_PTR(-EBUSY);
1598 __pool_inc(pool);
1599
1600 } else {
1601 pool = __pool_table_lookup(pool_md);
1602 if (pool) {
1603 if (pool->md_dev != metadata_dev)
1604 return ERR_PTR(-EINVAL);
1605 __pool_inc(pool);
1606
1607 } else
1608 pool = pool_create(pool_md, metadata_dev, block_size, error);
1609 }
1610
1611 return pool;
1612}
1613
1614/*----------------------------------------------------------------
1615 * Pool target methods
1616 *--------------------------------------------------------------*/
1617static void pool_dtr(struct dm_target *ti)
1618{
1619 struct pool_c *pt = ti->private;
1620
1621 mutex_lock(&dm_thin_pool_table.mutex);
1622
1623 unbind_control_target(pt->pool, ti);
1624 __pool_dec(pt->pool);
1625 dm_put_device(ti, pt->metadata_dev);
1626 dm_put_device(ti, pt->data_dev);
1627 kfree(pt);
1628
1629 mutex_unlock(&dm_thin_pool_table.mutex);
1630}
1631
1632struct pool_features {
1633 unsigned zero_new_blocks:1;
1634};
1635
1636static int parse_pool_features(struct dm_arg_set *as, struct pool_features *pf,
1637 struct dm_target *ti)
1638{
1639 int r;
1640 unsigned argc;
1641 const char *arg_name;
1642
1643 static struct dm_arg _args[] = {
1644 {0, 1, "Invalid number of pool feature arguments"},
1645 };
1646
1647 /*
1648 * No feature arguments supplied.
1649 */
1650 if (!as->argc)
1651 return 0;
1652
1653 r = dm_read_arg_group(_args, as, &argc, &ti->error);
1654 if (r)
1655 return -EINVAL;
1656
1657 while (argc && !r) {
1658 arg_name = dm_shift_arg(as);
1659 argc--;
1660
1661 if (!strcasecmp(arg_name, "skip_block_zeroing")) {
1662 pf->zero_new_blocks = 0;
1663 continue;
1664 }
1665
1666 ti->error = "Unrecognised pool feature requested";
1667 r = -EINVAL;
1668 }
1669
1670 return r;
1671}
1672
1673/*
1674 * thin-pool <metadata dev> <data dev>
1675 * <data block size (sectors)>
1676 * <low water mark (blocks)>
1677 * [<#feature args> [<arg>]*]
1678 *
1679 * Optional feature arguments are:
1680 * skip_block_zeroing: skips the zeroing of newly-provisioned blocks.
1681 */
1682static int pool_ctr(struct dm_target *ti, unsigned argc, char **argv)
1683{
1684 int r;
1685 struct pool_c *pt;
1686 struct pool *pool;
1687 struct pool_features pf;
1688 struct dm_arg_set as;
1689 struct dm_dev *data_dev;
1690 unsigned long block_size;
1691 dm_block_t low_water_blocks;
1692 struct dm_dev *metadata_dev;
1693 sector_t metadata_dev_size;
1694
1695 /*
1696 * FIXME Remove validation from scope of lock.
1697 */
1698 mutex_lock(&dm_thin_pool_table.mutex);
1699
1700 if (argc < 4) {
1701 ti->error = "Invalid argument count";
1702 r = -EINVAL;
1703 goto out_unlock;
1704 }
1705 as.argc = argc;
1706 as.argv = argv;
1707
1708 r = dm_get_device(ti, argv[0], FMODE_READ | FMODE_WRITE, &metadata_dev);
1709 if (r) {
1710 ti->error = "Error opening metadata block device";
1711 goto out_unlock;
1712 }
1713
1714 metadata_dev_size = i_size_read(metadata_dev->bdev->bd_inode) >> SECTOR_SHIFT;
1715 if (metadata_dev_size > METADATA_DEV_MAX_SECTORS) {
1716 ti->error = "Metadata device is too large";
1717 r = -EINVAL;
1718 goto out_metadata;
1719 }
1720
1721 r = dm_get_device(ti, argv[1], FMODE_READ | FMODE_WRITE, &data_dev);
1722 if (r) {
1723 ti->error = "Error getting data device";
1724 goto out_metadata;
1725 }
1726
1727 if (kstrtoul(argv[2], 10, &block_size) || !block_size ||
1728 block_size < DATA_DEV_BLOCK_SIZE_MIN_SECTORS ||
1729 block_size > DATA_DEV_BLOCK_SIZE_MAX_SECTORS ||
1730 !is_power_of_2(block_size)) {
1731 ti->error = "Invalid block size";
1732 r = -EINVAL;
1733 goto out;
1734 }
1735
1736 if (kstrtoull(argv[3], 10, (unsigned long long *)&low_water_blocks)) {
1737 ti->error = "Invalid low water mark";
1738 r = -EINVAL;
1739 goto out;
1740 }
1741
1742 /*
1743 * Set default pool features.
1744 */
1745 memset(&pf, 0, sizeof(pf));
1746 pf.zero_new_blocks = 1;
1747
1748 dm_consume_args(&as, 4);
1749 r = parse_pool_features(&as, &pf, ti);
1750 if (r)
1751 goto out;
1752
1753 pt = kzalloc(sizeof(*pt), GFP_KERNEL);
1754 if (!pt) {
1755 r = -ENOMEM;
1756 goto out;
1757 }
1758
1759 pool = __pool_find(dm_table_get_md(ti->table), metadata_dev->bdev,
1760 block_size, &ti->error);
1761 if (IS_ERR(pool)) {
1762 r = PTR_ERR(pool);
1763 goto out_free_pt;
1764 }
1765
1766 pt->pool = pool;
1767 pt->ti = ti;
1768 pt->metadata_dev = metadata_dev;
1769 pt->data_dev = data_dev;
1770 pt->low_water_blocks = low_water_blocks;
1771 pt->zero_new_blocks = pf.zero_new_blocks;
1772 ti->num_flush_requests = 1;
1773 ti->num_discard_requests = 0;
1774 ti->private = pt;
1775
1776 pt->callbacks.congested_fn = pool_is_congested;
1777 dm_table_add_target_callbacks(ti->table, &pt->callbacks);
1778
1779 mutex_unlock(&dm_thin_pool_table.mutex);
1780
1781 return 0;
1782
1783out_free_pt:
1784 kfree(pt);
1785out:
1786 dm_put_device(ti, data_dev);
1787out_metadata:
1788 dm_put_device(ti, metadata_dev);
1789out_unlock:
1790 mutex_unlock(&dm_thin_pool_table.mutex);
1791
1792 return r;
1793}
1794
1795static int pool_map(struct dm_target *ti, struct bio *bio,
1796 union map_info *map_context)
1797{
1798 int r;
1799 struct pool_c *pt = ti->private;
1800 struct pool *pool = pt->pool;
1801 unsigned long flags;
1802
1803 /*
1804 * As this is a singleton target, ti->begin is always zero.
1805 */
1806 spin_lock_irqsave(&pool->lock, flags);
1807 bio->bi_bdev = pt->data_dev->bdev;
1808 r = DM_MAPIO_REMAPPED;
1809 spin_unlock_irqrestore(&pool->lock, flags);
1810
1811 return r;
1812}
1813
1814/*
1815 * Retrieves the number of blocks of the data device from
1816 * the superblock and compares it to the actual device size,
1817 * thus resizing the data device in case it has grown.
1818 *
1819 * This both copes with opening preallocated data devices in the ctr
1820 * being followed by a resume
1821 * -and-
1822 * calling the resume method individually after userspace has
1823 * grown the data device in reaction to a table event.
1824 */
1825static int pool_preresume(struct dm_target *ti)
1826{
1827 int r;
1828 struct pool_c *pt = ti->private;
1829 struct pool *pool = pt->pool;
1830 dm_block_t data_size, sb_data_size;
1831
1832 /*
1833 * Take control of the pool object.
1834 */
1835 r = bind_control_target(pool, ti);
1836 if (r)
1837 return r;
1838
1839 data_size = ti->len >> pool->block_shift;
1840 r = dm_pool_get_data_dev_size(pool->pmd, &sb_data_size);
1841 if (r) {
1842 DMERR("failed to retrieve data device size");
1843 return r;
1844 }
1845
1846 if (data_size < sb_data_size) {
1847 DMERR("pool target too small, is %llu blocks (expected %llu)",
1848 data_size, sb_data_size);
1849 return -EINVAL;
1850
1851 } else if (data_size > sb_data_size) {
1852 r = dm_pool_resize_data_dev(pool->pmd, data_size);
1853 if (r) {
1854 DMERR("failed to resize data device");
1855 return r;
1856 }
1857
1858 r = dm_pool_commit_metadata(pool->pmd);
1859 if (r) {
1860 DMERR("%s: dm_pool_commit_metadata() failed, error = %d",
1861 __func__, r);
1862 return r;
1863 }
1864 }
1865
1866 return 0;
1867}
1868
1869static void pool_resume(struct dm_target *ti)
1870{
1871 struct pool_c *pt = ti->private;
1872 struct pool *pool = pt->pool;
1873 unsigned long flags;
1874
1875 spin_lock_irqsave(&pool->lock, flags);
1876 pool->low_water_triggered = 0;
1877 pool->no_free_space = 0;
1878 __requeue_bios(pool);
1879 spin_unlock_irqrestore(&pool->lock, flags);
1880
1881 wake_worker(pool);
1882}
1883
1884static void pool_postsuspend(struct dm_target *ti)
1885{
1886 int r;
1887 struct pool_c *pt = ti->private;
1888 struct pool *pool = pt->pool;
1889
1890 flush_workqueue(pool->wq);
1891
1892 r = dm_pool_commit_metadata(pool->pmd);
1893 if (r < 0) {
1894 DMERR("%s: dm_pool_commit_metadata() failed, error = %d",
1895 __func__, r);
1896 /* FIXME: invalidate device? error the next FUA or FLUSH bio ?*/
1897 }
1898}
1899
1900static int check_arg_count(unsigned argc, unsigned args_required)
1901{
1902 if (argc != args_required) {
1903 DMWARN("Message received with %u arguments instead of %u.",
1904 argc, args_required);
1905 return -EINVAL;
1906 }
1907
1908 return 0;
1909}
1910
1911static int read_dev_id(char *arg, dm_thin_id *dev_id, int warning)
1912{
1913 if (!kstrtoull(arg, 10, (unsigned long long *)dev_id) &&
1914 *dev_id <= MAX_DEV_ID)
1915 return 0;
1916
1917 if (warning)
1918 DMWARN("Message received with invalid device id: %s", arg);
1919
1920 return -EINVAL;
1921}
1922
1923static int process_create_thin_mesg(unsigned argc, char **argv, struct pool *pool)
1924{
1925 dm_thin_id dev_id;
1926 int r;
1927
1928 r = check_arg_count(argc, 2);
1929 if (r)
1930 return r;
1931
1932 r = read_dev_id(argv[1], &dev_id, 1);
1933 if (r)
1934 return r;
1935
1936 r = dm_pool_create_thin(pool->pmd, dev_id);
1937 if (r) {
1938 DMWARN("Creation of new thinly-provisioned device with id %s failed.",
1939 argv[1]);
1940 return r;
1941 }
1942
1943 return 0;
1944}
1945
1946static int process_create_snap_mesg(unsigned argc, char **argv, struct pool *pool)
1947{
1948 dm_thin_id dev_id;
1949 dm_thin_id origin_dev_id;
1950 int r;
1951
1952 r = check_arg_count(argc, 3);
1953 if (r)
1954 return r;
1955
1956 r = read_dev_id(argv[1], &dev_id, 1);
1957 if (r)
1958 return r;
1959
1960 r = read_dev_id(argv[2], &origin_dev_id, 1);
1961 if (r)
1962 return r;
1963
1964 r = dm_pool_create_snap(pool->pmd, dev_id, origin_dev_id);
1965 if (r) {
1966 DMWARN("Creation of new snapshot %s of device %s failed.",
1967 argv[1], argv[2]);
1968 return r;
1969 }
1970
1971 return 0;
1972}
1973
1974static int process_delete_mesg(unsigned argc, char **argv, struct pool *pool)
1975{
1976 dm_thin_id dev_id;
1977 int r;
1978
1979 r = check_arg_count(argc, 2);
1980 if (r)
1981 return r;
1982
1983 r = read_dev_id(argv[1], &dev_id, 1);
1984 if (r)
1985 return r;
1986
1987 r = dm_pool_delete_thin_device(pool->pmd, dev_id);
1988 if (r)
1989 DMWARN("Deletion of thin device %s failed.", argv[1]);
1990
1991 return r;
1992}
1993
1994static int process_set_transaction_id_mesg(unsigned argc, char **argv, struct pool *pool)
1995{
1996 dm_thin_id old_id, new_id;
1997 int r;
1998
1999 r = check_arg_count(argc, 3);
2000 if (r)
2001 return r;
2002
2003 if (kstrtoull(argv[1], 10, (unsigned long long *)&old_id)) {
2004 DMWARN("set_transaction_id message: Unrecognised id %s.", argv[1]);
2005 return -EINVAL;
2006 }
2007
2008 if (kstrtoull(argv[2], 10, (unsigned long long *)&new_id)) {
2009 DMWARN("set_transaction_id message: Unrecognised new id %s.", argv[2]);
2010 return -EINVAL;
2011 }
2012
2013 r = dm_pool_set_metadata_transaction_id(pool->pmd, old_id, new_id);
2014 if (r) {
2015 DMWARN("Failed to change transaction id from %s to %s.",
2016 argv[1], argv[2]);
2017 return r;
2018 }
2019
2020 return 0;
2021}
2022
2023/*
2024 * Messages supported:
2025 * create_thin <dev_id>
2026 * create_snap <dev_id> <origin_id>
2027 * delete <dev_id>
2028 * trim <dev_id> <new_size_in_sectors>
2029 * set_transaction_id <current_trans_id> <new_trans_id>
2030 */
2031static int pool_message(struct dm_target *ti, unsigned argc, char **argv)
2032{
2033 int r = -EINVAL;
2034 struct pool_c *pt = ti->private;
2035 struct pool *pool = pt->pool;
2036
2037 if (!strcasecmp(argv[0], "create_thin"))
2038 r = process_create_thin_mesg(argc, argv, pool);
2039
2040 else if (!strcasecmp(argv[0], "create_snap"))
2041 r = process_create_snap_mesg(argc, argv, pool);
2042
2043 else if (!strcasecmp(argv[0], "delete"))
2044 r = process_delete_mesg(argc, argv, pool);
2045
2046 else if (!strcasecmp(argv[0], "set_transaction_id"))
2047 r = process_set_transaction_id_mesg(argc, argv, pool);
2048
2049 else
2050 DMWARN("Unrecognised thin pool target message received: %s", argv[0]);
2051
2052 if (!r) {
2053 r = dm_pool_commit_metadata(pool->pmd);
2054 if (r)
2055 DMERR("%s message: dm_pool_commit_metadata() failed, error = %d",
2056 argv[0], r);
2057 }
2058
2059 return r;
2060}
2061
2062/*
2063 * Status line is:
2064 * <transaction id> <used metadata sectors>/<total metadata sectors>
2065 * <used data sectors>/<total data sectors> <held metadata root>
2066 */
2067static int pool_status(struct dm_target *ti, status_type_t type,
2068 char *result, unsigned maxlen)
2069{
2070 int r;
2071 unsigned sz = 0;
2072 uint64_t transaction_id;
2073 dm_block_t nr_free_blocks_data;
2074 dm_block_t nr_free_blocks_metadata;
2075 dm_block_t nr_blocks_data;
2076 dm_block_t nr_blocks_metadata;
2077 dm_block_t held_root;
2078 char buf[BDEVNAME_SIZE];
2079 char buf2[BDEVNAME_SIZE];
2080 struct pool_c *pt = ti->private;
2081 struct pool *pool = pt->pool;
2082
2083 switch (type) {
2084 case STATUSTYPE_INFO:
2085 r = dm_pool_get_metadata_transaction_id(pool->pmd,
2086 &transaction_id);
2087 if (r)
2088 return r;
2089
2090 r = dm_pool_get_free_metadata_block_count(pool->pmd,
2091 &nr_free_blocks_metadata);
2092 if (r)
2093 return r;
2094
2095 r = dm_pool_get_metadata_dev_size(pool->pmd, &nr_blocks_metadata);
2096 if (r)
2097 return r;
2098
2099 r = dm_pool_get_free_block_count(pool->pmd,
2100 &nr_free_blocks_data);
2101 if (r)
2102 return r;
2103
2104 r = dm_pool_get_data_dev_size(pool->pmd, &nr_blocks_data);
2105 if (r)
2106 return r;
2107
2108 r = dm_pool_get_held_metadata_root(pool->pmd, &held_root);
2109 if (r)
2110 return r;
2111
2112 DMEMIT("%llu %llu/%llu %llu/%llu ",
2113 (unsigned long long)transaction_id,
2114 (unsigned long long)(nr_blocks_metadata - nr_free_blocks_metadata),
2115 (unsigned long long)nr_blocks_metadata,
2116 (unsigned long long)(nr_blocks_data - nr_free_blocks_data),
2117 (unsigned long long)nr_blocks_data);
2118
2119 if (held_root)
2120 DMEMIT("%llu", held_root);
2121 else
2122 DMEMIT("-");
2123
2124 break;
2125
2126 case STATUSTYPE_TABLE:
2127 DMEMIT("%s %s %lu %llu ",
2128 format_dev_t(buf, pt->metadata_dev->bdev->bd_dev),
2129 format_dev_t(buf2, pt->data_dev->bdev->bd_dev),
2130 (unsigned long)pool->sectors_per_block,
2131 (unsigned long long)pt->low_water_blocks);
2132
2133 DMEMIT("%u ", !pool->zero_new_blocks);
2134
2135 if (!pool->zero_new_blocks)
2136 DMEMIT("skip_block_zeroing ");
2137 break;
2138 }
2139
2140 return 0;
2141}
2142
2143static int pool_iterate_devices(struct dm_target *ti,
2144 iterate_devices_callout_fn fn, void *data)
2145{
2146 struct pool_c *pt = ti->private;
2147
2148 return fn(ti, pt->data_dev, 0, ti->len, data);
2149}
2150
2151static int pool_merge(struct dm_target *ti, struct bvec_merge_data *bvm,
2152 struct bio_vec *biovec, int max_size)
2153{
2154 struct pool_c *pt = ti->private;
2155 struct request_queue *q = bdev_get_queue(pt->data_dev->bdev);
2156
2157 if (!q->merge_bvec_fn)
2158 return max_size;
2159
2160 bvm->bi_bdev = pt->data_dev->bdev;
2161
2162 return min(max_size, q->merge_bvec_fn(q, bvm, biovec));
2163}
2164
2165static void pool_io_hints(struct dm_target *ti, struct queue_limits *limits)
2166{
2167 struct pool_c *pt = ti->private;
2168 struct pool *pool = pt->pool;
2169
2170 blk_limits_io_min(limits, 0);
2171 blk_limits_io_opt(limits, pool->sectors_per_block << SECTOR_SHIFT);
2172}
2173
2174static struct target_type pool_target = {
2175 .name = "thin-pool",
2176 .features = DM_TARGET_SINGLETON | DM_TARGET_ALWAYS_WRITEABLE |
2177 DM_TARGET_IMMUTABLE,
2178 .version = {1, 0, 0},
2179 .module = THIS_MODULE,
2180 .ctr = pool_ctr,
2181 .dtr = pool_dtr,
2182 .map = pool_map,
2183 .postsuspend = pool_postsuspend,
2184 .preresume = pool_preresume,
2185 .resume = pool_resume,
2186 .message = pool_message,
2187 .status = pool_status,
2188 .merge = pool_merge,
2189 .iterate_devices = pool_iterate_devices,
2190 .io_hints = pool_io_hints,
2191};
2192
2193/*----------------------------------------------------------------
2194 * Thin target methods
2195 *--------------------------------------------------------------*/
2196static void thin_dtr(struct dm_target *ti)
2197{
2198 struct thin_c *tc = ti->private;
2199
2200 mutex_lock(&dm_thin_pool_table.mutex);
2201
2202 __pool_dec(tc->pool);
2203 dm_pool_close_thin_device(tc->td);
2204 dm_put_device(ti, tc->pool_dev);
2205 kfree(tc);
2206
2207 mutex_unlock(&dm_thin_pool_table.mutex);
2208}
2209
2210/*
2211 * Thin target parameters:
2212 *
2213 * <pool_dev> <dev_id>
2214 *
2215 * pool_dev: the path to the pool (eg, /dev/mapper/my_pool)
2216 * dev_id: the internal device identifier
2217 */
2218static int thin_ctr(struct dm_target *ti, unsigned argc, char **argv)
2219{
2220 int r;
2221 struct thin_c *tc;
2222 struct dm_dev *pool_dev;
2223 struct mapped_device *pool_md;
2224
2225 mutex_lock(&dm_thin_pool_table.mutex);
2226
2227 if (argc != 2) {
2228 ti->error = "Invalid argument count";
2229 r = -EINVAL;
2230 goto out_unlock;
2231 }
2232
2233 tc = ti->private = kzalloc(sizeof(*tc), GFP_KERNEL);
2234 if (!tc) {
2235 ti->error = "Out of memory";
2236 r = -ENOMEM;
2237 goto out_unlock;
2238 }
2239
2240 r = dm_get_device(ti, argv[0], dm_table_get_mode(ti->table), &pool_dev);
2241 if (r) {
2242 ti->error = "Error opening pool device";
2243 goto bad_pool_dev;
2244 }
2245 tc->pool_dev = pool_dev;
2246
2247 if (read_dev_id(argv[1], (unsigned long long *)&tc->dev_id, 0)) {
2248 ti->error = "Invalid device id";
2249 r = -EINVAL;
2250 goto bad_common;
2251 }
2252
2253 pool_md = dm_get_md(tc->pool_dev->bdev->bd_dev);
2254 if (!pool_md) {
2255 ti->error = "Couldn't get pool mapped device";
2256 r = -EINVAL;
2257 goto bad_common;
2258 }
2259
2260 tc->pool = __pool_table_lookup(pool_md);
2261 if (!tc->pool) {
2262 ti->error = "Couldn't find pool object";
2263 r = -EINVAL;
2264 goto bad_pool_lookup;
2265 }
2266 __pool_inc(tc->pool);
2267
2268 r = dm_pool_open_thin_device(tc->pool->pmd, tc->dev_id, &tc->td);
2269 if (r) {
2270 ti->error = "Couldn't open thin internal device";
2271 goto bad_thin_open;
2272 }
2273
2274 ti->split_io = tc->pool->sectors_per_block;
2275 ti->num_flush_requests = 1;
2276 ti->num_discard_requests = 0;
2277 ti->discards_supported = 0;
2278
2279 dm_put(pool_md);
2280
2281 mutex_unlock(&dm_thin_pool_table.mutex);
2282
2283 return 0;
2284
2285bad_thin_open:
2286 __pool_dec(tc->pool);
2287bad_pool_lookup:
2288 dm_put(pool_md);
2289bad_common:
2290 dm_put_device(ti, tc->pool_dev);
2291bad_pool_dev:
2292 kfree(tc);
2293out_unlock:
2294 mutex_unlock(&dm_thin_pool_table.mutex);
2295
2296 return r;
2297}
2298
2299static int thin_map(struct dm_target *ti, struct bio *bio,
2300 union map_info *map_context)
2301{
2302 bio->bi_sector -= ti->begin;
2303
2304 return thin_bio_map(ti, bio, map_context);
2305}
2306
2307static void thin_postsuspend(struct dm_target *ti)
2308{
2309 if (dm_noflush_suspending(ti))
2310 requeue_io((struct thin_c *)ti->private);
2311}
2312
2313/*
2314 * <nr mapped sectors> <highest mapped sector>
2315 */
2316static int thin_status(struct dm_target *ti, status_type_t type,
2317 char *result, unsigned maxlen)
2318{
2319 int r;
2320 ssize_t sz = 0;
2321 dm_block_t mapped, highest;
2322 char buf[BDEVNAME_SIZE];
2323 struct thin_c *tc = ti->private;
2324
2325 if (!tc->td)
2326 DMEMIT("-");
2327 else {
2328 switch (type) {
2329 case STATUSTYPE_INFO:
2330 r = dm_thin_get_mapped_count(tc->td, &mapped);
2331 if (r)
2332 return r;
2333
2334 r = dm_thin_get_highest_mapped_block(tc->td, &highest);
2335 if (r < 0)
2336 return r;
2337
2338 DMEMIT("%llu ", mapped * tc->pool->sectors_per_block);
2339 if (r)
2340 DMEMIT("%llu", ((highest + 1) *
2341 tc->pool->sectors_per_block) - 1);
2342 else
2343 DMEMIT("-");
2344 break;
2345
2346 case STATUSTYPE_TABLE:
2347 DMEMIT("%s %lu",
2348 format_dev_t(buf, tc->pool_dev->bdev->bd_dev),
2349 (unsigned long) tc->dev_id);
2350 break;
2351 }
2352 }
2353
2354 return 0;
2355}
2356
2357static int thin_iterate_devices(struct dm_target *ti,
2358 iterate_devices_callout_fn fn, void *data)
2359{
2360 dm_block_t blocks;
2361 struct thin_c *tc = ti->private;
2362
2363 /*
2364 * We can't call dm_pool_get_data_dev_size() since that blocks. So
2365 * we follow a more convoluted path through to the pool's target.
2366 */
2367 if (!tc->pool->ti)
2368 return 0; /* nothing is bound */
2369
2370 blocks = tc->pool->ti->len >> tc->pool->block_shift;
2371 if (blocks)
2372 return fn(ti, tc->pool_dev, 0, tc->pool->sectors_per_block * blocks, data);
2373
2374 return 0;
2375}
2376
2377static void thin_io_hints(struct dm_target *ti, struct queue_limits *limits)
2378{
2379 struct thin_c *tc = ti->private;
2380
2381 blk_limits_io_min(limits, 0);
2382 blk_limits_io_opt(limits, tc->pool->sectors_per_block << SECTOR_SHIFT);
2383}
2384
2385static struct target_type thin_target = {
2386 .name = "thin",
2387 .version = {1, 0, 0},
2388 .module = THIS_MODULE,
2389 .ctr = thin_ctr,
2390 .dtr = thin_dtr,
2391 .map = thin_map,
2392 .postsuspend = thin_postsuspend,
2393 .status = thin_status,
2394 .iterate_devices = thin_iterate_devices,
2395 .io_hints = thin_io_hints,
2396};
2397
2398/*----------------------------------------------------------------*/
2399
2400static int __init dm_thin_init(void)
2401{
2402 int r;
2403
2404 pool_table_init();
2405
2406 r = dm_register_target(&thin_target);
2407 if (r)
2408 return r;
2409
2410 r = dm_register_target(&pool_target);
2411 if (r)
2412 dm_unregister_target(&thin_target);
2413
2414 return r;
2415}
2416
2417static void dm_thin_exit(void)
2418{
2419 dm_unregister_target(&thin_target);
2420 dm_unregister_target(&pool_target);
2421}
2422
2423module_init(dm_thin_init);
2424module_exit(dm_thin_exit);
2425
2426MODULE_DESCRIPTION(DM_NAME "device-mapper thin provisioning target");
2427MODULE_AUTHOR("Joe Thornber <dm-devel@redhat.com>");
2428MODULE_LICENSE("GPL");
diff --git a/drivers/md/dm-uevent.c b/drivers/md/dm-uevent.c
index 6b1e3b61b25e..8efe033bab55 100644
--- a/drivers/md/dm-uevent.c
+++ b/drivers/md/dm-uevent.c
@@ -22,6 +22,7 @@
22#include <linux/slab.h> 22#include <linux/slab.h>
23#include <linux/kobject.h> 23#include <linux/kobject.h>
24#include <linux/dm-ioctl.h> 24#include <linux/dm-ioctl.h>
25#include <linux/export.h>
25 26
26#include "dm.h" 27#include "dm.h"
27#include "dm-uevent.h" 28#include "dm-uevent.h"
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 52b39f335bb3..4720f68f817e 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -25,6 +25,16 @@
25 25
26#define DM_MSG_PREFIX "core" 26#define DM_MSG_PREFIX "core"
27 27
28#ifdef CONFIG_PRINTK
29/*
30 * ratelimit state to be used in DMXXX_LIMIT().
31 */
32DEFINE_RATELIMIT_STATE(dm_ratelimit_state,
33 DEFAULT_RATELIMIT_INTERVAL,
34 DEFAULT_RATELIMIT_BURST);
35EXPORT_SYMBOL(dm_ratelimit_state);
36#endif
37
28/* 38/*
29 * Cookies are numeric values sent with CHANGE and REMOVE 39 * Cookies are numeric values sent with CHANGE and REMOVE
30 * uevents while resuming, removing or renaming the device. 40 * uevents while resuming, removing or renaming the device.
@@ -130,6 +140,8 @@ struct mapped_device {
130 /* Protect queue and type against concurrent access. */ 140 /* Protect queue and type against concurrent access. */
131 struct mutex type_lock; 141 struct mutex type_lock;
132 142
143 struct target_type *immutable_target_type;
144
133 struct gendisk *disk; 145 struct gendisk *disk;
134 char name[16]; 146 char name[16];
135 147
@@ -180,9 +192,6 @@ struct mapped_device {
180 /* forced geometry settings */ 192 /* forced geometry settings */
181 struct hd_geometry geometry; 193 struct hd_geometry geometry;
182 194
183 /* For saving the address of __make_request for request based dm */
184 make_request_fn *saved_make_request_fn;
185
186 /* sysfs handle */ 195 /* sysfs handle */
187 struct kobject kobj; 196 struct kobject kobj;
188 197
@@ -1391,7 +1400,7 @@ out:
1391 * The request function that just remaps the bio built up by 1400 * The request function that just remaps the bio built up by
1392 * dm_merge_bvec. 1401 * dm_merge_bvec.
1393 */ 1402 */
1394static int _dm_request(struct request_queue *q, struct bio *bio) 1403static void _dm_request(struct request_queue *q, struct bio *bio)
1395{ 1404{
1396 int rw = bio_data_dir(bio); 1405 int rw = bio_data_dir(bio);
1397 struct mapped_device *md = q->queuedata; 1406 struct mapped_device *md = q->queuedata;
@@ -1412,19 +1421,12 @@ static int _dm_request(struct request_queue *q, struct bio *bio)
1412 queue_io(md, bio); 1421 queue_io(md, bio);
1413 else 1422 else
1414 bio_io_error(bio); 1423 bio_io_error(bio);
1415 return 0; 1424 return;
1416 } 1425 }
1417 1426
1418 __split_and_process_bio(md, bio); 1427 __split_and_process_bio(md, bio);
1419 up_read(&md->io_lock); 1428 up_read(&md->io_lock);
1420 return 0; 1429 return;
1421}
1422
1423static int dm_make_request(struct request_queue *q, struct bio *bio)
1424{
1425 struct mapped_device *md = q->queuedata;
1426
1427 return md->saved_make_request_fn(q, bio); /* call __make_request() */
1428} 1430}
1429 1431
1430static int dm_request_based(struct mapped_device *md) 1432static int dm_request_based(struct mapped_device *md)
@@ -1432,14 +1434,14 @@ static int dm_request_based(struct mapped_device *md)
1432 return blk_queue_stackable(md->queue); 1434 return blk_queue_stackable(md->queue);
1433} 1435}
1434 1436
1435static int dm_request(struct request_queue *q, struct bio *bio) 1437static void dm_request(struct request_queue *q, struct bio *bio)
1436{ 1438{
1437 struct mapped_device *md = q->queuedata; 1439 struct mapped_device *md = q->queuedata;
1438 1440
1439 if (dm_request_based(md)) 1441 if (dm_request_based(md))
1440 return dm_make_request(q, bio); 1442 blk_queue_bio(q, bio);
1441 1443 else
1442 return _dm_request(q, bio); 1444 _dm_request(q, bio);
1443} 1445}
1444 1446
1445void dm_dispatch_request(struct request *rq) 1447void dm_dispatch_request(struct request *rq)
@@ -2086,6 +2088,8 @@ static struct dm_table *__bind(struct mapped_device *md, struct dm_table *t,
2086 write_lock_irqsave(&md->map_lock, flags); 2088 write_lock_irqsave(&md->map_lock, flags);
2087 old_map = md->map; 2089 old_map = md->map;
2088 md->map = t; 2090 md->map = t;
2091 md->immutable_target_type = dm_table_get_immutable_target_type(t);
2092
2089 dm_table_set_restrictions(t, q, limits); 2093 dm_table_set_restrictions(t, q, limits);
2090 if (merge_is_optional) 2094 if (merge_is_optional)
2091 set_bit(DMF_MERGE_IS_OPTIONAL, &md->flags); 2095 set_bit(DMF_MERGE_IS_OPTIONAL, &md->flags);
@@ -2156,6 +2160,11 @@ unsigned dm_get_md_type(struct mapped_device *md)
2156 return md->type; 2160 return md->type;
2157} 2161}
2158 2162
2163struct target_type *dm_get_immutable_target_type(struct mapped_device *md)
2164{
2165 return md->immutable_target_type;
2166}
2167
2159/* 2168/*
2160 * Fully initialize a request-based queue (->elevator, ->request_fn, etc). 2169 * Fully initialize a request-based queue (->elevator, ->request_fn, etc).
2161 */ 2170 */
@@ -2172,7 +2181,6 @@ static int dm_init_request_based_queue(struct mapped_device *md)
2172 return 0; 2181 return 0;
2173 2182
2174 md->queue = q; 2183 md->queue = q;
2175 md->saved_make_request_fn = md->queue->make_request_fn;
2176 dm_init_md_queue(md); 2184 dm_init_md_queue(md);
2177 blk_queue_softirq_done(md->queue, dm_softirq_done); 2185 blk_queue_softirq_done(md->queue, dm_softirq_done);
2178 blk_queue_prep_rq(md->queue, dm_prep_fn); 2186 blk_queue_prep_rq(md->queue, dm_prep_fn);
@@ -2231,6 +2239,7 @@ struct mapped_device *dm_get_md(dev_t dev)
2231 2239
2232 return md; 2240 return md;
2233} 2241}
2242EXPORT_SYMBOL_GPL(dm_get_md);
2234 2243
2235void *dm_get_mdptr(struct mapped_device *md) 2244void *dm_get_mdptr(struct mapped_device *md)
2236{ 2245{
@@ -2316,7 +2325,6 @@ static int dm_wait_for_completion(struct mapped_device *md, int interruptible)
2316 while (1) { 2325 while (1) {
2317 set_current_state(interruptible); 2326 set_current_state(interruptible);
2318 2327
2319 smp_mb();
2320 if (!md_in_flight(md)) 2328 if (!md_in_flight(md))
2321 break; 2329 break;
2322 2330
diff --git a/drivers/md/dm.h b/drivers/md/dm.h
index 6745dbd278a4..b7dacd59d8d7 100644
--- a/drivers/md/dm.h
+++ b/drivers/md/dm.h
@@ -60,6 +60,7 @@ int 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);
62unsigned dm_table_get_type(struct dm_table *t); 62unsigned dm_table_get_type(struct dm_table *t);
63struct target_type *dm_table_get_immutable_target_type(struct dm_table *t);
63bool dm_table_request_based(struct dm_table *t); 64bool dm_table_request_based(struct dm_table *t);
64bool dm_table_supports_discards(struct dm_table *t); 65bool dm_table_supports_discards(struct dm_table *t);
65int dm_table_alloc_md_mempools(struct dm_table *t); 66int dm_table_alloc_md_mempools(struct dm_table *t);
@@ -72,6 +73,7 @@ void dm_lock_md_type(struct mapped_device *md);
72void dm_unlock_md_type(struct mapped_device *md); 73void dm_unlock_md_type(struct mapped_device *md);
73void dm_set_md_type(struct mapped_device *md, unsigned type); 74void dm_set_md_type(struct mapped_device *md, unsigned type);
74unsigned dm_get_md_type(struct mapped_device *md); 75unsigned dm_get_md_type(struct mapped_device *md);
76struct target_type *dm_get_immutable_target_type(struct mapped_device *md);
75 77
76int dm_setup_md_queue(struct mapped_device *md); 78int dm_setup_md_queue(struct mapped_device *md);
77 79
diff --git a/drivers/md/faulty.c b/drivers/md/faulty.c
index 60816b132c2e..feb2c3c7bb44 100644
--- a/drivers/md/faulty.c
+++ b/drivers/md/faulty.c
@@ -63,6 +63,7 @@
63 63
64#define MaxFault 50 64#define MaxFault 50
65#include <linux/blkdev.h> 65#include <linux/blkdev.h>
66#include <linux/module.h>
66#include <linux/raid/md_u.h> 67#include <linux/raid/md_u.h>
67#include <linux/slab.h> 68#include <linux/slab.h>
68#include "md.h" 69#include "md.h"
@@ -169,7 +170,7 @@ static void add_sector(struct faulty_conf *conf, sector_t start, int mode)
169 conf->nfaults = n+1; 170 conf->nfaults = n+1;
170} 171}
171 172
172static int make_request(struct mddev *mddev, struct bio *bio) 173static void make_request(struct mddev *mddev, struct bio *bio)
173{ 174{
174 struct faulty_conf *conf = mddev->private; 175 struct faulty_conf *conf = mddev->private;
175 int failit = 0; 176 int failit = 0;
@@ -181,7 +182,7 @@ static int make_request(struct mddev *mddev, struct bio *bio)
181 * just fail immediately 182 * just fail immediately
182 */ 183 */
183 bio_endio(bio, -EIO); 184 bio_endio(bio, -EIO);
184 return 0; 185 return;
185 } 186 }
186 187
187 if (check_sector(conf, bio->bi_sector, bio->bi_sector+(bio->bi_size>>9), 188 if (check_sector(conf, bio->bi_sector, bio->bi_sector+(bio->bi_size>>9),
@@ -211,15 +212,15 @@ static int make_request(struct mddev *mddev, struct bio *bio)
211 } 212 }
212 if (failit) { 213 if (failit) {
213 struct bio *b = bio_clone_mddev(bio, GFP_NOIO, mddev); 214 struct bio *b = bio_clone_mddev(bio, GFP_NOIO, mddev);
215
214 b->bi_bdev = conf->rdev->bdev; 216 b->bi_bdev = conf->rdev->bdev;
215 b->bi_private = bio; 217 b->bi_private = bio;
216 b->bi_end_io = faulty_fail; 218 b->bi_end_io = faulty_fail;
217 generic_make_request(b); 219 bio = b;
218 return 0; 220 } else
219 } else {
220 bio->bi_bdev = conf->rdev->bdev; 221 bio->bi_bdev = conf->rdev->bdev;
221 return 1; 222
222 } 223 generic_make_request(bio);
223} 224}
224 225
225static void status(struct seq_file *seq, struct mddev *mddev) 226static void status(struct seq_file *seq, struct mddev *mddev)
diff --git a/drivers/md/linear.c b/drivers/md/linear.c
index 10c5844460cb..c3273efd08cb 100644
--- a/drivers/md/linear.c
+++ b/drivers/md/linear.c
@@ -19,6 +19,7 @@
19#include <linux/blkdev.h> 19#include <linux/blkdev.h>
20#include <linux/raid/md_u.h> 20#include <linux/raid/md_u.h>
21#include <linux/seq_file.h> 21#include <linux/seq_file.h>
22#include <linux/module.h>
22#include <linux/slab.h> 23#include <linux/slab.h>
23#include "md.h" 24#include "md.h"
24#include "linear.h" 25#include "linear.h"
@@ -264,14 +265,14 @@ static int linear_stop (struct mddev *mddev)
264 return 0; 265 return 0;
265} 266}
266 267
267static int linear_make_request (struct mddev *mddev, struct bio *bio) 268static void linear_make_request(struct mddev *mddev, struct bio *bio)
268{ 269{
269 struct dev_info *tmp_dev; 270 struct dev_info *tmp_dev;
270 sector_t start_sector; 271 sector_t start_sector;
271 272
272 if (unlikely(bio->bi_rw & REQ_FLUSH)) { 273 if (unlikely(bio->bi_rw & REQ_FLUSH)) {
273 md_flush_request(mddev, bio); 274 md_flush_request(mddev, bio);
274 return 0; 275 return;
275 } 276 }
276 277
277 rcu_read_lock(); 278 rcu_read_lock();
@@ -293,7 +294,7 @@ static int linear_make_request (struct mddev *mddev, struct bio *bio)
293 (unsigned long long)start_sector); 294 (unsigned long long)start_sector);
294 rcu_read_unlock(); 295 rcu_read_unlock();
295 bio_io_error(bio); 296 bio_io_error(bio);
296 return 0; 297 return;
297 } 298 }
298 if (unlikely(bio->bi_sector + (bio->bi_size >> 9) > 299 if (unlikely(bio->bi_sector + (bio->bi_size >> 9) >
299 tmp_dev->end_sector)) { 300 tmp_dev->end_sector)) {
@@ -307,20 +308,17 @@ static int linear_make_request (struct mddev *mddev, struct bio *bio)
307 308
308 bp = bio_split(bio, end_sector - bio->bi_sector); 309 bp = bio_split(bio, end_sector - bio->bi_sector);
309 310
310 if (linear_make_request(mddev, &bp->bio1)) 311 linear_make_request(mddev, &bp->bio1);
311 generic_make_request(&bp->bio1); 312 linear_make_request(mddev, &bp->bio2);
312 if (linear_make_request(mddev, &bp->bio2))
313 generic_make_request(&bp->bio2);
314 bio_pair_release(bp); 313 bio_pair_release(bp);
315 return 0; 314 return;
316 } 315 }
317 316
318 bio->bi_bdev = tmp_dev->rdev->bdev; 317 bio->bi_bdev = tmp_dev->rdev->bdev;
319 bio->bi_sector = bio->bi_sector - start_sector 318 bio->bi_sector = bio->bi_sector - start_sector
320 + tmp_dev->rdev->data_offset; 319 + tmp_dev->rdev->data_offset;
321 rcu_read_unlock(); 320 rcu_read_unlock();
322 321 generic_make_request(bio);
323 return 1;
324} 322}
325 323
326static void linear_status (struct seq_file *seq, struct mddev *mddev) 324static void linear_status (struct seq_file *seq, struct mddev *mddev)
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 266e82ebaf11..84acfe7d10e4 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -44,6 +44,7 @@
44#include <linux/hdreg.h> 44#include <linux/hdreg.h>
45#include <linux/proc_fs.h> 45#include <linux/proc_fs.h>
46#include <linux/random.h> 46#include <linux/random.h>
47#include <linux/module.h>
47#include <linux/reboot.h> 48#include <linux/reboot.h>
48#include <linux/file.h> 49#include <linux/file.h>
49#include <linux/compat.h> 50#include <linux/compat.h>
@@ -332,18 +333,17 @@ static DEFINE_SPINLOCK(all_mddevs_lock);
332 * call has finished, the bio has been linked into some internal structure 333 * call has finished, the bio has been linked into some internal structure
333 * and so is visible to ->quiesce(), so we don't need the refcount any more. 334 * and so is visible to ->quiesce(), so we don't need the refcount any more.
334 */ 335 */
335static int md_make_request(struct request_queue *q, struct bio *bio) 336static void md_make_request(struct request_queue *q, struct bio *bio)
336{ 337{
337 const int rw = bio_data_dir(bio); 338 const int rw = bio_data_dir(bio);
338 struct mddev *mddev = q->queuedata; 339 struct mddev *mddev = q->queuedata;
339 int rv;
340 int cpu; 340 int cpu;
341 unsigned int sectors; 341 unsigned int sectors;
342 342
343 if (mddev == NULL || mddev->pers == NULL 343 if (mddev == NULL || mddev->pers == NULL
344 || !mddev->ready) { 344 || !mddev->ready) {
345 bio_io_error(bio); 345 bio_io_error(bio);
346 return 0; 346 return;
347 } 347 }
348 smp_rmb(); /* Ensure implications of 'active' are visible */ 348 smp_rmb(); /* Ensure implications of 'active' are visible */
349 rcu_read_lock(); 349 rcu_read_lock();
@@ -368,7 +368,7 @@ static int md_make_request(struct request_queue *q, struct bio *bio)
368 * go away inside make_request 368 * go away inside make_request
369 */ 369 */
370 sectors = bio_sectors(bio); 370 sectors = bio_sectors(bio);
371 rv = mddev->pers->make_request(mddev, bio); 371 mddev->pers->make_request(mddev, bio);
372 372
373 cpu = part_stat_lock(); 373 cpu = part_stat_lock();
374 part_stat_inc(cpu, &mddev->gendisk->part0, ios[rw]); 374 part_stat_inc(cpu, &mddev->gendisk->part0, ios[rw]);
@@ -377,8 +377,6 @@ static int md_make_request(struct request_queue *q, struct bio *bio)
377 377
378 if (atomic_dec_and_test(&mddev->active_io) && mddev->suspended) 378 if (atomic_dec_and_test(&mddev->active_io) && mddev->suspended)
379 wake_up(&mddev->sb_wait); 379 wake_up(&mddev->sb_wait);
380
381 return rv;
382} 380}
383 381
384/* mddev_suspend makes sure no new requests are submitted 382/* mddev_suspend makes sure no new requests are submitted
@@ -477,8 +475,7 @@ static void md_submit_flush_data(struct work_struct *ws)
477 bio_endio(bio, 0); 475 bio_endio(bio, 0);
478 else { 476 else {
479 bio->bi_rw &= ~REQ_FLUSH; 477 bio->bi_rw &= ~REQ_FLUSH;
480 if (mddev->pers->make_request(mddev, bio)) 478 mddev->pers->make_request(mddev, bio);
481 generic_make_request(bio);
482 } 479 }
483 480
484 mddev->flush_bio = NULL; 481 mddev->flush_bio = NULL;
diff --git a/drivers/md/md.h b/drivers/md/md.h
index 51c1d91557e0..cf742d9306ec 100644
--- a/drivers/md/md.h
+++ b/drivers/md/md.h
@@ -419,7 +419,7 @@ struct md_personality
419 int level; 419 int level;
420 struct list_head list; 420 struct list_head list;
421 struct module *owner; 421 struct module *owner;
422 int (*make_request)(struct mddev *mddev, struct bio *bio); 422 void (*make_request)(struct mddev *mddev, struct bio *bio);
423 int (*run)(struct mddev *mddev); 423 int (*run)(struct mddev *mddev);
424 int (*stop)(struct mddev *mddev); 424 int (*stop)(struct mddev *mddev);
425 void (*status)(struct seq_file *seq, struct mddev *mddev); 425 void (*status)(struct seq_file *seq, struct mddev *mddev);
diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c
index d32c785e17d4..5899246fa37e 100644
--- a/drivers/md/multipath.c
+++ b/drivers/md/multipath.c
@@ -20,6 +20,7 @@
20 */ 20 */
21 21
22#include <linux/blkdev.h> 22#include <linux/blkdev.h>
23#include <linux/module.h>
23#include <linux/raid/md_u.h> 24#include <linux/raid/md_u.h>
24#include <linux/seq_file.h> 25#include <linux/seq_file.h>
25#include <linux/slab.h> 26#include <linux/slab.h>
@@ -106,7 +107,7 @@ static void multipath_end_request(struct bio *bio, int error)
106 rdev_dec_pending(rdev, conf->mddev); 107 rdev_dec_pending(rdev, conf->mddev);
107} 108}
108 109
109static int multipath_make_request(struct mddev *mddev, struct bio * bio) 110static void multipath_make_request(struct mddev *mddev, struct bio * bio)
110{ 111{
111 struct mpconf *conf = mddev->private; 112 struct mpconf *conf = mddev->private;
112 struct multipath_bh * mp_bh; 113 struct multipath_bh * mp_bh;
@@ -114,7 +115,7 @@ static int multipath_make_request(struct mddev *mddev, struct bio * bio)
114 115
115 if (unlikely(bio->bi_rw & REQ_FLUSH)) { 116 if (unlikely(bio->bi_rw & REQ_FLUSH)) {
116 md_flush_request(mddev, bio); 117 md_flush_request(mddev, bio);
117 return 0; 118 return;
118 } 119 }
119 120
120 mp_bh = mempool_alloc(conf->pool, GFP_NOIO); 121 mp_bh = mempool_alloc(conf->pool, GFP_NOIO);
@@ -126,7 +127,7 @@ static int multipath_make_request(struct mddev *mddev, struct bio * bio)
126 if (mp_bh->path < 0) { 127 if (mp_bh->path < 0) {
127 bio_endio(bio, -EIO); 128 bio_endio(bio, -EIO);
128 mempool_free(mp_bh, conf->pool); 129 mempool_free(mp_bh, conf->pool);
129 return 0; 130 return;
130 } 131 }
131 multipath = conf->multipaths + mp_bh->path; 132 multipath = conf->multipaths + mp_bh->path;
132 133
@@ -137,7 +138,7 @@ static int multipath_make_request(struct mddev *mddev, struct bio * bio)
137 mp_bh->bio.bi_end_io = multipath_end_request; 138 mp_bh->bio.bi_end_io = multipath_end_request;
138 mp_bh->bio.bi_private = mp_bh; 139 mp_bh->bio.bi_private = mp_bh;
139 generic_make_request(&mp_bh->bio); 140 generic_make_request(&mp_bh->bio);
140 return 0; 141 return;
141} 142}
142 143
143static void multipath_status (struct seq_file *seq, struct mddev *mddev) 144static void multipath_status (struct seq_file *seq, struct mddev *mddev)
diff --git a/drivers/md/persistent-data/Kconfig b/drivers/md/persistent-data/Kconfig
new file mode 100644
index 000000000000..ceb359050a59
--- /dev/null
+++ b/drivers/md/persistent-data/Kconfig
@@ -0,0 +1,8 @@
1config DM_PERSISTENT_DATA
2 tristate
3 depends on BLK_DEV_DM && EXPERIMENTAL
4 select LIBCRC32C
5 select DM_BUFIO
6 ---help---
7 Library providing immutable on-disk data structure support for
8 device-mapper targets such as the thin provisioning target.
diff --git a/drivers/md/persistent-data/Makefile b/drivers/md/persistent-data/Makefile
new file mode 100644
index 000000000000..cfa95f662230
--- /dev/null
+++ b/drivers/md/persistent-data/Makefile
@@ -0,0 +1,11 @@
1obj-$(CONFIG_DM_PERSISTENT_DATA) += dm-persistent-data.o
2dm-persistent-data-objs := \
3 dm-block-manager.o \
4 dm-space-map-checker.o \
5 dm-space-map-common.o \
6 dm-space-map-disk.o \
7 dm-space-map-metadata.o \
8 dm-transaction-manager.o \
9 dm-btree.o \
10 dm-btree-remove.o \
11 dm-btree-spine.o
diff --git a/drivers/md/persistent-data/dm-block-manager.c b/drivers/md/persistent-data/dm-block-manager.c
new file mode 100644
index 000000000000..0317ecdc6e53
--- /dev/null
+++ b/drivers/md/persistent-data/dm-block-manager.c
@@ -0,0 +1,620 @@
1/*
2 * Copyright (C) 2011 Red Hat, Inc.
3 *
4 * This file is released under the GPL.
5 */
6#include "dm-block-manager.h"
7#include "dm-persistent-data-internal.h"
8#include "../dm-bufio.h"
9
10#include <linux/crc32c.h>
11#include <linux/module.h>
12#include <linux/slab.h>
13#include <linux/rwsem.h>
14#include <linux/device-mapper.h>
15#include <linux/stacktrace.h>
16
17#define DM_MSG_PREFIX "block manager"
18
19/*----------------------------------------------------------------*/
20
21/*
22 * This is a read/write semaphore with a couple of differences.
23 *
24 * i) There is a restriction on the number of concurrent read locks that
25 * may be held at once. This is just an implementation detail.
26 *
27 * ii) Recursive locking attempts are detected and return EINVAL. A stack
28 * trace is also emitted for the previous lock aquisition.
29 *
30 * iii) Priority is given to write locks.
31 */
32#define MAX_HOLDERS 4
33#define MAX_STACK 10
34
35typedef unsigned long stack_entries[MAX_STACK];
36
37struct block_lock {
38 spinlock_t lock;
39 __s32 count;
40 struct list_head waiters;
41 struct task_struct *holders[MAX_HOLDERS];
42
43#ifdef CONFIG_DM_DEBUG_BLOCK_STACK_TRACING
44 struct stack_trace traces[MAX_HOLDERS];
45 stack_entries entries[MAX_HOLDERS];
46#endif
47};
48
49struct waiter {
50 struct list_head list;
51 struct task_struct *task;
52 int wants_write;
53};
54
55static unsigned __find_holder(struct block_lock *lock,
56 struct task_struct *task)
57{
58 unsigned i;
59
60 for (i = 0; i < MAX_HOLDERS; i++)
61 if (lock->holders[i] == task)
62 break;
63
64 BUG_ON(i == MAX_HOLDERS);
65 return i;
66}
67
68/* call this *after* you increment lock->count */
69static void __add_holder(struct block_lock *lock, struct task_struct *task)
70{
71 unsigned h = __find_holder(lock, NULL);
72#ifdef CONFIG_DM_DEBUG_BLOCK_STACK_TRACING
73 struct stack_trace *t;
74#endif
75
76 get_task_struct(task);
77 lock->holders[h] = task;
78
79#ifdef CONFIG_DM_DEBUG_BLOCK_STACK_TRACING
80 t = lock->traces + h;
81 t->nr_entries = 0;
82 t->max_entries = MAX_STACK;
83 t->entries = lock->entries[h];
84 t->skip = 2;
85 save_stack_trace(t);
86#endif
87}
88
89/* call this *before* you decrement lock->count */
90static void __del_holder(struct block_lock *lock, struct task_struct *task)
91{
92 unsigned h = __find_holder(lock, task);
93 lock->holders[h] = NULL;
94 put_task_struct(task);
95}
96
97static int __check_holder(struct block_lock *lock)
98{
99 unsigned i;
100#ifdef CONFIG_DM_DEBUG_BLOCK_STACK_TRACING
101 static struct stack_trace t;
102 static stack_entries entries;
103#endif
104
105 for (i = 0; i < MAX_HOLDERS; i++) {
106 if (lock->holders[i] == current) {
107 DMERR("recursive lock detected in pool metadata");
108#ifdef CONFIG_DM_DEBUG_BLOCK_STACK_TRACING
109 DMERR("previously held here:");
110 print_stack_trace(lock->traces + i, 4);
111
112 DMERR("subsequent aquisition attempted here:");
113 t.nr_entries = 0;
114 t.max_entries = MAX_STACK;
115 t.entries = entries;
116 t.skip = 3;
117 save_stack_trace(&t);
118 print_stack_trace(&t, 4);
119#endif
120 return -EINVAL;
121 }
122 }
123
124 return 0;
125}
126
127static void __wait(struct waiter *w)
128{
129 for (;;) {
130 set_task_state(current, TASK_UNINTERRUPTIBLE);
131
132 if (!w->task)
133 break;
134
135 schedule();
136 }
137
138 set_task_state(current, TASK_RUNNING);
139}
140
141static void __wake_waiter(struct waiter *w)
142{
143 struct task_struct *task;
144
145 list_del(&w->list);
146 task = w->task;
147 smp_mb();
148 w->task = NULL;
149 wake_up_process(task);
150}
151
152/*
153 * We either wake a few readers or a single writer.
154 */
155static void __wake_many(struct block_lock *lock)
156{
157 struct waiter *w, *tmp;
158
159 BUG_ON(lock->count < 0);
160 list_for_each_entry_safe(w, tmp, &lock->waiters, list) {
161 if (lock->count >= MAX_HOLDERS)
162 return;
163
164 if (w->wants_write) {
165 if (lock->count > 0)
166 return; /* still read locked */
167
168 lock->count = -1;
169 __add_holder(lock, w->task);
170 __wake_waiter(w);
171 return;
172 }
173
174 lock->count++;
175 __add_holder(lock, w->task);
176 __wake_waiter(w);
177 }
178}
179
180static void bl_init(struct block_lock *lock)
181{
182 int i;
183
184 spin_lock_init(&lock->lock);
185 lock->count = 0;
186 INIT_LIST_HEAD(&lock->waiters);
187 for (i = 0; i < MAX_HOLDERS; i++)
188 lock->holders[i] = NULL;
189}
190
191static int __available_for_read(struct block_lock *lock)
192{
193 return lock->count >= 0 &&
194 lock->count < MAX_HOLDERS &&
195 list_empty(&lock->waiters);
196}
197
198static int bl_down_read(struct block_lock *lock)
199{
200 int r;
201 struct waiter w;
202
203 spin_lock(&lock->lock);
204 r = __check_holder(lock);
205 if (r) {
206 spin_unlock(&lock->lock);
207 return r;
208 }
209
210 if (__available_for_read(lock)) {
211 lock->count++;
212 __add_holder(lock, current);
213 spin_unlock(&lock->lock);
214 return 0;
215 }
216
217 get_task_struct(current);
218
219 w.task = current;
220 w.wants_write = 0;
221 list_add_tail(&w.list, &lock->waiters);
222 spin_unlock(&lock->lock);
223
224 __wait(&w);
225 put_task_struct(current);
226 return 0;
227}
228
229static int bl_down_read_nonblock(struct block_lock *lock)
230{
231 int r;
232
233 spin_lock(&lock->lock);
234 r = __check_holder(lock);
235 if (r)
236 goto out;
237
238 if (__available_for_read(lock)) {
239 lock->count++;
240 __add_holder(lock, current);
241 r = 0;
242 } else
243 r = -EWOULDBLOCK;
244
245out:
246 spin_unlock(&lock->lock);
247 return r;
248}
249
250static void bl_up_read(struct block_lock *lock)
251{
252 spin_lock(&lock->lock);
253 BUG_ON(lock->count <= 0);
254 __del_holder(lock, current);
255 --lock->count;
256 if (!list_empty(&lock->waiters))
257 __wake_many(lock);
258 spin_unlock(&lock->lock);
259}
260
261static int bl_down_write(struct block_lock *lock)
262{
263 int r;
264 struct waiter w;
265
266 spin_lock(&lock->lock);
267 r = __check_holder(lock);
268 if (r) {
269 spin_unlock(&lock->lock);
270 return r;
271 }
272
273 if (lock->count == 0 && list_empty(&lock->waiters)) {
274 lock->count = -1;
275 __add_holder(lock, current);
276 spin_unlock(&lock->lock);
277 return 0;
278 }
279
280 get_task_struct(current);
281 w.task = current;
282 w.wants_write = 1;
283
284 /*
285 * Writers given priority. We know there's only one mutator in the
286 * system, so ignoring the ordering reversal.
287 */
288 list_add(&w.list, &lock->waiters);
289 spin_unlock(&lock->lock);
290
291 __wait(&w);
292 put_task_struct(current);
293
294 return 0;
295}
296
297static void bl_up_write(struct block_lock *lock)
298{
299 spin_lock(&lock->lock);
300 __del_holder(lock, current);
301 lock->count = 0;
302 if (!list_empty(&lock->waiters))
303 __wake_many(lock);
304 spin_unlock(&lock->lock);
305}
306
307static void report_recursive_bug(dm_block_t b, int r)
308{
309 if (r == -EINVAL)
310 DMERR("recursive acquisition of block %llu requested.",
311 (unsigned long long) b);
312}
313
314/*----------------------------------------------------------------*/
315
316/*
317 * Block manager is currently implemented using dm-bufio. struct
318 * dm_block_manager and struct dm_block map directly onto a couple of
319 * structs in the bufio interface. I want to retain the freedom to move
320 * away from bufio in the future. So these structs are just cast within
321 * this .c file, rather than making it through to the public interface.
322 */
323static struct dm_buffer *to_buffer(struct dm_block *b)
324{
325 return (struct dm_buffer *) b;
326}
327
328static struct dm_bufio_client *to_bufio(struct dm_block_manager *bm)
329{
330 return (struct dm_bufio_client *) bm;
331}
332
333dm_block_t dm_block_location(struct dm_block *b)
334{
335 return dm_bufio_get_block_number(to_buffer(b));
336}
337EXPORT_SYMBOL_GPL(dm_block_location);
338
339void *dm_block_data(struct dm_block *b)
340{
341 return dm_bufio_get_block_data(to_buffer(b));
342}
343EXPORT_SYMBOL_GPL(dm_block_data);
344
345struct buffer_aux {
346 struct dm_block_validator *validator;
347 struct block_lock lock;
348 int write_locked;
349};
350
351static void dm_block_manager_alloc_callback(struct dm_buffer *buf)
352{
353 struct buffer_aux *aux = dm_bufio_get_aux_data(buf);
354 aux->validator = NULL;
355 bl_init(&aux->lock);
356}
357
358static void dm_block_manager_write_callback(struct dm_buffer *buf)
359{
360 struct buffer_aux *aux = dm_bufio_get_aux_data(buf);
361 if (aux->validator) {
362 aux->validator->prepare_for_write(aux->validator, (struct dm_block *) buf,
363 dm_bufio_get_block_size(dm_bufio_get_client(buf)));
364 }
365}
366
367/*----------------------------------------------------------------
368 * Public interface
369 *--------------------------------------------------------------*/
370struct dm_block_manager *dm_block_manager_create(struct block_device *bdev,
371 unsigned block_size,
372 unsigned cache_size,
373 unsigned max_held_per_thread)
374{
375 return (struct dm_block_manager *)
376 dm_bufio_client_create(bdev, block_size, max_held_per_thread,
377 sizeof(struct buffer_aux),
378 dm_block_manager_alloc_callback,
379 dm_block_manager_write_callback);
380}
381EXPORT_SYMBOL_GPL(dm_block_manager_create);
382
383void dm_block_manager_destroy(struct dm_block_manager *bm)
384{
385 return dm_bufio_client_destroy(to_bufio(bm));
386}
387EXPORT_SYMBOL_GPL(dm_block_manager_destroy);
388
389unsigned dm_bm_block_size(struct dm_block_manager *bm)
390{
391 return dm_bufio_get_block_size(to_bufio(bm));
392}
393EXPORT_SYMBOL_GPL(dm_bm_block_size);
394
395dm_block_t dm_bm_nr_blocks(struct dm_block_manager *bm)
396{
397 return dm_bufio_get_device_size(to_bufio(bm));
398}
399
400static int dm_bm_validate_buffer(struct dm_block_manager *bm,
401 struct dm_buffer *buf,
402 struct buffer_aux *aux,
403 struct dm_block_validator *v)
404{
405 if (unlikely(!aux->validator)) {
406 int r;
407 if (!v)
408 return 0;
409 r = v->check(v, (struct dm_block *) buf, dm_bufio_get_block_size(to_bufio(bm)));
410 if (unlikely(r))
411 return r;
412 aux->validator = v;
413 } else {
414 if (unlikely(aux->validator != v)) {
415 DMERR("validator mismatch (old=%s vs new=%s) for block %llu",
416 aux->validator->name, v ? v->name : "NULL",
417 (unsigned long long)
418 dm_bufio_get_block_number(buf));
419 return -EINVAL;
420 }
421 }
422
423 return 0;
424}
425int dm_bm_read_lock(struct dm_block_manager *bm, dm_block_t b,
426 struct dm_block_validator *v,
427 struct dm_block **result)
428{
429 struct buffer_aux *aux;
430 void *p;
431 int r;
432
433 p = dm_bufio_read(to_bufio(bm), b, (struct dm_buffer **) result);
434 if (unlikely(IS_ERR(p)))
435 return PTR_ERR(p);
436
437 aux = dm_bufio_get_aux_data(to_buffer(*result));
438 r = bl_down_read(&aux->lock);
439 if (unlikely(r)) {
440 dm_bufio_release(to_buffer(*result));
441 report_recursive_bug(b, r);
442 return r;
443 }
444
445 aux->write_locked = 0;
446
447 r = dm_bm_validate_buffer(bm, to_buffer(*result), aux, v);
448 if (unlikely(r)) {
449 bl_up_read(&aux->lock);
450 dm_bufio_release(to_buffer(*result));
451 return r;
452 }
453
454 return 0;
455}
456EXPORT_SYMBOL_GPL(dm_bm_read_lock);
457
458int dm_bm_write_lock(struct dm_block_manager *bm,
459 dm_block_t b, struct dm_block_validator *v,
460 struct dm_block **result)
461{
462 struct buffer_aux *aux;
463 void *p;
464 int r;
465
466 p = dm_bufio_read(to_bufio(bm), b, (struct dm_buffer **) result);
467 if (unlikely(IS_ERR(p)))
468 return PTR_ERR(p);
469
470 aux = dm_bufio_get_aux_data(to_buffer(*result));
471 r = bl_down_write(&aux->lock);
472 if (r) {
473 dm_bufio_release(to_buffer(*result));
474 report_recursive_bug(b, r);
475 return r;
476 }
477
478 aux->write_locked = 1;
479
480 r = dm_bm_validate_buffer(bm, to_buffer(*result), aux, v);
481 if (unlikely(r)) {
482 bl_up_write(&aux->lock);
483 dm_bufio_release(to_buffer(*result));
484 return r;
485 }
486
487 return 0;
488}
489EXPORT_SYMBOL_GPL(dm_bm_write_lock);
490
491int dm_bm_read_try_lock(struct dm_block_manager *bm,
492 dm_block_t b, struct dm_block_validator *v,
493 struct dm_block **result)
494{
495 struct buffer_aux *aux;
496 void *p;
497 int r;
498
499 p = dm_bufio_get(to_bufio(bm), b, (struct dm_buffer **) result);
500 if (unlikely(IS_ERR(p)))
501 return PTR_ERR(p);
502 if (unlikely(!p))
503 return -EWOULDBLOCK;
504
505 aux = dm_bufio_get_aux_data(to_buffer(*result));
506 r = bl_down_read_nonblock(&aux->lock);
507 if (r < 0) {
508 dm_bufio_release(to_buffer(*result));
509 report_recursive_bug(b, r);
510 return r;
511 }
512 aux->write_locked = 0;
513
514 r = dm_bm_validate_buffer(bm, to_buffer(*result), aux, v);
515 if (unlikely(r)) {
516 bl_up_read(&aux->lock);
517 dm_bufio_release(to_buffer(*result));
518 return r;
519 }
520
521 return 0;
522}
523
524int dm_bm_write_lock_zero(struct dm_block_manager *bm,
525 dm_block_t b, struct dm_block_validator *v,
526 struct dm_block **result)
527{
528 int r;
529 struct buffer_aux *aux;
530 void *p;
531
532 p = dm_bufio_new(to_bufio(bm), b, (struct dm_buffer **) result);
533 if (unlikely(IS_ERR(p)))
534 return PTR_ERR(p);
535
536 memset(p, 0, dm_bm_block_size(bm));
537
538 aux = dm_bufio_get_aux_data(to_buffer(*result));
539 r = bl_down_write(&aux->lock);
540 if (r) {
541 dm_bufio_release(to_buffer(*result));
542 return r;
543 }
544
545 aux->write_locked = 1;
546 aux->validator = v;
547
548 return 0;
549}
550
551int dm_bm_unlock(struct dm_block *b)
552{
553 struct buffer_aux *aux;
554 aux = dm_bufio_get_aux_data(to_buffer(b));
555
556 if (aux->write_locked) {
557 dm_bufio_mark_buffer_dirty(to_buffer(b));
558 bl_up_write(&aux->lock);
559 } else
560 bl_up_read(&aux->lock);
561
562 dm_bufio_release(to_buffer(b));
563
564 return 0;
565}
566EXPORT_SYMBOL_GPL(dm_bm_unlock);
567
568int dm_bm_unlock_move(struct dm_block *b, dm_block_t n)
569{
570 struct buffer_aux *aux;
571
572 aux = dm_bufio_get_aux_data(to_buffer(b));
573
574 if (aux->write_locked) {
575 dm_bufio_mark_buffer_dirty(to_buffer(b));
576 bl_up_write(&aux->lock);
577 } else
578 bl_up_read(&aux->lock);
579
580 dm_bufio_release_move(to_buffer(b), n);
581 return 0;
582}
583
584int dm_bm_flush_and_unlock(struct dm_block_manager *bm,
585 struct dm_block *superblock)
586{
587 int r;
588
589 r = dm_bufio_write_dirty_buffers(to_bufio(bm));
590 if (unlikely(r))
591 return r;
592 r = dm_bufio_issue_flush(to_bufio(bm));
593 if (unlikely(r))
594 return r;
595
596 dm_bm_unlock(superblock);
597
598 r = dm_bufio_write_dirty_buffers(to_bufio(bm));
599 if (unlikely(r))
600 return r;
601 r = dm_bufio_issue_flush(to_bufio(bm));
602 if (unlikely(r))
603 return r;
604
605 return 0;
606}
607
608u32 dm_bm_checksum(const void *data, size_t len, u32 init_xor)
609{
610 return crc32c(~(u32) 0, data, len) ^ init_xor;
611}
612EXPORT_SYMBOL_GPL(dm_bm_checksum);
613
614/*----------------------------------------------------------------*/
615
616MODULE_LICENSE("GPL");
617MODULE_AUTHOR("Joe Thornber <dm-devel@redhat.com>");
618MODULE_DESCRIPTION("Immutable metadata library for dm");
619
620/*----------------------------------------------------------------*/
diff --git a/drivers/md/persistent-data/dm-block-manager.h b/drivers/md/persistent-data/dm-block-manager.h
new file mode 100644
index 000000000000..924833d2dfa6
--- /dev/null
+++ b/drivers/md/persistent-data/dm-block-manager.h
@@ -0,0 +1,123 @@
1/*
2 * Copyright (C) 2011 Red Hat, Inc.
3 *
4 * This file is released under the GPL.
5 */
6
7#ifndef _LINUX_DM_BLOCK_MANAGER_H
8#define _LINUX_DM_BLOCK_MANAGER_H
9
10#include <linux/types.h>
11#include <linux/blkdev.h>
12
13/*----------------------------------------------------------------*/
14
15/*
16 * Block number.
17 */
18typedef uint64_t dm_block_t;
19struct dm_block;
20
21dm_block_t dm_block_location(struct dm_block *b);
22void *dm_block_data(struct dm_block *b);
23
24/*----------------------------------------------------------------*/
25
26/*
27 * @name should be a unique identifier for the block manager, no longer
28 * than 32 chars.
29 *
30 * @max_held_per_thread should be the maximum number of locks, read or
31 * write, that an individual thread holds at any one time.
32 */
33struct dm_block_manager;
34struct dm_block_manager *dm_block_manager_create(
35 struct block_device *bdev, unsigned block_size,
36 unsigned cache_size, unsigned max_held_per_thread);
37void dm_block_manager_destroy(struct dm_block_manager *bm);
38
39unsigned dm_bm_block_size(struct dm_block_manager *bm);
40dm_block_t dm_bm_nr_blocks(struct dm_block_manager *bm);
41
42/*----------------------------------------------------------------*/
43
44/*
45 * The validator allows the caller to verify newly-read data and modify
46 * the data just before writing, e.g. to calculate checksums. It's
47 * important to be consistent with your use of validators. The only time
48 * you can change validators is if you call dm_bm_write_lock_zero.
49 */
50struct dm_block_validator {
51 const char *name;
52 void (*prepare_for_write)(struct dm_block_validator *v, struct dm_block *b, size_t block_size);
53
54 /*
55 * Return 0 if the checksum is valid or < 0 on error.
56 */
57 int (*check)(struct dm_block_validator *v, struct dm_block *b, size_t block_size);
58};
59
60/*----------------------------------------------------------------*/
61
62/*
63 * You can have multiple concurrent readers or a single writer holding a
64 * block lock.
65 */
66
67/*
68 * dm_bm_lock() locks a block and returns through @result a pointer to
69 * memory that holds a copy of that block. If you have write-locked the
70 * block then any changes you make to memory pointed to by @result will be
71 * written back to the disk sometime after dm_bm_unlock is called.
72 */
73int dm_bm_read_lock(struct dm_block_manager *bm, dm_block_t b,
74 struct dm_block_validator *v,
75 struct dm_block **result);
76
77int dm_bm_write_lock(struct dm_block_manager *bm, dm_block_t b,
78 struct dm_block_validator *v,
79 struct dm_block **result);
80
81/*
82 * The *_try_lock variants return -EWOULDBLOCK if the block isn't
83 * available immediately.
84 */
85int dm_bm_read_try_lock(struct dm_block_manager *bm, dm_block_t b,
86 struct dm_block_validator *v,
87 struct dm_block **result);
88
89/*
90 * Use dm_bm_write_lock_zero() when you know you're going to
91 * overwrite the block completely. It saves a disk read.
92 */
93int dm_bm_write_lock_zero(struct dm_block_manager *bm, dm_block_t b,
94 struct dm_block_validator *v,
95 struct dm_block **result);
96
97int dm_bm_unlock(struct dm_block *b);
98
99/*
100 * An optimisation; we often want to copy a block's contents to a new
101 * block. eg, as part of the shadowing operation. It's far better for
102 * bufio to do this move behind the scenes than hold 2 locks and memcpy the
103 * data.
104 */
105int dm_bm_unlock_move(struct dm_block *b, dm_block_t n);
106
107/*
108 * It's a common idiom to have a superblock that should be committed last.
109 *
110 * @superblock should be write-locked on entry. It will be unlocked during
111 * this function. All dirty blocks are guaranteed to be written and flushed
112 * before the superblock.
113 *
114 * This method always blocks.
115 */
116int dm_bm_flush_and_unlock(struct dm_block_manager *bm,
117 struct dm_block *superblock);
118
119u32 dm_bm_checksum(const void *data, size_t len, u32 init_xor);
120
121/*----------------------------------------------------------------*/
122
123#endif /* _LINUX_DM_BLOCK_MANAGER_H */
diff --git a/drivers/md/persistent-data/dm-btree-internal.h b/drivers/md/persistent-data/dm-btree-internal.h
new file mode 100644
index 000000000000..d279c768f8f1
--- /dev/null
+++ b/drivers/md/persistent-data/dm-btree-internal.h
@@ -0,0 +1,137 @@
1/*
2 * Copyright (C) 2011 Red Hat, Inc.
3 *
4 * This file is released under the GPL.
5 */
6
7#ifndef DM_BTREE_INTERNAL_H
8#define DM_BTREE_INTERNAL_H
9
10#include "dm-btree.h"
11
12/*----------------------------------------------------------------*/
13
14/*
15 * We'll need 2 accessor functions for n->csum and n->blocknr
16 * to support dm-btree-spine.c in that case.
17 */
18
19enum node_flags {
20 INTERNAL_NODE = 1,
21 LEAF_NODE = 1 << 1
22};
23
24/*
25 * Every btree node begins with this structure. Make sure it's a multiple
26 * of 8-bytes in size, otherwise the 64bit keys will be mis-aligned.
27 */
28struct node_header {
29 __le32 csum;
30 __le32 flags;
31 __le64 blocknr; /* Block this node is supposed to live in. */
32
33 __le32 nr_entries;
34 __le32 max_entries;
35 __le32 value_size;
36 __le32 padding;
37} __packed;
38
39struct node {
40 struct node_header header;
41 __le64 keys[0];
42} __packed;
43
44
45void inc_children(struct dm_transaction_manager *tm, struct node *n,
46 struct dm_btree_value_type *vt);
47
48int new_block(struct dm_btree_info *info, struct dm_block **result);
49int unlock_block(struct dm_btree_info *info, struct dm_block *b);
50
51/*
52 * Spines keep track of the rolling locks. There are 2 variants, read-only
53 * and one that uses shadowing. These are separate structs to allow the
54 * type checker to spot misuse, for example accidentally calling read_lock
55 * on a shadow spine.
56 */
57struct ro_spine {
58 struct dm_btree_info *info;
59
60 int count;
61 struct dm_block *nodes[2];
62};
63
64void init_ro_spine(struct ro_spine *s, struct dm_btree_info *info);
65int exit_ro_spine(struct ro_spine *s);
66int ro_step(struct ro_spine *s, dm_block_t new_child);
67struct node *ro_node(struct ro_spine *s);
68
69struct shadow_spine {
70 struct dm_btree_info *info;
71
72 int count;
73 struct dm_block *nodes[2];
74
75 dm_block_t root;
76};
77
78void init_shadow_spine(struct shadow_spine *s, struct dm_btree_info *info);
79int exit_shadow_spine(struct shadow_spine *s);
80
81int shadow_step(struct shadow_spine *s, dm_block_t b,
82 struct dm_btree_value_type *vt);
83
84/*
85 * The spine must have at least one entry before calling this.
86 */
87struct dm_block *shadow_current(struct shadow_spine *s);
88
89/*
90 * The spine must have at least two entries before calling this.
91 */
92struct dm_block *shadow_parent(struct shadow_spine *s);
93
94int shadow_has_parent(struct shadow_spine *s);
95
96int shadow_root(struct shadow_spine *s);
97
98/*
99 * Some inlines.
100 */
101static inline __le64 *key_ptr(struct node *n, uint32_t index)
102{
103 return n->keys + index;
104}
105
106static inline void *value_base(struct node *n)
107{
108 return &n->keys[le32_to_cpu(n->header.max_entries)];
109}
110
111/*
112 * FIXME: Now that value size is stored in node we don't need the third parm.
113 */
114static inline void *value_ptr(struct node *n, uint32_t index, size_t value_size)
115{
116 BUG_ON(value_size != le32_to_cpu(n->header.value_size));
117 return value_base(n) + (value_size * index);
118}
119
120/*
121 * Assumes the values are suitably-aligned and converts to core format.
122 */
123static inline uint64_t value64(struct node *n, uint32_t index)
124{
125 __le64 *values_le = value_base(n);
126
127 return le64_to_cpu(values_le[index]);
128}
129
130/*
131 * Searching for a key within a single node.
132 */
133int lower_bound(struct node *n, uint64_t key);
134
135extern struct dm_block_validator btree_node_validator;
136
137#endif /* DM_BTREE_INTERNAL_H */
diff --git a/drivers/md/persistent-data/dm-btree-remove.c b/drivers/md/persistent-data/dm-btree-remove.c
new file mode 100644
index 000000000000..65fd85ec6514
--- /dev/null
+++ b/drivers/md/persistent-data/dm-btree-remove.c
@@ -0,0 +1,566 @@
1/*
2 * Copyright (C) 2011 Red Hat, Inc.
3 *
4 * This file is released under the GPL.
5 */
6
7#include "dm-btree.h"
8#include "dm-btree-internal.h"
9#include "dm-transaction-manager.h"
10
11#include <linux/module.h>
12
13/*
14 * Removing an entry from a btree
15 * ==============================
16 *
17 * A very important constraint for our btree is that no node, except the
18 * root, may have fewer than a certain number of entries.
19 * (MIN_ENTRIES <= nr_entries <= MAX_ENTRIES).
20 *
21 * Ensuring this is complicated by the way we want to only ever hold the
22 * locks on 2 nodes concurrently, and only change nodes in a top to bottom
23 * fashion.
24 *
25 * Each node may have a left or right sibling. When decending the spine,
26 * if a node contains only MIN_ENTRIES then we try and increase this to at
27 * least MIN_ENTRIES + 1. We do this in the following ways:
28 *
29 * [A] No siblings => this can only happen if the node is the root, in which
30 * case we copy the childs contents over the root.
31 *
32 * [B] No left sibling
33 * ==> rebalance(node, right sibling)
34 *
35 * [C] No right sibling
36 * ==> rebalance(left sibling, node)
37 *
38 * [D] Both siblings, total_entries(left, node, right) <= DEL_THRESHOLD
39 * ==> delete node adding it's contents to left and right
40 *
41 * [E] Both siblings, total_entries(left, node, right) > DEL_THRESHOLD
42 * ==> rebalance(left, node, right)
43 *
44 * After these operations it's possible that the our original node no
45 * longer contains the desired sub tree. For this reason this rebalancing
46 * is performed on the children of the current node. This also avoids
47 * having a special case for the root.
48 *
49 * Once this rebalancing has occurred we can then step into the child node
50 * for internal nodes. Or delete the entry for leaf nodes.
51 */
52
53/*
54 * Some little utilities for moving node data around.
55 */
56static void node_shift(struct node *n, int shift)
57{
58 uint32_t nr_entries = le32_to_cpu(n->header.nr_entries);
59 uint32_t value_size = le32_to_cpu(n->header.value_size);
60
61 if (shift < 0) {
62 shift = -shift;
63 BUG_ON(shift > nr_entries);
64 BUG_ON((void *) key_ptr(n, shift) >= value_ptr(n, shift, value_size));
65 memmove(key_ptr(n, 0),
66 key_ptr(n, shift),
67 (nr_entries - shift) * sizeof(__le64));
68 memmove(value_ptr(n, 0, value_size),
69 value_ptr(n, shift, value_size),
70 (nr_entries - shift) * value_size);
71 } else {
72 BUG_ON(nr_entries + shift > le32_to_cpu(n->header.max_entries));
73 memmove(key_ptr(n, shift),
74 key_ptr(n, 0),
75 nr_entries * sizeof(__le64));
76 memmove(value_ptr(n, shift, value_size),
77 value_ptr(n, 0, value_size),
78 nr_entries * value_size);
79 }
80}
81
82static void node_copy(struct node *left, struct node *right, int shift)
83{
84 uint32_t nr_left = le32_to_cpu(left->header.nr_entries);
85 uint32_t value_size = le32_to_cpu(left->header.value_size);
86 BUG_ON(value_size != le32_to_cpu(right->header.value_size));
87
88 if (shift < 0) {
89 shift = -shift;
90 BUG_ON(nr_left + shift > le32_to_cpu(left->header.max_entries));
91 memcpy(key_ptr(left, nr_left),
92 key_ptr(right, 0),
93 shift * sizeof(__le64));
94 memcpy(value_ptr(left, nr_left, value_size),
95 value_ptr(right, 0, value_size),
96 shift * value_size);
97 } else {
98 BUG_ON(shift > le32_to_cpu(right->header.max_entries));
99 memcpy(key_ptr(right, 0),
100 key_ptr(left, nr_left - shift),
101 shift * sizeof(__le64));
102 memcpy(value_ptr(right, 0, value_size),
103 value_ptr(left, nr_left - shift, value_size),
104 shift * value_size);
105 }
106}
107
108/*
109 * Delete a specific entry from a leaf node.
110 */
111static void delete_at(struct node *n, unsigned index)
112{
113 unsigned nr_entries = le32_to_cpu(n->header.nr_entries);
114 unsigned nr_to_copy = nr_entries - (index + 1);
115 uint32_t value_size = le32_to_cpu(n->header.value_size);
116 BUG_ON(index >= nr_entries);
117
118 if (nr_to_copy) {
119 memmove(key_ptr(n, index),
120 key_ptr(n, index + 1),
121 nr_to_copy * sizeof(__le64));
122
123 memmove(value_ptr(n, index, value_size),
124 value_ptr(n, index + 1, value_size),
125 nr_to_copy * value_size);
126 }
127
128 n->header.nr_entries = cpu_to_le32(nr_entries - 1);
129}
130
131static unsigned del_threshold(struct node *n)
132{
133 return le32_to_cpu(n->header.max_entries) / 3;
134}
135
136static unsigned merge_threshold(struct node *n)
137{
138 /*
139 * The extra one is because we know we're potentially going to
140 * delete an entry.
141 */
142 return 2 * (le32_to_cpu(n->header.max_entries) / 3) + 1;
143}
144
145struct child {
146 unsigned index;
147 struct dm_block *block;
148 struct node *n;
149};
150
151static struct dm_btree_value_type le64_type = {
152 .context = NULL,
153 .size = sizeof(__le64),
154 .inc = NULL,
155 .dec = NULL,
156 .equal = NULL
157};
158
159static int init_child(struct dm_btree_info *info, struct node *parent,
160 unsigned index, struct child *result)
161{
162 int r, inc;
163 dm_block_t root;
164
165 result->index = index;
166 root = value64(parent, index);
167
168 r = dm_tm_shadow_block(info->tm, root, &btree_node_validator,
169 &result->block, &inc);
170 if (r)
171 return r;
172
173 result->n = dm_block_data(result->block);
174
175 if (inc)
176 inc_children(info->tm, result->n, &le64_type);
177
178 *((__le64 *) value_ptr(parent, index, sizeof(__le64))) =
179 cpu_to_le64(dm_block_location(result->block));
180
181 return 0;
182}
183
184static int exit_child(struct dm_btree_info *info, struct child *c)
185{
186 return dm_tm_unlock(info->tm, c->block);
187}
188
189static void shift(struct node *left, struct node *right, int count)
190{
191 if (!count)
192 return;
193
194 if (count > 0) {
195 node_shift(right, count);
196 node_copy(left, right, count);
197 } else {
198 node_copy(left, right, count);
199 node_shift(right, count);
200 }
201
202 left->header.nr_entries =
203 cpu_to_le32(le32_to_cpu(left->header.nr_entries) - count);
204 BUG_ON(le32_to_cpu(left->header.nr_entries) > le32_to_cpu(left->header.max_entries));
205
206 right->header.nr_entries =
207 cpu_to_le32(le32_to_cpu(right->header.nr_entries) + count);
208 BUG_ON(le32_to_cpu(right->header.nr_entries) > le32_to_cpu(right->header.max_entries));
209}
210
211static void __rebalance2(struct dm_btree_info *info, struct node *parent,
212 struct child *l, struct child *r)
213{
214 struct node *left = l->n;
215 struct node *right = r->n;
216 uint32_t nr_left = le32_to_cpu(left->header.nr_entries);
217 uint32_t nr_right = le32_to_cpu(right->header.nr_entries);
218
219 if (nr_left + nr_right <= merge_threshold(left)) {
220 /*
221 * Merge
222 */
223 node_copy(left, right, -nr_right);
224 left->header.nr_entries = cpu_to_le32(nr_left + nr_right);
225 delete_at(parent, r->index);
226
227 /*
228 * We need to decrement the right block, but not it's
229 * children, since they're still referenced by left.
230 */
231 dm_tm_dec(info->tm, dm_block_location(r->block));
232 } else {
233 /*
234 * Rebalance.
235 */
236 unsigned target_left = (nr_left + nr_right) / 2;
237 unsigned shift_ = nr_left - target_left;
238 BUG_ON(le32_to_cpu(left->header.max_entries) <= nr_left - shift_);
239 BUG_ON(le32_to_cpu(right->header.max_entries) <= nr_right + shift_);
240 shift(left, right, nr_left - target_left);
241 *key_ptr(parent, r->index) = right->keys[0];
242 }
243}
244
245static int rebalance2(struct shadow_spine *s, struct dm_btree_info *info,
246 unsigned left_index)
247{
248 int r;
249 struct node *parent;
250 struct child left, right;
251
252 parent = dm_block_data(shadow_current(s));
253
254 r = init_child(info, parent, left_index, &left);
255 if (r)
256 return r;
257
258 r = init_child(info, parent, left_index + 1, &right);
259 if (r) {
260 exit_child(info, &left);
261 return r;
262 }
263
264 __rebalance2(info, parent, &left, &right);
265
266 r = exit_child(info, &left);
267 if (r) {
268 exit_child(info, &right);
269 return r;
270 }
271
272 return exit_child(info, &right);
273}
274
275static void __rebalance3(struct dm_btree_info *info, struct node *parent,
276 struct child *l, struct child *c, struct child *r)
277{
278 struct node *left = l->n;
279 struct node *center = c->n;
280 struct node *right = r->n;
281
282 uint32_t nr_left = le32_to_cpu(left->header.nr_entries);
283 uint32_t nr_center = le32_to_cpu(center->header.nr_entries);
284 uint32_t nr_right = le32_to_cpu(right->header.nr_entries);
285 uint32_t max_entries = le32_to_cpu(left->header.max_entries);
286
287 unsigned target;
288
289 BUG_ON(left->header.max_entries != center->header.max_entries);
290 BUG_ON(center->header.max_entries != right->header.max_entries);
291
292 if (((nr_left + nr_center + nr_right) / 2) < merge_threshold(center)) {
293 /*
294 * Delete center node:
295 *
296 * We dump as many entries from center as possible into
297 * left, then the rest in right, then rebalance2. This
298 * wastes some cpu, but I want something simple atm.
299 */
300 unsigned shift = min(max_entries - nr_left, nr_center);
301
302 BUG_ON(nr_left + shift > max_entries);
303 node_copy(left, center, -shift);
304 left->header.nr_entries = cpu_to_le32(nr_left + shift);
305
306 if (shift != nr_center) {
307 shift = nr_center - shift;
308 BUG_ON((nr_right + shift) >= max_entries);
309 node_shift(right, shift);
310 node_copy(center, right, shift);
311 right->header.nr_entries = cpu_to_le32(nr_right + shift);
312 }
313 *key_ptr(parent, r->index) = right->keys[0];
314
315 delete_at(parent, c->index);
316 r->index--;
317
318 dm_tm_dec(info->tm, dm_block_location(c->block));
319 __rebalance2(info, parent, l, r);
320
321 return;
322 }
323
324 /*
325 * Rebalance
326 */
327 target = (nr_left + nr_center + nr_right) / 3;
328 BUG_ON(target > max_entries);
329
330 /*
331 * Adjust the left node
332 */
333 shift(left, center, nr_left - target);
334
335 /*
336 * Adjust the right node
337 */
338 shift(center, right, target - nr_right);
339 *key_ptr(parent, c->index) = center->keys[0];
340 *key_ptr(parent, r->index) = right->keys[0];
341}
342
343static int rebalance3(struct shadow_spine *s, struct dm_btree_info *info,
344 unsigned left_index)
345{
346 int r;
347 struct node *parent = dm_block_data(shadow_current(s));
348 struct child left, center, right;
349
350 /*
351 * FIXME: fill out an array?
352 */
353 r = init_child(info, parent, left_index, &left);
354 if (r)
355 return r;
356
357 r = init_child(info, parent, left_index + 1, &center);
358 if (r) {
359 exit_child(info, &left);
360 return r;
361 }
362
363 r = init_child(info, parent, left_index + 2, &right);
364 if (r) {
365 exit_child(info, &left);
366 exit_child(info, &center);
367 return r;
368 }
369
370 __rebalance3(info, parent, &left, &center, &right);
371
372 r = exit_child(info, &left);
373 if (r) {
374 exit_child(info, &center);
375 exit_child(info, &right);
376 return r;
377 }
378
379 r = exit_child(info, &center);
380 if (r) {
381 exit_child(info, &right);
382 return r;
383 }
384
385 r = exit_child(info, &right);
386 if (r)
387 return r;
388
389 return 0;
390}
391
392static int get_nr_entries(struct dm_transaction_manager *tm,
393 dm_block_t b, uint32_t *result)
394{
395 int r;
396 struct dm_block *block;
397 struct node *n;
398
399 r = dm_tm_read_lock(tm, b, &btree_node_validator, &block);
400 if (r)
401 return r;
402
403 n = dm_block_data(block);
404 *result = le32_to_cpu(n->header.nr_entries);
405
406 return dm_tm_unlock(tm, block);
407}
408
409static int rebalance_children(struct shadow_spine *s,
410 struct dm_btree_info *info, uint64_t key)
411{
412 int i, r, has_left_sibling, has_right_sibling;
413 uint32_t child_entries;
414 struct node *n;
415
416 n = dm_block_data(shadow_current(s));
417
418 if (le32_to_cpu(n->header.nr_entries) == 1) {
419 struct dm_block *child;
420 dm_block_t b = value64(n, 0);
421
422 r = dm_tm_read_lock(info->tm, b, &btree_node_validator, &child);
423 if (r)
424 return r;
425
426 memcpy(n, dm_block_data(child),
427 dm_bm_block_size(dm_tm_get_bm(info->tm)));
428 r = dm_tm_unlock(info->tm, child);
429 if (r)
430 return r;
431
432 dm_tm_dec(info->tm, dm_block_location(child));
433 return 0;
434 }
435
436 i = lower_bound(n, key);
437 if (i < 0)
438 return -ENODATA;
439
440 r = get_nr_entries(info->tm, value64(n, i), &child_entries);
441 if (r)
442 return r;
443
444 if (child_entries > del_threshold(n))
445 return 0;
446
447 has_left_sibling = i > 0;
448 has_right_sibling = i < (le32_to_cpu(n->header.nr_entries) - 1);
449
450 if (!has_left_sibling)
451 r = rebalance2(s, info, i);
452
453 else if (!has_right_sibling)
454 r = rebalance2(s, info, i - 1);
455
456 else
457 r = rebalance3(s, info, i - 1);
458
459 return r;
460}
461
462static int do_leaf(struct node *n, uint64_t key, unsigned *index)
463{
464 int i = lower_bound(n, key);
465
466 if ((i < 0) ||
467 (i >= le32_to_cpu(n->header.nr_entries)) ||
468 (le64_to_cpu(n->keys[i]) != key))
469 return -ENODATA;
470
471 *index = i;
472
473 return 0;
474}
475
476/*
477 * Prepares for removal from one level of the hierarchy. The caller must
478 * call delete_at() to remove the entry at index.
479 */
480static int remove_raw(struct shadow_spine *s, struct dm_btree_info *info,
481 struct dm_btree_value_type *vt, dm_block_t root,
482 uint64_t key, unsigned *index)
483{
484 int i = *index, r;
485 struct node *n;
486
487 for (;;) {
488 r = shadow_step(s, root, vt);
489 if (r < 0)
490 break;
491
492 /*
493 * We have to patch up the parent node, ugly, but I don't
494 * see a way to do this automatically as part of the spine
495 * op.
496 */
497 if (shadow_has_parent(s)) {
498 __le64 location = cpu_to_le64(dm_block_location(shadow_current(s)));
499 memcpy(value_ptr(dm_block_data(shadow_parent(s)), i, sizeof(__le64)),
500 &location, sizeof(__le64));
501 }
502
503 n = dm_block_data(shadow_current(s));
504
505 if (le32_to_cpu(n->header.flags) & LEAF_NODE)
506 return do_leaf(n, key, index);
507
508 r = rebalance_children(s, info, key);
509 if (r)
510 break;
511
512 n = dm_block_data(shadow_current(s));
513 if (le32_to_cpu(n->header.flags) & LEAF_NODE)
514 return do_leaf(n, key, index);
515
516 i = lower_bound(n, key);
517
518 /*
519 * We know the key is present, or else
520 * rebalance_children would have returned
521 * -ENODATA
522 */
523 root = value64(n, i);
524 }
525
526 return r;
527}
528
529int dm_btree_remove(struct dm_btree_info *info, dm_block_t root,
530 uint64_t *keys, dm_block_t *new_root)
531{
532 unsigned level, last_level = info->levels - 1;
533 int index = 0, r = 0;
534 struct shadow_spine spine;
535 struct node *n;
536
537 init_shadow_spine(&spine, info);
538 for (level = 0; level < info->levels; level++) {
539 r = remove_raw(&spine, info,
540 (level == last_level ?
541 &info->value_type : &le64_type),
542 root, keys[level], (unsigned *)&index);
543 if (r < 0)
544 break;
545
546 n = dm_block_data(shadow_current(&spine));
547 if (level != last_level) {
548 root = value64(n, index);
549 continue;
550 }
551
552 BUG_ON(index < 0 || index >= le32_to_cpu(n->header.nr_entries));
553
554 if (info->value_type.dec)
555 info->value_type.dec(info->value_type.context,
556 value_ptr(n, index, info->value_type.size));
557
558 delete_at(n, index);
559 }
560
561 *new_root = shadow_root(&spine);
562 exit_shadow_spine(&spine);
563
564 return r;
565}
566EXPORT_SYMBOL_GPL(dm_btree_remove);
diff --git a/drivers/md/persistent-data/dm-btree-spine.c b/drivers/md/persistent-data/dm-btree-spine.c
new file mode 100644
index 000000000000..d9a7912ee8ee
--- /dev/null
+++ b/drivers/md/persistent-data/dm-btree-spine.c
@@ -0,0 +1,244 @@
1/*
2 * Copyright (C) 2011 Red Hat, Inc.
3 *
4 * This file is released under the GPL.
5 */
6
7#include "dm-btree-internal.h"
8#include "dm-transaction-manager.h"
9
10#include <linux/device-mapper.h>
11
12#define DM_MSG_PREFIX "btree spine"
13
14/*----------------------------------------------------------------*/
15
16#define BTREE_CSUM_XOR 121107
17
18static int node_check(struct dm_block_validator *v,
19 struct dm_block *b,
20 size_t block_size);
21
22static void node_prepare_for_write(struct dm_block_validator *v,
23 struct dm_block *b,
24 size_t block_size)
25{
26 struct node *n = dm_block_data(b);
27 struct node_header *h = &n->header;
28
29 h->blocknr = cpu_to_le64(dm_block_location(b));
30 h->csum = cpu_to_le32(dm_bm_checksum(&h->flags,
31 block_size - sizeof(__le32),
32 BTREE_CSUM_XOR));
33
34 BUG_ON(node_check(v, b, 4096));
35}
36
37static int node_check(struct dm_block_validator *v,
38 struct dm_block *b,
39 size_t block_size)
40{
41 struct node *n = dm_block_data(b);
42 struct node_header *h = &n->header;
43 size_t value_size;
44 __le32 csum_disk;
45 uint32_t flags;
46
47 if (dm_block_location(b) != le64_to_cpu(h->blocknr)) {
48 DMERR("node_check failed blocknr %llu wanted %llu",
49 le64_to_cpu(h->blocknr), dm_block_location(b));
50 return -ENOTBLK;
51 }
52
53 csum_disk = cpu_to_le32(dm_bm_checksum(&h->flags,
54 block_size - sizeof(__le32),
55 BTREE_CSUM_XOR));
56 if (csum_disk != h->csum) {
57 DMERR("node_check failed csum %u wanted %u",
58 le32_to_cpu(csum_disk), le32_to_cpu(h->csum));
59 return -EILSEQ;
60 }
61
62 value_size = le32_to_cpu(h->value_size);
63
64 if (sizeof(struct node_header) +
65 (sizeof(__le64) + value_size) * le32_to_cpu(h->max_entries) > block_size) {
66 DMERR("node_check failed: max_entries too large");
67 return -EILSEQ;
68 }
69
70 if (le32_to_cpu(h->nr_entries) > le32_to_cpu(h->max_entries)) {
71 DMERR("node_check failed, too many entries");
72 return -EILSEQ;
73 }
74
75 /*
76 * The node must be either INTERNAL or LEAF.
77 */
78 flags = le32_to_cpu(h->flags);
79 if (!(flags & INTERNAL_NODE) && !(flags & LEAF_NODE)) {
80 DMERR("node_check failed, node is neither INTERNAL or LEAF");
81 return -EILSEQ;
82 }
83
84 return 0;
85}
86
87struct dm_block_validator btree_node_validator = {
88 .name = "btree_node",
89 .prepare_for_write = node_prepare_for_write,
90 .check = node_check
91};
92
93/*----------------------------------------------------------------*/
94
95static int bn_read_lock(struct dm_btree_info *info, dm_block_t b,
96 struct dm_block **result)
97{
98 return dm_tm_read_lock(info->tm, b, &btree_node_validator, result);
99}
100
101static int bn_shadow(struct dm_btree_info *info, dm_block_t orig,
102 struct dm_btree_value_type *vt,
103 struct dm_block **result)
104{
105 int r, inc;
106
107 r = dm_tm_shadow_block(info->tm, orig, &btree_node_validator,
108 result, &inc);
109 if (!r && inc)
110 inc_children(info->tm, dm_block_data(*result), vt);
111
112 return r;
113}
114
115int new_block(struct dm_btree_info *info, struct dm_block **result)
116{
117 return dm_tm_new_block(info->tm, &btree_node_validator, result);
118}
119
120int unlock_block(struct dm_btree_info *info, struct dm_block *b)
121{
122 return dm_tm_unlock(info->tm, b);
123}
124
125/*----------------------------------------------------------------*/
126
127void init_ro_spine(struct ro_spine *s, struct dm_btree_info *info)
128{
129 s->info = info;
130 s->count = 0;
131 s->nodes[0] = NULL;
132 s->nodes[1] = NULL;
133}
134
135int exit_ro_spine(struct ro_spine *s)
136{
137 int r = 0, i;
138
139 for (i = 0; i < s->count; i++) {
140 int r2 = unlock_block(s->info, s->nodes[i]);
141 if (r2 < 0)
142 r = r2;
143 }
144
145 return r;
146}
147
148int ro_step(struct ro_spine *s, dm_block_t new_child)
149{
150 int r;
151
152 if (s->count == 2) {
153 r = unlock_block(s->info, s->nodes[0]);
154 if (r < 0)
155 return r;
156 s->nodes[0] = s->nodes[1];
157 s->count--;
158 }
159
160 r = bn_read_lock(s->info, new_child, s->nodes + s->count);
161 if (!r)
162 s->count++;
163
164 return r;
165}
166
167struct node *ro_node(struct ro_spine *s)
168{
169 struct dm_block *block;
170
171 BUG_ON(!s->count);
172 block = s->nodes[s->count - 1];
173
174 return dm_block_data(block);
175}
176
177/*----------------------------------------------------------------*/
178
179void init_shadow_spine(struct shadow_spine *s, struct dm_btree_info *info)
180{
181 s->info = info;
182 s->count = 0;
183}
184
185int exit_shadow_spine(struct shadow_spine *s)
186{
187 int r = 0, i;
188
189 for (i = 0; i < s->count; i++) {
190 int r2 = unlock_block(s->info, s->nodes[i]);
191 if (r2 < 0)
192 r = r2;
193 }
194
195 return r;
196}
197
198int shadow_step(struct shadow_spine *s, dm_block_t b,
199 struct dm_btree_value_type *vt)
200{
201 int r;
202
203 if (s->count == 2) {
204 r = unlock_block(s->info, s->nodes[0]);
205 if (r < 0)
206 return r;
207 s->nodes[0] = s->nodes[1];
208 s->count--;
209 }
210
211 r = bn_shadow(s->info, b, vt, s->nodes + s->count);
212 if (!r) {
213 if (!s->count)
214 s->root = dm_block_location(s->nodes[0]);
215
216 s->count++;
217 }
218
219 return r;
220}
221
222struct dm_block *shadow_current(struct shadow_spine *s)
223{
224 BUG_ON(!s->count);
225
226 return s->nodes[s->count - 1];
227}
228
229struct dm_block *shadow_parent(struct shadow_spine *s)
230{
231 BUG_ON(s->count != 2);
232
233 return s->count == 2 ? s->nodes[0] : NULL;
234}
235
236int shadow_has_parent(struct shadow_spine *s)
237{
238 return s->count >= 2;
239}
240
241int shadow_root(struct shadow_spine *s)
242{
243 return s->root;
244}
diff --git a/drivers/md/persistent-data/dm-btree.c b/drivers/md/persistent-data/dm-btree.c
new file mode 100644
index 000000000000..e0638be53ea4
--- /dev/null
+++ b/drivers/md/persistent-data/dm-btree.c
@@ -0,0 +1,805 @@
1/*
2 * Copyright (C) 2011 Red Hat, Inc.
3 *
4 * This file is released under the GPL.
5 */
6
7#include "dm-btree-internal.h"
8#include "dm-space-map.h"
9#include "dm-transaction-manager.h"
10
11#include <linux/module.h>
12#include <linux/device-mapper.h>
13
14#define DM_MSG_PREFIX "btree"
15
16/*----------------------------------------------------------------
17 * Array manipulation
18 *--------------------------------------------------------------*/
19static void memcpy_disk(void *dest, const void *src, size_t len)
20 __dm_written_to_disk(src)
21{
22 memcpy(dest, src, len);
23 __dm_unbless_for_disk(src);
24}
25
26static void array_insert(void *base, size_t elt_size, unsigned nr_elts,
27 unsigned index, void *elt)
28 __dm_written_to_disk(elt)
29{
30 if (index < nr_elts)
31 memmove(base + (elt_size * (index + 1)),
32 base + (elt_size * index),
33 (nr_elts - index) * elt_size);
34
35 memcpy_disk(base + (elt_size * index), elt, elt_size);
36}
37
38/*----------------------------------------------------------------*/
39
40/* makes the assumption that no two keys are the same. */
41static int bsearch(struct node *n, uint64_t key, int want_hi)
42{
43 int lo = -1, hi = le32_to_cpu(n->header.nr_entries);
44
45 while (hi - lo > 1) {
46 int mid = lo + ((hi - lo) / 2);
47 uint64_t mid_key = le64_to_cpu(n->keys[mid]);
48
49 if (mid_key == key)
50 return mid;
51
52 if (mid_key < key)
53 lo = mid;
54 else
55 hi = mid;
56 }
57
58 return want_hi ? hi : lo;
59}
60
61int lower_bound(struct node *n, uint64_t key)
62{
63 return bsearch(n, key, 0);
64}
65
66void inc_children(struct dm_transaction_manager *tm, struct node *n,
67 struct dm_btree_value_type *vt)
68{
69 unsigned i;
70 uint32_t nr_entries = le32_to_cpu(n->header.nr_entries);
71
72 if (le32_to_cpu(n->header.flags) & INTERNAL_NODE)
73 for (i = 0; i < nr_entries; i++)
74 dm_tm_inc(tm, value64(n, i));
75 else if (vt->inc)
76 for (i = 0; i < nr_entries; i++)
77 vt->inc(vt->context,
78 value_ptr(n, i, vt->size));
79}
80
81static int insert_at(size_t value_size, struct node *node, unsigned index,
82 uint64_t key, void *value)
83 __dm_written_to_disk(value)
84{
85 uint32_t nr_entries = le32_to_cpu(node->header.nr_entries);
86 __le64 key_le = cpu_to_le64(key);
87
88 if (index > nr_entries ||
89 index >= le32_to_cpu(node->header.max_entries)) {
90 DMERR("too many entries in btree node for insert");
91 __dm_unbless_for_disk(value);
92 return -ENOMEM;
93 }
94
95 __dm_bless_for_disk(&key_le);
96
97 array_insert(node->keys, sizeof(*node->keys), nr_entries, index, &key_le);
98 array_insert(value_base(node), value_size, nr_entries, index, value);
99 node->header.nr_entries = cpu_to_le32(nr_entries + 1);
100
101 return 0;
102}
103
104/*----------------------------------------------------------------*/
105
106/*
107 * We want 3n entries (for some n). This works more nicely for repeated
108 * insert remove loops than (2n + 1).
109 */
110static uint32_t calc_max_entries(size_t value_size, size_t block_size)
111{
112 uint32_t total, n;
113 size_t elt_size = sizeof(uint64_t) + value_size; /* key + value */
114
115 block_size -= sizeof(struct node_header);
116 total = block_size / elt_size;
117 n = total / 3; /* rounds down */
118
119 return 3 * n;
120}
121
122int dm_btree_empty(struct dm_btree_info *info, dm_block_t *root)
123{
124 int r;
125 struct dm_block *b;
126 struct node *n;
127 size_t block_size;
128 uint32_t max_entries;
129
130 r = new_block(info, &b);
131 if (r < 0)
132 return r;
133
134 block_size = dm_bm_block_size(dm_tm_get_bm(info->tm));
135 max_entries = calc_max_entries(info->value_type.size, block_size);
136
137 n = dm_block_data(b);
138 memset(n, 0, block_size);
139 n->header.flags = cpu_to_le32(LEAF_NODE);
140 n->header.nr_entries = cpu_to_le32(0);
141 n->header.max_entries = cpu_to_le32(max_entries);
142 n->header.value_size = cpu_to_le32(info->value_type.size);
143
144 *root = dm_block_location(b);
145 return unlock_block(info, b);
146}
147EXPORT_SYMBOL_GPL(dm_btree_empty);
148
149/*----------------------------------------------------------------*/
150
151/*
152 * Deletion uses a recursive algorithm, since we have limited stack space
153 * we explicitly manage our own stack on the heap.
154 */
155#define MAX_SPINE_DEPTH 64
156struct frame {
157 struct dm_block *b;
158 struct node *n;
159 unsigned level;
160 unsigned nr_children;
161 unsigned current_child;
162};
163
164struct del_stack {
165 struct dm_transaction_manager *tm;
166 int top;
167 struct frame spine[MAX_SPINE_DEPTH];
168};
169
170static int top_frame(struct del_stack *s, struct frame **f)
171{
172 if (s->top < 0) {
173 DMERR("btree deletion stack empty");
174 return -EINVAL;
175 }
176
177 *f = s->spine + s->top;
178
179 return 0;
180}
181
182static int unprocessed_frames(struct del_stack *s)
183{
184 return s->top >= 0;
185}
186
187static int push_frame(struct del_stack *s, dm_block_t b, unsigned level)
188{
189 int r;
190 uint32_t ref_count;
191
192 if (s->top >= MAX_SPINE_DEPTH - 1) {
193 DMERR("btree deletion stack out of memory");
194 return -ENOMEM;
195 }
196
197 r = dm_tm_ref(s->tm, b, &ref_count);
198 if (r)
199 return r;
200
201 if (ref_count > 1)
202 /*
203 * This is a shared node, so we can just decrement it's
204 * reference counter and leave the children.
205 */
206 dm_tm_dec(s->tm, b);
207
208 else {
209 struct frame *f = s->spine + ++s->top;
210
211 r = dm_tm_read_lock(s->tm, b, &btree_node_validator, &f->b);
212 if (r) {
213 s->top--;
214 return r;
215 }
216
217 f->n = dm_block_data(f->b);
218 f->level = level;
219 f->nr_children = le32_to_cpu(f->n->header.nr_entries);
220 f->current_child = 0;
221 }
222
223 return 0;
224}
225
226static void pop_frame(struct del_stack *s)
227{
228 struct frame *f = s->spine + s->top--;
229
230 dm_tm_dec(s->tm, dm_block_location(f->b));
231 dm_tm_unlock(s->tm, f->b);
232}
233
234int dm_btree_del(struct dm_btree_info *info, dm_block_t root)
235{
236 int r;
237 struct del_stack *s;
238
239 s = kmalloc(sizeof(*s), GFP_KERNEL);
240 if (!s)
241 return -ENOMEM;
242 s->tm = info->tm;
243 s->top = -1;
244
245 r = push_frame(s, root, 1);
246 if (r)
247 goto out;
248
249 while (unprocessed_frames(s)) {
250 uint32_t flags;
251 struct frame *f;
252 dm_block_t b;
253
254 r = top_frame(s, &f);
255 if (r)
256 goto out;
257
258 if (f->current_child >= f->nr_children) {
259 pop_frame(s);
260 continue;
261 }
262
263 flags = le32_to_cpu(f->n->header.flags);
264 if (flags & INTERNAL_NODE) {
265 b = value64(f->n, f->current_child);
266 f->current_child++;
267 r = push_frame(s, b, f->level);
268 if (r)
269 goto out;
270
271 } else if (f->level != (info->levels - 1)) {
272 b = value64(f->n, f->current_child);
273 f->current_child++;
274 r = push_frame(s, b, f->level + 1);
275 if (r)
276 goto out;
277
278 } else {
279 if (info->value_type.dec) {
280 unsigned i;
281
282 for (i = 0; i < f->nr_children; i++)
283 info->value_type.dec(info->value_type.context,
284 value_ptr(f->n, i, info->value_type.size));
285 }
286 f->current_child = f->nr_children;
287 }
288 }
289
290out:
291 kfree(s);
292 return r;
293}
294EXPORT_SYMBOL_GPL(dm_btree_del);
295
296/*----------------------------------------------------------------*/
297
298static int btree_lookup_raw(struct ro_spine *s, dm_block_t block, uint64_t key,
299 int (*search_fn)(struct node *, uint64_t),
300 uint64_t *result_key, void *v, size_t value_size)
301{
302 int i, r;
303 uint32_t flags, nr_entries;
304
305 do {
306 r = ro_step(s, block);
307 if (r < 0)
308 return r;
309
310 i = search_fn(ro_node(s), key);
311
312 flags = le32_to_cpu(ro_node(s)->header.flags);
313 nr_entries = le32_to_cpu(ro_node(s)->header.nr_entries);
314 if (i < 0 || i >= nr_entries)
315 return -ENODATA;
316
317 if (flags & INTERNAL_NODE)
318 block = value64(ro_node(s), i);
319
320 } while (!(flags & LEAF_NODE));
321
322 *result_key = le64_to_cpu(ro_node(s)->keys[i]);
323 memcpy(v, value_ptr(ro_node(s), i, value_size), value_size);
324
325 return 0;
326}
327
328int dm_btree_lookup(struct dm_btree_info *info, dm_block_t root,
329 uint64_t *keys, void *value_le)
330{
331 unsigned level, last_level = info->levels - 1;
332 int r = -ENODATA;
333 uint64_t rkey;
334 __le64 internal_value_le;
335 struct ro_spine spine;
336
337 init_ro_spine(&spine, info);
338 for (level = 0; level < info->levels; level++) {
339 size_t size;
340 void *value_p;
341
342 if (level == last_level) {
343 value_p = value_le;
344 size = info->value_type.size;
345
346 } else {
347 value_p = &internal_value_le;
348 size = sizeof(uint64_t);
349 }
350
351 r = btree_lookup_raw(&spine, root, keys[level],
352 lower_bound, &rkey,
353 value_p, size);
354
355 if (!r) {
356 if (rkey != keys[level]) {
357 exit_ro_spine(&spine);
358 return -ENODATA;
359 }
360 } else {
361 exit_ro_spine(&spine);
362 return r;
363 }
364
365 root = le64_to_cpu(internal_value_le);
366 }
367 exit_ro_spine(&spine);
368
369 return r;
370}
371EXPORT_SYMBOL_GPL(dm_btree_lookup);
372
373/*
374 * Splits a node by creating a sibling node and shifting half the nodes
375 * contents across. Assumes there is a parent node, and it has room for
376 * another child.
377 *
378 * Before:
379 * +--------+
380 * | Parent |
381 * +--------+
382 * |
383 * v
384 * +----------+
385 * | A ++++++ |
386 * +----------+
387 *
388 *
389 * After:
390 * +--------+
391 * | Parent |
392 * +--------+
393 * | |
394 * v +------+
395 * +---------+ |
396 * | A* +++ | v
397 * +---------+ +-------+
398 * | B +++ |
399 * +-------+
400 *
401 * Where A* is a shadow of A.
402 */
403static int btree_split_sibling(struct shadow_spine *s, dm_block_t root,
404 unsigned parent_index, uint64_t key)
405{
406 int r;
407 size_t size;
408 unsigned nr_left, nr_right;
409 struct dm_block *left, *right, *parent;
410 struct node *ln, *rn, *pn;
411 __le64 location;
412
413 left = shadow_current(s);
414
415 r = new_block(s->info, &right);
416 if (r < 0)
417 return r;
418
419 ln = dm_block_data(left);
420 rn = dm_block_data(right);
421
422 nr_left = le32_to_cpu(ln->header.nr_entries) / 2;
423 nr_right = le32_to_cpu(ln->header.nr_entries) - nr_left;
424
425 ln->header.nr_entries = cpu_to_le32(nr_left);
426
427 rn->header.flags = ln->header.flags;
428 rn->header.nr_entries = cpu_to_le32(nr_right);
429 rn->header.max_entries = ln->header.max_entries;
430 rn->header.value_size = ln->header.value_size;
431 memcpy(rn->keys, ln->keys + nr_left, nr_right * sizeof(rn->keys[0]));
432
433 size = le32_to_cpu(ln->header.flags) & INTERNAL_NODE ?
434 sizeof(uint64_t) : s->info->value_type.size;
435 memcpy(value_ptr(rn, 0, size), value_ptr(ln, nr_left, size),
436 size * nr_right);
437
438 /*
439 * Patch up the parent
440 */
441 parent = shadow_parent(s);
442
443 pn = dm_block_data(parent);
444 location = cpu_to_le64(dm_block_location(left));
445 __dm_bless_for_disk(&location);
446 memcpy_disk(value_ptr(pn, parent_index, sizeof(__le64)),
447 &location, sizeof(__le64));
448
449 location = cpu_to_le64(dm_block_location(right));
450 __dm_bless_for_disk(&location);
451
452 r = insert_at(sizeof(__le64), pn, parent_index + 1,
453 le64_to_cpu(rn->keys[0]), &location);
454 if (r)
455 return r;
456
457 if (key < le64_to_cpu(rn->keys[0])) {
458 unlock_block(s->info, right);
459 s->nodes[1] = left;
460 } else {
461 unlock_block(s->info, left);
462 s->nodes[1] = right;
463 }
464
465 return 0;
466}
467
468/*
469 * Splits a node by creating two new children beneath the given node.
470 *
471 * Before:
472 * +----------+
473 * | A ++++++ |
474 * +----------+
475 *
476 *
477 * After:
478 * +------------+
479 * | A (shadow) |
480 * +------------+
481 * | |
482 * +------+ +----+
483 * | |
484 * v v
485 * +-------+ +-------+
486 * | B +++ | | C +++ |
487 * +-------+ +-------+
488 */
489static int btree_split_beneath(struct shadow_spine *s, uint64_t key)
490{
491 int r;
492 size_t size;
493 unsigned nr_left, nr_right;
494 struct dm_block *left, *right, *new_parent;
495 struct node *pn, *ln, *rn;
496 __le64 val;
497
498 new_parent = shadow_current(s);
499
500 r = new_block(s->info, &left);
501 if (r < 0)
502 return r;
503
504 r = new_block(s->info, &right);
505 if (r < 0) {
506 /* FIXME: put left */
507 return r;
508 }
509
510 pn = dm_block_data(new_parent);
511 ln = dm_block_data(left);
512 rn = dm_block_data(right);
513
514 nr_left = le32_to_cpu(pn->header.nr_entries) / 2;
515 nr_right = le32_to_cpu(pn->header.nr_entries) - nr_left;
516
517 ln->header.flags = pn->header.flags;
518 ln->header.nr_entries = cpu_to_le32(nr_left);
519 ln->header.max_entries = pn->header.max_entries;
520 ln->header.value_size = pn->header.value_size;
521
522 rn->header.flags = pn->header.flags;
523 rn->header.nr_entries = cpu_to_le32(nr_right);
524 rn->header.max_entries = pn->header.max_entries;
525 rn->header.value_size = pn->header.value_size;
526
527 memcpy(ln->keys, pn->keys, nr_left * sizeof(pn->keys[0]));
528 memcpy(rn->keys, pn->keys + nr_left, nr_right * sizeof(pn->keys[0]));
529
530 size = le32_to_cpu(pn->header.flags) & INTERNAL_NODE ?
531 sizeof(__le64) : s->info->value_type.size;
532 memcpy(value_ptr(ln, 0, size), value_ptr(pn, 0, size), nr_left * size);
533 memcpy(value_ptr(rn, 0, size), value_ptr(pn, nr_left, size),
534 nr_right * size);
535
536 /* new_parent should just point to l and r now */
537 pn->header.flags = cpu_to_le32(INTERNAL_NODE);
538 pn->header.nr_entries = cpu_to_le32(2);
539 pn->header.max_entries = cpu_to_le32(
540 calc_max_entries(sizeof(__le64),
541 dm_bm_block_size(
542 dm_tm_get_bm(s->info->tm))));
543 pn->header.value_size = cpu_to_le32(sizeof(__le64));
544
545 val = cpu_to_le64(dm_block_location(left));
546 __dm_bless_for_disk(&val);
547 pn->keys[0] = ln->keys[0];
548 memcpy_disk(value_ptr(pn, 0, sizeof(__le64)), &val, sizeof(__le64));
549
550 val = cpu_to_le64(dm_block_location(right));
551 __dm_bless_for_disk(&val);
552 pn->keys[1] = rn->keys[0];
553 memcpy_disk(value_ptr(pn, 1, sizeof(__le64)), &val, sizeof(__le64));
554
555 /*
556 * rejig the spine. This is ugly, since it knows too
557 * much about the spine
558 */
559 if (s->nodes[0] != new_parent) {
560 unlock_block(s->info, s->nodes[0]);
561 s->nodes[0] = new_parent;
562 }
563 if (key < le64_to_cpu(rn->keys[0])) {
564 unlock_block(s->info, right);
565 s->nodes[1] = left;
566 } else {
567 unlock_block(s->info, left);
568 s->nodes[1] = right;
569 }
570 s->count = 2;
571
572 return 0;
573}
574
575static int btree_insert_raw(struct shadow_spine *s, dm_block_t root,
576 struct dm_btree_value_type *vt,
577 uint64_t key, unsigned *index)
578{
579 int r, i = *index, top = 1;
580 struct node *node;
581
582 for (;;) {
583 r = shadow_step(s, root, vt);
584 if (r < 0)
585 return r;
586
587 node = dm_block_data(shadow_current(s));
588
589 /*
590 * We have to patch up the parent node, ugly, but I don't
591 * see a way to do this automatically as part of the spine
592 * op.
593 */
594 if (shadow_has_parent(s) && i >= 0) { /* FIXME: second clause unness. */
595 __le64 location = cpu_to_le64(dm_block_location(shadow_current(s)));
596
597 __dm_bless_for_disk(&location);
598 memcpy_disk(value_ptr(dm_block_data(shadow_parent(s)), i, sizeof(uint64_t)),
599 &location, sizeof(__le64));
600 }
601
602 node = dm_block_data(shadow_current(s));
603
604 if (node->header.nr_entries == node->header.max_entries) {
605 if (top)
606 r = btree_split_beneath(s, key);
607 else
608 r = btree_split_sibling(s, root, i, key);
609
610 if (r < 0)
611 return r;
612 }
613
614 node = dm_block_data(shadow_current(s));
615
616 i = lower_bound(node, key);
617
618 if (le32_to_cpu(node->header.flags) & LEAF_NODE)
619 break;
620
621 if (i < 0) {
622 /* change the bounds on the lowest key */
623 node->keys[0] = cpu_to_le64(key);
624 i = 0;
625 }
626
627 root = value64(node, i);
628 top = 0;
629 }
630
631 if (i < 0 || le64_to_cpu(node->keys[i]) != key)
632 i++;
633
634 *index = i;
635 return 0;
636}
637
638static int insert(struct dm_btree_info *info, dm_block_t root,
639 uint64_t *keys, void *value, dm_block_t *new_root,
640 int *inserted)
641 __dm_written_to_disk(value)
642{
643 int r, need_insert;
644 unsigned level, index = -1, last_level = info->levels - 1;
645 dm_block_t block = root;
646 struct shadow_spine spine;
647 struct node *n;
648 struct dm_btree_value_type le64_type;
649
650 le64_type.context = NULL;
651 le64_type.size = sizeof(__le64);
652 le64_type.inc = NULL;
653 le64_type.dec = NULL;
654 le64_type.equal = NULL;
655
656 init_shadow_spine(&spine, info);
657
658 for (level = 0; level < (info->levels - 1); level++) {
659 r = btree_insert_raw(&spine, block, &le64_type, keys[level], &index);
660 if (r < 0)
661 goto bad;
662
663 n = dm_block_data(shadow_current(&spine));
664 need_insert = ((index >= le32_to_cpu(n->header.nr_entries)) ||
665 (le64_to_cpu(n->keys[index]) != keys[level]));
666
667 if (need_insert) {
668 dm_block_t new_tree;
669 __le64 new_le;
670
671 r = dm_btree_empty(info, &new_tree);
672 if (r < 0)
673 goto bad;
674
675 new_le = cpu_to_le64(new_tree);
676 __dm_bless_for_disk(&new_le);
677
678 r = insert_at(sizeof(uint64_t), n, index,
679 keys[level], &new_le);
680 if (r)
681 goto bad;
682 }
683
684 if (level < last_level)
685 block = value64(n, index);
686 }
687
688 r = btree_insert_raw(&spine, block, &info->value_type,
689 keys[level], &index);
690 if (r < 0)
691 goto bad;
692
693 n = dm_block_data(shadow_current(&spine));
694 need_insert = ((index >= le32_to_cpu(n->header.nr_entries)) ||
695 (le64_to_cpu(n->keys[index]) != keys[level]));
696
697 if (need_insert) {
698 if (inserted)
699 *inserted = 1;
700
701 r = insert_at(info->value_type.size, n, index,
702 keys[level], value);
703 if (r)
704 goto bad_unblessed;
705 } else {
706 if (inserted)
707 *inserted = 0;
708
709 if (info->value_type.dec &&
710 (!info->value_type.equal ||
711 !info->value_type.equal(
712 info->value_type.context,
713 value_ptr(n, index, info->value_type.size),
714 value))) {
715 info->value_type.dec(info->value_type.context,
716 value_ptr(n, index, info->value_type.size));
717 }
718 memcpy_disk(value_ptr(n, index, info->value_type.size),
719 value, info->value_type.size);
720 }
721
722 *new_root = shadow_root(&spine);
723 exit_shadow_spine(&spine);
724
725 return 0;
726
727bad:
728 __dm_unbless_for_disk(value);
729bad_unblessed:
730 exit_shadow_spine(&spine);
731 return r;
732}
733
734int dm_btree_insert(struct dm_btree_info *info, dm_block_t root,
735 uint64_t *keys, void *value, dm_block_t *new_root)
736 __dm_written_to_disk(value)
737{
738 return insert(info, root, keys, value, new_root, NULL);
739}
740EXPORT_SYMBOL_GPL(dm_btree_insert);
741
742int dm_btree_insert_notify(struct dm_btree_info *info, dm_block_t root,
743 uint64_t *keys, void *value, dm_block_t *new_root,
744 int *inserted)
745 __dm_written_to_disk(value)
746{
747 return insert(info, root, keys, value, new_root, inserted);
748}
749EXPORT_SYMBOL_GPL(dm_btree_insert_notify);
750
751/*----------------------------------------------------------------*/
752
753static int find_highest_key(struct ro_spine *s, dm_block_t block,
754 uint64_t *result_key, dm_block_t *next_block)
755{
756 int i, r;
757 uint32_t flags;
758
759 do {
760 r = ro_step(s, block);
761 if (r < 0)
762 return r;
763
764 flags = le32_to_cpu(ro_node(s)->header.flags);
765 i = le32_to_cpu(ro_node(s)->header.nr_entries);
766 if (!i)
767 return -ENODATA;
768 else
769 i--;
770
771 *result_key = le64_to_cpu(ro_node(s)->keys[i]);
772 if (next_block || flags & INTERNAL_NODE)
773 block = value64(ro_node(s), i);
774
775 } while (flags & INTERNAL_NODE);
776
777 if (next_block)
778 *next_block = block;
779 return 0;
780}
781
782int dm_btree_find_highest_key(struct dm_btree_info *info, dm_block_t root,
783 uint64_t *result_keys)
784{
785 int r = 0, count = 0, level;
786 struct ro_spine spine;
787
788 init_ro_spine(&spine, info);
789 for (level = 0; level < info->levels; level++) {
790 r = find_highest_key(&spine, root, result_keys + level,
791 level == info->levels - 1 ? NULL : &root);
792 if (r == -ENODATA) {
793 r = 0;
794 break;
795
796 } else if (r)
797 break;
798
799 count++;
800 }
801 exit_ro_spine(&spine);
802
803 return r ? r : count;
804}
805EXPORT_SYMBOL_GPL(dm_btree_find_highest_key);
diff --git a/drivers/md/persistent-data/dm-btree.h b/drivers/md/persistent-data/dm-btree.h
new file mode 100644
index 000000000000..ae02c84410ff
--- /dev/null
+++ b/drivers/md/persistent-data/dm-btree.h
@@ -0,0 +1,145 @@
1/*
2 * Copyright (C) 2011 Red Hat, Inc.
3 *
4 * This file is released under the GPL.
5 */
6#ifndef _LINUX_DM_BTREE_H
7#define _LINUX_DM_BTREE_H
8
9#include "dm-block-manager.h"
10
11struct dm_transaction_manager;
12
13/*----------------------------------------------------------------*/
14
15/*
16 * Annotations used to check on-disk metadata is handled as little-endian.
17 */
18#ifdef __CHECKER__
19# define __dm_written_to_disk(x) __releases(x)
20# define __dm_reads_from_disk(x) __acquires(x)
21# define __dm_bless_for_disk(x) __acquire(x)
22# define __dm_unbless_for_disk(x) __release(x)
23#else
24# define __dm_written_to_disk(x)
25# define __dm_reads_from_disk(x)
26# define __dm_bless_for_disk(x)
27# define __dm_unbless_for_disk(x)
28#endif
29
30/*----------------------------------------------------------------*/
31
32/*
33 * Manipulates hierarchical B+ trees with 64-bit keys and arbitrary-sized
34 * values.
35 */
36
37/*
38 * Infomation about the values stored within the btree.
39 */
40struct dm_btree_value_type {
41 void *context;
42
43 /*
44 * The size in bytes of each value.
45 */
46 uint32_t size;
47
48 /*
49 * Any of these methods can be safely set to NULL if you do not
50 * need the corresponding feature.
51 */
52
53 /*
54 * The btree is making a duplicate of the value, for instance
55 * because previously-shared btree nodes have now diverged.
56 * @value argument is the new copy that the copy function may modify.
57 * (Probably it just wants to increment a reference count
58 * somewhere.) This method is _not_ called for insertion of a new
59 * value: It is assumed the ref count is already 1.
60 */
61 void (*inc)(void *context, void *value);
62
63 /*
64 * This value is being deleted. The btree takes care of freeing
65 * the memory pointed to by @value. Often the del function just
66 * needs to decrement a reference count somewhere.
67 */
68 void (*dec)(void *context, void *value);
69
70 /*
71 * A test for equality between two values. When a value is
72 * overwritten with a new one, the old one has the dec method
73 * called _unless_ the new and old value are deemed equal.
74 */
75 int (*equal)(void *context, void *value1, void *value2);
76};
77
78/*
79 * The shape and contents of a btree.
80 */
81struct dm_btree_info {
82 struct dm_transaction_manager *tm;
83
84 /*
85 * Number of nested btrees. (Not the depth of a single tree.)
86 */
87 unsigned levels;
88 struct dm_btree_value_type value_type;
89};
90
91/*
92 * Set up an empty tree. O(1).
93 */
94int dm_btree_empty(struct dm_btree_info *info, dm_block_t *root);
95
96/*
97 * Delete a tree. O(n) - this is the slow one! It can also block, so
98 * please don't call it on an IO path.
99 */
100int dm_btree_del(struct dm_btree_info *info, dm_block_t root);
101
102/*
103 * All the lookup functions return -ENODATA if the key cannot be found.
104 */
105
106/*
107 * Tries to find a key that matches exactly. O(ln(n))
108 */
109int dm_btree_lookup(struct dm_btree_info *info, dm_block_t root,
110 uint64_t *keys, void *value_le);
111
112/*
113 * Insertion (or overwrite an existing value). O(ln(n))
114 */
115int dm_btree_insert(struct dm_btree_info *info, dm_block_t root,
116 uint64_t *keys, void *value, dm_block_t *new_root)
117 __dm_written_to_disk(value);
118
119/*
120 * A variant of insert that indicates whether it actually inserted or just
121 * overwrote. Useful if you're keeping track of the number of entries in a
122 * tree.
123 */
124int dm_btree_insert_notify(struct dm_btree_info *info, dm_block_t root,
125 uint64_t *keys, void *value, dm_block_t *new_root,
126 int *inserted)
127 __dm_written_to_disk(value);
128
129/*
130 * Remove a key if present. This doesn't remove empty sub trees. Normally
131 * subtrees represent a separate entity, like a snapshot map, so this is
132 * correct behaviour. O(ln(n)).
133 */
134int dm_btree_remove(struct dm_btree_info *info, dm_block_t root,
135 uint64_t *keys, dm_block_t *new_root);
136
137/*
138 * Returns < 0 on failure. Otherwise the number of key entries that have
139 * been filled out. Remember trees can have zero entries, and as such have
140 * no highest key.
141 */
142int dm_btree_find_highest_key(struct dm_btree_info *info, dm_block_t root,
143 uint64_t *result_keys);
144
145#endif /* _LINUX_DM_BTREE_H */
diff --git a/drivers/md/persistent-data/dm-persistent-data-internal.h b/drivers/md/persistent-data/dm-persistent-data-internal.h
new file mode 100644
index 000000000000..c49e26fff36c
--- /dev/null
+++ b/drivers/md/persistent-data/dm-persistent-data-internal.h
@@ -0,0 +1,19 @@
1/*
2 * Copyright (C) 2011 Red Hat, Inc.
3 *
4 * This file is released under the GPL.
5 */
6
7#ifndef _DM_PERSISTENT_DATA_INTERNAL_H
8#define _DM_PERSISTENT_DATA_INTERNAL_H
9
10#include "dm-block-manager.h"
11
12static inline unsigned dm_hash_block(dm_block_t b, unsigned hash_mask)
13{
14 const unsigned BIG_PRIME = 4294967291UL;
15
16 return (((unsigned) b) * BIG_PRIME) & hash_mask;
17}
18
19#endif /* _PERSISTENT_DATA_INTERNAL_H */
diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
new file mode 100644
index 000000000000..bb44a937fe63
--- /dev/null
+++ b/drivers/md/persistent-data/dm-space-map-checker.c
@@ -0,0 +1,437 @@
1/*
2 * Copyright (C) 2011 Red Hat, Inc.
3 *
4 * This file is released under the GPL.
5 */
6
7#include "dm-space-map-checker.h"
8
9#include <linux/device-mapper.h>
10
11#ifdef CONFIG_DM_DEBUG_SPACE_MAPS
12
13#define DM_MSG_PREFIX "space map checker"
14
15/*----------------------------------------------------------------*/
16
17struct count_array {
18 dm_block_t nr;
19 dm_block_t nr_free;
20
21 uint32_t *counts;
22};
23
24static int ca_get_count(struct count_array *ca, dm_block_t b, uint32_t *count)
25{
26 if (b >= ca->nr)
27 return -EINVAL;
28
29 *count = ca->counts[b];
30 return 0;
31}
32
33static int ca_count_more_than_one(struct count_array *ca, dm_block_t b, int *r)
34{
35 if (b >= ca->nr)
36 return -EINVAL;
37
38 *r = ca->counts[b] > 1;
39 return 0;
40}
41
42static int ca_set_count(struct count_array *ca, dm_block_t b, uint32_t count)
43{
44 uint32_t old_count;
45
46 if (b >= ca->nr)
47 return -EINVAL;
48
49 old_count = ca->counts[b];
50
51 if (!count && old_count)
52 ca->nr_free++;
53
54 else if (count && !old_count)
55 ca->nr_free--;
56
57 ca->counts[b] = count;
58 return 0;
59}
60
61static int ca_inc_block(struct count_array *ca, dm_block_t b)
62{
63 if (b >= ca->nr)
64 return -EINVAL;
65
66 ca_set_count(ca, b, ca->counts[b] + 1);
67 return 0;
68}
69
70static int ca_dec_block(struct count_array *ca, dm_block_t b)
71{
72 if (b >= ca->nr)
73 return -EINVAL;
74
75 BUG_ON(ca->counts[b] == 0);
76 ca_set_count(ca, b, ca->counts[b] - 1);
77 return 0;
78}
79
80static int ca_create(struct count_array *ca, struct dm_space_map *sm)
81{
82 int r;
83 dm_block_t nr_blocks;
84
85 r = dm_sm_get_nr_blocks(sm, &nr_blocks);
86 if (r)
87 return r;
88
89 ca->nr = nr_blocks;
90 ca->nr_free = nr_blocks;
91 ca->counts = kzalloc(sizeof(*ca->counts) * nr_blocks, GFP_KERNEL);
92 if (!ca->counts)
93 return -ENOMEM;
94
95 return 0;
96}
97
98static int ca_load(struct count_array *ca, struct dm_space_map *sm)
99{
100 int r;
101 uint32_t count;
102 dm_block_t nr_blocks, i;
103
104 r = dm_sm_get_nr_blocks(sm, &nr_blocks);
105 if (r)
106 return r;
107
108 BUG_ON(ca->nr != nr_blocks);
109
110 DMWARN("Loading debug space map from disk. This may take some time");
111 for (i = 0; i < nr_blocks; i++) {
112 r = dm_sm_get_count(sm, i, &count);
113 if (r) {
114 DMERR("load failed");
115 return r;
116 }
117
118 ca_set_count(ca, i, count);
119 }
120 DMWARN("Load complete");
121
122 return 0;
123}
124
125static int ca_extend(struct count_array *ca, dm_block_t extra_blocks)
126{
127 dm_block_t nr_blocks = ca->nr + extra_blocks;
128 uint32_t *counts = kzalloc(sizeof(*counts) * nr_blocks, GFP_KERNEL);
129 if (!counts)
130 return -ENOMEM;
131
132 memcpy(counts, ca->counts, sizeof(*counts) * ca->nr);
133 kfree(ca->counts);
134 ca->nr = nr_blocks;
135 ca->nr_free += extra_blocks;
136 ca->counts = counts;
137 return 0;
138}
139
140static int ca_commit(struct count_array *old, struct count_array *new)
141{
142 if (old->nr != new->nr) {
143 BUG_ON(old->nr > new->nr);
144 ca_extend(old, new->nr - old->nr);
145 }
146
147 BUG_ON(old->nr != new->nr);
148 old->nr_free = new->nr_free;
149 memcpy(old->counts, new->counts, sizeof(*old->counts) * old->nr);
150 return 0;
151}
152
153static void ca_destroy(struct count_array *ca)
154{
155 kfree(ca->counts);
156}
157
158/*----------------------------------------------------------------*/
159
160struct sm_checker {
161 struct dm_space_map sm;
162
163 struct count_array old_counts;
164 struct count_array counts;
165
166 struct dm_space_map *real_sm;
167};
168
169static void sm_checker_destroy(struct dm_space_map *sm)
170{
171 struct sm_checker *smc = container_of(sm, struct sm_checker, sm);
172
173 dm_sm_destroy(smc->real_sm);
174 ca_destroy(&smc->old_counts);
175 ca_destroy(&smc->counts);
176 kfree(smc);
177}
178
179static int sm_checker_get_nr_blocks(struct dm_space_map *sm, dm_block_t *count)
180{
181 struct sm_checker *smc = container_of(sm, struct sm_checker, sm);
182 int r = dm_sm_get_nr_blocks(smc->real_sm, count);
183 if (!r)
184 BUG_ON(smc->old_counts.nr != *count);
185 return r;
186}
187
188static int sm_checker_get_nr_free(struct dm_space_map *sm, dm_block_t *count)
189{
190 struct sm_checker *smc = container_of(sm, struct sm_checker, sm);
191 int r = dm_sm_get_nr_free(smc->real_sm, count);
192 if (!r) {
193 /*
194 * Slow, but we know it's correct.
195 */
196 dm_block_t b, n = 0;
197 for (b = 0; b < smc->old_counts.nr; b++)
198 if (smc->old_counts.counts[b] == 0 &&
199 smc->counts.counts[b] == 0)
200 n++;
201
202 if (n != *count)
203 DMERR("free block counts differ, checker %u, sm-disk:%u",
204 (unsigned) n, (unsigned) *count);
205 }
206 return r;
207}
208
209static int sm_checker_new_block(struct dm_space_map *sm, dm_block_t *b)
210{
211 struct sm_checker *smc = container_of(sm, struct sm_checker, sm);
212 int r = dm_sm_new_block(smc->real_sm, b);
213
214 if (!r) {
215 BUG_ON(*b >= smc->old_counts.nr);
216 BUG_ON(smc->old_counts.counts[*b] != 0);
217 BUG_ON(*b >= smc->counts.nr);
218 BUG_ON(smc->counts.counts[*b] != 0);
219 ca_set_count(&smc->counts, *b, 1);
220 }
221
222 return r;
223}
224
225static int sm_checker_inc_block(struct dm_space_map *sm, dm_block_t b)
226{
227 struct sm_checker *smc = container_of(sm, struct sm_checker, sm);
228 int r = dm_sm_inc_block(smc->real_sm, b);
229 int r2 = ca_inc_block(&smc->counts, b);
230 BUG_ON(r != r2);
231 return r;
232}
233
234static int sm_checker_dec_block(struct dm_space_map *sm, dm_block_t b)
235{
236 struct sm_checker *smc = container_of(sm, struct sm_checker, sm);
237 int r = dm_sm_dec_block(smc->real_sm, b);
238 int r2 = ca_dec_block(&smc->counts, b);
239 BUG_ON(r != r2);
240 return r;
241}
242
243static int sm_checker_get_count(struct dm_space_map *sm, dm_block_t b, uint32_t *result)
244{
245 struct sm_checker *smc = container_of(sm, struct sm_checker, sm);
246 uint32_t result2 = 0;
247 int r = dm_sm_get_count(smc->real_sm, b, result);
248 int r2 = ca_get_count(&smc->counts, b, &result2);
249
250 BUG_ON(r != r2);
251 if (!r)
252 BUG_ON(*result != result2);
253 return r;
254}
255
256static int sm_checker_count_more_than_one(struct dm_space_map *sm, dm_block_t b, int *result)
257{
258 struct sm_checker *smc = container_of(sm, struct sm_checker, sm);
259 int result2 = 0;
260 int r = dm_sm_count_is_more_than_one(smc->real_sm, b, result);
261 int r2 = ca_count_more_than_one(&smc->counts, b, &result2);
262
263 BUG_ON(r != r2);
264 if (!r)
265 BUG_ON(!(*result) && result2);
266 return r;
267}
268
269static int sm_checker_set_count(struct dm_space_map *sm, dm_block_t b, uint32_t count)
270{
271 struct sm_checker *smc = container_of(sm, struct sm_checker, sm);
272 uint32_t old_rc;
273 int r = dm_sm_set_count(smc->real_sm, b, count);
274 int r2;
275
276 BUG_ON(b >= smc->counts.nr);
277 old_rc = smc->counts.counts[b];
278 r2 = ca_set_count(&smc->counts, b, count);
279 BUG_ON(r != r2);
280
281 return r;
282}
283
284static int sm_checker_commit(struct dm_space_map *sm)
285{
286 struct sm_checker *smc = container_of(sm, struct sm_checker, sm);
287 int r;
288
289 r = dm_sm_commit(smc->real_sm);
290 if (r)
291 return r;
292
293 r = ca_commit(&smc->old_counts, &smc->counts);
294 if (r)
295 return r;
296
297 return 0;
298}
299
300static int sm_checker_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
301{
302 struct sm_checker *smc = container_of(sm, struct sm_checker, sm);
303 int r = dm_sm_extend(smc->real_sm, extra_blocks);
304 if (r)
305 return r;
306
307 return ca_extend(&smc->counts, extra_blocks);
308}
309
310static int sm_checker_root_size(struct dm_space_map *sm, size_t *result)
311{
312 struct sm_checker *smc = container_of(sm, struct sm_checker, sm);
313 return dm_sm_root_size(smc->real_sm, result);
314}
315
316static int sm_checker_copy_root(struct dm_space_map *sm, void *copy_to_here_le, size_t len)
317{
318 struct sm_checker *smc = container_of(sm, struct sm_checker, sm);
319 return dm_sm_copy_root(smc->real_sm, copy_to_here_le, len);
320}
321
322/*----------------------------------------------------------------*/
323
324static struct dm_space_map ops_ = {
325 .destroy = sm_checker_destroy,
326 .get_nr_blocks = sm_checker_get_nr_blocks,
327 .get_nr_free = sm_checker_get_nr_free,
328 .inc_block = sm_checker_inc_block,
329 .dec_block = sm_checker_dec_block,
330 .new_block = sm_checker_new_block,
331 .get_count = sm_checker_get_count,
332 .count_is_more_than_one = sm_checker_count_more_than_one,
333 .set_count = sm_checker_set_count,
334 .commit = sm_checker_commit,
335 .extend = sm_checker_extend,
336 .root_size = sm_checker_root_size,
337 .copy_root = sm_checker_copy_root
338};
339
340struct dm_space_map *dm_sm_checker_create(struct dm_space_map *sm)
341{
342 int r;
343 struct sm_checker *smc;
344
345 if (!sm)
346 return NULL;
347
348 smc = kmalloc(sizeof(*smc), GFP_KERNEL);
349 if (!smc)
350 return NULL;
351
352 memcpy(&smc->sm, &ops_, sizeof(smc->sm));
353 r = ca_create(&smc->old_counts, sm);
354 if (r) {
355 kfree(smc);
356 return NULL;
357 }
358
359 r = ca_create(&smc->counts, sm);
360 if (r) {
361 ca_destroy(&smc->old_counts);
362 kfree(smc);
363 return NULL;
364 }
365
366 smc->real_sm = sm;
367
368 r = ca_load(&smc->counts, sm);
369 if (r) {
370 ca_destroy(&smc->counts);
371 ca_destroy(&smc->old_counts);
372 kfree(smc);
373 return NULL;
374 }
375
376 r = ca_commit(&smc->old_counts, &smc->counts);
377 if (r) {
378 ca_destroy(&smc->counts);
379 ca_destroy(&smc->old_counts);
380 kfree(smc);
381 return NULL;
382 }
383
384 return &smc->sm;
385}
386EXPORT_SYMBOL_GPL(dm_sm_checker_create);
387
388struct dm_space_map *dm_sm_checker_create_fresh(struct dm_space_map *sm)
389{
390 int r;
391 struct sm_checker *smc;
392
393 if (!sm)
394 return NULL;
395
396 smc = kmalloc(sizeof(*smc), GFP_KERNEL);
397 if (!smc)
398 return NULL;
399
400 memcpy(&smc->sm, &ops_, sizeof(smc->sm));
401 r = ca_create(&smc->old_counts, sm);
402 if (r) {
403 kfree(smc);
404 return NULL;
405 }
406
407 r = ca_create(&smc->counts, sm);
408 if (r) {
409 ca_destroy(&smc->old_counts);
410 kfree(smc);
411 return NULL;
412 }
413
414 smc->real_sm = sm;
415 return &smc->sm;
416}
417EXPORT_SYMBOL_GPL(dm_sm_checker_create_fresh);
418
419/*----------------------------------------------------------------*/
420
421#else
422
423struct dm_space_map *dm_sm_checker_create(struct dm_space_map *sm)
424{
425 return sm;
426}
427EXPORT_SYMBOL_GPL(dm_sm_checker_create);
428
429struct dm_space_map *dm_sm_checker_create_fresh(struct dm_space_map *sm)
430{
431 return sm;
432}
433EXPORT_SYMBOL_GPL(dm_sm_checker_create_fresh);
434
435/*----------------------------------------------------------------*/
436
437#endif
diff --git a/drivers/md/persistent-data/dm-space-map-checker.h b/drivers/md/persistent-data/dm-space-map-checker.h
new file mode 100644
index 000000000000..444dccf6688c
--- /dev/null
+++ b/drivers/md/persistent-data/dm-space-map-checker.h
@@ -0,0 +1,26 @@
1/*
2 * Copyright (C) 2011 Red Hat, Inc.
3 *
4 * This file is released under the GPL.
5 */
6
7#ifndef SNAPSHOTS_SPACE_MAP_CHECKER_H
8#define SNAPSHOTS_SPACE_MAP_CHECKER_H
9
10#include "dm-space-map.h"
11
12/*----------------------------------------------------------------*/
13
14/*
15 * This space map wraps a real on-disk space map, and verifies all of its
16 * operations. It uses a lot of memory, so only use if you have a specific
17 * problem that you're debugging.
18 *
19 * Ownership of @sm passes.
20 */
21struct dm_space_map *dm_sm_checker_create(struct dm_space_map *sm);
22struct dm_space_map *dm_sm_checker_create_fresh(struct dm_space_map *sm);
23
24/*----------------------------------------------------------------*/
25
26#endif
diff --git a/drivers/md/persistent-data/dm-space-map-common.c b/drivers/md/persistent-data/dm-space-map-common.c
new file mode 100644
index 000000000000..df2494c06cdc
--- /dev/null
+++ b/drivers/md/persistent-data/dm-space-map-common.c
@@ -0,0 +1,705 @@
1/*
2 * Copyright (C) 2011 Red Hat, Inc.
3 *
4 * This file is released under the GPL.
5 */
6
7#include "dm-space-map-common.h"
8#include "dm-transaction-manager.h"
9
10#include <linux/bitops.h>
11#include <linux/device-mapper.h>
12
13#define DM_MSG_PREFIX "space map common"
14
15/*----------------------------------------------------------------*/
16
17/*
18 * Index validator.
19 */
20#define INDEX_CSUM_XOR 160478
21
22static void index_prepare_for_write(struct dm_block_validator *v,
23 struct dm_block *b,
24 size_t block_size)
25{
26 struct disk_metadata_index *mi_le = dm_block_data(b);
27
28 mi_le->blocknr = cpu_to_le64(dm_block_location(b));
29 mi_le->csum = cpu_to_le32(dm_bm_checksum(&mi_le->padding,
30 block_size - sizeof(__le32),
31 INDEX_CSUM_XOR));
32}
33
34static int index_check(struct dm_block_validator *v,
35 struct dm_block *b,
36 size_t block_size)
37{
38 struct disk_metadata_index *mi_le = dm_block_data(b);
39 __le32 csum_disk;
40
41 if (dm_block_location(b) != le64_to_cpu(mi_le->blocknr)) {
42 DMERR("index_check failed blocknr %llu wanted %llu",
43 le64_to_cpu(mi_le->blocknr), dm_block_location(b));
44 return -ENOTBLK;
45 }
46
47 csum_disk = cpu_to_le32(dm_bm_checksum(&mi_le->padding,
48 block_size - sizeof(__le32),
49 INDEX_CSUM_XOR));
50 if (csum_disk != mi_le->csum) {
51 DMERR("index_check failed csum %u wanted %u",
52 le32_to_cpu(csum_disk), le32_to_cpu(mi_le->csum));
53 return -EILSEQ;
54 }
55
56 return 0;
57}
58
59static struct dm_block_validator index_validator = {
60 .name = "index",
61 .prepare_for_write = index_prepare_for_write,
62 .check = index_check
63};
64
65/*----------------------------------------------------------------*/
66
67/*
68 * Bitmap validator
69 */
70#define BITMAP_CSUM_XOR 240779
71
72static void bitmap_prepare_for_write(struct dm_block_validator *v,
73 struct dm_block *b,
74 size_t block_size)
75{
76 struct disk_bitmap_header *disk_header = dm_block_data(b);
77
78 disk_header->blocknr = cpu_to_le64(dm_block_location(b));
79 disk_header->csum = cpu_to_le32(dm_bm_checksum(&disk_header->not_used,
80 block_size - sizeof(__le32),
81 BITMAP_CSUM_XOR));
82}
83
84static int bitmap_check(struct dm_block_validator *v,
85 struct dm_block *b,
86 size_t block_size)
87{
88 struct disk_bitmap_header *disk_header = dm_block_data(b);
89 __le32 csum_disk;
90
91 if (dm_block_location(b) != le64_to_cpu(disk_header->blocknr)) {
92 DMERR("bitmap check failed blocknr %llu wanted %llu",
93 le64_to_cpu(disk_header->blocknr), dm_block_location(b));
94 return -ENOTBLK;
95 }
96
97 csum_disk = cpu_to_le32(dm_bm_checksum(&disk_header->not_used,
98 block_size - sizeof(__le32),
99 BITMAP_CSUM_XOR));
100 if (csum_disk != disk_header->csum) {
101 DMERR("bitmap check failed csum %u wanted %u",
102 le32_to_cpu(csum_disk), le32_to_cpu(disk_header->csum));
103 return -EILSEQ;
104 }
105
106 return 0;
107}
108
109static struct dm_block_validator dm_sm_bitmap_validator = {
110 .name = "sm_bitmap",
111 .prepare_for_write = bitmap_prepare_for_write,
112 .check = bitmap_check
113};
114
115/*----------------------------------------------------------------*/
116
117#define ENTRIES_PER_WORD 32
118#define ENTRIES_SHIFT 5
119
120static void *dm_bitmap_data(struct dm_block *b)
121{
122 return dm_block_data(b) + sizeof(struct disk_bitmap_header);
123}
124
125#define WORD_MASK_HIGH 0xAAAAAAAAAAAAAAAAULL
126
127static unsigned bitmap_word_used(void *addr, unsigned b)
128{
129 __le64 *words_le = addr;
130 __le64 *w_le = words_le + (b >> ENTRIES_SHIFT);
131
132 uint64_t bits = le64_to_cpu(*w_le);
133 uint64_t mask = (bits + WORD_MASK_HIGH + 1) & WORD_MASK_HIGH;
134
135 return !(~bits & mask);
136}
137
138static unsigned sm_lookup_bitmap(void *addr, unsigned b)
139{
140 __le64 *words_le = addr;
141 __le64 *w_le = words_le + (b >> ENTRIES_SHIFT);
142 unsigned hi, lo;
143
144 b = (b & (ENTRIES_PER_WORD - 1)) << 1;
145 hi = !!test_bit_le(b, (void *) w_le);
146 lo = !!test_bit_le(b + 1, (void *) w_le);
147 return (hi << 1) | lo;
148}
149
150static void sm_set_bitmap(void *addr, unsigned b, unsigned val)
151{
152 __le64 *words_le = addr;
153 __le64 *w_le = words_le + (b >> ENTRIES_SHIFT);
154
155 b = (b & (ENTRIES_PER_WORD - 1)) << 1;
156
157 if (val & 2)
158 __set_bit_le(b, (void *) w_le);
159 else
160 __clear_bit_le(b, (void *) w_le);
161
162 if (val & 1)
163 __set_bit_le(b + 1, (void *) w_le);
164 else
165 __clear_bit_le(b + 1, (void *) w_le);
166}
167
168static int sm_find_free(void *addr, unsigned begin, unsigned end,
169 unsigned *result)
170{
171 while (begin < end) {
172 if (!(begin & (ENTRIES_PER_WORD - 1)) &&
173 bitmap_word_used(addr, begin)) {
174 begin += ENTRIES_PER_WORD;
175 continue;
176 }
177
178 if (!sm_lookup_bitmap(addr, begin)) {
179 *result = begin;
180 return 0;
181 }
182
183 begin++;
184 }
185
186 return -ENOSPC;
187}
188
189/*----------------------------------------------------------------*/
190
191static int sm_ll_init(struct ll_disk *ll, struct dm_transaction_manager *tm)
192{
193 ll->tm = tm;
194
195 ll->bitmap_info.tm = tm;
196 ll->bitmap_info.levels = 1;
197
198 /*
199 * Because the new bitmap blocks are created via a shadow
200 * operation, the old entry has already had its reference count
201 * decremented and we don't need the btree to do any bookkeeping.
202 */
203 ll->bitmap_info.value_type.size = sizeof(struct disk_index_entry);
204 ll->bitmap_info.value_type.inc = NULL;
205 ll->bitmap_info.value_type.dec = NULL;
206 ll->bitmap_info.value_type.equal = NULL;
207
208 ll->ref_count_info.tm = tm;
209 ll->ref_count_info.levels = 1;
210 ll->ref_count_info.value_type.size = sizeof(uint32_t);
211 ll->ref_count_info.value_type.inc = NULL;
212 ll->ref_count_info.value_type.dec = NULL;
213 ll->ref_count_info.value_type.equal = NULL;
214
215 ll->block_size = dm_bm_block_size(dm_tm_get_bm(tm));
216
217 if (ll->block_size > (1 << 30)) {
218 DMERR("block size too big to hold bitmaps");
219 return -EINVAL;
220 }
221
222 ll->entries_per_block = (ll->block_size - sizeof(struct disk_bitmap_header)) *
223 ENTRIES_PER_BYTE;
224 ll->nr_blocks = 0;
225 ll->bitmap_root = 0;
226 ll->ref_count_root = 0;
227
228 return 0;
229}
230
231int sm_ll_extend(struct ll_disk *ll, dm_block_t extra_blocks)
232{
233 int r;
234 dm_block_t i, nr_blocks, nr_indexes;
235 unsigned old_blocks, blocks;
236
237 nr_blocks = ll->nr_blocks + extra_blocks;
238 old_blocks = dm_sector_div_up(ll->nr_blocks, ll->entries_per_block);
239 blocks = dm_sector_div_up(nr_blocks, ll->entries_per_block);
240
241 nr_indexes = dm_sector_div_up(nr_blocks, ll->entries_per_block);
242 if (nr_indexes > ll->max_entries(ll)) {
243 DMERR("space map too large");
244 return -EINVAL;
245 }
246
247 for (i = old_blocks; i < blocks; i++) {
248 struct dm_block *b;
249 struct disk_index_entry idx;
250
251 r = dm_tm_new_block(ll->tm, &dm_sm_bitmap_validator, &b);
252 if (r < 0)
253 return r;
254 idx.blocknr = cpu_to_le64(dm_block_location(b));
255
256 r = dm_tm_unlock(ll->tm, b);
257 if (r < 0)
258 return r;
259
260 idx.nr_free = cpu_to_le32(ll->entries_per_block);
261 idx.none_free_before = 0;
262
263 r = ll->save_ie(ll, i, &idx);
264 if (r < 0)
265 return r;
266 }
267
268 ll->nr_blocks = nr_blocks;
269 return 0;
270}
271
272int sm_ll_lookup_bitmap(struct ll_disk *ll, dm_block_t b, uint32_t *result)
273{
274 int r;
275 dm_block_t index = b;
276 struct disk_index_entry ie_disk;
277 struct dm_block *blk;
278
279 b = do_div(index, ll->entries_per_block);
280 r = ll->load_ie(ll, index, &ie_disk);
281 if (r < 0)
282 return r;
283
284 r = dm_tm_read_lock(ll->tm, le64_to_cpu(ie_disk.blocknr),
285 &dm_sm_bitmap_validator, &blk);
286 if (r < 0)
287 return r;
288
289 *result = sm_lookup_bitmap(dm_bitmap_data(blk), b);
290
291 return dm_tm_unlock(ll->tm, blk);
292}
293
294int sm_ll_lookup(struct ll_disk *ll, dm_block_t b, uint32_t *result)
295{
296 __le32 le_rc;
297 int r = sm_ll_lookup_bitmap(ll, b, result);
298
299 if (r)
300 return r;
301
302 if (*result != 3)
303 return r;
304
305 r = dm_btree_lookup(&ll->ref_count_info, ll->ref_count_root, &b, &le_rc);
306 if (r < 0)
307 return r;
308
309 *result = le32_to_cpu(le_rc);
310
311 return r;
312}
313
314int sm_ll_find_free_block(struct ll_disk *ll, dm_block_t begin,
315 dm_block_t end, dm_block_t *result)
316{
317 int r;
318 struct disk_index_entry ie_disk;
319 dm_block_t i, index_begin = begin;
320 dm_block_t index_end = dm_sector_div_up(end, ll->entries_per_block);
321
322 /*
323 * FIXME: Use shifts
324 */
325 begin = do_div(index_begin, ll->entries_per_block);
326 end = do_div(end, ll->entries_per_block);
327
328 for (i = index_begin; i < index_end; i++, begin = 0) {
329 struct dm_block *blk;
330 unsigned position;
331 uint32_t bit_end;
332
333 r = ll->load_ie(ll, i, &ie_disk);
334 if (r < 0)
335 return r;
336
337 if (le32_to_cpu(ie_disk.nr_free) == 0)
338 continue;
339
340 r = dm_tm_read_lock(ll->tm, le64_to_cpu(ie_disk.blocknr),
341 &dm_sm_bitmap_validator, &blk);
342 if (r < 0)
343 return r;
344
345 bit_end = (i == index_end - 1) ? end : ll->entries_per_block;
346
347 r = sm_find_free(dm_bitmap_data(blk),
348 max_t(unsigned, begin, le32_to_cpu(ie_disk.none_free_before)),
349 bit_end, &position);
350 if (r == -ENOSPC) {
351 /*
352 * This might happen because we started searching
353 * part way through the bitmap.
354 */
355 dm_tm_unlock(ll->tm, blk);
356 continue;
357
358 } else if (r < 0) {
359 dm_tm_unlock(ll->tm, blk);
360 return r;
361 }
362
363 r = dm_tm_unlock(ll->tm, blk);
364 if (r < 0)
365 return r;
366
367 *result = i * ll->entries_per_block + (dm_block_t) position;
368 return 0;
369 }
370
371 return -ENOSPC;
372}
373
374int sm_ll_insert(struct ll_disk *ll, dm_block_t b,
375 uint32_t ref_count, enum allocation_event *ev)
376{
377 int r;
378 uint32_t bit, old;
379 struct dm_block *nb;
380 dm_block_t index = b;
381 struct disk_index_entry ie_disk;
382 void *bm_le;
383 int inc;
384
385 bit = do_div(index, ll->entries_per_block);
386 r = ll->load_ie(ll, index, &ie_disk);
387 if (r < 0)
388 return r;
389
390 r = dm_tm_shadow_block(ll->tm, le64_to_cpu(ie_disk.blocknr),
391 &dm_sm_bitmap_validator, &nb, &inc);
392 if (r < 0) {
393 DMERR("dm_tm_shadow_block() failed");
394 return r;
395 }
396 ie_disk.blocknr = cpu_to_le64(dm_block_location(nb));
397
398 bm_le = dm_bitmap_data(nb);
399 old = sm_lookup_bitmap(bm_le, bit);
400
401 if (ref_count <= 2) {
402 sm_set_bitmap(bm_le, bit, ref_count);
403
404 r = dm_tm_unlock(ll->tm, nb);
405 if (r < 0)
406 return r;
407
408#if 0
409 /* FIXME: dm_btree_remove doesn't handle this yet */
410 if (old > 2) {
411 r = dm_btree_remove(&ll->ref_count_info,
412 ll->ref_count_root,
413 &b, &ll->ref_count_root);
414 if (r)
415 return r;
416 }
417#endif
418
419 } else {
420 __le32 le_rc = cpu_to_le32(ref_count);
421
422 sm_set_bitmap(bm_le, bit, 3);
423 r = dm_tm_unlock(ll->tm, nb);
424 if (r < 0)
425 return r;
426
427 __dm_bless_for_disk(&le_rc);
428 r = dm_btree_insert(&ll->ref_count_info, ll->ref_count_root,
429 &b, &le_rc, &ll->ref_count_root);
430 if (r < 0) {
431 DMERR("ref count insert failed");
432 return r;
433 }
434 }
435
436 if (ref_count && !old) {
437 *ev = SM_ALLOC;
438 ll->nr_allocated++;
439 ie_disk.nr_free = cpu_to_le32(le32_to_cpu(ie_disk.nr_free) - 1);
440 if (le32_to_cpu(ie_disk.none_free_before) == bit)
441 ie_disk.none_free_before = cpu_to_le32(bit + 1);
442
443 } else if (old && !ref_count) {
444 *ev = SM_FREE;
445 ll->nr_allocated--;
446 ie_disk.nr_free = cpu_to_le32(le32_to_cpu(ie_disk.nr_free) + 1);
447 ie_disk.none_free_before = cpu_to_le32(min(le32_to_cpu(ie_disk.none_free_before), bit));
448 }
449
450 return ll->save_ie(ll, index, &ie_disk);
451}
452
453int sm_ll_inc(struct ll_disk *ll, dm_block_t b, enum allocation_event *ev)
454{
455 int r;
456 uint32_t rc;
457
458 r = sm_ll_lookup(ll, b, &rc);
459 if (r)
460 return r;
461
462 return sm_ll_insert(ll, b, rc + 1, ev);
463}
464
465int sm_ll_dec(struct ll_disk *ll, dm_block_t b, enum allocation_event *ev)
466{
467 int r;
468 uint32_t rc;
469
470 r = sm_ll_lookup(ll, b, &rc);
471 if (r)
472 return r;
473
474 if (!rc)
475 return -EINVAL;
476
477 return sm_ll_insert(ll, b, rc - 1, ev);
478}
479
480int sm_ll_commit(struct ll_disk *ll)
481{
482 return ll->commit(ll);
483}
484
485/*----------------------------------------------------------------*/
486
487static int metadata_ll_load_ie(struct ll_disk *ll, dm_block_t index,
488 struct disk_index_entry *ie)
489{
490 memcpy(ie, ll->mi_le.index + index, sizeof(*ie));
491 return 0;
492}
493
494static int metadata_ll_save_ie(struct ll_disk *ll, dm_block_t index,
495 struct disk_index_entry *ie)
496{
497 memcpy(ll->mi_le.index + index, ie, sizeof(*ie));
498 return 0;
499}
500
501static int metadata_ll_init_index(struct ll_disk *ll)
502{
503 int r;
504 struct dm_block *b;
505
506 r = dm_tm_new_block(ll->tm, &index_validator, &b);
507 if (r < 0)
508 return r;
509
510 memcpy(dm_block_data(b), &ll->mi_le, sizeof(ll->mi_le));
511 ll->bitmap_root = dm_block_location(b);
512
513 return dm_tm_unlock(ll->tm, b);
514}
515
516static int metadata_ll_open(struct ll_disk *ll)
517{
518 int r;
519 struct dm_block *block;
520
521 r = dm_tm_read_lock(ll->tm, ll->bitmap_root,
522 &index_validator, &block);
523 if (r)
524 return r;
525
526 memcpy(&ll->mi_le, dm_block_data(block), sizeof(ll->mi_le));
527 return dm_tm_unlock(ll->tm, block);
528}
529
530static dm_block_t metadata_ll_max_entries(struct ll_disk *ll)
531{
532 return MAX_METADATA_BITMAPS;
533}
534
535static int metadata_ll_commit(struct ll_disk *ll)
536{
537 int r, inc;
538 struct dm_block *b;
539
540 r = dm_tm_shadow_block(ll->tm, ll->bitmap_root, &index_validator, &b, &inc);
541 if (r)
542 return r;
543
544 memcpy(dm_block_data(b), &ll->mi_le, sizeof(ll->mi_le));
545 ll->bitmap_root = dm_block_location(b);
546
547 return dm_tm_unlock(ll->tm, b);
548}
549
550int sm_ll_new_metadata(struct ll_disk *ll, struct dm_transaction_manager *tm)
551{
552 int r;
553
554 r = sm_ll_init(ll, tm);
555 if (r < 0)
556 return r;
557
558 ll->load_ie = metadata_ll_load_ie;
559 ll->save_ie = metadata_ll_save_ie;
560 ll->init_index = metadata_ll_init_index;
561 ll->open_index = metadata_ll_open;
562 ll->max_entries = metadata_ll_max_entries;
563 ll->commit = metadata_ll_commit;
564
565 ll->nr_blocks = 0;
566 ll->nr_allocated = 0;
567
568 r = ll->init_index(ll);
569 if (r < 0)
570 return r;
571
572 r = dm_btree_empty(&ll->ref_count_info, &ll->ref_count_root);
573 if (r < 0)
574 return r;
575
576 return 0;
577}
578
579int sm_ll_open_metadata(struct ll_disk *ll, struct dm_transaction_manager *tm,
580 void *root_le, size_t len)
581{
582 int r;
583 struct disk_sm_root *smr = root_le;
584
585 if (len < sizeof(struct disk_sm_root)) {
586 DMERR("sm_metadata root too small");
587 return -ENOMEM;
588 }
589
590 r = sm_ll_init(ll, tm);
591 if (r < 0)
592 return r;
593
594 ll->load_ie = metadata_ll_load_ie;
595 ll->save_ie = metadata_ll_save_ie;
596 ll->init_index = metadata_ll_init_index;
597 ll->open_index = metadata_ll_open;
598 ll->max_entries = metadata_ll_max_entries;
599 ll->commit = metadata_ll_commit;
600
601 ll->nr_blocks = le64_to_cpu(smr->nr_blocks);
602 ll->nr_allocated = le64_to_cpu(smr->nr_allocated);
603 ll->bitmap_root = le64_to_cpu(smr->bitmap_root);
604 ll->ref_count_root = le64_to_cpu(smr->ref_count_root);
605
606 return ll->open_index(ll);
607}
608
609/*----------------------------------------------------------------*/
610
611static int disk_ll_load_ie(struct ll_disk *ll, dm_block_t index,
612 struct disk_index_entry *ie)
613{
614 return dm_btree_lookup(&ll->bitmap_info, ll->bitmap_root, &index, ie);
615}
616
617static int disk_ll_save_ie(struct ll_disk *ll, dm_block_t index,
618 struct disk_index_entry *ie)
619{
620 __dm_bless_for_disk(ie);
621 return dm_btree_insert(&ll->bitmap_info, ll->bitmap_root,
622 &index, ie, &ll->bitmap_root);
623}
624
625static int disk_ll_init_index(struct ll_disk *ll)
626{
627 return dm_btree_empty(&ll->bitmap_info, &ll->bitmap_root);
628}
629
630static int disk_ll_open(struct ll_disk *ll)
631{
632 /* nothing to do */
633 return 0;
634}
635
636static dm_block_t disk_ll_max_entries(struct ll_disk *ll)
637{
638 return -1ULL;
639}
640
641static int disk_ll_commit(struct ll_disk *ll)
642{
643 return 0;
644}
645
646int sm_ll_new_disk(struct ll_disk *ll, struct dm_transaction_manager *tm)
647{
648 int r;
649
650 r = sm_ll_init(ll, tm);
651 if (r < 0)
652 return r;
653
654 ll->load_ie = disk_ll_load_ie;
655 ll->save_ie = disk_ll_save_ie;
656 ll->init_index = disk_ll_init_index;
657 ll->open_index = disk_ll_open;
658 ll->max_entries = disk_ll_max_entries;
659 ll->commit = disk_ll_commit;
660
661 ll->nr_blocks = 0;
662 ll->nr_allocated = 0;
663
664 r = ll->init_index(ll);
665 if (r < 0)
666 return r;
667
668 r = dm_btree_empty(&ll->ref_count_info, &ll->ref_count_root);
669 if (r < 0)
670 return r;
671
672 return 0;
673}
674
675int sm_ll_open_disk(struct ll_disk *ll, struct dm_transaction_manager *tm,
676 void *root_le, size_t len)
677{
678 int r;
679 struct disk_sm_root *smr = root_le;
680
681 if (len < sizeof(struct disk_sm_root)) {
682 DMERR("sm_metadata root too small");
683 return -ENOMEM;
684 }
685
686 r = sm_ll_init(ll, tm);
687 if (r < 0)
688 return r;
689
690 ll->load_ie = disk_ll_load_ie;
691 ll->save_ie = disk_ll_save_ie;
692 ll->init_index = disk_ll_init_index;
693 ll->open_index = disk_ll_open;
694 ll->max_entries = disk_ll_max_entries;
695 ll->commit = disk_ll_commit;
696
697 ll->nr_blocks = le64_to_cpu(smr->nr_blocks);
698 ll->nr_allocated = le64_to_cpu(smr->nr_allocated);
699 ll->bitmap_root = le64_to_cpu(smr->bitmap_root);
700 ll->ref_count_root = le64_to_cpu(smr->ref_count_root);
701
702 return ll->open_index(ll);
703}
704
705/*----------------------------------------------------------------*/
diff --git a/drivers/md/persistent-data/dm-space-map-common.h b/drivers/md/persistent-data/dm-space-map-common.h
new file mode 100644
index 000000000000..8f220821a9a9
--- /dev/null
+++ b/drivers/md/persistent-data/dm-space-map-common.h
@@ -0,0 +1,126 @@
1/*
2 * Copyright (C) 2011 Red Hat, Inc.
3 *
4 * This file is released under the GPL.
5 */
6
7#ifndef DM_SPACE_MAP_COMMON_H
8#define DM_SPACE_MAP_COMMON_H
9
10#include "dm-btree.h"
11
12/*----------------------------------------------------------------*/
13
14/*
15 * Low level disk format
16 *
17 * Bitmap btree
18 * ------------
19 *
20 * Each value stored in the btree is an index_entry. This points to a
21 * block that is used as a bitmap. Within the bitmap hold 2 bits per
22 * entry, which represent UNUSED = 0, REF_COUNT = 1, REF_COUNT = 2 and
23 * REF_COUNT = many.
24 *
25 * Refcount btree
26 * --------------
27 *
28 * Any entry that has a ref count higher than 2 gets entered in the ref
29 * count tree. The leaf values for this tree is the 32-bit ref count.
30 */
31
32struct disk_index_entry {
33 __le64 blocknr;
34 __le32 nr_free;
35 __le32 none_free_before;
36} __packed;
37
38
39#define MAX_METADATA_BITMAPS 255
40struct disk_metadata_index {
41 __le32 csum;
42 __le32 padding;
43 __le64 blocknr;
44
45 struct disk_index_entry index[MAX_METADATA_BITMAPS];
46} __packed;
47
48struct ll_disk;
49
50typedef int (*load_ie_fn)(struct ll_disk *ll, dm_block_t index, struct disk_index_entry *result);
51typedef int (*save_ie_fn)(struct ll_disk *ll, dm_block_t index, struct disk_index_entry *ie);
52typedef int (*init_index_fn)(struct ll_disk *ll);
53typedef int (*open_index_fn)(struct ll_disk *ll);
54typedef dm_block_t (*max_index_entries_fn)(struct ll_disk *ll);
55typedef int (*commit_fn)(struct ll_disk *ll);
56
57struct ll_disk {
58 struct dm_transaction_manager *tm;
59 struct dm_btree_info bitmap_info;
60 struct dm_btree_info ref_count_info;
61
62 uint32_t block_size;
63 uint32_t entries_per_block;
64 dm_block_t nr_blocks;
65 dm_block_t nr_allocated;
66
67 /*
68 * bitmap_root may be a btree root or a simple index.
69 */
70 dm_block_t bitmap_root;
71
72 dm_block_t ref_count_root;
73
74 struct disk_metadata_index mi_le;
75 load_ie_fn load_ie;
76 save_ie_fn save_ie;
77 init_index_fn init_index;
78 open_index_fn open_index;
79 max_index_entries_fn max_entries;
80 commit_fn commit;
81};
82
83struct disk_sm_root {
84 __le64 nr_blocks;
85 __le64 nr_allocated;
86 __le64 bitmap_root;
87 __le64 ref_count_root;
88} __packed;
89
90#define ENTRIES_PER_BYTE 4
91
92struct disk_bitmap_header {
93 __le32 csum;
94 __le32 not_used;
95 __le64 blocknr;
96} __packed;
97
98enum allocation_event {
99 SM_NONE,
100 SM_ALLOC,
101 SM_FREE,
102};
103
104/*----------------------------------------------------------------*/
105
106int sm_ll_extend(struct ll_disk *ll, dm_block_t extra_blocks);
107int sm_ll_lookup_bitmap(struct ll_disk *ll, dm_block_t b, uint32_t *result);
108int sm_ll_lookup(struct ll_disk *ll, dm_block_t b, uint32_t *result);
109int sm_ll_find_free_block(struct ll_disk *ll, dm_block_t begin,
110 dm_block_t end, dm_block_t *result);
111int sm_ll_insert(struct ll_disk *ll, dm_block_t b, uint32_t ref_count, enum allocation_event *ev);
112int sm_ll_inc(struct ll_disk *ll, dm_block_t b, enum allocation_event *ev);
113int sm_ll_dec(struct ll_disk *ll, dm_block_t b, enum allocation_event *ev);
114int sm_ll_commit(struct ll_disk *ll);
115
116int sm_ll_new_metadata(struct ll_disk *ll, struct dm_transaction_manager *tm);
117int sm_ll_open_metadata(struct ll_disk *ll, struct dm_transaction_manager *tm,
118 void *root_le, size_t len);
119
120int sm_ll_new_disk(struct ll_disk *ll, struct dm_transaction_manager *tm);
121int sm_ll_open_disk(struct ll_disk *ll, struct dm_transaction_manager *tm,
122 void *root_le, size_t len);
123
124/*----------------------------------------------------------------*/
125
126#endif /* DM_SPACE_MAP_COMMON_H */
diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
new file mode 100644
index 000000000000..aeff7852cf79
--- /dev/null
+++ b/drivers/md/persistent-data/dm-space-map-disk.c
@@ -0,0 +1,335 @@
1/*
2 * Copyright (C) 2011 Red Hat, Inc.
3 *
4 * This file is released under the GPL.
5 */
6
7#include "dm-space-map-checker.h"
8#include "dm-space-map-common.h"
9#include "dm-space-map-disk.h"
10#include "dm-space-map.h"
11#include "dm-transaction-manager.h"
12
13#include <linux/list.h>
14#include <linux/slab.h>
15#include <linux/module.h>
16#include <linux/device-mapper.h>
17
18#define DM_MSG_PREFIX "space map disk"
19
20/*----------------------------------------------------------------*/
21
22/*
23 * Space map interface.
24 */
25struct sm_disk {
26 struct dm_space_map sm;
27
28 struct ll_disk ll;
29 struct ll_disk old_ll;
30
31 dm_block_t begin;
32 dm_block_t nr_allocated_this_transaction;
33};
34
35static void sm_disk_destroy(struct dm_space_map *sm)
36{
37 struct sm_disk *smd = container_of(sm, struct sm_disk, sm);
38
39 kfree(smd);
40}
41
42static int sm_disk_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
43{
44 struct sm_disk *smd = container_of(sm, struct sm_disk, sm);
45
46 return sm_ll_extend(&smd->ll, extra_blocks);
47}
48
49static int sm_disk_get_nr_blocks(struct dm_space_map *sm, dm_block_t *count)
50{
51 struct sm_disk *smd = container_of(sm, struct sm_disk, sm);
52 *count = smd->old_ll.nr_blocks;
53
54 return 0;
55}
56
57static int sm_disk_get_nr_free(struct dm_space_map *sm, dm_block_t *count)
58{
59 struct sm_disk *smd = container_of(sm, struct sm_disk, sm);
60 *count = (smd->old_ll.nr_blocks - smd->old_ll.nr_allocated) - smd->nr_allocated_this_transaction;
61
62 return 0;
63}
64
65static int sm_disk_get_count(struct dm_space_map *sm, dm_block_t b,
66 uint32_t *result)
67{
68 struct sm_disk *smd = container_of(sm, struct sm_disk, sm);
69 return sm_ll_lookup(&smd->ll, b, result);
70}
71
72static int sm_disk_count_is_more_than_one(struct dm_space_map *sm, dm_block_t b,
73 int *result)
74{
75 int r;
76 uint32_t count;
77
78 r = sm_disk_get_count(sm, b, &count);
79 if (r)
80 return r;
81
82 return count > 1;
83}
84
85static int sm_disk_set_count(struct dm_space_map *sm, dm_block_t b,
86 uint32_t count)
87{
88 int r;
89 uint32_t old_count;
90 enum allocation_event ev;
91 struct sm_disk *smd = container_of(sm, struct sm_disk, sm);
92
93 r = sm_ll_insert(&smd->ll, b, count, &ev);
94 if (!r) {
95 switch (ev) {
96 case SM_NONE:
97 break;
98
99 case SM_ALLOC:
100 /*
101 * This _must_ be free in the prior transaction
102 * otherwise we've lost atomicity.
103 */
104 smd->nr_allocated_this_transaction++;
105 break;
106
107 case SM_FREE:
108 /*
109 * It's only free if it's also free in the last
110 * transaction.
111 */
112 r = sm_ll_lookup(&smd->old_ll, b, &old_count);
113 if (r)
114 return r;
115
116 if (!old_count)
117 smd->nr_allocated_this_transaction--;
118 break;
119 }
120 }
121
122 return r;
123}
124
125static int sm_disk_inc_block(struct dm_space_map *sm, dm_block_t b)
126{
127 int r;
128 enum allocation_event ev;
129 struct sm_disk *smd = container_of(sm, struct sm_disk, sm);
130
131 r = sm_ll_inc(&smd->ll, b, &ev);
132 if (!r && (ev == SM_ALLOC))
133 /*
134 * This _must_ be free in the prior transaction
135 * otherwise we've lost atomicity.
136 */
137 smd->nr_allocated_this_transaction++;
138
139 return r;
140}
141
142static int sm_disk_dec_block(struct dm_space_map *sm, dm_block_t b)
143{
144 int r;
145 uint32_t old_count;
146 enum allocation_event ev;
147 struct sm_disk *smd = container_of(sm, struct sm_disk, sm);
148
149 r = sm_ll_dec(&smd->ll, b, &ev);
150 if (!r && (ev == SM_FREE)) {
151 /*
152 * It's only free if it's also free in the last
153 * transaction.
154 */
155 r = sm_ll_lookup(&smd->old_ll, b, &old_count);
156 if (r)
157 return r;
158
159 if (!old_count)
160 smd->nr_allocated_this_transaction--;
161 }
162
163 return r;
164}
165
166static int sm_disk_new_block(struct dm_space_map *sm, dm_block_t *b)
167{
168 int r;
169 enum allocation_event ev;
170 struct sm_disk *smd = container_of(sm, struct sm_disk, sm);
171
172 /* FIXME: we should loop round a couple of times */
173 r = sm_ll_find_free_block(&smd->old_ll, smd->begin, smd->old_ll.nr_blocks, b);
174 if (r)
175 return r;
176
177 smd->begin = *b + 1;
178 r = sm_ll_inc(&smd->ll, *b, &ev);
179 if (!r) {
180 BUG_ON(ev != SM_ALLOC);
181 smd->nr_allocated_this_transaction++;
182 }
183
184 return r;
185}
186
187static int sm_disk_commit(struct dm_space_map *sm)
188{
189 int r;
190 dm_block_t nr_free;
191 struct sm_disk *smd = container_of(sm, struct sm_disk, sm);
192
193 r = sm_disk_get_nr_free(sm, &nr_free);
194 if (r)
195 return r;
196
197 r = sm_ll_commit(&smd->ll);
198 if (r)
199 return r;
200
201 memcpy(&smd->old_ll, &smd->ll, sizeof(smd->old_ll));
202 smd->begin = 0;
203 smd->nr_allocated_this_transaction = 0;
204
205 r = sm_disk_get_nr_free(sm, &nr_free);
206 if (r)
207 return r;
208
209 return 0;
210}
211
212static int sm_disk_root_size(struct dm_space_map *sm, size_t *result)
213{
214 *result = sizeof(struct disk_sm_root);
215
216 return 0;
217}
218
219static int sm_disk_copy_root(struct dm_space_map *sm, void *where_le, size_t max)
220{
221 struct sm_disk *smd = container_of(sm, struct sm_disk, sm);
222 struct disk_sm_root root_le;
223
224 root_le.nr_blocks = cpu_to_le64(smd->ll.nr_blocks);
225 root_le.nr_allocated = cpu_to_le64(smd->ll.nr_allocated);
226 root_le.bitmap_root = cpu_to_le64(smd->ll.bitmap_root);
227 root_le.ref_count_root = cpu_to_le64(smd->ll.ref_count_root);
228
229 if (max < sizeof(root_le))
230 return -ENOSPC;
231
232 memcpy(where_le, &root_le, sizeof(root_le));
233
234 return 0;
235}
236
237/*----------------------------------------------------------------*/
238
239static struct dm_space_map ops = {
240 .destroy = sm_disk_destroy,
241 .extend = sm_disk_extend,
242 .get_nr_blocks = sm_disk_get_nr_blocks,
243 .get_nr_free = sm_disk_get_nr_free,
244 .get_count = sm_disk_get_count,
245 .count_is_more_than_one = sm_disk_count_is_more_than_one,
246 .set_count = sm_disk_set_count,
247 .inc_block = sm_disk_inc_block,
248 .dec_block = sm_disk_dec_block,
249 .new_block = sm_disk_new_block,
250 .commit = sm_disk_commit,
251 .root_size = sm_disk_root_size,
252 .copy_root = sm_disk_copy_root
253};
254
255static struct dm_space_map *dm_sm_disk_create_real(
256 struct dm_transaction_manager *tm,
257 dm_block_t nr_blocks)
258{
259 int r;
260 struct sm_disk *smd;
261
262 smd = kmalloc(sizeof(*smd), GFP_KERNEL);
263 if (!smd)
264 return ERR_PTR(-ENOMEM);
265
266 smd->begin = 0;
267 smd->nr_allocated_this_transaction = 0;
268 memcpy(&smd->sm, &ops, sizeof(smd->sm));
269
270 r = sm_ll_new_disk(&smd->ll, tm);
271 if (r)
272 goto bad;
273
274 r = sm_ll_extend(&smd->ll, nr_blocks);
275 if (r)
276 goto bad;
277
278 r = sm_disk_commit(&smd->sm);
279 if (r)
280 goto bad;
281
282 return &smd->sm;
283
284bad:
285 kfree(smd);
286 return ERR_PTR(r);
287}
288
289struct dm_space_map *dm_sm_disk_create(struct dm_transaction_manager *tm,
290 dm_block_t nr_blocks)
291{
292 struct dm_space_map *sm = dm_sm_disk_create_real(tm, nr_blocks);
293 return dm_sm_checker_create_fresh(sm);
294}
295EXPORT_SYMBOL_GPL(dm_sm_disk_create);
296
297static struct dm_space_map *dm_sm_disk_open_real(
298 struct dm_transaction_manager *tm,
299 void *root_le, size_t len)
300{
301 int r;
302 struct sm_disk *smd;
303
304 smd = kmalloc(sizeof(*smd), GFP_KERNEL);
305 if (!smd)
306 return ERR_PTR(-ENOMEM);
307
308 smd->begin = 0;
309 smd->nr_allocated_this_transaction = 0;
310 memcpy(&smd->sm, &ops, sizeof(smd->sm));
311
312 r = sm_ll_open_disk(&smd->ll, tm, root_le, len);
313 if (r)
314 goto bad;
315
316 r = sm_disk_commit(&smd->sm);
317 if (r)
318 goto bad;
319
320 return &smd->sm;
321
322bad:
323 kfree(smd);
324 return ERR_PTR(r);
325}
326
327struct dm_space_map *dm_sm_disk_open(struct dm_transaction_manager *tm,
328 void *root_le, size_t len)
329{
330 return dm_sm_checker_create(
331 dm_sm_disk_open_real(tm, root_le, len));
332}
333EXPORT_SYMBOL_GPL(dm_sm_disk_open);
334
335/*----------------------------------------------------------------*/
diff --git a/drivers/md/persistent-data/dm-space-map-disk.h b/drivers/md/persistent-data/dm-space-map-disk.h
new file mode 100644
index 000000000000..447a0a9a2d9f
--- /dev/null
+++ b/drivers/md/persistent-data/dm-space-map-disk.h
@@ -0,0 +1,25 @@
1/*
2 * Copyright (C) 2011 Red Hat, Inc.
3 *
4 * This file is released under the GPL.
5 */
6
7#ifndef _LINUX_DM_SPACE_MAP_DISK_H
8#define _LINUX_DM_SPACE_MAP_DISK_H
9
10#include "dm-block-manager.h"
11
12struct dm_space_map;
13struct dm_transaction_manager;
14
15/*
16 * Unfortunately we have to use two-phase construction due to the cycle
17 * between the tm and sm.
18 */
19struct dm_space_map *dm_sm_disk_create(struct dm_transaction_manager *tm,
20 dm_block_t nr_blocks);
21
22struct dm_space_map *dm_sm_disk_open(struct dm_transaction_manager *tm,
23 void *root, size_t len);
24
25#endif /* _LINUX_DM_SPACE_MAP_DISK_H */
diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
new file mode 100644
index 000000000000..e89ae5e7a519
--- /dev/null
+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
@@ -0,0 +1,596 @@
1/*
2 * Copyright (C) 2011 Red Hat, Inc.
3 *
4 * This file is released under the GPL.
5 */
6
7#include "dm-space-map.h"
8#include "dm-space-map-common.h"
9#include "dm-space-map-metadata.h"
10
11#include <linux/list.h>
12#include <linux/slab.h>
13#include <linux/device-mapper.h>
14
15#define DM_MSG_PREFIX "space map metadata"
16
17/*----------------------------------------------------------------*/
18
19/*
20 * Space map interface.
21 *
22 * The low level disk format is written using the standard btree and
23 * transaction manager. This means that performing disk operations may
24 * cause us to recurse into the space map in order to allocate new blocks.
25 * For this reason we have a pool of pre-allocated blocks large enough to
26 * service any metadata_ll_disk operation.
27 */
28
29/*
30 * FIXME: we should calculate this based on the size of the device.
31 * Only the metadata space map needs this functionality.
32 */
33#define MAX_RECURSIVE_ALLOCATIONS 1024
34
35enum block_op_type {
36 BOP_INC,
37 BOP_DEC
38};
39
40struct block_op {
41 enum block_op_type type;
42 dm_block_t block;
43};
44
45struct sm_metadata {
46 struct dm_space_map sm;
47
48 struct ll_disk ll;
49 struct ll_disk old_ll;
50
51 dm_block_t begin;
52
53 unsigned recursion_count;
54 unsigned allocated_this_transaction;
55 unsigned nr_uncommitted;
56 struct block_op uncommitted[MAX_RECURSIVE_ALLOCATIONS];
57};
58
59static int add_bop(struct sm_metadata *smm, enum block_op_type type, dm_block_t b)
60{
61 struct block_op *op;
62
63 if (smm->nr_uncommitted == MAX_RECURSIVE_ALLOCATIONS) {
64 DMERR("too many recursive allocations");
65 return -ENOMEM;
66 }
67
68 op = smm->uncommitted + smm->nr_uncommitted++;
69 op->type = type;
70 op->block = b;
71
72 return 0;
73}
74
75static int commit_bop(struct sm_metadata *smm, struct block_op *op)
76{
77 int r = 0;
78 enum allocation_event ev;
79
80 switch (op->type) {
81 case BOP_INC:
82 r = sm_ll_inc(&smm->ll, op->block, &ev);
83 break;
84
85 case BOP_DEC:
86 r = sm_ll_dec(&smm->ll, op->block, &ev);
87 break;
88 }
89
90 return r;
91}
92
93static void in(struct sm_metadata *smm)
94{
95 smm->recursion_count++;
96}
97
98static int out(struct sm_metadata *smm)
99{
100 int r = 0;
101
102 /*
103 * If we're not recursing then very bad things are happening.
104 */
105 if (!smm->recursion_count) {
106 DMERR("lost track of recursion depth");
107 return -ENOMEM;
108 }
109
110 if (smm->recursion_count == 1 && smm->nr_uncommitted) {
111 while (smm->nr_uncommitted && !r) {
112 smm->nr_uncommitted--;
113 r = commit_bop(smm, smm->uncommitted +
114 smm->nr_uncommitted);
115 if (r)
116 break;
117 }
118 }
119
120 smm->recursion_count--;
121
122 return r;
123}
124
125/*
126 * When using the out() function above, we often want to combine an error
127 * code for the operation run in the recursive context with that from
128 * out().
129 */
130static int combine_errors(int r1, int r2)
131{
132 return r1 ? r1 : r2;
133}
134
135static int recursing(struct sm_metadata *smm)
136{
137 return smm->recursion_count;
138}
139
140static void sm_metadata_destroy(struct dm_space_map *sm)
141{
142 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
143
144 kfree(smm);
145}
146
147static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
148{
149 DMERR("doesn't support extend");
150 return -EINVAL;
151}
152
153static int sm_metadata_get_nr_blocks(struct dm_space_map *sm, dm_block_t *count)
154{
155 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
156
157 *count = smm->ll.nr_blocks;
158
159 return 0;
160}
161
162static int sm_metadata_get_nr_free(struct dm_space_map *sm, dm_block_t *count)
163{
164 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
165
166 *count = smm->old_ll.nr_blocks - smm->old_ll.nr_allocated -
167 smm->allocated_this_transaction;
168
169 return 0;
170}
171
172static int sm_metadata_get_count(struct dm_space_map *sm, dm_block_t b,
173 uint32_t *result)
174{
175 int r, i;
176 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
177 unsigned adjustment = 0;
178
179 /*
180 * We may have some uncommitted adjustments to add. This list
181 * should always be really short.
182 */
183 for (i = 0; i < smm->nr_uncommitted; i++) {
184 struct block_op *op = smm->uncommitted + i;
185
186 if (op->block != b)
187 continue;
188
189 switch (op->type) {
190 case BOP_INC:
191 adjustment++;
192 break;
193
194 case BOP_DEC:
195 adjustment--;
196 break;
197 }
198 }
199
200 r = sm_ll_lookup(&smm->ll, b, result);
201 if (r)
202 return r;
203
204 *result += adjustment;
205
206 return 0;
207}
208
209static int sm_metadata_count_is_more_than_one(struct dm_space_map *sm,
210 dm_block_t b, int *result)
211{
212 int r, i, adjustment = 0;
213 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
214 uint32_t rc;
215
216 /*
217 * We may have some uncommitted adjustments to add. This list
218 * should always be really short.
219 */
220 for (i = 0; i < smm->nr_uncommitted; i++) {
221 struct block_op *op = smm->uncommitted + i;
222
223 if (op->block != b)
224 continue;
225
226 switch (op->type) {
227 case BOP_INC:
228 adjustment++;
229 break;
230
231 case BOP_DEC:
232 adjustment--;
233 break;
234 }
235 }
236
237 if (adjustment > 1) {
238 *result = 1;
239 return 0;
240 }
241
242 r = sm_ll_lookup_bitmap(&smm->ll, b, &rc);
243 if (r)
244 return r;
245
246 if (rc == 3)
247 /*
248 * We err on the side of caution, and always return true.
249 */
250 *result = 1;
251 else
252 *result = rc + adjustment > 1;
253
254 return 0;
255}
256
257static int sm_metadata_set_count(struct dm_space_map *sm, dm_block_t b,
258 uint32_t count)
259{
260 int r, r2;
261 enum allocation_event ev;
262 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
263
264 if (smm->recursion_count) {
265 DMERR("cannot recurse set_count()");
266 return -EINVAL;
267 }
268
269 in(smm);
270 r = sm_ll_insert(&smm->ll, b, count, &ev);
271 r2 = out(smm);
272
273 return combine_errors(r, r2);
274}
275
276static int sm_metadata_inc_block(struct dm_space_map *sm, dm_block_t b)
277{
278 int r, r2 = 0;
279 enum allocation_event ev;
280 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
281
282 if (recursing(smm))
283 r = add_bop(smm, BOP_INC, b);
284 else {
285 in(smm);
286 r = sm_ll_inc(&smm->ll, b, &ev);
287 r2 = out(smm);
288 }
289
290 return combine_errors(r, r2);
291}
292
293static int sm_metadata_dec_block(struct dm_space_map *sm, dm_block_t b)
294{
295 int r, r2 = 0;
296 enum allocation_event ev;
297 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
298
299 if (recursing(smm))
300 r = add_bop(smm, BOP_DEC, b);
301 else {
302 in(smm);
303 r = sm_ll_dec(&smm->ll, b, &ev);
304 r2 = out(smm);
305 }
306
307 return combine_errors(r, r2);
308}
309
310static int sm_metadata_new_block_(struct dm_space_map *sm, dm_block_t *b)
311{
312 int r, r2 = 0;
313 enum allocation_event ev;
314 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
315
316 r = sm_ll_find_free_block(&smm->old_ll, smm->begin, smm->old_ll.nr_blocks, b);
317 if (r)
318 return r;
319
320 smm->begin = *b + 1;
321
322 if (recursing(smm))
323 r = add_bop(smm, BOP_INC, *b);
324 else {
325 in(smm);
326 r = sm_ll_inc(&smm->ll, *b, &ev);
327 r2 = out(smm);
328 }
329
330 if (!r)
331 smm->allocated_this_transaction++;
332
333 return combine_errors(r, r2);
334}
335
336static int sm_metadata_new_block(struct dm_space_map *sm, dm_block_t *b)
337{
338 int r = sm_metadata_new_block_(sm, b);
339 if (r)
340 DMERR("out of metadata space");
341 return r;
342}
343
344static int sm_metadata_commit(struct dm_space_map *sm)
345{
346 int r;
347 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
348
349 r = sm_ll_commit(&smm->ll);
350 if (r)
351 return r;
352
353 memcpy(&smm->old_ll, &smm->ll, sizeof(smm->old_ll));
354 smm->begin = 0;
355 smm->allocated_this_transaction = 0;
356
357 return 0;
358}
359
360static int sm_metadata_root_size(struct dm_space_map *sm, size_t *result)
361{
362 *result = sizeof(struct disk_sm_root);
363
364 return 0;
365}
366
367static int sm_metadata_copy_root(struct dm_space_map *sm, void *where_le, size_t max)
368{
369 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
370 struct disk_sm_root root_le;
371
372 root_le.nr_blocks = cpu_to_le64(smm->ll.nr_blocks);
373 root_le.nr_allocated = cpu_to_le64(smm->ll.nr_allocated);
374 root_le.bitmap_root = cpu_to_le64(smm->ll.bitmap_root);
375 root_le.ref_count_root = cpu_to_le64(smm->ll.ref_count_root);
376
377 if (max < sizeof(root_le))
378 return -ENOSPC;
379
380 memcpy(where_le, &root_le, sizeof(root_le));
381
382 return 0;
383}
384
385static struct dm_space_map ops = {
386 .destroy = sm_metadata_destroy,
387 .extend = sm_metadata_extend,
388 .get_nr_blocks = sm_metadata_get_nr_blocks,
389 .get_nr_free = sm_metadata_get_nr_free,
390 .get_count = sm_metadata_get_count,
391 .count_is_more_than_one = sm_metadata_count_is_more_than_one,
392 .set_count = sm_metadata_set_count,
393 .inc_block = sm_metadata_inc_block,
394 .dec_block = sm_metadata_dec_block,
395 .new_block = sm_metadata_new_block,
396 .commit = sm_metadata_commit,
397 .root_size = sm_metadata_root_size,
398 .copy_root = sm_metadata_copy_root
399};
400
401/*----------------------------------------------------------------*/
402
403/*
404 * When a new space map is created that manages its own space. We use
405 * this tiny bootstrap allocator.
406 */
407static void sm_bootstrap_destroy(struct dm_space_map *sm)
408{
409}
410
411static int sm_bootstrap_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
412{
413 DMERR("boostrap doesn't support extend");
414
415 return -EINVAL;
416}
417
418static int sm_bootstrap_get_nr_blocks(struct dm_space_map *sm, dm_block_t *count)
419{
420 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
421
422 return smm->ll.nr_blocks;
423}
424
425static int sm_bootstrap_get_nr_free(struct dm_space_map *sm, dm_block_t *count)
426{
427 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
428
429 *count = smm->ll.nr_blocks - smm->begin;
430
431 return 0;
432}
433
434static int sm_bootstrap_get_count(struct dm_space_map *sm, dm_block_t b,
435 uint32_t *result)
436{
437 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
438
439 return b < smm->begin ? 1 : 0;
440}
441
442static int sm_bootstrap_count_is_more_than_one(struct dm_space_map *sm,
443 dm_block_t b, int *result)
444{
445 *result = 0;
446
447 return 0;
448}
449
450static int sm_bootstrap_set_count(struct dm_space_map *sm, dm_block_t b,
451 uint32_t count)
452{
453 DMERR("boostrap doesn't support set_count");
454
455 return -EINVAL;
456}
457
458static int sm_bootstrap_new_block(struct dm_space_map *sm, dm_block_t *b)
459{
460 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
461
462 /*
463 * We know the entire device is unused.
464 */
465 if (smm->begin == smm->ll.nr_blocks)
466 return -ENOSPC;
467
468 *b = smm->begin++;
469
470 return 0;
471}
472
473static int sm_bootstrap_inc_block(struct dm_space_map *sm, dm_block_t b)
474{
475 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
476
477 return add_bop(smm, BOP_INC, b);
478}
479
480static int sm_bootstrap_dec_block(struct dm_space_map *sm, dm_block_t b)
481{
482 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
483
484 return add_bop(smm, BOP_DEC, b);
485}
486
487static int sm_bootstrap_commit(struct dm_space_map *sm)
488{
489 return 0;
490}
491
492static int sm_bootstrap_root_size(struct dm_space_map *sm, size_t *result)
493{
494 DMERR("boostrap doesn't support root_size");
495
496 return -EINVAL;
497}
498
499static int sm_bootstrap_copy_root(struct dm_space_map *sm, void *where,
500 size_t max)
501{
502 DMERR("boostrap doesn't support copy_root");
503
504 return -EINVAL;
505}
506
507static struct dm_space_map bootstrap_ops = {
508 .destroy = sm_bootstrap_destroy,
509 .extend = sm_bootstrap_extend,
510 .get_nr_blocks = sm_bootstrap_get_nr_blocks,
511 .get_nr_free = sm_bootstrap_get_nr_free,
512 .get_count = sm_bootstrap_get_count,
513 .count_is_more_than_one = sm_bootstrap_count_is_more_than_one,
514 .set_count = sm_bootstrap_set_count,
515 .inc_block = sm_bootstrap_inc_block,
516 .dec_block = sm_bootstrap_dec_block,
517 .new_block = sm_bootstrap_new_block,
518 .commit = sm_bootstrap_commit,
519 .root_size = sm_bootstrap_root_size,
520 .copy_root = sm_bootstrap_copy_root
521};
522
523/*----------------------------------------------------------------*/
524
525struct dm_space_map *dm_sm_metadata_init(void)
526{
527 struct sm_metadata *smm;
528
529 smm = kmalloc(sizeof(*smm), GFP_KERNEL);
530 if (!smm)
531 return ERR_PTR(-ENOMEM);
532
533 memcpy(&smm->sm, &ops, sizeof(smm->sm));
534
535 return &smm->sm;
536}
537
538int dm_sm_metadata_create(struct dm_space_map *sm,
539 struct dm_transaction_manager *tm,
540 dm_block_t nr_blocks,
541 dm_block_t superblock)
542{
543 int r;
544 dm_block_t i;
545 enum allocation_event ev;
546 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
547
548 smm->begin = superblock + 1;
549 smm->recursion_count = 0;
550 smm->allocated_this_transaction = 0;
551 smm->nr_uncommitted = 0;
552
553 memcpy(&smm->sm, &bootstrap_ops, sizeof(smm->sm));
554
555 r = sm_ll_new_metadata(&smm->ll, tm);
556 if (r)
557 return r;
558
559 r = sm_ll_extend(&smm->ll, nr_blocks);
560 if (r)
561 return r;
562
563 memcpy(&smm->sm, &ops, sizeof(smm->sm));
564
565 /*
566 * Now we need to update the newly created data structures with the
567 * allocated blocks that they were built from.
568 */
569 for (i = superblock; !r && i < smm->begin; i++)
570 r = sm_ll_inc(&smm->ll, i, &ev);
571
572 if (r)
573 return r;
574
575 return sm_metadata_commit(sm);
576}
577
578int dm_sm_metadata_open(struct dm_space_map *sm,
579 struct dm_transaction_manager *tm,
580 void *root_le, size_t len)
581{
582 int r;
583 struct sm_metadata *smm = container_of(sm, struct sm_metadata, sm);
584
585 r = sm_ll_open_metadata(&smm->ll, tm, root_le, len);
586 if (r)
587 return r;
588
589 smm->begin = 0;
590 smm->recursion_count = 0;
591 smm->allocated_this_transaction = 0;
592 smm->nr_uncommitted = 0;
593
594 memcpy(&smm->old_ll, &smm->ll, sizeof(smm->old_ll));
595 return 0;
596}
diff --git a/drivers/md/persistent-data/dm-space-map-metadata.h b/drivers/md/persistent-data/dm-space-map-metadata.h
new file mode 100644
index 000000000000..39bba0801cf2
--- /dev/null
+++ b/drivers/md/persistent-data/dm-space-map-metadata.h
@@ -0,0 +1,33 @@
1/*
2 * Copyright (C) 2011 Red Hat, Inc.
3 *
4 * This file is released under the GPL.
5 */
6
7#ifndef DM_SPACE_MAP_METADATA_H
8#define DM_SPACE_MAP_METADATA_H
9
10#include "dm-transaction-manager.h"
11
12/*
13 * Unfortunately we have to use two-phase construction due to the cycle
14 * between the tm and sm.
15 */
16struct dm_space_map *dm_sm_metadata_init(void);
17
18/*
19 * Create a fresh space map.
20 */
21int dm_sm_metadata_create(struct dm_space_map *sm,
22 struct dm_transaction_manager *tm,
23 dm_block_t nr_blocks,
24 dm_block_t superblock);
25
26/*
27 * Open from a previously-recorded root.
28 */
29int dm_sm_metadata_open(struct dm_space_map *sm,
30 struct dm_transaction_manager *tm,
31 void *root_le, size_t len);
32
33#endif /* DM_SPACE_MAP_METADATA_H */
diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
new file mode 100644
index 000000000000..1cbfc6b1638a
--- /dev/null
+++ b/drivers/md/persistent-data/dm-space-map.h
@@ -0,0 +1,134 @@
1/*
2 * Copyright (C) 2011 Red Hat, Inc.
3 *
4 * This file is released under the GPL.
5 */
6
7#ifndef _LINUX_DM_SPACE_MAP_H
8#define _LINUX_DM_SPACE_MAP_H
9
10#include "dm-block-manager.h"
11
12/*
13 * struct dm_space_map keeps a record of how many times each block in a device
14 * is referenced. It needs to be fixed on disk as part of the transaction.
15 */
16struct dm_space_map {
17 void (*destroy)(struct dm_space_map *sm);
18
19 /*
20 * You must commit before allocating the newly added space.
21 */
22 int (*extend)(struct dm_space_map *sm, dm_block_t extra_blocks);
23
24 /*
25 * Extensions do not appear in this count until after commit has
26 * been called.
27 */
28 int (*get_nr_blocks)(struct dm_space_map *sm, dm_block_t *count);
29
30 /*
31 * Space maps must never allocate a block from the previous
32 * transaction, in case we need to rollback. This complicates the
33 * semantics of get_nr_free(), it should return the number of blocks
34 * that are available for allocation _now_. For instance you may
35 * have blocks with a zero reference count that will not be
36 * available for allocation until after the next commit.
37 */
38 int (*get_nr_free)(struct dm_space_map *sm, dm_block_t *count);
39
40 int (*get_count)(struct dm_space_map *sm, dm_block_t b, uint32_t *result);
41 int (*count_is_more_than_one)(struct dm_space_map *sm, dm_block_t b,
42 int *result);
43 int (*set_count)(struct dm_space_map *sm, dm_block_t b, uint32_t count);
44
45 int (*commit)(struct dm_space_map *sm);
46
47 int (*inc_block)(struct dm_space_map *sm, dm_block_t b);
48 int (*dec_block)(struct dm_space_map *sm, dm_block_t b);
49
50 /*
51 * new_block will increment the returned block.
52 */
53 int (*new_block)(struct dm_space_map *sm, dm_block_t *b);
54
55 /*
56 * The root contains all the information needed to fix the space map.
57 * Generally this info is small, so squirrel it away in a disk block
58 * along with other info.
59 */
60 int (*root_size)(struct dm_space_map *sm, size_t *result);
61 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
62};
63
64/*----------------------------------------------------------------*/
65
66static inline void dm_sm_destroy(struct dm_space_map *sm)
67{
68 sm->destroy(sm);
69}
70
71static inline int dm_sm_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
72{
73 return sm->extend(sm, extra_blocks);
74}
75
76static inline int dm_sm_get_nr_blocks(struct dm_space_map *sm, dm_block_t *count)
77{
78 return sm->get_nr_blocks(sm, count);
79}
80
81static inline int dm_sm_get_nr_free(struct dm_space_map *sm, dm_block_t *count)
82{
83 return sm->get_nr_free(sm, count);
84}
85
86static inline int dm_sm_get_count(struct dm_space_map *sm, dm_block_t b,
87 uint32_t *result)
88{
89 return sm->get_count(sm, b, result);
90}
91
92static inline int dm_sm_count_is_more_than_one(struct dm_space_map *sm,
93 dm_block_t b, int *result)
94{
95 return sm->count_is_more_than_one(sm, b, result);
96}
97
98static inline int dm_sm_set_count(struct dm_space_map *sm, dm_block_t b,
99 uint32_t count)
100{
101 return sm->set_count(sm, b, count);
102}
103
104static inline int dm_sm_commit(struct dm_space_map *sm)
105{
106 return sm->commit(sm);
107}
108
109static inline int dm_sm_inc_block(struct dm_space_map *sm, dm_block_t b)
110{
111 return sm->inc_block(sm, b);
112}
113
114static inline int dm_sm_dec_block(struct dm_space_map *sm, dm_block_t b)
115{
116 return sm->dec_block(sm, b);
117}
118
119static inline int dm_sm_new_block(struct dm_space_map *sm, dm_block_t *b)
120{
121 return sm->new_block(sm, b);
122}
123
124static inline int dm_sm_root_size(struct dm_space_map *sm, size_t *result)
125{
126 return sm->root_size(sm, result);
127}
128
129static inline int dm_sm_copy_root(struct dm_space_map *sm, void *copy_to_here_le, size_t len)
130{
131 return sm->copy_root(sm, copy_to_here_le, len);
132}
133
134#endif /* _LINUX_DM_SPACE_MAP_H */
diff --git a/drivers/md/persistent-data/dm-transaction-manager.c b/drivers/md/persistent-data/dm-transaction-manager.c
new file mode 100644
index 000000000000..728e89a3f978
--- /dev/null
+++ b/drivers/md/persistent-data/dm-transaction-manager.c
@@ -0,0 +1,400 @@
1/*
2 * Copyright (C) 2011 Red Hat, Inc.
3 *
4 * This file is released under the GPL.
5 */
6#include "dm-transaction-manager.h"
7#include "dm-space-map.h"
8#include "dm-space-map-checker.h"
9#include "dm-space-map-disk.h"
10#include "dm-space-map-metadata.h"
11#include "dm-persistent-data-internal.h"
12
13#include <linux/module.h>
14#include <linux/slab.h>
15#include <linux/device-mapper.h>
16
17#define DM_MSG_PREFIX "transaction manager"
18
19/*----------------------------------------------------------------*/
20
21struct shadow_info {
22 struct hlist_node hlist;
23 dm_block_t where;
24};
25
26/*
27 * It would be nice if we scaled with the size of transaction.
28 */
29#define HASH_SIZE 256
30#define HASH_MASK (HASH_SIZE - 1)
31
32struct dm_transaction_manager {
33 int is_clone;
34 struct dm_transaction_manager *real;
35
36 struct dm_block_manager *bm;
37 struct dm_space_map *sm;
38
39 spinlock_t lock;
40 struct hlist_head buckets[HASH_SIZE];
41};
42
43/*----------------------------------------------------------------*/
44
45static int is_shadow(struct dm_transaction_manager *tm, dm_block_t b)
46{
47 int r = 0;
48 unsigned bucket = dm_hash_block(b, HASH_MASK);
49 struct shadow_info *si;
50 struct hlist_node *n;
51
52 spin_lock(&tm->lock);
53 hlist_for_each_entry(si, n, tm->buckets + bucket, hlist)
54 if (si->where == b) {
55 r = 1;
56 break;
57 }
58 spin_unlock(&tm->lock);
59
60 return r;
61}
62
63/*
64 * This can silently fail if there's no memory. We're ok with this since
65 * creating redundant shadows causes no harm.
66 */
67static void insert_shadow(struct dm_transaction_manager *tm, dm_block_t b)
68{
69 unsigned bucket;
70 struct shadow_info *si;
71
72 si = kmalloc(sizeof(*si), GFP_NOIO);
73 if (si) {
74 si->where = b;
75 bucket = dm_hash_block(b, HASH_MASK);
76 spin_lock(&tm->lock);
77 hlist_add_head(&si->hlist, tm->buckets + bucket);
78 spin_unlock(&tm->lock);
79 }
80}
81
82static void wipe_shadow_table(struct dm_transaction_manager *tm)
83{
84 struct shadow_info *si;
85 struct hlist_node *n, *tmp;
86 struct hlist_head *bucket;
87 int i;
88
89 spin_lock(&tm->lock);
90 for (i = 0; i < HASH_SIZE; i++) {
91 bucket = tm->buckets + i;
92 hlist_for_each_entry_safe(si, n, tmp, bucket, hlist)
93 kfree(si);
94
95 INIT_HLIST_HEAD(bucket);
96 }
97
98 spin_unlock(&tm->lock);
99}
100
101/*----------------------------------------------------------------*/
102
103static struct dm_transaction_manager *dm_tm_create(struct dm_block_manager *bm,
104 struct dm_space_map *sm)
105{
106 int i;
107 struct dm_transaction_manager *tm;
108
109 tm = kmalloc(sizeof(*tm), GFP_KERNEL);
110 if (!tm)
111 return ERR_PTR(-ENOMEM);
112
113 tm->is_clone = 0;
114 tm->real = NULL;
115 tm->bm = bm;
116 tm->sm = sm;
117
118 spin_lock_init(&tm->lock);
119 for (i = 0; i < HASH_SIZE; i++)
120 INIT_HLIST_HEAD(tm->buckets + i);
121
122 return tm;
123}
124
125struct dm_transaction_manager *dm_tm_create_non_blocking_clone(struct dm_transaction_manager *real)
126{
127 struct dm_transaction_manager *tm;
128
129 tm = kmalloc(sizeof(*tm), GFP_KERNEL);
130 if (tm) {
131 tm->is_clone = 1;
132 tm->real = real;
133 }
134
135 return tm;
136}
137EXPORT_SYMBOL_GPL(dm_tm_create_non_blocking_clone);
138
139void dm_tm_destroy(struct dm_transaction_manager *tm)
140{
141 kfree(tm);
142}
143EXPORT_SYMBOL_GPL(dm_tm_destroy);
144
145int dm_tm_pre_commit(struct dm_transaction_manager *tm)
146{
147 int r;
148
149 if (tm->is_clone)
150 return -EWOULDBLOCK;
151
152 r = dm_sm_commit(tm->sm);
153 if (r < 0)
154 return r;
155
156 return 0;
157}
158EXPORT_SYMBOL_GPL(dm_tm_pre_commit);
159
160int dm_tm_commit(struct dm_transaction_manager *tm, struct dm_block *root)
161{
162 if (tm->is_clone)
163 return -EWOULDBLOCK;
164
165 wipe_shadow_table(tm);
166
167 return dm_bm_flush_and_unlock(tm->bm, root);
168}
169EXPORT_SYMBOL_GPL(dm_tm_commit);
170
171int dm_tm_new_block(struct dm_transaction_manager *tm,
172 struct dm_block_validator *v,
173 struct dm_block **result)
174{
175 int r;
176 dm_block_t new_block;
177
178 if (tm->is_clone)
179 return -EWOULDBLOCK;
180
181 r = dm_sm_new_block(tm->sm, &new_block);
182 if (r < 0)
183 return r;
184
185 r = dm_bm_write_lock_zero(tm->bm, new_block, v, result);
186 if (r < 0) {
187 dm_sm_dec_block(tm->sm, new_block);
188 return r;
189 }
190
191 /*
192 * New blocks count as shadows in that they don't need to be
193 * shadowed again.
194 */
195 insert_shadow(tm, new_block);
196
197 return 0;
198}
199
200static int __shadow_block(struct dm_transaction_manager *tm, dm_block_t orig,
201 struct dm_block_validator *v,
202 struct dm_block **result)
203{
204 int r;
205 dm_block_t new;
206 struct dm_block *orig_block;
207
208 r = dm_sm_new_block(tm->sm, &new);
209 if (r < 0)
210 return r;
211
212 r = dm_sm_dec_block(tm->sm, orig);
213 if (r < 0)
214 return r;
215
216 r = dm_bm_read_lock(tm->bm, orig, v, &orig_block);
217 if (r < 0)
218 return r;
219
220 r = dm_bm_unlock_move(orig_block, new);
221 if (r < 0) {
222 dm_bm_unlock(orig_block);
223 return r;
224 }
225
226 return dm_bm_write_lock(tm->bm, new, v, result);
227}
228
229int dm_tm_shadow_block(struct dm_transaction_manager *tm, dm_block_t orig,
230 struct dm_block_validator *v, struct dm_block **result,
231 int *inc_children)
232{
233 int r;
234
235 if (tm->is_clone)
236 return -EWOULDBLOCK;
237
238 r = dm_sm_count_is_more_than_one(tm->sm, orig, inc_children);
239 if (r < 0)
240 return r;
241
242 if (is_shadow(tm, orig) && !*inc_children)
243 return dm_bm_write_lock(tm->bm, orig, v, result);
244
245 r = __shadow_block(tm, orig, v, result);
246 if (r < 0)
247 return r;
248 insert_shadow(tm, dm_block_location(*result));
249
250 return r;
251}
252
253int dm_tm_read_lock(struct dm_transaction_manager *tm, dm_block_t b,
254 struct dm_block_validator *v,
255 struct dm_block **blk)
256{
257 if (tm->is_clone)
258 return dm_bm_read_try_lock(tm->real->bm, b, v, blk);
259
260 return dm_bm_read_lock(tm->bm, b, v, blk);
261}
262
263int dm_tm_unlock(struct dm_transaction_manager *tm, struct dm_block *b)
264{
265 return dm_bm_unlock(b);
266}
267EXPORT_SYMBOL_GPL(dm_tm_unlock);
268
269void dm_tm_inc(struct dm_transaction_manager *tm, dm_block_t b)
270{
271 /*
272 * The non-blocking clone doesn't support this.
273 */
274 BUG_ON(tm->is_clone);
275
276 dm_sm_inc_block(tm->sm, b);
277}
278EXPORT_SYMBOL_GPL(dm_tm_inc);
279
280void dm_tm_dec(struct dm_transaction_manager *tm, dm_block_t b)
281{
282 /*
283 * The non-blocking clone doesn't support this.
284 */
285 BUG_ON(tm->is_clone);
286
287 dm_sm_dec_block(tm->sm, b);
288}
289EXPORT_SYMBOL_GPL(dm_tm_dec);
290
291int dm_tm_ref(struct dm_transaction_manager *tm, dm_block_t b,
292 uint32_t *result)
293{
294 if (tm->is_clone)
295 return -EWOULDBLOCK;
296
297 return dm_sm_get_count(tm->sm, b, result);
298}
299
300struct dm_block_manager *dm_tm_get_bm(struct dm_transaction_manager *tm)
301{
302 return tm->bm;
303}
304
305/*----------------------------------------------------------------*/
306
307static int dm_tm_create_internal(struct dm_block_manager *bm,
308 dm_block_t sb_location,
309 struct dm_block_validator *sb_validator,
310 size_t root_offset, size_t root_max_len,
311 struct dm_transaction_manager **tm,
312 struct dm_space_map **sm,
313 struct dm_block **sblock,
314 int create)
315{
316 int r;
317 struct dm_space_map *inner;
318
319 inner = dm_sm_metadata_init();
320 if (IS_ERR(inner))
321 return PTR_ERR(inner);
322
323 *tm = dm_tm_create(bm, inner);
324 if (IS_ERR(*tm)) {
325 dm_sm_destroy(inner);
326 return PTR_ERR(*tm);
327 }
328
329 if (create) {
330 r = dm_bm_write_lock_zero(dm_tm_get_bm(*tm), sb_location,
331 sb_validator, sblock);
332 if (r < 0) {
333 DMERR("couldn't lock superblock");
334 goto bad1;
335 }
336
337 r = dm_sm_metadata_create(inner, *tm, dm_bm_nr_blocks(bm),
338 sb_location);
339 if (r) {
340 DMERR("couldn't create metadata space map");
341 goto bad2;
342 }
343
344 *sm = dm_sm_checker_create(inner);
345 if (!*sm)
346 goto bad2;
347
348 } else {
349 r = dm_bm_write_lock(dm_tm_get_bm(*tm), sb_location,
350 sb_validator, sblock);
351 if (r < 0) {
352 DMERR("couldn't lock superblock");
353 goto bad1;
354 }
355
356 r = dm_sm_metadata_open(inner, *tm,
357 dm_block_data(*sblock) + root_offset,
358 root_max_len);
359 if (r) {
360 DMERR("couldn't open metadata space map");
361 goto bad2;
362 }
363
364 *sm = dm_sm_checker_create(inner);
365 if (!*sm)
366 goto bad2;
367 }
368
369 return 0;
370
371bad2:
372 dm_tm_unlock(*tm, *sblock);
373bad1:
374 dm_tm_destroy(*tm);
375 dm_sm_destroy(inner);
376 return r;
377}
378
379int dm_tm_create_with_sm(struct dm_block_manager *bm, dm_block_t sb_location,
380 struct dm_block_validator *sb_validator,
381 struct dm_transaction_manager **tm,
382 struct dm_space_map **sm, struct dm_block **sblock)
383{
384 return dm_tm_create_internal(bm, sb_location, sb_validator,
385 0, 0, tm, sm, sblock, 1);
386}
387EXPORT_SYMBOL_GPL(dm_tm_create_with_sm);
388
389int dm_tm_open_with_sm(struct dm_block_manager *bm, dm_block_t sb_location,
390 struct dm_block_validator *sb_validator,
391 size_t root_offset, size_t root_max_len,
392 struct dm_transaction_manager **tm,
393 struct dm_space_map **sm, struct dm_block **sblock)
394{
395 return dm_tm_create_internal(bm, sb_location, sb_validator, root_offset,
396 root_max_len, tm, sm, sblock, 0);
397}
398EXPORT_SYMBOL_GPL(dm_tm_open_with_sm);
399
400/*----------------------------------------------------------------*/
diff --git a/drivers/md/persistent-data/dm-transaction-manager.h b/drivers/md/persistent-data/dm-transaction-manager.h
new file mode 100644
index 000000000000..6da784871db4
--- /dev/null
+++ b/drivers/md/persistent-data/dm-transaction-manager.h
@@ -0,0 +1,130 @@
1/*
2 * Copyright (C) 2011 Red Hat, Inc.
3 *
4 * This file is released under the GPL.
5 */
6
7#ifndef _LINUX_DM_TRANSACTION_MANAGER_H
8#define _LINUX_DM_TRANSACTION_MANAGER_H
9
10#include "dm-block-manager.h"
11
12struct dm_transaction_manager;
13struct dm_space_map;
14
15/*----------------------------------------------------------------*/
16
17/*
18 * This manages the scope of a transaction. It also enforces immutability
19 * of the on-disk data structures by limiting access to writeable blocks.
20 *
21 * Clients should not fiddle with the block manager directly.
22 */
23
24void dm_tm_destroy(struct dm_transaction_manager *tm);
25
26/*
27 * The non-blocking version of a transaction manager is intended for use in
28 * fast path code that needs to do lookups e.g. a dm mapping function.
29 * You create the non-blocking variant from a normal tm. The interface is
30 * the same, except that most functions will just return -EWOULDBLOCK.
31 * Methods that return void yet may block should not be called on a clone
32 * viz. dm_tm_inc, dm_tm_dec. Call dm_tm_destroy() as you would with a normal
33 * tm when you've finished with it. You may not destroy the original prior
34 * to clones.
35 */
36struct dm_transaction_manager *dm_tm_create_non_blocking_clone(struct dm_transaction_manager *real);
37
38/*
39 * We use a 2-phase commit here.
40 *
41 * i) In the first phase the block manager is told to start flushing, and
42 * the changes to the space map are written to disk. You should interrogate
43 * your particular space map to get detail of its root node etc. to be
44 * included in your superblock.
45 *
46 * ii) @root will be committed last. You shouldn't use more than the
47 * first 512 bytes of @root if you wish the transaction to survive a power
48 * failure. You *must* have a write lock held on @root for both stage (i)
49 * and (ii). The commit will drop the write lock.
50 */
51int dm_tm_pre_commit(struct dm_transaction_manager *tm);
52int dm_tm_commit(struct dm_transaction_manager *tm, struct dm_block *root);
53
54/*
55 * These methods are the only way to get hold of a writeable block.
56 */
57
58/*
59 * dm_tm_new_block() is pretty self-explanatory. Make sure you do actually
60 * write to the whole of @data before you unlock, otherwise you could get
61 * a data leak. (The other option is for tm_new_block() to zero new blocks
62 * before handing them out, which will be redundant in most, if not all,
63 * cases).
64 * Zeroes the new block and returns with write lock held.
65 */
66int dm_tm_new_block(struct dm_transaction_manager *tm,
67 struct dm_block_validator *v,
68 struct dm_block **result);
69
70/*
71 * dm_tm_shadow_block() allocates a new block and copies the data from @orig
72 * to it. It then decrements the reference count on original block. Use
73 * this to update the contents of a block in a data structure, don't
74 * confuse this with a clone - you shouldn't access the orig block after
75 * this operation. Because the tm knows the scope of the transaction it
76 * can optimise requests for a shadow of a shadow to a no-op. Don't forget
77 * to unlock when you've finished with the shadow.
78 *
79 * The @inc_children flag is used to tell the caller whether it needs to
80 * adjust reference counts for children. (Data in the block may refer to
81 * other blocks.)
82 *
83 * Shadowing implicitly drops a reference on @orig so you must not have
84 * it locked when you call this.
85 */
86int dm_tm_shadow_block(struct dm_transaction_manager *tm, dm_block_t orig,
87 struct dm_block_validator *v,
88 struct dm_block **result, int *inc_children);
89
90/*
91 * Read access. You can lock any block you want. If there's a write lock
92 * on it outstanding then it'll block.
93 */
94int dm_tm_read_lock(struct dm_transaction_manager *tm, dm_block_t b,
95 struct dm_block_validator *v,
96 struct dm_block **result);
97
98int dm_tm_unlock(struct dm_transaction_manager *tm, struct dm_block *b);
99
100/*
101 * Functions for altering the reference count of a block directly.
102 */
103void dm_tm_inc(struct dm_transaction_manager *tm, dm_block_t b);
104
105void dm_tm_dec(struct dm_transaction_manager *tm, dm_block_t b);
106
107int dm_tm_ref(struct dm_transaction_manager *tm, dm_block_t b,
108 uint32_t *result);
109
110struct dm_block_manager *dm_tm_get_bm(struct dm_transaction_manager *tm);
111
112/*
113 * A little utility that ties the knot by producing a transaction manager
114 * that has a space map managed by the transaction manager...
115 *
116 * Returns a tm that has an open transaction to write the new disk sm.
117 * Caller should store the new sm root and commit.
118 */
119int dm_tm_create_with_sm(struct dm_block_manager *bm, dm_block_t sb_location,
120 struct dm_block_validator *sb_validator,
121 struct dm_transaction_manager **tm,
122 struct dm_space_map **sm, struct dm_block **sblock);
123
124int dm_tm_open_with_sm(struct dm_block_manager *bm, dm_block_t sb_location,
125 struct dm_block_validator *sb_validator,
126 size_t root_offset, size_t root_max_len,
127 struct dm_transaction_manager **tm,
128 struct dm_space_map **sm, struct dm_block **sblock);
129
130#endif /* _LINUX_DM_TRANSACTION_MANAGER_H */
diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 0eb08a4df759..7294bd115e34 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -20,6 +20,7 @@
20 20
21#include <linux/blkdev.h> 21#include <linux/blkdev.h>
22#include <linux/seq_file.h> 22#include <linux/seq_file.h>
23#include <linux/module.h>
23#include <linux/slab.h> 24#include <linux/slab.h>
24#include "md.h" 25#include "md.h"
25#include "raid0.h" 26#include "raid0.h"
@@ -468,7 +469,7 @@ static inline int is_io_in_chunk_boundary(struct mddev *mddev,
468 } 469 }
469} 470}
470 471
471static int raid0_make_request(struct mddev *mddev, struct bio *bio) 472static void raid0_make_request(struct mddev *mddev, struct bio *bio)
472{ 473{
473 unsigned int chunk_sects; 474 unsigned int chunk_sects;
474 sector_t sector_offset; 475 sector_t sector_offset;
@@ -477,7 +478,7 @@ static int raid0_make_request(struct mddev *mddev, struct bio *bio)
477 478
478 if (unlikely(bio->bi_rw & REQ_FLUSH)) { 479 if (unlikely(bio->bi_rw & REQ_FLUSH)) {
479 md_flush_request(mddev, bio); 480 md_flush_request(mddev, bio);
480 return 0; 481 return;
481 } 482 }
482 483
483 chunk_sects = mddev->chunk_sectors; 484 chunk_sects = mddev->chunk_sectors;
@@ -497,13 +498,10 @@ static int raid0_make_request(struct mddev *mddev, struct bio *bio)
497 else 498 else
498 bp = bio_split(bio, chunk_sects - 499 bp = bio_split(bio, chunk_sects -
499 sector_div(sector, chunk_sects)); 500 sector_div(sector, chunk_sects));
500 if (raid0_make_request(mddev, &bp->bio1)) 501 raid0_make_request(mddev, &bp->bio1);
501 generic_make_request(&bp->bio1); 502 raid0_make_request(mddev, &bp->bio2);
502 if (raid0_make_request(mddev, &bp->bio2))
503 generic_make_request(&bp->bio2);
504
505 bio_pair_release(bp); 503 bio_pair_release(bp);
506 return 0; 504 return;
507 } 505 }
508 506
509 sector_offset = bio->bi_sector; 507 sector_offset = bio->bi_sector;
@@ -513,10 +511,9 @@ static int raid0_make_request(struct mddev *mddev, struct bio *bio)
513 bio->bi_bdev = tmp_dev->bdev; 511 bio->bi_bdev = tmp_dev->bdev;
514 bio->bi_sector = sector_offset + zone->dev_start + 512 bio->bi_sector = sector_offset + zone->dev_start +
515 tmp_dev->data_offset; 513 tmp_dev->data_offset;
516 /* 514
517 * Let the main block layer submit the IO and resolve recursion: 515 generic_make_request(bio);
518 */ 516 return;
519 return 1;
520 517
521bad_map: 518bad_map:
522 printk("md/raid0:%s: make_request bug: can't convert block across chunks" 519 printk("md/raid0:%s: make_request bug: can't convert block across chunks"
@@ -525,7 +522,7 @@ bad_map:
525 (unsigned long long)bio->bi_sector, bio->bi_size >> 10); 522 (unsigned long long)bio->bi_sector, bio->bi_size >> 10);
526 523
527 bio_io_error(bio); 524 bio_io_error(bio);
528 return 0; 525 return;
529} 526}
530 527
531static void raid0_status(struct seq_file *seq, struct mddev *mddev) 528static void raid0_status(struct seq_file *seq, struct mddev *mddev)
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 4602fc57c961..ede2461e79c5 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -34,6 +34,7 @@
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/delay.h> 35#include <linux/delay.h>
36#include <linux/blkdev.h> 36#include <linux/blkdev.h>
37#include <linux/module.h>
37#include <linux/seq_file.h> 38#include <linux/seq_file.h>
38#include <linux/ratelimit.h> 39#include <linux/ratelimit.h>
39#include "md.h" 40#include "md.h"
@@ -807,7 +808,7 @@ do_sync_io:
807 pr_debug("%dB behind alloc failed, doing sync I/O\n", bio->bi_size); 808 pr_debug("%dB behind alloc failed, doing sync I/O\n", bio->bi_size);
808} 809}
809 810
810static int make_request(struct mddev *mddev, struct bio * bio) 811static void make_request(struct mddev *mddev, struct bio * bio)
811{ 812{
812 struct r1conf *conf = mddev->private; 813 struct r1conf *conf = mddev->private;
813 struct mirror_info *mirror; 814 struct mirror_info *mirror;
@@ -892,7 +893,7 @@ read_again:
892 if (rdisk < 0) { 893 if (rdisk < 0) {
893 /* couldn't find anywhere to read from */ 894 /* couldn't find anywhere to read from */
894 raid_end_bio_io(r1_bio); 895 raid_end_bio_io(r1_bio);
895 return 0; 896 return;
896 } 897 }
897 mirror = conf->mirrors + rdisk; 898 mirror = conf->mirrors + rdisk;
898 899
@@ -950,7 +951,7 @@ read_again:
950 goto read_again; 951 goto read_again;
951 } else 952 } else
952 generic_make_request(read_bio); 953 generic_make_request(read_bio);
953 return 0; 954 return;
954 } 955 }
955 956
956 /* 957 /*
@@ -1151,8 +1152,6 @@ read_again:
1151 1152
1152 if (do_sync || !bitmap || !plugged) 1153 if (do_sync || !bitmap || !plugged)
1153 md_wakeup_thread(mddev->thread); 1154 md_wakeup_thread(mddev->thread);
1154
1155 return 0;
1156} 1155}
1157 1156
1158static void status(struct seq_file *seq, struct mddev *mddev) 1157static void status(struct seq_file *seq, struct mddev *mddev)
@@ -2193,7 +2192,6 @@ static sector_t sync_request(struct mddev *mddev, sector_t sector_nr, int *skipp
2193 bio->bi_next = NULL; 2192 bio->bi_next = NULL;
2194 bio->bi_flags &= ~(BIO_POOL_MASK-1); 2193 bio->bi_flags &= ~(BIO_POOL_MASK-1);
2195 bio->bi_flags |= 1 << BIO_UPTODATE; 2194 bio->bi_flags |= 1 << BIO_UPTODATE;
2196 bio->bi_comp_cpu = -1;
2197 bio->bi_rw = READ; 2195 bio->bi_rw = READ;
2198 bio->bi_vcnt = 0; 2196 bio->bi_vcnt = 0;
2199 bio->bi_idx = 0; 2197 bio->bi_idx = 0;
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index c025a8276dc1..685ddf325ee4 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -21,6 +21,7 @@
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/delay.h> 22#include <linux/delay.h>
23#include <linux/blkdev.h> 23#include <linux/blkdev.h>
24#include <linux/module.h>
24#include <linux/seq_file.h> 25#include <linux/seq_file.h>
25#include <linux/ratelimit.h> 26#include <linux/ratelimit.h>
26#include "md.h" 27#include "md.h"
@@ -842,7 +843,7 @@ static void unfreeze_array(struct r10conf *conf)
842 spin_unlock_irq(&conf->resync_lock); 843 spin_unlock_irq(&conf->resync_lock);
843} 844}
844 845
845static int make_request(struct mddev *mddev, struct bio * bio) 846static void make_request(struct mddev *mddev, struct bio * bio)
846{ 847{
847 struct r10conf *conf = mddev->private; 848 struct r10conf *conf = mddev->private;
848 struct mirror_info *mirror; 849 struct mirror_info *mirror;
@@ -861,7 +862,7 @@ static int make_request(struct mddev *mddev, struct bio * bio)
861 862
862 if (unlikely(bio->bi_rw & REQ_FLUSH)) { 863 if (unlikely(bio->bi_rw & REQ_FLUSH)) {
863 md_flush_request(mddev, bio); 864 md_flush_request(mddev, bio);
864 return 0; 865 return;
865 } 866 }
866 867
867 /* If this request crosses a chunk boundary, we need to 868 /* If this request crosses a chunk boundary, we need to
@@ -893,10 +894,8 @@ static int make_request(struct mddev *mddev, struct bio * bio)
893 conf->nr_waiting++; 894 conf->nr_waiting++;
894 spin_unlock_irq(&conf->resync_lock); 895 spin_unlock_irq(&conf->resync_lock);
895 896
896 if (make_request(mddev, &bp->bio1)) 897 make_request(mddev, &bp->bio1);
897 generic_make_request(&bp->bio1); 898 make_request(mddev, &bp->bio2);
898 if (make_request(mddev, &bp->bio2))
899 generic_make_request(&bp->bio2);
900 899
901 spin_lock_irq(&conf->resync_lock); 900 spin_lock_irq(&conf->resync_lock);
902 conf->nr_waiting--; 901 conf->nr_waiting--;
@@ -904,14 +903,14 @@ static int make_request(struct mddev *mddev, struct bio * bio)
904 spin_unlock_irq(&conf->resync_lock); 903 spin_unlock_irq(&conf->resync_lock);
905 904
906 bio_pair_release(bp); 905 bio_pair_release(bp);
907 return 0; 906 return;
908 bad_map: 907 bad_map:
909 printk("md/raid10:%s: make_request bug: can't convert block across chunks" 908 printk("md/raid10:%s: make_request bug: can't convert block across chunks"
910 " or bigger than %dk %llu %d\n", mdname(mddev), chunk_sects/2, 909 " or bigger than %dk %llu %d\n", mdname(mddev), chunk_sects/2,
911 (unsigned long long)bio->bi_sector, bio->bi_size >> 10); 910 (unsigned long long)bio->bi_sector, bio->bi_size >> 10);
912 911
913 bio_io_error(bio); 912 bio_io_error(bio);
914 return 0; 913 return;
915 } 914 }
916 915
917 md_write_start(mddev, bio); 916 md_write_start(mddev, bio);
@@ -954,7 +953,7 @@ read_again:
954 slot = r10_bio->read_slot; 953 slot = r10_bio->read_slot;
955 if (disk < 0) { 954 if (disk < 0) {
956 raid_end_bio_io(r10_bio); 955 raid_end_bio_io(r10_bio);
957 return 0; 956 return;
958 } 957 }
959 mirror = conf->mirrors + disk; 958 mirror = conf->mirrors + disk;
960 959
@@ -1002,7 +1001,7 @@ read_again:
1002 goto read_again; 1001 goto read_again;
1003 } else 1002 } else
1004 generic_make_request(read_bio); 1003 generic_make_request(read_bio);
1005 return 0; 1004 return;
1006 } 1005 }
1007 1006
1008 /* 1007 /*
@@ -1176,7 +1175,6 @@ retry_write:
1176 1175
1177 if (do_sync || !mddev->bitmap || !plugged) 1176 if (do_sync || !mddev->bitmap || !plugged)
1178 md_wakeup_thread(mddev->thread); 1177 md_wakeup_thread(mddev->thread);
1179 return 0;
1180} 1178}
1181 1179
1182static void status(struct seq_file *seq, struct mddev *mddev) 1180static void status(struct seq_file *seq, struct mddev *mddev)
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index f6fe053a5bed..472aedfb07cf 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -47,6 +47,7 @@
47#include <linux/kthread.h> 47#include <linux/kthread.h>
48#include <linux/raid/pq.h> 48#include <linux/raid/pq.h>
49#include <linux/async_tx.h> 49#include <linux/async_tx.h>
50#include <linux/module.h>
50#include <linux/async.h> 51#include <linux/async.h>
51#include <linux/seq_file.h> 52#include <linux/seq_file.h>
52#include <linux/cpu.h> 53#include <linux/cpu.h>
@@ -3688,7 +3689,7 @@ static struct stripe_head *__get_priority_stripe(struct r5conf *conf)
3688 return sh; 3689 return sh;
3689} 3690}
3690 3691
3691static int make_request(struct mddev *mddev, struct bio * bi) 3692static void make_request(struct mddev *mddev, struct bio * bi)
3692{ 3693{
3693 struct r5conf *conf = mddev->private; 3694 struct r5conf *conf = mddev->private;
3694 int dd_idx; 3695 int dd_idx;
@@ -3701,7 +3702,7 @@ static int make_request(struct mddev *mddev, struct bio * bi)
3701 3702
3702 if (unlikely(bi->bi_rw & REQ_FLUSH)) { 3703 if (unlikely(bi->bi_rw & REQ_FLUSH)) {
3703 md_flush_request(mddev, bi); 3704 md_flush_request(mddev, bi);
3704 return 0; 3705 return;
3705 } 3706 }
3706 3707
3707 md_write_start(mddev, bi); 3708 md_write_start(mddev, bi);
@@ -3709,7 +3710,7 @@ static int make_request(struct mddev *mddev, struct bio * bi)
3709 if (rw == READ && 3710 if (rw == READ &&
3710 mddev->reshape_position == MaxSector && 3711 mddev->reshape_position == MaxSector &&
3711 chunk_aligned_read(mddev,bi)) 3712 chunk_aligned_read(mddev,bi))
3712 return 0; 3713 return;
3713 3714
3714 logical_sector = bi->bi_sector & ~((sector_t)STRIPE_SECTORS-1); 3715 logical_sector = bi->bi_sector & ~((sector_t)STRIPE_SECTORS-1);
3715 last_sector = bi->bi_sector + (bi->bi_size>>9); 3716 last_sector = bi->bi_sector + (bi->bi_size>>9);
@@ -3844,8 +3845,6 @@ static int make_request(struct mddev *mddev, struct bio * bi)
3844 3845
3845 bio_endio(bi, 0); 3846 bio_endio(bi, 0);
3846 } 3847 }
3847
3848 return 0;
3849} 3848}
3850 3849
3851static sector_t raid5_size(struct mddev *mddev, sector_t sectors, int raid_disks); 3850static sector_t raid5_size(struct mddev *mddev, sector_t sectors, int raid_disks);
diff --git a/drivers/media/common/saa7146_core.c b/drivers/media/common/saa7146_core.c
index f5d53a202344..d6b1cf66042d 100644
--- a/drivers/media/common/saa7146_core.c
+++ b/drivers/media/common/saa7146_core.c
@@ -21,6 +21,7 @@
21#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 21#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22 22
23#include <media/saa7146.h> 23#include <media/saa7146.h>
24#include <linux/module.h>
24 25
25LIST_HEAD(saa7146_devices); 26LIST_HEAD(saa7146_devices);
26DEFINE_MUTEX(saa7146_devices_lock); 27DEFINE_MUTEX(saa7146_devices_lock);
diff --git a/drivers/media/common/saa7146_fops.c b/drivers/media/common/saa7146_fops.c
index a92546144eaa..71f8e018e564 100644
--- a/drivers/media/common/saa7146_fops.c
+++ b/drivers/media/common/saa7146_fops.c
@@ -1,6 +1,7 @@
1#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 1#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
2 2
3#include <media/saa7146_vv.h> 3#include <media/saa7146_vv.h>
4#include <linux/module.h>
4 5
5/****************************************************************************/ 6/****************************************************************************/
6/* resource management functions, shamelessly stolen from saa7134 driver */ 7/* resource management functions, shamelessly stolen from saa7134 driver */
diff --git a/drivers/media/common/saa7146_hlp.c b/drivers/media/common/saa7146_hlp.c
index 79ad73accb27..bc1f545c95cb 100644
--- a/drivers/media/common/saa7146_hlp.c
+++ b/drivers/media/common/saa7146_hlp.c
@@ -1,6 +1,7 @@
1#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 1#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
2 2
3#include <linux/kernel.h> 3#include <linux/kernel.h>
4#include <linux/export.h>
4#include <media/saa7146_vv.h> 5#include <media/saa7146_vv.h>
5 6
6static void calculate_output_format_register(struct saa7146_dev* saa, u32 palette, u32* clip_format) 7static void calculate_output_format_register(struct saa7146_dev* saa, u32 palette, u32* clip_format)
diff --git a/drivers/media/common/saa7146_video.c b/drivers/media/common/saa7146_video.c
index 384b358d3037..ce30533fd972 100644
--- a/drivers/media/common/saa7146_video.c
+++ b/drivers/media/common/saa7146_video.c
@@ -2,6 +2,7 @@
2 2
3#include <media/saa7146_vv.h> 3#include <media/saa7146_vv.h>
4#include <media/v4l2-chip-ident.h> 4#include <media/v4l2-chip-ident.h>
5#include <linux/module.h>
5 6
6static int max_memory = 32; 7static int max_memory = 32;
7 8
diff --git a/drivers/media/common/tuners/tuner-types.c b/drivers/media/common/tuners/tuner-types.c
index 94a603a60842..e13683bab6b3 100644
--- a/drivers/media/common/tuners/tuner-types.c
+++ b/drivers/media/common/tuners/tuner-types.c
@@ -5,6 +5,7 @@
5 */ 5 */
6 6
7#include <linux/i2c.h> 7#include <linux/i2c.h>
8#include <linux/module.h>
8#include <media/tuner.h> 9#include <media/tuner.h>
9#include <media/tuner-types.h> 10#include <media/tuner-types.h>
10 11
diff --git a/drivers/media/dvb/ddbridge/Makefile b/drivers/media/dvb/ddbridge/Makefile
index cf7214edf65f..38019bafb862 100644
--- a/drivers/media/dvb/ddbridge/Makefile
+++ b/drivers/media/dvb/ddbridge/Makefile
@@ -11,4 +11,4 @@ ccflags-y += -Idrivers/media/dvb/frontends/
11ccflags-y += -Idrivers/media/common/tuners/ 11ccflags-y += -Idrivers/media/common/tuners/
12 12
13# For the staging CI driver cxd2099 13# For the staging CI driver cxd2099
14ccflags-y += -Idrivers/staging/cxd2099/ 14ccflags-y += -Idrivers/staging/media/cxd2099/
diff --git a/drivers/media/dvb/dvb-usb/Makefile b/drivers/media/dvb/dvb-usb/Makefile
index 7d0710bb1978..26c8b9e57050 100644
--- a/drivers/media/dvb/dvb-usb/Makefile
+++ b/drivers/media/dvb/dvb-usb/Makefile
@@ -102,6 +102,7 @@ obj-$(CONFIG_DVB_USB_IT913X) += dvb-usb-it913x.o
102 102
103dvb-usb-mxl111sf-objs = mxl111sf.o mxl111sf-phy.o mxl111sf-i2c.o mxl111sf-gpio.o 103dvb-usb-mxl111sf-objs = mxl111sf.o mxl111sf-phy.o mxl111sf-i2c.o mxl111sf-gpio.o
104obj-$(CONFIG_DVB_USB_MXL111SF) += dvb-usb-mxl111sf.o 104obj-$(CONFIG_DVB_USB_MXL111SF) += dvb-usb-mxl111sf.o
105obj-$(CONFIG_DVB_USB_MXL111SF) += mxl111sf-demod.o
105obj-$(CONFIG_DVB_USB_MXL111SF) += mxl111sf-tuner.o 106obj-$(CONFIG_DVB_USB_MXL111SF) += mxl111sf-tuner.o
106 107
107ccflags-y += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/ 108ccflags-y += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
index 2ad33ba92ba2..2d08c9b5128a 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
@@ -37,6 +37,7 @@
37#define USB_VID_HAUPPAUGE 0x2040 37#define USB_VID_HAUPPAUGE 0x2040
38#define USB_VID_HYPER_PALTEK 0x1025 38#define USB_VID_HYPER_PALTEK 0x1025
39#define USB_VID_INTEL 0x8086 39#define USB_VID_INTEL 0x8086
40#define USB_VID_ITETECH 0x048d
40#define USB_VID_KWORLD 0xeb2a 41#define USB_VID_KWORLD 0xeb2a
41#define USB_VID_KWORLD_2 0x1b80 42#define USB_VID_KWORLD_2 0x1b80
42#define USB_VID_KYE 0x0458 43#define USB_VID_KYE 0x0458
@@ -126,6 +127,7 @@
126#define USB_PID_GRANDTEC_DVBT_USB_COLD 0x0fa0 127#define USB_PID_GRANDTEC_DVBT_USB_COLD 0x0fa0
127#define USB_PID_GRANDTEC_DVBT_USB_WARM 0x0fa1 128#define USB_PID_GRANDTEC_DVBT_USB_WARM 0x0fa1
128#define USB_PID_INTEL_CE9500 0x9500 129#define USB_PID_INTEL_CE9500 0x9500
130#define USB_PID_ITETECH_IT9135 0x9135
129#define USB_PID_KWORLD_399U 0xe399 131#define USB_PID_KWORLD_399U 0xe399
130#define USB_PID_KWORLD_399U_2 0xe400 132#define USB_PID_KWORLD_399U_2 0xe400
131#define USB_PID_KWORLD_395U 0xe396 133#define USB_PID_KWORLD_395U 0xe396
diff --git a/drivers/media/dvb/dvb-usb/it913x.c b/drivers/media/dvb/dvb-usb/it913x.c
index f027a2c1c3e8..c46226187143 100644
--- a/drivers/media/dvb/dvb-usb/it913x.c
+++ b/drivers/media/dvb/dvb-usb/it913x.c
@@ -60,6 +60,17 @@ struct it913x_state {
60 u8 id; 60 u8 id;
61}; 61};
62 62
63struct ite_config {
64 u8 chip_ver;
65 u16 chip_type;
66 u32 firmware;
67 u8 tuner_id_0;
68 u8 tuner_id_1;
69 u8 dual_mode;
70};
71
72struct ite_config it913x_config;
73
63static int it913x_bulk_write(struct usb_device *dev, 74static int it913x_bulk_write(struct usb_device *dev,
64 u8 *snd, int len, u8 pipe) 75 u8 *snd, int len, u8 pipe)
65{ 76{
@@ -191,18 +202,23 @@ static int it913x_read_reg(struct usb_device *udev, u32 reg)
191static u32 it913x_query(struct usb_device *udev, u8 pro) 202static u32 it913x_query(struct usb_device *udev, u8 pro)
192{ 203{
193 int ret; 204 int ret;
194 u32 res = 0;
195 u8 data[4]; 205 u8 data[4];
196 ret = it913x_io(udev, READ_LONG, pro, CMD_DEMOD_READ, 206 ret = it913x_io(udev, READ_LONG, pro, CMD_DEMOD_READ,
197 0x1222, 0, &data[0], 1); 207 0x1222, 0, &data[0], 3);
198 if (data[0] == 0x1) { 208
199 ret = it913x_io(udev, READ_SHORT, pro, 209 it913x_config.chip_ver = data[0];
210 it913x_config.chip_type = (u16)(data[2] << 8) + data[1];
211
212 info("Chip Version=%02x Chip Type=%04x", it913x_config.chip_ver,
213 it913x_config.chip_type);
214
215 ret |= it913x_io(udev, READ_SHORT, pro,
200 CMD_QUERYINFO, 0, 0x1, &data[0], 4); 216 CMD_QUERYINFO, 0, 0x1, &data[0], 4);
201 res = (data[0] << 24) + (data[1] << 16) + 217
218 it913x_config.firmware = (data[0] << 24) + (data[1] << 16) +
202 (data[2] << 8) + data[3]; 219 (data[2] << 8) + data[3];
203 }
204 220
205 return (ret < 0) ? 0 : res; 221 return (ret < 0) ? 0 : it913x_config.firmware;
206} 222}
207 223
208static int it913x_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff) 224static int it913x_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
@@ -336,26 +352,35 @@ static int it913x_identify_state(struct usb_device *udev,
336 int *cold) 352 int *cold)
337{ 353{
338 int ret = 0, firm_no; 354 int ret = 0, firm_no;
339 u8 reg, adap, ep, tun0, tun1; 355 u8 reg, remote;
340 356
341 firm_no = it913x_return_status(udev); 357 firm_no = it913x_return_status(udev);
342 358
343 ep = it913x_read_reg(udev, 0x49ac); 359 /* checnk for dual mode */
344 adap = it913x_read_reg(udev, 0x49c5); 360 it913x_config.dual_mode = it913x_read_reg(udev, 0x49c5);
345 tun0 = it913x_read_reg(udev, 0x49d0); 361
346 info("No. Adapters=%x Endpoints=%x Tuner Type=%x", adap, ep, tun0); 362 /* TODO different remotes */
363 remote = it913x_read_reg(udev, 0x49ac); /* Remote */
364 if (remote == 0)
365 props->rc.core.rc_codes = NULL;
366
367 /* TODO at the moment tuner_id is always assigned to 0x38 */
368 it913x_config.tuner_id_0 = it913x_read_reg(udev, 0x49d0);
369
370 info("Dual mode=%x Remote=%x Tuner Type=%x", it913x_config.dual_mode
371 , remote, it913x_config.tuner_id_0);
347 372
348 if (firm_no > 0) { 373 if (firm_no > 0) {
349 *cold = 0; 374 *cold = 0;
350 return 0; 375 return 0;
351 } 376 }
352 377
353 if (adap > 2) { 378 if (it913x_config.dual_mode) {
354 tun1 = it913x_read_reg(udev, 0x49e0); 379 it913x_config.tuner_id_1 = it913x_read_reg(udev, 0x49e0);
355 ret = it913x_wr_reg(udev, DEV_0, GPIOH1_EN, 0x1); 380 ret = it913x_wr_reg(udev, DEV_0, GPIOH1_EN, 0x1);
356 ret |= it913x_wr_reg(udev, DEV_0, GPIOH1_ON, 0x1); 381 ret |= it913x_wr_reg(udev, DEV_0, GPIOH1_ON, 0x1);
357 ret |= it913x_wr_reg(udev, DEV_0, GPIOH1_O, 0x1); 382 ret |= it913x_wr_reg(udev, DEV_0, GPIOH1_O, 0x1);
358 msleep(50); /* Delay noticed reset cycle ? */ 383 msleep(50);
359 ret |= it913x_wr_reg(udev, DEV_0, GPIOH1_O, 0x0); 384 ret |= it913x_wr_reg(udev, DEV_0, GPIOH1_O, 0x0);
360 msleep(50); 385 msleep(50);
361 reg = it913x_read_reg(udev, GPIOH1_O); 386 reg = it913x_read_reg(udev, GPIOH1_O);
@@ -366,14 +391,19 @@ static int it913x_identify_state(struct usb_device *udev,
366 ret = it913x_wr_reg(udev, DEV_0, 391 ret = it913x_wr_reg(udev, DEV_0,
367 GPIOH1_O, 0x0); 392 GPIOH1_O, 0x0);
368 } 393 }
394 props->num_adapters = 2;
369 } else 395 } else
370 props->num_adapters = 1; 396 props->num_adapters = 1;
371 397
372 reg = it913x_read_reg(udev, IO_MUX_POWER_CLK); 398 reg = it913x_read_reg(udev, IO_MUX_POWER_CLK);
373 399
374 ret |= it913x_wr_reg(udev, DEV_0, 0x4bfb, CHIP2_I2C_ADDR); 400 if (it913x_config.dual_mode) {
375 401 ret |= it913x_wr_reg(udev, DEV_0, 0x4bfb, CHIP2_I2C_ADDR);
376 ret |= it913x_wr_reg(udev, DEV_0, CLK_O_EN, 0x1); 402 ret |= it913x_wr_reg(udev, DEV_0, CLK_O_EN, 0x1);
403 } else {
404 ret |= it913x_wr_reg(udev, DEV_0, 0x4bfb, 0x0);
405 ret |= it913x_wr_reg(udev, DEV_0, CLK_O_EN, 0x0);
406 }
377 407
378 *cold = 1; 408 *cold = 1;
379 409
@@ -403,13 +433,11 @@ static int it913x_download_firmware(struct usb_device *udev,
403 const struct firmware *fw) 433 const struct firmware *fw)
404{ 434{
405 int ret = 0, i; 435 int ret = 0, i;
406 u8 packet_size, dlen, tun1; 436 u8 packet_size, dlen;
407 u8 *fw_data; 437 u8 *fw_data;
408 438
409 packet_size = 0x29; 439 packet_size = 0x29;
410 440
411 tun1 = it913x_read_reg(udev, 0x49e0);
412
413 ret = it913x_wr_reg(udev, DEV_0, I2C_CLK, I2C_CLK_100); 441 ret = it913x_wr_reg(udev, DEV_0, I2C_CLK, I2C_CLK_100);
414 442
415 info("FRM Starting Firmware Download"); 443 info("FRM Starting Firmware Download");
@@ -444,11 +472,12 @@ static int it913x_download_firmware(struct usb_device *udev,
444 ret |= it913x_wr_reg(udev, DEV_0, I2C_CLK, I2C_CLK_400); 472 ret |= it913x_wr_reg(udev, DEV_0, I2C_CLK, I2C_CLK_400);
445 473
446 /* Tuner function */ 474 /* Tuner function */
447 ret |= it913x_wr_reg(udev, DEV_0_DMOD , 0xec4c, 0xa0); 475 if (it913x_config.dual_mode)
476 ret |= it913x_wr_reg(udev, DEV_0_DMOD , 0xec4c, 0xa0);
448 477
449 ret |= it913x_wr_reg(udev, DEV_0, PADODPU, 0x0); 478 ret |= it913x_wr_reg(udev, DEV_0, PADODPU, 0x0);
450 ret |= it913x_wr_reg(udev, DEV_0, AGC_O_D, 0x0); 479 ret |= it913x_wr_reg(udev, DEV_0, AGC_O_D, 0x0);
451 if (tun1 > 0) { 480 if (it913x_config.dual_mode) {
452 ret |= it913x_wr_reg(udev, DEV_1, PADODPU, 0x0); 481 ret |= it913x_wr_reg(udev, DEV_1, PADODPU, 0x0);
453 ret |= it913x_wr_reg(udev, DEV_1, AGC_O_D, 0x0); 482 ret |= it913x_wr_reg(udev, DEV_1, AGC_O_D, 0x0);
454 } 483 }
@@ -475,9 +504,28 @@ static int it913x_frontend_attach(struct dvb_usb_adapter *adap)
475 u8 adf = it913x_read_reg(udev, IO_MUX_POWER_CLK); 504 u8 adf = it913x_read_reg(udev, IO_MUX_POWER_CLK);
476 u8 adap_addr = I2C_BASE_ADDR + (adap->id << 5); 505 u8 adap_addr = I2C_BASE_ADDR + (adap->id << 5);
477 u16 ep_size = adap->props.fe[0].stream.u.bulk.buffersize; 506 u16 ep_size = adap->props.fe[0].stream.u.bulk.buffersize;
507 u8 tuner_id, tuner_type;
508
509 if (adap->id == 0)
510 tuner_id = it913x_config.tuner_id_0;
511 else
512 tuner_id = it913x_config.tuner_id_1;
513
514 /* TODO we always use IT9137 possible references here*/
515 /* Documentation suggests don't care */
516 switch (tuner_id) {
517 case 0x51:
518 case 0x52:
519 case 0x60:
520 case 0x61:
521 case 0x62:
522 default:
523 case 0x38:
524 tuner_type = IT9137;
525 }
478 526
479 adap->fe_adap[0].fe = dvb_attach(it913x_fe_attach, 527 adap->fe_adap[0].fe = dvb_attach(it913x_fe_attach,
480 &adap->dev->i2c_adap, adap_addr, adf, IT9137); 528 &adap->dev->i2c_adap, adap_addr, adf, tuner_type);
481 529
482 if (adap->id == 0 && adap->fe_adap[0].fe) { 530 if (adap->id == 0 && adap->fe_adap[0].fe) {
483 ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2_SW_RST, 0x1); 531 ret = it913x_wr_reg(udev, DEV_0_DMOD, MP2_SW_RST, 0x1);
@@ -533,6 +581,7 @@ static int it913x_probe(struct usb_interface *intf,
533 581
534static struct usb_device_id it913x_table[] = { 582static struct usb_device_id it913x_table[] = {
535 { USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_UB499_2T_T09) }, 583 { USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_UB499_2T_T09) },
584 { USB_DEVICE(USB_VID_ITETECH, USB_PID_ITETECH_IT9135) },
536 {} /* Terminating entry */ 585 {} /* Terminating entry */
537}; 586};
538 587
@@ -608,12 +657,14 @@ static struct dvb_usb_device_properties it913x_properties = {
608 .rc_codes = RC_MAP_KWORLD_315U, 657 .rc_codes = RC_MAP_KWORLD_315U,
609 }, 658 },
610 .i2c_algo = &it913x_i2c_algo, 659 .i2c_algo = &it913x_i2c_algo,
611 .num_device_descs = 1, 660 .num_device_descs = 2,
612 .devices = { 661 .devices = {
613 { "Kworld UB499-2T T09(IT9137)", 662 { "Kworld UB499-2T T09(IT9137)",
614 { &it913x_table[0], NULL }, 663 { &it913x_table[0], NULL },
615 }, 664 },
616 665 { "ITE 9135 Generic",
666 { &it913x_table[1], NULL },
667 },
617 } 668 }
618}; 669};
619 670
@@ -647,5 +698,5 @@ module_exit(it913x_module_exit);
647 698
648MODULE_AUTHOR("Malcolm Priestley <tvboxspy@gmail.com>"); 699MODULE_AUTHOR("Malcolm Priestley <tvboxspy@gmail.com>");
649MODULE_DESCRIPTION("it913x USB 2 Driver"); 700MODULE_DESCRIPTION("it913x USB 2 Driver");
650MODULE_VERSION("1.06"); 701MODULE_VERSION("1.07");
651MODULE_LICENSE("GPL"); 702MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/mxl111sf-demod.c b/drivers/media/dvb/dvb-usb/mxl111sf-demod.c
new file mode 100644
index 000000000000..d1f58371c711
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/mxl111sf-demod.c
@@ -0,0 +1,614 @@
1/*
2 * mxl111sf-demod.c - driver for the MaxLinear MXL111SF DVB-T demodulator
3 *
4 * Copyright (C) 2010 Michael Krufky <mkrufky@kernellabs.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21#include "mxl111sf-demod.h"
22#include "mxl111sf-reg.h"
23
24/* debug */
25static int mxl111sf_demod_debug;
26module_param_named(debug, mxl111sf_demod_debug, int, 0644);
27MODULE_PARM_DESC(debug, "set debugging level (1=info (or-able)).");
28
29#define mxl_dbg(fmt, arg...) \
30 if (mxl111sf_demod_debug) \
31 mxl_printk(KERN_DEBUG, fmt, ##arg)
32
33/* ------------------------------------------------------------------------ */
34
35struct mxl111sf_demod_state {
36 struct mxl111sf_state *mxl_state;
37
38 struct mxl111sf_demod_config *cfg;
39
40 struct dvb_frontend fe;
41};
42
43/* ------------------------------------------------------------------------ */
44
45static int mxl111sf_demod_read_reg(struct mxl111sf_demod_state *state,
46 u8 addr, u8 *data)
47{
48 return (state->cfg->read_reg) ?
49 state->cfg->read_reg(state->mxl_state, addr, data) :
50 -EINVAL;
51}
52
53static int mxl111sf_demod_write_reg(struct mxl111sf_demod_state *state,
54 u8 addr, u8 data)
55{
56 return (state->cfg->write_reg) ?
57 state->cfg->write_reg(state->mxl_state, addr, data) :
58 -EINVAL;
59}
60
61static
62int mxl111sf_demod_program_regs(struct mxl111sf_demod_state *state,
63 struct mxl111sf_reg_ctrl_info *ctrl_reg_info)
64{
65 return (state->cfg->program_regs) ?
66 state->cfg->program_regs(state->mxl_state, ctrl_reg_info) :
67 -EINVAL;
68}
69
70/* ------------------------------------------------------------------------ */
71/* TPS */
72
73static
74int mxl1x1sf_demod_get_tps_code_rate(struct mxl111sf_demod_state *state,
75 fe_code_rate_t *code_rate)
76{
77 u8 val;
78 int ret = mxl111sf_demod_read_reg(state, V6_CODE_RATE_TPS_REG, &val);
79 /* bit<2:0> - 000:1/2, 001:2/3, 010:3/4, 011:5/6, 100:7/8 */
80 if (mxl_fail(ret))
81 goto fail;
82
83 switch (val & V6_CODE_RATE_TPS_MASK) {
84 case 0:
85 *code_rate = FEC_1_2;
86 break;
87 case 1:
88 *code_rate = FEC_2_3;
89 break;
90 case 2:
91 *code_rate = FEC_3_4;
92 break;
93 case 3:
94 *code_rate = FEC_5_6;
95 break;
96 case 4:
97 *code_rate = FEC_7_8;
98 break;
99 }
100fail:
101 return ret;
102}
103
104static
105int mxl1x1sf_demod_get_tps_constellation(struct mxl111sf_demod_state *state,
106 fe_modulation_t *constellation)
107{
108 u8 val;
109 int ret = mxl111sf_demod_read_reg(state, V6_MODORDER_TPS_REG, &val);
110 /* Constellation, 00 : QPSK, 01 : 16QAM, 10:64QAM */
111 if (mxl_fail(ret))
112 goto fail;
113
114 switch ((val & V6_PARAM_CONSTELLATION_MASK) >> 4) {
115 case 0:
116 *constellation = QPSK;
117 break;
118 case 1:
119 *constellation = QAM_16;
120 break;
121 case 2:
122 *constellation = QAM_64;
123 break;
124 }
125fail:
126 return ret;
127}
128
129static
130int mxl1x1sf_demod_get_tps_guard_fft_mode(struct mxl111sf_demod_state *state,
131 fe_transmit_mode_t *fft_mode)
132{
133 u8 val;
134 int ret = mxl111sf_demod_read_reg(state, V6_MODE_TPS_REG, &val);
135 /* FFT Mode, 00:2K, 01:8K, 10:4K */
136 if (mxl_fail(ret))
137 goto fail;
138
139 switch ((val & V6_PARAM_FFT_MODE_MASK) >> 2) {
140 case 0:
141 *fft_mode = TRANSMISSION_MODE_2K;
142 break;
143 case 1:
144 *fft_mode = TRANSMISSION_MODE_8K;
145 break;
146 case 2:
147 *fft_mode = TRANSMISSION_MODE_4K;
148 break;
149 }
150fail:
151 return ret;
152}
153
154static
155int mxl1x1sf_demod_get_tps_guard_interval(struct mxl111sf_demod_state *state,
156 fe_guard_interval_t *guard)
157{
158 u8 val;
159 int ret = mxl111sf_demod_read_reg(state, V6_CP_TPS_REG, &val);
160 /* 00:1/32, 01:1/16, 10:1/8, 11:1/4 */
161 if (mxl_fail(ret))
162 goto fail;
163
164 switch ((val & V6_PARAM_GI_MASK) >> 4) {
165 case 0:
166 *guard = GUARD_INTERVAL_1_32;
167 break;
168 case 1:
169 *guard = GUARD_INTERVAL_1_16;
170 break;
171 case 2:
172 *guard = GUARD_INTERVAL_1_8;
173 break;
174 case 3:
175 *guard = GUARD_INTERVAL_1_4;
176 break;
177 }
178fail:
179 return ret;
180}
181
182static
183int mxl1x1sf_demod_get_tps_hierarchy(struct mxl111sf_demod_state *state,
184 fe_hierarchy_t *hierarchy)
185{
186 u8 val;
187 int ret = mxl111sf_demod_read_reg(state, V6_TPS_HIERACHY_REG, &val);
188 /* bit<6:4> - 000:Non hierarchy, 001:1, 010:2, 011:4 */
189 if (mxl_fail(ret))
190 goto fail;
191
192 switch ((val & V6_TPS_HIERARCHY_INFO_MASK) >> 6) {
193 case 0:
194 *hierarchy = HIERARCHY_NONE;
195 break;
196 case 1:
197 *hierarchy = HIERARCHY_1;
198 break;
199 case 2:
200 *hierarchy = HIERARCHY_2;
201 break;
202 case 3:
203 *hierarchy = HIERARCHY_4;
204 break;
205 }
206fail:
207 return ret;
208}
209
210/* ------------------------------------------------------------------------ */
211/* LOCKS */
212
213static
214int mxl1x1sf_demod_get_sync_lock_status(struct mxl111sf_demod_state *state,
215 int *sync_lock)
216{
217 u8 val = 0;
218 int ret = mxl111sf_demod_read_reg(state, V6_SYNC_LOCK_REG, &val);
219 if (mxl_fail(ret))
220 goto fail;
221 *sync_lock = (val & SYNC_LOCK_MASK) >> 4;
222fail:
223 return ret;
224}
225
226static
227int mxl1x1sf_demod_get_rs_lock_status(struct mxl111sf_demod_state *state,
228 int *rs_lock)
229{
230 u8 val = 0;
231 int ret = mxl111sf_demod_read_reg(state, V6_RS_LOCK_DET_REG, &val);
232 if (mxl_fail(ret))
233 goto fail;
234 *rs_lock = (val & RS_LOCK_DET_MASK) >> 3;
235fail:
236 return ret;
237}
238
239static
240int mxl1x1sf_demod_get_tps_lock_status(struct mxl111sf_demod_state *state,
241 int *tps_lock)
242{
243 u8 val = 0;
244 int ret = mxl111sf_demod_read_reg(state, V6_TPS_LOCK_REG, &val);
245 if (mxl_fail(ret))
246 goto fail;
247 *tps_lock = (val & V6_PARAM_TPS_LOCK_MASK) >> 6;
248fail:
249 return ret;
250}
251
252static
253int mxl1x1sf_demod_get_fec_lock_status(struct mxl111sf_demod_state *state,
254 int *fec_lock)
255{
256 u8 val = 0;
257 int ret = mxl111sf_demod_read_reg(state, V6_IRQ_STATUS_REG, &val);
258 if (mxl_fail(ret))
259 goto fail;
260 *fec_lock = (val & IRQ_MASK_FEC_LOCK) >> 4;
261fail:
262 return ret;
263}
264
265#if 0
266static
267int mxl1x1sf_demod_get_cp_lock_status(struct mxl111sf_demod_state *state,
268 int *cp_lock)
269{
270 u8 val = 0;
271 int ret = mxl111sf_demod_read_reg(state, V6_CP_LOCK_DET_REG, &val);
272 if (mxl_fail(ret))
273 goto fail;
274 *cp_lock = (val & V6_CP_LOCK_DET_MASK) >> 2;
275fail:
276 return ret;
277}
278#endif
279
280static int mxl1x1sf_demod_reset_irq_status(struct mxl111sf_demod_state *state)
281{
282 return mxl111sf_demod_write_reg(state, 0x0e, 0xff);
283}
284
285/* ------------------------------------------------------------------------ */
286
287static int mxl111sf_demod_set_frontend(struct dvb_frontend *fe,
288 struct dvb_frontend_parameters *param)
289{
290 struct mxl111sf_demod_state *state = fe->demodulator_priv;
291 int ret = 0;
292
293 struct mxl111sf_reg_ctrl_info phy_pll_patch[] = {
294 {0x00, 0xff, 0x01}, /* change page to 1 */
295 {0x40, 0xff, 0x05},
296 {0x40, 0xff, 0x01},
297 {0x41, 0xff, 0xca},
298 {0x41, 0xff, 0xc0},
299 {0x00, 0xff, 0x00}, /* change page to 0 */
300 {0, 0, 0}
301 };
302
303 mxl_dbg("()");
304
305 if (fe->ops.tuner_ops.set_params) {
306 ret = fe->ops.tuner_ops.set_params(fe, param);
307 if (mxl_fail(ret))
308 goto fail;
309 msleep(50);
310 }
311 ret = mxl111sf_demod_program_regs(state, phy_pll_patch);
312 mxl_fail(ret);
313 msleep(50);
314 ret = mxl1x1sf_demod_reset_irq_status(state);
315 mxl_fail(ret);
316 msleep(100);
317fail:
318 return ret;
319}
320
321/* ------------------------------------------------------------------------ */
322
323#if 0
324/* resets TS Packet error count */
325/* After setting 7th bit of V5_PER_COUNT_RESET_REG, it should be reset to 0. */
326static
327int mxl1x1sf_demod_reset_packet_error_count(struct mxl111sf_demod_state *state)
328{
329 struct mxl111sf_reg_ctrl_info reset_per_count[] = {
330 {0x20, 0x01, 0x01},
331 {0x20, 0x01, 0x00},
332 {0, 0, 0}
333 };
334 return mxl111sf_demod_program_regs(state, reset_per_count);
335}
336#endif
337
338/* returns TS Packet error count */
339/* PER Count = FEC_PER_COUNT * (2 ** (FEC_PER_SCALE * 4)) */
340static int mxl111sf_demod_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
341{
342 struct mxl111sf_demod_state *state = fe->demodulator_priv;
343 u32 fec_per_count, fec_per_scale;
344 u8 val;
345 int ret;
346
347 *ucblocks = 0;
348
349 /* FEC_PER_COUNT Register */
350 ret = mxl111sf_demod_read_reg(state, V6_FEC_PER_COUNT_REG, &val);
351 if (mxl_fail(ret))
352 goto fail;
353
354 fec_per_count = val;
355
356 /* FEC_PER_SCALE Register */
357 ret = mxl111sf_demod_read_reg(state, V6_FEC_PER_SCALE_REG, &val);
358 if (mxl_fail(ret))
359 goto fail;
360
361 val &= V6_FEC_PER_SCALE_MASK;
362 val *= 4;
363
364 fec_per_scale = 1 << val;
365
366 fec_per_count *= fec_per_scale;
367
368 *ucblocks = fec_per_count;
369fail:
370 return ret;
371}
372
373#ifdef MXL111SF_DEMOD_ENABLE_CALCULATIONS
374/* FIXME: leaving this enabled breaks the build on some architectures,
375 * and we shouldn't have any floating point math in the kernel, anyway.
376 *
377 * These macros need to be re-written, but it's harmless to simply
378 * return zero for now. */
379#define CALCULATE_BER(avg_errors, count) \
380 ((u32)(avg_errors * 4)/(count*64*188*8))
381#define CALCULATE_SNR(data) \
382 ((u32)((10 * (u32)data / 64) - 2.5))
383#else
384#define CALCULATE_BER(avg_errors, count) 0
385#define CALCULATE_SNR(data) 0
386#endif
387
388static int mxl111sf_demod_read_ber(struct dvb_frontend *fe, u32 *ber)
389{
390 struct mxl111sf_demod_state *state = fe->demodulator_priv;
391 u8 val1, val2, val3;
392 int ret;
393
394 *ber = 0;
395
396 ret = mxl111sf_demod_read_reg(state, V6_RS_AVG_ERRORS_LSB_REG, &val1);
397 if (mxl_fail(ret))
398 goto fail;
399 ret = mxl111sf_demod_read_reg(state, V6_RS_AVG_ERRORS_MSB_REG, &val2);
400 if (mxl_fail(ret))
401 goto fail;
402 ret = mxl111sf_demod_read_reg(state, V6_N_ACCUMULATE_REG, &val3);
403 if (mxl_fail(ret))
404 goto fail;
405
406 *ber = CALCULATE_BER((val1 | (val2 << 8)), val3);
407fail:
408 return ret;
409}
410
411static int mxl111sf_demod_calc_snr(struct mxl111sf_demod_state *state,
412 u16 *snr)
413{
414 u8 val1, val2;
415 int ret;
416
417 *snr = 0;
418
419 ret = mxl111sf_demod_read_reg(state, V6_SNR_RB_LSB_REG, &val1);
420 if (mxl_fail(ret))
421 goto fail;
422 ret = mxl111sf_demod_read_reg(state, V6_SNR_RB_MSB_REG, &val2);
423 if (mxl_fail(ret))
424 goto fail;
425
426 *snr = CALCULATE_SNR(val1 | ((val2 & 0x03) << 8));
427fail:
428 return ret;
429}
430
431static int mxl111sf_demod_read_snr(struct dvb_frontend *fe, u16 *snr)
432{
433 struct mxl111sf_demod_state *state = fe->demodulator_priv;
434
435 int ret = mxl111sf_demod_calc_snr(state, snr);
436 if (mxl_fail(ret))
437 goto fail;
438
439 *snr /= 10; /* 0.1 dB */
440fail:
441 return ret;
442}
443
444static int mxl111sf_demod_read_status(struct dvb_frontend *fe,
445 fe_status_t *status)
446{
447 struct mxl111sf_demod_state *state = fe->demodulator_priv;
448 int ret, locked, cr_lock, sync_lock, fec_lock;
449
450 *status = 0;
451
452 ret = mxl1x1sf_demod_get_rs_lock_status(state, &locked);
453 if (mxl_fail(ret))
454 goto fail;
455 ret = mxl1x1sf_demod_get_tps_lock_status(state, &cr_lock);
456 if (mxl_fail(ret))
457 goto fail;
458 ret = mxl1x1sf_demod_get_sync_lock_status(state, &sync_lock);
459 if (mxl_fail(ret))
460 goto fail;
461 ret = mxl1x1sf_demod_get_fec_lock_status(state, &fec_lock);
462 if (mxl_fail(ret))
463 goto fail;
464
465 if (locked)
466 *status |= FE_HAS_SIGNAL;
467 if (cr_lock)
468 *status |= FE_HAS_CARRIER;
469 if (sync_lock)
470 *status |= FE_HAS_SYNC;
471 if (fec_lock) /* false positives? */
472 *status |= FE_HAS_VITERBI;
473
474 if ((locked) && (cr_lock) && (sync_lock))
475 *status |= FE_HAS_LOCK;
476fail:
477 return ret;
478}
479
480static int mxl111sf_demod_read_signal_strength(struct dvb_frontend *fe,
481 u16 *signal_strength)
482{
483 struct mxl111sf_demod_state *state = fe->demodulator_priv;
484 fe_modulation_t constellation;
485 u16 snr;
486
487 mxl111sf_demod_calc_snr(state, &snr);
488 mxl1x1sf_demod_get_tps_constellation(state, &constellation);
489
490 switch (constellation) {
491 case QPSK:
492 *signal_strength = (snr >= 1300) ?
493 min(65535, snr * 44) : snr * 38;
494 break;
495 case QAM_16:
496 *signal_strength = (snr >= 1500) ?
497 min(65535, snr * 38) : snr * 33;
498 break;
499 case QAM_64:
500 *signal_strength = (snr >= 2000) ?
501 min(65535, snr * 29) : snr * 25;
502 break;
503 default:
504 *signal_strength = 0;
505 return -EINVAL;
506 }
507
508 return 0;
509}
510
511static int mxl111sf_demod_get_frontend(struct dvb_frontend *fe,
512 struct dvb_frontend_parameters *p)
513{
514 struct mxl111sf_demod_state *state = fe->demodulator_priv;
515
516 mxl_dbg("()");
517#if 0
518 p->inversion = /* FIXME */ ? INVERSION_ON : INVERSION_OFF;
519#endif
520 if (fe->ops.tuner_ops.get_bandwidth)
521 fe->ops.tuner_ops.get_bandwidth(fe, &p->u.ofdm.bandwidth);
522 if (fe->ops.tuner_ops.get_frequency)
523 fe->ops.tuner_ops.get_frequency(fe, &p->frequency);
524 mxl1x1sf_demod_get_tps_code_rate(state, &p->u.ofdm.code_rate_HP);
525 mxl1x1sf_demod_get_tps_code_rate(state, &p->u.ofdm.code_rate_LP);
526 mxl1x1sf_demod_get_tps_constellation(state, &p->u.ofdm.constellation);
527 mxl1x1sf_demod_get_tps_guard_fft_mode(state,
528 &p->u.ofdm.transmission_mode);
529 mxl1x1sf_demod_get_tps_guard_interval(state,
530 &p->u.ofdm.guard_interval);
531 mxl1x1sf_demod_get_tps_hierarchy(state,
532 &p->u.ofdm.hierarchy_information);
533
534 return 0;
535}
536
537static
538int mxl111sf_demod_get_tune_settings(struct dvb_frontend *fe,
539 struct dvb_frontend_tune_settings *tune)
540{
541 tune->min_delay_ms = 1000;
542 return 0;
543}
544
545static void mxl111sf_demod_release(struct dvb_frontend *fe)
546{
547 struct mxl111sf_demod_state *state = fe->demodulator_priv;
548 mxl_dbg("()");
549 kfree(state);
550 fe->demodulator_priv = NULL;
551}
552
553static struct dvb_frontend_ops mxl111sf_demod_ops = {
554
555 .info = {
556 .name = "MaxLinear MxL111SF DVB-T demodulator",
557 .type = FE_OFDM,
558 .frequency_min = 177000000,
559 .frequency_max = 858000000,
560 .frequency_stepsize = 166666,
561 .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
562 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
563 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 |
564 FE_CAN_QAM_AUTO |
565 FE_CAN_HIERARCHY_AUTO | FE_CAN_GUARD_INTERVAL_AUTO |
566 FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_RECOVER
567 },
568 .release = mxl111sf_demod_release,
569#if 0
570 .init = mxl111sf_init,
571 .i2c_gate_ctrl = mxl111sf_i2c_gate_ctrl,
572#endif
573 .set_frontend = mxl111sf_demod_set_frontend,
574 .get_frontend = mxl111sf_demod_get_frontend,
575 .get_tune_settings = mxl111sf_demod_get_tune_settings,
576 .read_status = mxl111sf_demod_read_status,
577 .read_signal_strength = mxl111sf_demod_read_signal_strength,
578 .read_ber = mxl111sf_demod_read_ber,
579 .read_snr = mxl111sf_demod_read_snr,
580 .read_ucblocks = mxl111sf_demod_read_ucblocks,
581};
582
583struct dvb_frontend *mxl111sf_demod_attach(struct mxl111sf_state *mxl_state,
584 struct mxl111sf_demod_config *cfg)
585{
586 struct mxl111sf_demod_state *state = NULL;
587
588 mxl_dbg("()");
589
590 state = kzalloc(sizeof(struct mxl111sf_demod_state), GFP_KERNEL);
591 if (state == NULL)
592 return NULL;
593
594 state->mxl_state = mxl_state;
595 state->cfg = cfg;
596
597 memcpy(&state->fe.ops, &mxl111sf_demod_ops,
598 sizeof(struct dvb_frontend_ops));
599
600 state->fe.demodulator_priv = state;
601 return &state->fe;
602}
603EXPORT_SYMBOL_GPL(mxl111sf_demod_attach);
604
605MODULE_DESCRIPTION("MaxLinear MxL111SF DVB-T demodulator driver");
606MODULE_AUTHOR("Michael Krufky <mkrufky@kernellabs.com>");
607MODULE_LICENSE("GPL");
608MODULE_VERSION("0.1");
609
610/*
611 * Local variables:
612 * c-basic-offset: 8
613 * End:
614 */
diff --git a/drivers/media/dvb/dvb-usb/mxl111sf-demod.h b/drivers/media/dvb/dvb-usb/mxl111sf-demod.h
new file mode 100644
index 000000000000..432706ae5274
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/mxl111sf-demod.h
@@ -0,0 +1,55 @@
1/*
2 * mxl111sf-demod.h - driver for the MaxLinear MXL111SF DVB-T demodulator
3 *
4 * Copyright (C) 2010 Michael Krufky <mkrufky@kernellabs.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21#ifndef __MXL111SF_DEMOD_H__
22#define __MXL111SF_DEMOD_H__
23
24#include "dvb_frontend.h"
25#include "mxl111sf.h"
26
27struct mxl111sf_demod_config {
28 int (*read_reg)(struct mxl111sf_state *state, u8 addr, u8 *data);
29 int (*write_reg)(struct mxl111sf_state *state, u8 addr, u8 data);
30 int (*program_regs)(struct mxl111sf_state *state,
31 struct mxl111sf_reg_ctrl_info *ctrl_reg_info);
32};
33
34#if defined(CONFIG_DVB_USB_MXL111SF) || \
35 (defined(CONFIG_DVB_USB_MXL111SF_MODULE) && defined(MODULE))
36extern
37struct dvb_frontend *mxl111sf_demod_attach(struct mxl111sf_state *mxl_state,
38 struct mxl111sf_demod_config *cfg);
39#else
40static inline
41struct dvb_frontend *mxl111sf_demod_attach(struct mxl111sf_state *mxl_state,
42 struct mxl111sf_demod_config *cfg)
43{
44 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
45 return NULL;
46}
47#endif /* CONFIG_DVB_USB_MXL111SF */
48
49#endif /* __MXL111SF_DEMOD_H__ */
50
51/*
52 * Local variables:
53 * c-basic-offset: 8
54 * End:
55 */
diff --git a/drivers/media/dvb/dvb-usb/mxl111sf.c b/drivers/media/dvb/dvb-usb/mxl111sf.c
index 546ba5915a5b..b5c98da5d9e2 100644
--- a/drivers/media/dvb/dvb-usb/mxl111sf.c
+++ b/drivers/media/dvb/dvb-usb/mxl111sf.c
@@ -17,6 +17,7 @@
17#include "mxl111sf-i2c.h" 17#include "mxl111sf-i2c.h"
18#include "mxl111sf-gpio.h" 18#include "mxl111sf-gpio.h"
19 19
20#include "mxl111sf-demod.h"
20#include "mxl111sf-tuner.h" 21#include "mxl111sf-tuner.h"
21 22
22#include "lgdt3305.h" 23#include "lgdt3305.h"
@@ -362,6 +363,22 @@ static int mxl111sf_ep6_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
362 return ret; 363 return ret;
363} 364}
364 365
366static int mxl111sf_ep4_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
367{
368 struct dvb_usb_device *d = adap->dev;
369 struct mxl111sf_state *state = d->priv;
370 int ret = 0;
371
372 deb_info("%s(%d)\n", __func__, onoff);
373
374 if (onoff) {
375 ret = mxl111sf_enable_usb_output(state);
376 mxl_fail(ret);
377 }
378
379 return ret;
380}
381
365/* ------------------------------------------------------------------------ */ 382/* ------------------------------------------------------------------------ */
366 383
367static struct lgdt3305_config hauppauge_lgdt3305_config = { 384static struct lgdt3305_config hauppauge_lgdt3305_config = {
@@ -438,6 +455,70 @@ fail:
438 return ret; 455 return ret;
439} 456}
440 457
458static struct mxl111sf_demod_config mxl_demod_config = {
459 .read_reg = mxl111sf_read_reg,
460 .write_reg = mxl111sf_write_reg,
461 .program_regs = mxl111sf_ctrl_program_regs,
462};
463
464static int mxl111sf_attach_demod(struct dvb_usb_adapter *adap)
465{
466 struct dvb_usb_device *d = adap->dev;
467 struct mxl111sf_state *state = d->priv;
468 int fe_id = adap->num_frontends_initialized;
469 struct mxl111sf_adap_state *adap_state = adap->fe_adap[fe_id].priv;
470 int ret;
471
472 deb_adv("%s()\n", __func__);
473
474 /* save a pointer to the dvb_usb_device in device state */
475 state->d = d;
476 adap_state->alt_mode = (dvb_usb_mxl111sf_isoc) ? 1 : 2;
477 state->alt_mode = adap_state->alt_mode;
478
479 if (usb_set_interface(adap->dev->udev, 0, state->alt_mode) < 0)
480 err("set interface failed");
481
482 state->gpio_mode = MXL111SF_GPIO_MOD_DVBT;
483 adap_state->gpio_mode = state->gpio_mode;
484 adap_state->device_mode = MXL_SOC_MODE;
485 adap_state->ep6_clockphase = 1;
486
487 ret = mxl1x1sf_soft_reset(state);
488 if (mxl_fail(ret))
489 goto fail;
490 ret = mxl111sf_init_tuner_demod(state);
491 if (mxl_fail(ret))
492 goto fail;
493
494 ret = mxl1x1sf_set_device_mode(state, adap_state->device_mode);
495 if (mxl_fail(ret))
496 goto fail;
497
498 ret = mxl111sf_enable_usb_output(state);
499 if (mxl_fail(ret))
500 goto fail;
501 ret = mxl1x1sf_top_master_ctrl(state, 1);
502 if (mxl_fail(ret))
503 goto fail;
504
505 /* dont care if this fails */
506 mxl111sf_init_port_expander(state);
507
508 adap->fe_adap[fe_id].fe = dvb_attach(mxl111sf_demod_attach, state,
509 &mxl_demod_config);
510 if (adap->fe_adap[fe_id].fe) {
511 adap_state->fe_init = adap->fe_adap[fe_id].fe->ops.init;
512 adap->fe_adap[fe_id].fe->ops.init = mxl111sf_adap_fe_init;
513 adap_state->fe_sleep = adap->fe_adap[fe_id].fe->ops.sleep;
514 adap->fe_adap[fe_id].fe->ops.sleep = mxl111sf_adap_fe_sleep;
515 return 0;
516 }
517 ret = -EIO;
518fail:
519 return ret;
520}
521
441static inline int mxl111sf_set_ant_path(struct mxl111sf_state *state, 522static inline int mxl111sf_set_ant_path(struct mxl111sf_state *state,
442 int antpath) 523 int antpath)
443{ 524{
@@ -567,7 +648,8 @@ struct i2c_algorithm mxl111sf_i2c_algo = {
567#endif 648#endif
568}; 649};
569 650
570/* DVB USB Driver stuff */ 651static struct dvb_usb_device_properties mxl111sf_dvbt_bulk_properties;
652static struct dvb_usb_device_properties mxl111sf_dvbt_isoc_properties;
571static struct dvb_usb_device_properties mxl111sf_atsc_bulk_properties; 653static struct dvb_usb_device_properties mxl111sf_atsc_bulk_properties;
572static struct dvb_usb_device_properties mxl111sf_atsc_isoc_properties; 654static struct dvb_usb_device_properties mxl111sf_atsc_isoc_properties;
573 655
@@ -580,9 +662,15 @@ static int mxl111sf_probe(struct usb_interface *intf,
580 662
581 if (((dvb_usb_mxl111sf_isoc) && 663 if (((dvb_usb_mxl111sf_isoc) &&
582 (0 == dvb_usb_device_init(intf, 664 (0 == dvb_usb_device_init(intf,
665 &mxl111sf_dvbt_isoc_properties,
666 THIS_MODULE, &d, adapter_nr) ||
667 0 == dvb_usb_device_init(intf,
583 &mxl111sf_atsc_isoc_properties, 668 &mxl111sf_atsc_isoc_properties,
584 THIS_MODULE, &d, adapter_nr))) || 669 THIS_MODULE, &d, adapter_nr))) ||
585 0 == dvb_usb_device_init(intf, 670 0 == dvb_usb_device_init(intf,
671 &mxl111sf_dvbt_bulk_properties,
672 THIS_MODULE, &d, adapter_nr) ||
673 0 == dvb_usb_device_init(intf,
586 &mxl111sf_atsc_bulk_properties, 674 &mxl111sf_atsc_bulk_properties,
587 THIS_MODULE, &d, adapter_nr) || 0) { 675 THIS_MODULE, &d, adapter_nr) || 0) {
588 676
@@ -669,6 +757,36 @@ static struct usb_device_id mxl111sf_table[] = {
669MODULE_DEVICE_TABLE(usb, mxl111sf_table); 757MODULE_DEVICE_TABLE(usb, mxl111sf_table);
670 758
671 759
760#define MXL111SF_EP4_BULK_STREAMING_CONFIG \
761 .streaming_ctrl = mxl111sf_ep4_streaming_ctrl, \
762 .stream = { \
763 .type = USB_BULK, \
764 .count = 5, \
765 .endpoint = 0x04, \
766 .u = { \
767 .bulk = { \
768 .buffersize = 8192, \
769 } \
770 } \
771 }
772
773/* FIXME: works for v6 but not v8 silicon */
774#define MXL111SF_EP4_ISOC_STREAMING_CONFIG \
775 .streaming_ctrl = mxl111sf_ep4_streaming_ctrl, \
776 .stream = { \
777 .type = USB_ISOC, \
778 .count = 5, \
779 .endpoint = 0x04, \
780 .u = { \
781 .isoc = { \
782 .framesperurb = 96, \
783 /* FIXME: v6 SILICON: */ \
784 .framesize = 564, \
785 .interval = 1, \
786 } \
787 } \
788 }
789
672#define MXL111SF_EP6_BULK_STREAMING_CONFIG \ 790#define MXL111SF_EP6_BULK_STREAMING_CONFIG \
673 .streaming_ctrl = mxl111sf_ep6_streaming_ctrl, \ 791 .streaming_ctrl = mxl111sf_ep6_streaming_ctrl, \
674 .stream = { \ 792 .stream = { \
@@ -712,7 +830,7 @@ MODULE_DEVICE_TABLE(usb, mxl111sf_table);
712 .generic_bulk_ctrl_endpoint_response = MXL_EP1_REG_READ, \ 830 .generic_bulk_ctrl_endpoint_response = MXL_EP1_REG_READ, \
713 .size_of_priv = sizeof(struct mxl111sf_state) 831 .size_of_priv = sizeof(struct mxl111sf_state)
714 832
715static struct dvb_usb_device_properties mxl111sf_atsc_bulk_properties = { 833static struct dvb_usb_device_properties mxl111sf_dvbt_bulk_properties = {
716 MXL111SF_DEFAULT_DEVICE_PROPERTIES, 834 MXL111SF_DEFAULT_DEVICE_PROPERTIES,
717 835
718 .num_adapters = 1, 836 .num_adapters = 1,
@@ -723,10 +841,106 @@ static struct dvb_usb_device_properties mxl111sf_atsc_bulk_properties = {
723 .fe = {{ 841 .fe = {{
724 .size_of_priv = sizeof(struct mxl111sf_adap_state), 842 .size_of_priv = sizeof(struct mxl111sf_adap_state),
725 843
844 .frontend_attach = mxl111sf_attach_demod,
845 .tuner_attach = mxl111sf_attach_tuner,
846
847 MXL111SF_EP4_BULK_STREAMING_CONFIG,
848 } },
849 },
850 },
851 .num_device_descs = 4,
852 .devices = {
853 { "Hauppauge 126xxx DVBT (bulk)",
854 { NULL },
855 { &mxl111sf_table[4], &mxl111sf_table[8],
856 NULL },
857 },
858 { "Hauppauge 117xxx DVBT (bulk)",
859 { NULL },
860 { &mxl111sf_table[15], &mxl111sf_table[18],
861 NULL },
862 },
863 { "Hauppauge 138xxx DVBT (bulk)",
864 { NULL },
865 { &mxl111sf_table[20], &mxl111sf_table[22],
866 &mxl111sf_table[24], &mxl111sf_table[26],
867 NULL },
868 },
869 { "Hauppauge 126xxx (tp-bulk)",
870 { NULL },
871 { &mxl111sf_table[28], &mxl111sf_table[30],
872 NULL },
873 },
874 }
875};
876
877static struct dvb_usb_device_properties mxl111sf_dvbt_isoc_properties = {
878 MXL111SF_DEFAULT_DEVICE_PROPERTIES,
879
880 .num_adapters = 1,
881 .adapter = {
882 {
883 .fe_ioctl_override = mxl111sf_fe_ioctl_override,
884 .num_frontends = 1,
885 .fe = {{
886 .size_of_priv = sizeof(struct mxl111sf_adap_state),
887
888 .frontend_attach = mxl111sf_attach_demod,
889 .tuner_attach = mxl111sf_attach_tuner,
890
891 MXL111SF_EP4_ISOC_STREAMING_CONFIG,
892 } },
893 },
894 },
895 .num_device_descs = 4,
896 .devices = {
897 { "Hauppauge 126xxx DVBT (isoc)",
898 { NULL },
899 { &mxl111sf_table[4], &mxl111sf_table[8],
900 NULL },
901 },
902 { "Hauppauge 117xxx DVBT (isoc)",
903 { NULL },
904 { &mxl111sf_table[15], &mxl111sf_table[18],
905 NULL },
906 },
907 { "Hauppauge 138xxx DVBT (isoc)",
908 { NULL },
909 { &mxl111sf_table[20], &mxl111sf_table[22],
910 &mxl111sf_table[24], &mxl111sf_table[26],
911 NULL },
912 },
913 { "Hauppauge 126xxx (tp-isoc)",
914 { NULL },
915 { &mxl111sf_table[28], &mxl111sf_table[30],
916 NULL },
917 },
918 }
919};
920
921static struct dvb_usb_device_properties mxl111sf_atsc_bulk_properties = {
922 MXL111SF_DEFAULT_DEVICE_PROPERTIES,
923
924 .num_adapters = 1,
925 .adapter = {
926 {
927 .fe_ioctl_override = mxl111sf_fe_ioctl_override,
928 .num_frontends = 2,
929 .fe = {{
930 .size_of_priv = sizeof(struct mxl111sf_adap_state),
931
726 .frontend_attach = mxl111sf_lgdt3305_frontend_attach, 932 .frontend_attach = mxl111sf_lgdt3305_frontend_attach,
727 .tuner_attach = mxl111sf_attach_tuner, 933 .tuner_attach = mxl111sf_attach_tuner,
728 934
729 MXL111SF_EP6_BULK_STREAMING_CONFIG, 935 MXL111SF_EP6_BULK_STREAMING_CONFIG,
936 },
937 {
938 .size_of_priv = sizeof(struct mxl111sf_adap_state),
939
940 .frontend_attach = mxl111sf_attach_demod,
941 .tuner_attach = mxl111sf_attach_tuner,
942
943 MXL111SF_EP4_BULK_STREAMING_CONFIG,
730 }}, 944 }},
731 }, 945 },
732 }, 946 },
@@ -776,7 +990,7 @@ static struct dvb_usb_device_properties mxl111sf_atsc_isoc_properties = {
776 .adapter = { 990 .adapter = {
777 { 991 {
778 .fe_ioctl_override = mxl111sf_fe_ioctl_override, 992 .fe_ioctl_override = mxl111sf_fe_ioctl_override,
779 .num_frontends = 1, 993 .num_frontends = 2,
780 .fe = {{ 994 .fe = {{
781 .size_of_priv = sizeof(struct mxl111sf_adap_state), 995 .size_of_priv = sizeof(struct mxl111sf_adap_state),
782 996
@@ -784,6 +998,14 @@ static struct dvb_usb_device_properties mxl111sf_atsc_isoc_properties = {
784 .tuner_attach = mxl111sf_attach_tuner, 998 .tuner_attach = mxl111sf_attach_tuner,
785 999
786 MXL111SF_EP6_ISOC_STREAMING_CONFIG, 1000 MXL111SF_EP6_ISOC_STREAMING_CONFIG,
1001 },
1002 {
1003 .size_of_priv = sizeof(struct mxl111sf_adap_state),
1004
1005 .frontend_attach = mxl111sf_attach_demod,
1006 .tuner_attach = mxl111sf_attach_tuner,
1007
1008 MXL111SF_EP4_ISOC_STREAMING_CONFIG,
787 }}, 1009 }},
788 }, 1010 },
789 }, 1011 },
diff --git a/drivers/media/dvb/dvb-usb/mxl111sf.h b/drivers/media/dvb/dvb-usb/mxl111sf.h
index 5a2c7bb386cd..364d89f826bd 100644
--- a/drivers/media/dvb/dvb-usb/mxl111sf.h
+++ b/drivers/media/dvb/dvb-usb/mxl111sf.h
@@ -133,7 +133,7 @@ extern int dvb_usb_mxl111sf_debug;
133/* The following allows the mxl_fail() macro defined below to work 133/* The following allows the mxl_fail() macro defined below to work
134 * in externel modules, such as mxl111sf-tuner.ko, even though 134 * in externel modules, such as mxl111sf-tuner.ko, even though
135 * dvb_usb_mxl111sf_debug is not defined within those modules */ 135 * dvb_usb_mxl111sf_debug is not defined within those modules */
136#ifdef __MXL111SF_TUNER_H__ 136#if (defined(__MXL111SF_TUNER_H__)) || (defined(__MXL111SF_DEMOD_H__))
137#define MXL_ADV_DEBUG_ENABLED MXL_ADV_DBG 137#define MXL_ADV_DEBUG_ENABLED MXL_ADV_DBG
138#else 138#else
139#define MXL_ADV_DEBUG_ENABLED dvb_usb_mxl111sf_debug 139#define MXL_ADV_DEBUG_ENABLED dvb_usb_mxl111sf_debug
diff --git a/drivers/media/dvb/frontends/dibx000_common.c b/drivers/media/dvb/frontends/dibx000_common.c
index 774d507b66cc..43be7238311e 100644
--- a/drivers/media/dvb/frontends/dibx000_common.c
+++ b/drivers/media/dvb/frontends/dibx000_common.c
@@ -1,5 +1,6 @@
1#include <linux/i2c.h> 1#include <linux/i2c.h>
2#include <linux/mutex.h> 2#include <linux/mutex.h>
3#include <linux/module.h>
3 4
4#include "dibx000_common.h" 5#include "dibx000_common.h"
5 6
diff --git a/drivers/media/dvb/ngene/Makefile b/drivers/media/dvb/ngene/Makefile
index 89873615e683..13ebeffb705f 100644
--- a/drivers/media/dvb/ngene/Makefile
+++ b/drivers/media/dvb/ngene/Makefile
@@ -11,4 +11,4 @@ ccflags-y += -Idrivers/media/dvb/frontends/
11ccflags-y += -Idrivers/media/common/tuners/ 11ccflags-y += -Idrivers/media/common/tuners/
12 12
13# For the staging CI driver cxd2099 13# For the staging CI driver cxd2099
14ccflags-y += -Idrivers/staging/cxd2099/ 14ccflags-y += -Idrivers/staging/media/cxd2099/
diff --git a/drivers/media/dvb/siano/sms-cards.c b/drivers/media/dvb/siano/sms-cards.c
index af121db88ea0..680c781c8dd6 100644
--- a/drivers/media/dvb/siano/sms-cards.c
+++ b/drivers/media/dvb/siano/sms-cards.c
@@ -19,6 +19,7 @@
19 19
20#include "sms-cards.h" 20#include "sms-cards.h"
21#include "smsir.h" 21#include "smsir.h"
22#include <linux/module.h>
22 23
23static int sms_dbg; 24static int sms_dbg;
24module_param_named(cards_dbg, sms_dbg, int, 0644); 25module_param_named(cards_dbg, sms_dbg, int, 0644);
diff --git a/drivers/media/dvb/siano/smsendian.c b/drivers/media/dvb/siano/smsendian.c
index 457b6d02ef85..e2657c2f0109 100644
--- a/drivers/media/dvb/siano/smsendian.c
+++ b/drivers/media/dvb/siano/smsendian.c
@@ -19,6 +19,7 @@
19 19
20 ****************************************************************/ 20 ****************************************************************/
21 21
22#include <linux/export.h>
22#include <asm/byteorder.h> 23#include <asm/byteorder.h>
23 24
24#include "smsendian.h" 25#include "smsendian.h"
diff --git a/drivers/media/dvb/siano/smssdio.c b/drivers/media/dvb/siano/smssdio.c
index e57d38b0197c..91f8c8291e2b 100644
--- a/drivers/media/dvb/siano/smssdio.c
+++ b/drivers/media/dvb/siano/smssdio.c
@@ -39,6 +39,7 @@
39#include <linux/mmc/card.h> 39#include <linux/mmc/card.h>
40#include <linux/mmc/sdio_func.h> 40#include <linux/mmc/sdio_func.h>
41#include <linux/mmc/sdio_ids.h> 41#include <linux/mmc/sdio_ids.h>
42#include <linux/module.h>
42 43
43#include "smscoreapi.h" 44#include "smscoreapi.h"
44#include "sms-cards.h" 45#include "sms-cards.h"
diff --git a/drivers/media/dvb/siano/smsusb.c b/drivers/media/dvb/siano/smsusb.c
index 0c8164a2cc36..51c7121b321a 100644
--- a/drivers/media/dvb/siano/smsusb.c
+++ b/drivers/media/dvb/siano/smsusb.c
@@ -24,6 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
24#include <linux/usb.h> 24#include <linux/usb.h>
25#include <linux/firmware.h> 25#include <linux/firmware.h>
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/module.h>
27 28
28#include "smscoreapi.h" 29#include "smscoreapi.h"
29#include "sms-cards.h" 30#include "sms-cards.h"
diff --git a/drivers/media/media-device.c b/drivers/media/media-device.c
index 16b70b4412f7..6edc9ba81203 100644
--- a/drivers/media/media-device.c
+++ b/drivers/media/media-device.c
@@ -23,6 +23,7 @@
23#include <linux/types.h> 23#include <linux/types.h>
24#include <linux/ioctl.h> 24#include <linux/ioctl.h>
25#include <linux/media.h> 25#include <linux/media.h>
26#include <linux/export.h>
26 27
27#include <media/media-device.h> 28#include <media/media-device.h>
28#include <media/media-devnode.h> 29#include <media/media-devnode.h>
diff --git a/drivers/media/radio/Kconfig b/drivers/media/radio/Kconfig
index 52798a111e16..ccd5f0d8a012 100644
--- a/drivers/media/radio/Kconfig
+++ b/drivers/media/radio/Kconfig
@@ -426,7 +426,6 @@ config RADIO_TIMBERDALE
426config RADIO_WL1273 426config RADIO_WL1273
427 tristate "Texas Instruments WL1273 I2C FM Radio" 427 tristate "Texas Instruments WL1273 I2C FM Radio"
428 depends on I2C && VIDEO_V4L2 428 depends on I2C && VIDEO_V4L2
429 select MFD_CORE
430 select MFD_WL1273_CORE 429 select MFD_WL1273_CORE
431 select FW_LOADER 430 select FW_LOADER
432 ---help--- 431 ---help---
diff --git a/drivers/media/radio/radio-tea5764.c b/drivers/media/radio/radio-tea5764.c
index 95ddcc4845d3..db20904d01f0 100644
--- a/drivers/media/radio/radio-tea5764.c
+++ b/drivers/media/radio/radio-tea5764.c
@@ -128,8 +128,10 @@ struct tea5764_write_regs {
128 u16 rdsbbl; /* PAUSEDET & RDSBBL */ 128 u16 rdsbbl; /* PAUSEDET & RDSBBL */
129} __attribute__ ((packed)); 129} __attribute__ ((packed));
130 130
131#ifndef RADIO_TEA5764_XTAL 131#ifdef CONFIG_RADIO_TEA5764_XTAL
132#define RADIO_TEA5764_XTAL 1 132#define RADIO_TEA5764_XTAL 1
133#else
134#define RADIO_TEA5764_XTAL 0
133#endif 135#endif
134 136
135static int radio_nr = -1; 137static int radio_nr = -1;
diff --git a/drivers/media/radio/radio-timb.c b/drivers/media/radio/radio-timb.c
index f17b540d68a5..3e9209f84e09 100644
--- a/drivers/media/radio/radio-timb.c
+++ b/drivers/media/radio/radio-timb.c
@@ -23,6 +23,7 @@
23#include <linux/interrupt.h> 23#include <linux/interrupt.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/i2c.h> 25#include <linux/i2c.h>
26#include <linux/module.h>
26#include <media/timb_radio.h> 27#include <media/timb_radio.h>
27 28
28#define DRIVER_NAME "timb-radio" 29#define DRIVER_NAME "timb-radio"
diff --git a/drivers/media/radio/radio-wl1273.c b/drivers/media/radio/radio-wl1273.c
index 6d1e4e750f63..8aa4968d57bc 100644
--- a/drivers/media/radio/radio-wl1273.c
+++ b/drivers/media/radio/radio-wl1273.c
@@ -23,6 +23,7 @@
23#include <linux/interrupt.h> 23#include <linux/interrupt.h>
24#include <linux/mfd/wl1273-core.h> 24#include <linux/mfd/wl1273-core.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/module.h>
26#include <media/v4l2-common.h> 27#include <media/v4l2-common.h>
27#include <media/v4l2-ctrls.h> 28#include <media/v4l2-ctrls.h>
28#include <media/v4l2-device.h> 29#include <media/v4l2-device.h>
diff --git a/drivers/media/radio/si4713-i2c.c b/drivers/media/radio/si4713-i2c.c
index c9f4a8e65dc4..27aba936fb2b 100644
--- a/drivers/media/radio/si4713-i2c.c
+++ b/drivers/media/radio/si4713-i2c.c
@@ -29,6 +29,7 @@
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/gpio.h> 30#include <linux/gpio.h>
31#include <linux/regulator/consumer.h> 31#include <linux/regulator/consumer.h>
32#include <linux/module.h>
32#include <media/v4l2-device.h> 33#include <media/v4l2-device.h>
33#include <media/v4l2-ioctl.h> 34#include <media/v4l2-ioctl.h>
34#include <media/v4l2-common.h> 35#include <media/v4l2-common.h>
diff --git a/drivers/media/radio/wl128x/fmdrv_v4l2.c b/drivers/media/radio/wl128x/fmdrv_v4l2.c
index b93d8cf23b03..4f5c43d2566c 100644
--- a/drivers/media/radio/wl128x/fmdrv_v4l2.c
+++ b/drivers/media/radio/wl128x/fmdrv_v4l2.c
@@ -28,6 +28,8 @@
28 * 28 *
29 */ 29 */
30 30
31#include <linux/export.h>
32
31#include "fmdrv.h" 33#include "fmdrv.h"
32#include "fmdrv_v4l2.h" 34#include "fmdrv_v4l2.h"
33#include "fmdrv_common.h" 35#include "fmdrv_common.h"
diff --git a/drivers/media/rc/ir-jvc-decoder.c b/drivers/media/rc/ir-jvc-decoder.c
index 624449afaa61..035668e27f6b 100644
--- a/drivers/media/rc/ir-jvc-decoder.c
+++ b/drivers/media/rc/ir-jvc-decoder.c
@@ -13,6 +13,7 @@
13 */ 13 */
14 14
15#include <linux/bitrev.h> 15#include <linux/bitrev.h>
16#include <linux/module.h>
16#include "rc-core-priv.h" 17#include "rc-core-priv.h"
17 18
18#define JVC_NBITS 16 /* dev(8) + func(8) */ 19#define JVC_NBITS 16 /* dev(8) + func(8) */
diff --git a/drivers/media/rc/ir-lirc-codec.c b/drivers/media/rc/ir-lirc-codec.c
index ec2e67fd236b..5faba2a2fdd3 100644
--- a/drivers/media/rc/ir-lirc-codec.c
+++ b/drivers/media/rc/ir-lirc-codec.c
@@ -14,6 +14,7 @@
14 14
15#include <linux/sched.h> 15#include <linux/sched.h>
16#include <linux/wait.h> 16#include <linux/wait.h>
17#include <linux/module.h>
17#include <media/lirc.h> 18#include <media/lirc.h>
18#include <media/lirc_dev.h> 19#include <media/lirc_dev.h>
19#include <media/rc-core.h> 20#include <media/rc-core.h>
diff --git a/drivers/media/rc/ir-nec-decoder.c b/drivers/media/rc/ir-nec-decoder.c
index 63ee722dbd02..17f8db00435a 100644
--- a/drivers/media/rc/ir-nec-decoder.c
+++ b/drivers/media/rc/ir-nec-decoder.c
@@ -13,6 +13,7 @@
13 */ 13 */
14 14
15#include <linux/bitrev.h> 15#include <linux/bitrev.h>
16#include <linux/module.h>
16#include "rc-core-priv.h" 17#include "rc-core-priv.h"
17 18
18#define NEC_NBITS 32 19#define NEC_NBITS 32
diff --git a/drivers/media/rc/ir-raw.c b/drivers/media/rc/ir-raw.c
index 27808bb59eba..2e5cd3100b64 100644
--- a/drivers/media/rc/ir-raw.c
+++ b/drivers/media/rc/ir-raw.c
@@ -12,8 +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/export.h>
15#include <linux/kthread.h> 16#include <linux/kthread.h>
16#include <linux/mutex.h> 17#include <linux/mutex.h>
18#include <linux/kmod.h>
17#include <linux/sched.h> 19#include <linux/sched.h>
18#include <linux/freezer.h> 20#include <linux/freezer.h>
19#include "rc-core-priv.h" 21#include "rc-core-priv.h"
diff --git a/drivers/media/rc/ir-rc5-decoder.c b/drivers/media/rc/ir-rc5-decoder.c
index ebdba5539916..9ab663a507a4 100644
--- a/drivers/media/rc/ir-rc5-decoder.c
+++ b/drivers/media/rc/ir-rc5-decoder.c
@@ -21,6 +21,7 @@
21 */ 21 */
22 22
23#include "rc-core-priv.h" 23#include "rc-core-priv.h"
24#include <linux/module.h>
24 25
25#define RC5_NBITS 14 26#define RC5_NBITS 14
26#define RC5X_NBITS 20 27#define RC5X_NBITS 20
diff --git a/drivers/media/rc/ir-rc5-sz-decoder.c b/drivers/media/rc/ir-rc5-sz-decoder.c
index 90aa8868629a..ec8d4a2e2c5a 100644
--- a/drivers/media/rc/ir-rc5-sz-decoder.c
+++ b/drivers/media/rc/ir-rc5-sz-decoder.c
@@ -21,6 +21,7 @@
21 */ 21 */
22 22
23#include "rc-core-priv.h" 23#include "rc-core-priv.h"
24#include <linux/module.h>
24 25
25#define RC5_SZ_NBITS 15 26#define RC5_SZ_NBITS 15
26#define RC5_UNIT 888888 /* ns */ 27#define RC5_UNIT 888888 /* ns */
diff --git a/drivers/media/rc/ir-rc6-decoder.c b/drivers/media/rc/ir-rc6-decoder.c
index 755dafa3871b..140fb67e2f89 100644
--- a/drivers/media/rc/ir-rc6-decoder.c
+++ b/drivers/media/rc/ir-rc6-decoder.c
@@ -13,6 +13,7 @@
13 */ 13 */
14 14
15#include "rc-core-priv.h" 15#include "rc-core-priv.h"
16#include <linux/module.h>
16 17
17/* 18/*
18 * This decoder currently supports: 19 * This decoder currently supports:
diff --git a/drivers/media/rc/ir-sony-decoder.c b/drivers/media/rc/ir-sony-decoder.c
index a92de80c48db..d5e2b50aff1f 100644
--- a/drivers/media/rc/ir-sony-decoder.c
+++ b/drivers/media/rc/ir-sony-decoder.c
@@ -13,6 +13,7 @@
13 */ 13 */
14 14
15#include <linux/bitrev.h> 15#include <linux/bitrev.h>
16#include <linux/module.h>
16#include "rc-core-priv.h" 17#include "rc-core-priv.h"
17 18
18#define SONY_UNIT 600000 /* ns */ 19#define SONY_UNIT 600000 /* ns */
diff --git a/drivers/media/rc/keymaps/rc-adstech-dvb-t-pci.c b/drivers/media/rc/keymaps/rc-adstech-dvb-t-pci.c
index 9a8752fdcca1..b0e42df7ff82 100644
--- a/drivers/media/rc/keymaps/rc-adstech-dvb-t-pci.c
+++ b/drivers/media/rc/keymaps/rc-adstech-dvb-t-pci.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* ADS Tech Instant TV DVB-T PCI Remote */ 16/* ADS Tech Instant TV DVB-T PCI Remote */
16 17
diff --git a/drivers/media/rc/keymaps/rc-alink-dtu-m.c b/drivers/media/rc/keymaps/rc-alink-dtu-m.c
index fe652e928dc0..4e6ade8e616f 100644
--- a/drivers/media/rc/keymaps/rc-alink-dtu-m.c
+++ b/drivers/media/rc/keymaps/rc-alink-dtu-m.c
@@ -19,6 +19,7 @@
19 */ 19 */
20 20
21#include <media/rc-map.h> 21#include <media/rc-map.h>
22#include <linux/module.h>
22 23
23/* A-Link DTU(m) slim remote, 6 rows, 3 columns. */ 24/* A-Link DTU(m) slim remote, 6 rows, 3 columns. */
24static struct rc_map_table alink_dtu_m[] = { 25static struct rc_map_table alink_dtu_m[] = {
diff --git a/drivers/media/rc/keymaps/rc-anysee.c b/drivers/media/rc/keymaps/rc-anysee.c
index 884f1b51a8ee..c735fe10a390 100644
--- a/drivers/media/rc/keymaps/rc-anysee.c
+++ b/drivers/media/rc/keymaps/rc-anysee.c
@@ -19,6 +19,7 @@
19 */ 19 */
20 20
21#include <media/rc-map.h> 21#include <media/rc-map.h>
22#include <linux/module.h>
22 23
23static struct rc_map_table anysee[] = { 24static struct rc_map_table anysee[] = {
24 { 0x0800, KEY_0 }, 25 { 0x0800, KEY_0 },
diff --git a/drivers/media/rc/keymaps/rc-apac-viewcomp.c b/drivers/media/rc/keymaps/rc-apac-viewcomp.c
index 7af188209ff9..8c92ff95f94d 100644
--- a/drivers/media/rc/keymaps/rc-apac-viewcomp.c
+++ b/drivers/media/rc/keymaps/rc-apac-viewcomp.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* Attila Kondoros <attila.kondoros@chello.hu> */ 16/* Attila Kondoros <attila.kondoros@chello.hu> */
16 17
diff --git a/drivers/media/rc/keymaps/rc-asus-pc39.c b/drivers/media/rc/keymaps/rc-asus-pc39.c
index b2481154491b..2caf2117759b 100644
--- a/drivers/media/rc/keymaps/rc-asus-pc39.c
+++ b/drivers/media/rc/keymaps/rc-asus-pc39.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* 16/*
16 * Marc Fargas <telenieko@telenieko.com> 17 * Marc Fargas <telenieko@telenieko.com>
diff --git a/drivers/media/rc/keymaps/rc-ati-tv-wonder-hd-600.c b/drivers/media/rc/keymaps/rc-ati-tv-wonder-hd-600.c
index f766b24b0158..2031224a2027 100644
--- a/drivers/media/rc/keymaps/rc-ati-tv-wonder-hd-600.c
+++ b/drivers/media/rc/keymaps/rc-ati-tv-wonder-hd-600.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* ATI TV Wonder HD 600 USB 16/* ATI TV Wonder HD 600 USB
16 Devin Heitmueller <devin.heitmueller@gmail.com> 17 Devin Heitmueller <devin.heitmueller@gmail.com>
diff --git a/drivers/media/rc/keymaps/rc-avermedia-a16d.c b/drivers/media/rc/keymaps/rc-avermedia-a16d.c
index ec9beeebd410..894939ac17f2 100644
--- a/drivers/media/rc/keymaps/rc-avermedia-a16d.c
+++ b/drivers/media/rc/keymaps/rc-avermedia-a16d.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15static struct rc_map_table avermedia_a16d[] = { 16static struct rc_map_table avermedia_a16d[] = {
16 { 0x20, KEY_LIST}, 17 { 0x20, KEY_LIST},
diff --git a/drivers/media/rc/keymaps/rc-avermedia-cardbus.c b/drivers/media/rc/keymaps/rc-avermedia-cardbus.c
index 22f54d413a35..d2aaf5b9e39f 100644
--- a/drivers/media/rc/keymaps/rc-avermedia-cardbus.c
+++ b/drivers/media/rc/keymaps/rc-avermedia-cardbus.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* Oldrich Jedlicka <oldium.pro@seznam.cz> */ 16/* Oldrich Jedlicka <oldium.pro@seznam.cz> */
16 17
diff --git a/drivers/media/rc/keymaps/rc-avermedia-dvbt.c b/drivers/media/rc/keymaps/rc-avermedia-dvbt.c
index c25809d4c813..dc2baf062398 100644
--- a/drivers/media/rc/keymaps/rc-avermedia-dvbt.c
+++ b/drivers/media/rc/keymaps/rc-avermedia-dvbt.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* Matt Jesson <dvb@jesson.eclipse.co.uk */ 16/* Matt Jesson <dvb@jesson.eclipse.co.uk */
16 17
diff --git a/drivers/media/rc/keymaps/rc-avermedia-m135a.c b/drivers/media/rc/keymaps/rc-avermedia-m135a.c
index 3d2cbe4e5e46..04269d31fa19 100644
--- a/drivers/media/rc/keymaps/rc-avermedia-m135a.c
+++ b/drivers/media/rc/keymaps/rc-avermedia-m135a.c
@@ -10,6 +10,7 @@
10 */ 10 */
11 11
12#include <media/rc-map.h> 12#include <media/rc-map.h>
13#include <linux/module.h>
13 14
14/* 15/*
15 * Avermedia M135A with RM-JX and RM-K6 remote controls 16 * Avermedia M135A with RM-JX and RM-K6 remote controls
diff --git a/drivers/media/rc/keymaps/rc-avermedia-m733a-rm-k6.c b/drivers/media/rc/keymaps/rc-avermedia-m733a-rm-k6.c
index 8cd7f28808bd..e83b1a1939bf 100644
--- a/drivers/media/rc/keymaps/rc-avermedia-m733a-rm-k6.c
+++ b/drivers/media/rc/keymaps/rc-avermedia-m733a-rm-k6.c
@@ -9,6 +9,7 @@
9 */ 9 */
10 10
11#include <media/rc-map.h> 11#include <media/rc-map.h>
12#include <linux/module.h>
12 13
13/* 14/*
14 * Avermedia M733A with IR model RM-K6 15 * Avermedia M733A with IR model RM-K6
diff --git a/drivers/media/rc/keymaps/rc-avermedia-rm-ks.c b/drivers/media/rc/keymaps/rc-avermedia-rm-ks.c
index 9d68af217d8b..8344bcc595be 100644
--- a/drivers/media/rc/keymaps/rc-avermedia-rm-ks.c
+++ b/drivers/media/rc/keymaps/rc-avermedia-rm-ks.c
@@ -19,6 +19,7 @@
19 */ 19 */
20 20
21#include <media/rc-map.h> 21#include <media/rc-map.h>
22#include <linux/module.h>
22 23
23/* Initial keytable is from Jose Alberto Reguero <jareguero@telefonica.net> 24/* Initial keytable is from Jose Alberto Reguero <jareguero@telefonica.net>
24 and Felipe Morales Moreno <felipe.morales.moreno@gmail.com> */ 25 and Felipe Morales Moreno <felipe.morales.moreno@gmail.com> */
diff --git a/drivers/media/rc/keymaps/rc-avermedia.c b/drivers/media/rc/keymaps/rc-avermedia.c
index edfa71506d3e..c6063dfcd507 100644
--- a/drivers/media/rc/keymaps/rc-avermedia.c
+++ b/drivers/media/rc/keymaps/rc-avermedia.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* Alex Hermann <gaaf@gmx.net> */ 16/* Alex Hermann <gaaf@gmx.net> */
16 17
diff --git a/drivers/media/rc/keymaps/rc-avertv-303.c b/drivers/media/rc/keymaps/rc-avertv-303.c
index 32e94988dc94..14f78451e64e 100644
--- a/drivers/media/rc/keymaps/rc-avertv-303.c
+++ b/drivers/media/rc/keymaps/rc-avertv-303.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* AVERTV STUDIO 303 Remote */ 16/* AVERTV STUDIO 303 Remote */
16 17
diff --git a/drivers/media/rc/keymaps/rc-azurewave-ad-tu700.c b/drivers/media/rc/keymaps/rc-azurewave-ad-tu700.c
index c3f6d62ac892..ea7f2d0f31eb 100644
--- a/drivers/media/rc/keymaps/rc-azurewave-ad-tu700.c
+++ b/drivers/media/rc/keymaps/rc-azurewave-ad-tu700.c
@@ -19,6 +19,7 @@
19 */ 19 */
20 20
21#include <media/rc-map.h> 21#include <media/rc-map.h>
22#include <linux/module.h>
22 23
23static struct rc_map_table azurewave_ad_tu700[] = { 24static struct rc_map_table azurewave_ad_tu700[] = {
24 { 0x0000, KEY_TAB }, /* Tab */ 25 { 0x0000, KEY_TAB }, /* Tab */
diff --git a/drivers/media/rc/keymaps/rc-behold-columbus.c b/drivers/media/rc/keymaps/rc-behold-columbus.c
index 8bf058f67f0c..086b4b1f19e1 100644
--- a/drivers/media/rc/keymaps/rc-behold-columbus.c
+++ b/drivers/media/rc/keymaps/rc-behold-columbus.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* Beholder Intl. Ltd. 2008 16/* Beholder Intl. Ltd. 2008
16 * Dmitry Belimov d.belimov@google.com 17 * Dmitry Belimov d.belimov@google.com
diff --git a/drivers/media/rc/keymaps/rc-behold.c b/drivers/media/rc/keymaps/rc-behold.c
index c909a234c776..0877e3480941 100644
--- a/drivers/media/rc/keymaps/rc-behold.c
+++ b/drivers/media/rc/keymaps/rc-behold.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* 16/*
16 * Igor Kuznetsov <igk72@ya.ru> 17 * Igor Kuznetsov <igk72@ya.ru>
diff --git a/drivers/media/rc/keymaps/rc-budget-ci-old.c b/drivers/media/rc/keymaps/rc-budget-ci-old.c
index 2f66e4310d20..8311e092c098 100644
--- a/drivers/media/rc/keymaps/rc-budget-ci-old.c
+++ b/drivers/media/rc/keymaps/rc-budget-ci-old.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* 16/*
16 * From reading the following remotes: 17 * From reading the following remotes:
diff --git a/drivers/media/rc/keymaps/rc-cinergy-1400.c b/drivers/media/rc/keymaps/rc-cinergy-1400.c
index 284534b67e7d..0c87fbaf99ab 100644
--- a/drivers/media/rc/keymaps/rc-cinergy-1400.c
+++ b/drivers/media/rc/keymaps/rc-cinergy-1400.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* Cinergy 1400 DVB-T */ 16/* Cinergy 1400 DVB-T */
16 17
diff --git a/drivers/media/rc/keymaps/rc-cinergy.c b/drivers/media/rc/keymaps/rc-cinergy.c
index cf3a6bfb190c..309e9e3fb6f3 100644
--- a/drivers/media/rc/keymaps/rc-cinergy.c
+++ b/drivers/media/rc/keymaps/rc-cinergy.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15static struct rc_map_table cinergy[] = { 16static struct rc_map_table cinergy[] = {
16 { 0x00, KEY_0 }, 17 { 0x00, KEY_0 },
diff --git a/drivers/media/rc/keymaps/rc-dib0700-nec.c b/drivers/media/rc/keymaps/rc-dib0700-nec.c
index 7a5f5300caf9..4d13a7f2e5c3 100644
--- a/drivers/media/rc/keymaps/rc-dib0700-nec.c
+++ b/drivers/media/rc/keymaps/rc-dib0700-nec.c
@@ -16,6 +16,7 @@
16 */ 16 */
17 17
18#include <media/rc-map.h> 18#include <media/rc-map.h>
19#include <linux/module.h>
19 20
20static struct rc_map_table dib0700_nec_table[] = { 21static struct rc_map_table dib0700_nec_table[] = {
21 /* Key codes for the Pixelview SBTVD remote */ 22 /* Key codes for the Pixelview SBTVD remote */
diff --git a/drivers/media/rc/keymaps/rc-dib0700-rc5.c b/drivers/media/rc/keymaps/rc-dib0700-rc5.c
index 4af12e45dfba..ba81d9697cfc 100644
--- a/drivers/media/rc/keymaps/rc-dib0700-rc5.c
+++ b/drivers/media/rc/keymaps/rc-dib0700-rc5.c
@@ -16,6 +16,7 @@
16 */ 16 */
17 17
18#include <media/rc-map.h> 18#include <media/rc-map.h>
19#include <linux/module.h>
19 20
20static struct rc_map_table dib0700_rc5_table[] = { 21static struct rc_map_table dib0700_rc5_table[] = {
21 /* Key codes for the tiny Pinnacle remote*/ 22 /* Key codes for the tiny Pinnacle remote*/
diff --git a/drivers/media/rc/keymaps/rc-digitalnow-tinytwin.c b/drivers/media/rc/keymaps/rc-digitalnow-tinytwin.c
index f68b450f5593..bed78acb9198 100644
--- a/drivers/media/rc/keymaps/rc-digitalnow-tinytwin.c
+++ b/drivers/media/rc/keymaps/rc-digitalnow-tinytwin.c
@@ -19,6 +19,7 @@
19 */ 19 */
20 20
21#include <media/rc-map.h> 21#include <media/rc-map.h>
22#include <linux/module.h>
22 23
23static struct rc_map_table digitalnow_tinytwin[] = { 24static struct rc_map_table digitalnow_tinytwin[] = {
24 { 0x0000, KEY_MUTE }, /* [symbol speaker] */ 25 { 0x0000, KEY_MUTE }, /* [symbol speaker] */
diff --git a/drivers/media/rc/keymaps/rc-digittrade.c b/drivers/media/rc/keymaps/rc-digittrade.c
index 21d49871f2a3..a3b97a1fe223 100644
--- a/drivers/media/rc/keymaps/rc-digittrade.c
+++ b/drivers/media/rc/keymaps/rc-digittrade.c
@@ -19,6 +19,7 @@
19 */ 19 */
20 20
21#include <media/rc-map.h> 21#include <media/rc-map.h>
22#include <linux/module.h>
22 23
23/* Digittrade DVB-T USB Stick remote controller. */ 24/* Digittrade DVB-T USB Stick remote controller. */
24/* Imported from af9015.h. 25/* Imported from af9015.h.
diff --git a/drivers/media/rc/keymaps/rc-dm1105-nec.c b/drivers/media/rc/keymaps/rc-dm1105-nec.c
index d024fbf88bc4..67fc9fb0c007 100644
--- a/drivers/media/rc/keymaps/rc-dm1105-nec.c
+++ b/drivers/media/rc/keymaps/rc-dm1105-nec.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* DVBWorld remotes 16/* DVBWorld remotes
16 Igor M. Liplianin <liplianin@me.by> 17 Igor M. Liplianin <liplianin@me.by>
diff --git a/drivers/media/rc/keymaps/rc-dntv-live-dvb-t.c b/drivers/media/rc/keymaps/rc-dntv-live-dvb-t.c
index 82c0200029af..91ea91de9179 100644
--- a/drivers/media/rc/keymaps/rc-dntv-live-dvb-t.c
+++ b/drivers/media/rc/keymaps/rc-dntv-live-dvb-t.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* DigitalNow DNTV Live DVB-T Remote */ 16/* DigitalNow DNTV Live DVB-T Remote */
16 17
diff --git a/drivers/media/rc/keymaps/rc-dntv-live-dvbt-pro.c b/drivers/media/rc/keymaps/rc-dntv-live-dvbt-pro.c
index 015e99de06de..fd680d4d3eb6 100644
--- a/drivers/media/rc/keymaps/rc-dntv-live-dvbt-pro.c
+++ b/drivers/media/rc/keymaps/rc-dntv-live-dvbt-pro.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* DigitalNow DNTV Live! DVB-T Pro Remote */ 16/* DigitalNow DNTV Live! DVB-T Pro Remote */
16 17
diff --git a/drivers/media/rc/keymaps/rc-em-terratec.c b/drivers/media/rc/keymaps/rc-em-terratec.c
index 269d4299da34..d1fcd64c0f90 100644
--- a/drivers/media/rc/keymaps/rc-em-terratec.c
+++ b/drivers/media/rc/keymaps/rc-em-terratec.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15static struct rc_map_table em_terratec[] = { 16static struct rc_map_table em_terratec[] = {
16 { 0x01, KEY_CHANNEL }, 17 { 0x01, KEY_CHANNEL },
diff --git a/drivers/media/rc/keymaps/rc-encore-enltv-fm53.c b/drivers/media/rc/keymaps/rc-encore-enltv-fm53.c
index e388698a0697..2fe45e41fe49 100644
--- a/drivers/media/rc/keymaps/rc-encore-enltv-fm53.c
+++ b/drivers/media/rc/keymaps/rc-encore-enltv-fm53.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* Encore ENLTV-FM v5.3 16/* Encore ENLTV-FM v5.3
16 Mauro Carvalho Chehab <mchehab@infradead.org> 17 Mauro Carvalho Chehab <mchehab@infradead.org>
diff --git a/drivers/media/rc/keymaps/rc-encore-enltv.c b/drivers/media/rc/keymaps/rc-encore-enltv.c
index e56ac6e9670a..223de75a6d1c 100644
--- a/drivers/media/rc/keymaps/rc-encore-enltv.c
+++ b/drivers/media/rc/keymaps/rc-encore-enltv.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* Encore ENLTV-FM - black plastic, white front cover with white glowing buttons 16/* Encore ENLTV-FM - black plastic, white front cover with white glowing buttons
16 Juan Pablo Sormani <sorman@gmail.com> */ 17 Juan Pablo Sormani <sorman@gmail.com> */
diff --git a/drivers/media/rc/keymaps/rc-encore-enltv2.c b/drivers/media/rc/keymaps/rc-encore-enltv2.c
index b6264f1bc4c1..669cbff22b7e 100644
--- a/drivers/media/rc/keymaps/rc-encore-enltv2.c
+++ b/drivers/media/rc/keymaps/rc-encore-enltv2.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* Encore ENLTV2-FM - silver plastic - "Wand Media" written at the botton 16/* Encore ENLTV2-FM - silver plastic - "Wand Media" written at the botton
16 Mauro Carvalho Chehab <mchehab@infradead.org> */ 17 Mauro Carvalho Chehab <mchehab@infradead.org> */
diff --git a/drivers/media/rc/keymaps/rc-evga-indtube.c b/drivers/media/rc/keymaps/rc-evga-indtube.c
index a2bf24f6dfbb..2c647fc25916 100644
--- a/drivers/media/rc/keymaps/rc-evga-indtube.c
+++ b/drivers/media/rc/keymaps/rc-evga-indtube.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* EVGA inDtube 16/* EVGA inDtube
16 Devin Heitmueller <devin.heitmueller@gmail.com> 17 Devin Heitmueller <devin.heitmueller@gmail.com>
diff --git a/drivers/media/rc/keymaps/rc-eztv.c b/drivers/media/rc/keymaps/rc-eztv.c
index 1e8e5b2d6e36..76921445c1d9 100644
--- a/drivers/media/rc/keymaps/rc-eztv.c
+++ b/drivers/media/rc/keymaps/rc-eztv.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* Alfons Geser <a.geser@cox.net> 16/* Alfons Geser <a.geser@cox.net>
16 * updates from Job D. R. Borges <jobdrb@ig.com.br> */ 17 * updates from Job D. R. Borges <jobdrb@ig.com.br> */
diff --git a/drivers/media/rc/keymaps/rc-flydvb.c b/drivers/media/rc/keymaps/rc-flydvb.c
index a8b0f66edaa9..3a6bba311b08 100644
--- a/drivers/media/rc/keymaps/rc-flydvb.c
+++ b/drivers/media/rc/keymaps/rc-flydvb.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15static struct rc_map_table flydvb[] = { 16static struct rc_map_table flydvb[] = {
16 { 0x01, KEY_ZOOM }, /* Full Screen */ 17 { 0x01, KEY_ZOOM }, /* Full Screen */
diff --git a/drivers/media/rc/keymaps/rc-flyvideo.c b/drivers/media/rc/keymaps/rc-flyvideo.c
index 5bbe68371756..bf9da584643b 100644
--- a/drivers/media/rc/keymaps/rc-flyvideo.c
+++ b/drivers/media/rc/keymaps/rc-flyvideo.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15static struct rc_map_table flyvideo[] = { 16static struct rc_map_table flyvideo[] = {
16 { 0x0f, KEY_0 }, 17 { 0x0f, KEY_0 },
diff --git a/drivers/media/rc/keymaps/rc-fusionhdtv-mce.c b/drivers/media/rc/keymaps/rc-fusionhdtv-mce.c
index c80b25c65b57..2f0970fe7832 100644
--- a/drivers/media/rc/keymaps/rc-fusionhdtv-mce.c
+++ b/drivers/media/rc/keymaps/rc-fusionhdtv-mce.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* DViCO FUSION HDTV MCE remote */ 16/* DViCO FUSION HDTV MCE remote */
16 17
diff --git a/drivers/media/rc/keymaps/rc-gadmei-rm008z.c b/drivers/media/rc/keymaps/rc-gadmei-rm008z.c
index 068c9ead98dd..0e98ec467c34 100644
--- a/drivers/media/rc/keymaps/rc-gadmei-rm008z.c
+++ b/drivers/media/rc/keymaps/rc-gadmei-rm008z.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* GADMEI UTV330+ RM008Z remote 16/* GADMEI UTV330+ RM008Z remote
16 Shine Liu <shinel@foxmail.com> 17 Shine Liu <shinel@foxmail.com>
diff --git a/drivers/media/rc/keymaps/rc-genius-tvgo-a11mce.c b/drivers/media/rc/keymaps/rc-genius-tvgo-a11mce.c
index cdbbed467926..a2e2faa1d1b3 100644
--- a/drivers/media/rc/keymaps/rc-genius-tvgo-a11mce.c
+++ b/drivers/media/rc/keymaps/rc-genius-tvgo-a11mce.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* 16/*
16 * Remote control for the Genius TVGO A11MCE 17 * Remote control for the Genius TVGO A11MCE
diff --git a/drivers/media/rc/keymaps/rc-gotview7135.c b/drivers/media/rc/keymaps/rc-gotview7135.c
index a38bdde8c140..864614e19314 100644
--- a/drivers/media/rc/keymaps/rc-gotview7135.c
+++ b/drivers/media/rc/keymaps/rc-gotview7135.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* Mike Baikov <mike@baikov.com> */ 16/* Mike Baikov <mike@baikov.com> */
16 17
diff --git a/drivers/media/rc/keymaps/rc-hauppauge.c b/drivers/media/rc/keymaps/rc-hauppauge.c
index cd3db7779772..e51c6163378b 100644
--- a/drivers/media/rc/keymaps/rc-hauppauge.c
+++ b/drivers/media/rc/keymaps/rc-hauppauge.c
@@ -17,6 +17,7 @@
17 */ 17 */
18 18
19#include <media/rc-map.h> 19#include <media/rc-map.h>
20#include <linux/module.h>
20 21
21/* 22/*
22 * Hauppauge:the newer, gray remotes (seems there are multiple 23 * Hauppauge:the newer, gray remotes (seems there are multiple
diff --git a/drivers/media/rc/keymaps/rc-imon-mce.c b/drivers/media/rc/keymaps/rc-imon-mce.c
index 0ea2aa190d81..124c7228ba8c 100644
--- a/drivers/media/rc/keymaps/rc-imon-mce.c
+++ b/drivers/media/rc/keymaps/rc-imon-mce.c
@@ -10,6 +10,7 @@
10 */ 10 */
11 11
12#include <media/rc-map.h> 12#include <media/rc-map.h>
13#include <linux/module.h>
13 14
14/* mce-mode imon mce remote key table */ 15/* mce-mode imon mce remote key table */
15static struct rc_map_table imon_mce[] = { 16static struct rc_map_table imon_mce[] = {
diff --git a/drivers/media/rc/keymaps/rc-imon-pad.c b/drivers/media/rc/keymaps/rc-imon-pad.c
index 75d3843fdc30..999c6295c70e 100644
--- a/drivers/media/rc/keymaps/rc-imon-pad.c
+++ b/drivers/media/rc/keymaps/rc-imon-pad.c
@@ -10,6 +10,7 @@
10 */ 10 */
11 11
12#include <media/rc-map.h> 12#include <media/rc-map.h>
13#include <linux/module.h>
13 14
14/* 15/*
15 * standard imon remote key table, which isn't really entirely 16 * standard imon remote key table, which isn't really entirely
diff --git a/drivers/media/rc/keymaps/rc-iodata-bctv7e.c b/drivers/media/rc/keymaps/rc-iodata-bctv7e.c
index 1f59e163f75d..34540dfc3df5 100644
--- a/drivers/media/rc/keymaps/rc-iodata-bctv7e.c
+++ b/drivers/media/rc/keymaps/rc-iodata-bctv7e.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* IO-DATA BCTV7E Remote */ 16/* IO-DATA BCTV7E Remote */
16 17
diff --git a/drivers/media/rc/keymaps/rc-kaiomy.c b/drivers/media/rc/keymaps/rc-kaiomy.c
index f31dc5c1ad9c..4264a787c150 100644
--- a/drivers/media/rc/keymaps/rc-kaiomy.c
+++ b/drivers/media/rc/keymaps/rc-kaiomy.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* Kaiomy TVnPC U2 16/* Kaiomy TVnPC U2
16 Mauro Carvalho Chehab <mchehab@infradead.org> 17 Mauro Carvalho Chehab <mchehab@infradead.org>
diff --git a/drivers/media/rc/keymaps/rc-kworld-315u.c b/drivers/media/rc/keymaps/rc-kworld-315u.c
index 7f33edb47244..e48cd267dda6 100644
--- a/drivers/media/rc/keymaps/rc-kworld-315u.c
+++ b/drivers/media/rc/keymaps/rc-kworld-315u.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* Kworld 315U 16/* Kworld 315U
16 */ 17 */
diff --git a/drivers/media/rc/keymaps/rc-kworld-plus-tv-analog.c b/drivers/media/rc/keymaps/rc-kworld-plus-tv-analog.c
index 7fa17a369f2d..32998d6b787d 100644
--- a/drivers/media/rc/keymaps/rc-kworld-plus-tv-analog.c
+++ b/drivers/media/rc/keymaps/rc-kworld-plus-tv-analog.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* Kworld Plus TV Analog Lite PCI IR 16/* Kworld Plus TV Analog Lite PCI IR
16 Mauro Carvalho Chehab <mchehab@infradead.org> 17 Mauro Carvalho Chehab <mchehab@infradead.org>
diff --git a/drivers/media/rc/keymaps/rc-leadtek-y04g0051.c b/drivers/media/rc/keymaps/rc-leadtek-y04g0051.c
index 8faa54ff16e6..03d762d986ee 100644
--- a/drivers/media/rc/keymaps/rc-leadtek-y04g0051.c
+++ b/drivers/media/rc/keymaps/rc-leadtek-y04g0051.c
@@ -19,6 +19,7 @@
19 */ 19 */
20 20
21#include <media/rc-map.h> 21#include <media/rc-map.h>
22#include <linux/module.h>
22 23
23static struct rc_map_table leadtek_y04g0051[] = { 24static struct rc_map_table leadtek_y04g0051[] = {
24 { 0x0300, KEY_POWER2 }, 25 { 0x0300, KEY_POWER2 },
diff --git a/drivers/media/rc/keymaps/rc-lirc.c b/drivers/media/rc/keymaps/rc-lirc.c
index e8e23e233c39..fbf08fa6f46e 100644
--- a/drivers/media/rc/keymaps/rc-lirc.c
+++ b/drivers/media/rc/keymaps/rc-lirc.c
@@ -10,6 +10,7 @@
10 */ 10 */
11 11
12#include <media/rc-core.h> 12#include <media/rc-core.h>
13#include <linux/module.h>
13 14
14static struct rc_map_table lirc[] = { 15static struct rc_map_table lirc[] = {
15 { }, 16 { },
diff --git a/drivers/media/rc/keymaps/rc-lme2510.c b/drivers/media/rc/keymaps/rc-lme2510.c
index 129d3f9a461d..51f18bb50a37 100644
--- a/drivers/media/rc/keymaps/rc-lme2510.c
+++ b/drivers/media/rc/keymaps/rc-lme2510.c
@@ -10,6 +10,7 @@
10 */ 10 */
11 11
12#include <media/rc-map.h> 12#include <media/rc-map.h>
13#include <linux/module.h>
13 14
14 15
15static struct rc_map_table lme2510_rc[] = { 16static struct rc_map_table lme2510_rc[] = {
diff --git a/drivers/media/rc/keymaps/rc-manli.c b/drivers/media/rc/keymaps/rc-manli.c
index 23b2d04e7a9f..e7038bb71bf6 100644
--- a/drivers/media/rc/keymaps/rc-manli.c
+++ b/drivers/media/rc/keymaps/rc-manli.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* Michael Tokarev <mjt@tls.msk.ru> 16/* Michael Tokarev <mjt@tls.msk.ru>
16 keytable is used by MANLI MTV00[0x0c] and BeholdTV 40[13] at 17 keytable is used by MANLI MTV00[0x0c] and BeholdTV 40[13] at
diff --git a/drivers/media/rc/keymaps/rc-msi-digivox-ii.c b/drivers/media/rc/keymaps/rc-msi-digivox-ii.c
index 7b9a01b6e4cf..c64e9e30045d 100644
--- a/drivers/media/rc/keymaps/rc-msi-digivox-ii.c
+++ b/drivers/media/rc/keymaps/rc-msi-digivox-ii.c
@@ -19,6 +19,7 @@
19 */ 19 */
20 20
21#include <media/rc-map.h> 21#include <media/rc-map.h>
22#include <linux/module.h>
22 23
23static struct rc_map_table msi_digivox_ii[] = { 24static struct rc_map_table msi_digivox_ii[] = {
24 { 0x0002, KEY_2 }, 25 { 0x0002, KEY_2 },
diff --git a/drivers/media/rc/keymaps/rc-msi-digivox-iii.c b/drivers/media/rc/keymaps/rc-msi-digivox-iii.c
index ae9d06b39157..303a0b73175b 100644
--- a/drivers/media/rc/keymaps/rc-msi-digivox-iii.c
+++ b/drivers/media/rc/keymaps/rc-msi-digivox-iii.c
@@ -19,6 +19,7 @@
19 */ 19 */
20 20
21#include <media/rc-map.h> 21#include <media/rc-map.h>
22#include <linux/module.h>
22 23
23/* MSI DIGIVOX mini III */ 24/* MSI DIGIVOX mini III */
24/* Uses NEC extended 0x61d6. */ 25/* Uses NEC extended 0x61d6. */
diff --git a/drivers/media/rc/keymaps/rc-msi-tvanywhere-plus.c b/drivers/media/rc/keymaps/rc-msi-tvanywhere-plus.c
index 8e9969d1239b..c393d8a50bca 100644
--- a/drivers/media/rc/keymaps/rc-msi-tvanywhere-plus.c
+++ b/drivers/media/rc/keymaps/rc-msi-tvanywhere-plus.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* 16/*
16 Keycodes for remote on the MSI TV@nywhere Plus. The controller IC on the card 17 Keycodes for remote on the MSI TV@nywhere Plus. The controller IC on the card
diff --git a/drivers/media/rc/keymaps/rc-msi-tvanywhere.c b/drivers/media/rc/keymaps/rc-msi-tvanywhere.c
index fdd213ff1adf..a7003d3a3c8a 100644
--- a/drivers/media/rc/keymaps/rc-msi-tvanywhere.c
+++ b/drivers/media/rc/keymaps/rc-msi-tvanywhere.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* MSI TV@nywhere MASTER remote */ 16/* MSI TV@nywhere MASTER remote */
16 17
diff --git a/drivers/media/rc/keymaps/rc-nebula.c b/drivers/media/rc/keymaps/rc-nebula.c
index ddae20e9cd96..3f0ddd7afd30 100644
--- a/drivers/media/rc/keymaps/rc-nebula.c
+++ b/drivers/media/rc/keymaps/rc-nebula.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15static struct rc_map_table nebula[] = { 16static struct rc_map_table nebula[] = {
16 { 0x00, KEY_0 }, 17 { 0x00, KEY_0 },
diff --git a/drivers/media/rc/keymaps/rc-nec-terratec-cinergy-xs.c b/drivers/media/rc/keymaps/rc-nec-terratec-cinergy-xs.c
index 26f114c5c0de..f3b86c8db679 100644
--- a/drivers/media/rc/keymaps/rc-nec-terratec-cinergy-xs.c
+++ b/drivers/media/rc/keymaps/rc-nec-terratec-cinergy-xs.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* Terratec Cinergy Hybrid T USB XS FM 16/* Terratec Cinergy Hybrid T USB XS FM
16 Mauro Carvalho Chehab <mchehab@redhat.com> 17 Mauro Carvalho Chehab <mchehab@redhat.com>
diff --git a/drivers/media/rc/keymaps/rc-norwood.c b/drivers/media/rc/keymaps/rc-norwood.c
index f9f2fa2819b8..9e65f07157ab 100644
--- a/drivers/media/rc/keymaps/rc-norwood.c
+++ b/drivers/media/rc/keymaps/rc-norwood.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* Norwood Micro (non-Pro) TV Tuner 16/* Norwood Micro (non-Pro) TV Tuner
16 By Peter Naulls <peter@chocky.org> 17 By Peter Naulls <peter@chocky.org>
diff --git a/drivers/media/rc/keymaps/rc-npgtech.c b/drivers/media/rc/keymaps/rc-npgtech.c
index 4aa588bf6d69..65d0cfc3c33b 100644
--- a/drivers/media/rc/keymaps/rc-npgtech.c
+++ b/drivers/media/rc/keymaps/rc-npgtech.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15static struct rc_map_table npgtech[] = { 16static struct rc_map_table npgtech[] = {
16 { 0x1d, KEY_SWITCHVIDEOMODE }, /* switch inputs */ 17 { 0x1d, KEY_SWITCHVIDEOMODE }, /* switch inputs */
diff --git a/drivers/media/rc/keymaps/rc-pctv-sedna.c b/drivers/media/rc/keymaps/rc-pctv-sedna.c
index 7cdef6e6cc0f..bf2cbdfe2e32 100644
--- a/drivers/media/rc/keymaps/rc-pctv-sedna.c
+++ b/drivers/media/rc/keymaps/rc-pctv-sedna.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* Mapping for the 28 key remote control as seen at 16/* Mapping for the 28 key remote control as seen at
16 http://www.sednacomputer.com/photo/cardbus-tv.jpg 17 http://www.sednacomputer.com/photo/cardbus-tv.jpg
diff --git a/drivers/media/rc/keymaps/rc-pinnacle-color.c b/drivers/media/rc/keymaps/rc-pinnacle-color.c
index 23b8c505c6aa..b46cd8fe6438 100644
--- a/drivers/media/rc/keymaps/rc-pinnacle-color.c
+++ b/drivers/media/rc/keymaps/rc-pinnacle-color.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15static struct rc_map_table pinnacle_color[] = { 16static struct rc_map_table pinnacle_color[] = {
16 { 0x59, KEY_MUTE }, 17 { 0x59, KEY_MUTE },
diff --git a/drivers/media/rc/keymaps/rc-pinnacle-grey.c b/drivers/media/rc/keymaps/rc-pinnacle-grey.c
index 6ba8c368d10a..d525df9ad868 100644
--- a/drivers/media/rc/keymaps/rc-pinnacle-grey.c
+++ b/drivers/media/rc/keymaps/rc-pinnacle-grey.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15static struct rc_map_table pinnacle_grey[] = { 16static struct rc_map_table pinnacle_grey[] = {
16 { 0x3a, KEY_0 }, 17 { 0x3a, KEY_0 },
diff --git a/drivers/media/rc/keymaps/rc-pinnacle-pctv-hd.c b/drivers/media/rc/keymaps/rc-pinnacle-pctv-hd.c
index 31fc64cd17ba..a4603d035374 100644
--- a/drivers/media/rc/keymaps/rc-pinnacle-pctv-hd.c
+++ b/drivers/media/rc/keymaps/rc-pinnacle-pctv-hd.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* Pinnacle PCTV HD 800i mini remote */ 16/* Pinnacle PCTV HD 800i mini remote */
16 17
diff --git a/drivers/media/rc/keymaps/rc-pixelview-002t.c b/drivers/media/rc/keymaps/rc-pixelview-002t.c
index e5ab071f635a..33eb64333c6f 100644
--- a/drivers/media/rc/keymaps/rc-pixelview-002t.c
+++ b/drivers/media/rc/keymaps/rc-pixelview-002t.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* 16/*
16 * Keytable for 002-T IR remote provided together with Pixelview 17 * Keytable for 002-T IR remote provided together with Pixelview
diff --git a/drivers/media/rc/keymaps/rc-pixelview-mk12.c b/drivers/media/rc/keymaps/rc-pixelview-mk12.c
index 125fc3949c15..21f4dd25c2ec 100644
--- a/drivers/media/rc/keymaps/rc-pixelview-mk12.c
+++ b/drivers/media/rc/keymaps/rc-pixelview-mk12.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* 16/*
16 * Keytable for MK-F12 IR remote provided together with Pixelview 17 * Keytable for MK-F12 IR remote provided together with Pixelview
diff --git a/drivers/media/rc/keymaps/rc-pixelview-new.c b/drivers/media/rc/keymaps/rc-pixelview-new.c
index bd78d6ac1e16..f944ad2cac2b 100644
--- a/drivers/media/rc/keymaps/rc-pixelview-new.c
+++ b/drivers/media/rc/keymaps/rc-pixelview-new.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* 16/*
16 Mauro Carvalho Chehab <mchehab@infradead.org> 17 Mauro Carvalho Chehab <mchehab@infradead.org>
diff --git a/drivers/media/rc/keymaps/rc-pixelview.c b/drivers/media/rc/keymaps/rc-pixelview.c
index 06187e7db446..a6020eea7b95 100644
--- a/drivers/media/rc/keymaps/rc-pixelview.c
+++ b/drivers/media/rc/keymaps/rc-pixelview.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15static struct rc_map_table pixelview[] = { 16static struct rc_map_table pixelview[] = {
16 17
diff --git a/drivers/media/rc/keymaps/rc-powercolor-real-angel.c b/drivers/media/rc/keymaps/rc-powercolor-real-angel.c
index 5f9d546a86c4..e74c571a5e44 100644
--- a/drivers/media/rc/keymaps/rc-powercolor-real-angel.c
+++ b/drivers/media/rc/keymaps/rc-powercolor-real-angel.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* 16/*
16 * Remote control for Powercolor Real Angel 330 17 * Remote control for Powercolor Real Angel 330
diff --git a/drivers/media/rc/keymaps/rc-proteus-2309.c b/drivers/media/rc/keymaps/rc-proteus-2309.c
index 8a3a643879d4..adee8035ce96 100644
--- a/drivers/media/rc/keymaps/rc-proteus-2309.c
+++ b/drivers/media/rc/keymaps/rc-proteus-2309.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* Michal Majchrowicz <mmajchrowicz@gmail.com> */ 16/* Michal Majchrowicz <mmajchrowicz@gmail.com> */
16 17
diff --git a/drivers/media/rc/keymaps/rc-purpletv.c b/drivers/media/rc/keymaps/rc-purpletv.c
index ef90296bfd68..722597a20e4a 100644
--- a/drivers/media/rc/keymaps/rc-purpletv.c
+++ b/drivers/media/rc/keymaps/rc-purpletv.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15static struct rc_map_table purpletv[] = { 16static struct rc_map_table purpletv[] = {
16 { 0x03, KEY_POWER }, 17 { 0x03, KEY_POWER },
diff --git a/drivers/media/rc/keymaps/rc-pv951.c b/drivers/media/rc/keymaps/rc-pv951.c
index 5e8beee94de4..0105d63c07a9 100644
--- a/drivers/media/rc/keymaps/rc-pv951.c
+++ b/drivers/media/rc/keymaps/rc-pv951.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* Mark Phalan <phalanm@o2.ie> */ 16/* Mark Phalan <phalanm@o2.ie> */
16 17
diff --git a/drivers/media/rc/keymaps/rc-rc6-mce.c b/drivers/media/rc/keymaps/rc-rc6-mce.c
index c3907e211d39..753e43ec787b 100644
--- a/drivers/media/rc/keymaps/rc-rc6-mce.c
+++ b/drivers/media/rc/keymaps/rc-rc6-mce.c
@@ -13,6 +13,7 @@
13 */ 13 */
14 14
15#include <media/rc-map.h> 15#include <media/rc-map.h>
16#include <linux/module.h>
16 17
17static struct rc_map_table rc6_mce[] = { 18static struct rc_map_table rc6_mce[] = {
18 19
diff --git a/drivers/media/rc/keymaps/rc-real-audio-220-32-keys.c b/drivers/media/rc/keymaps/rc-real-audio-220-32-keys.c
index 6813d1102118..073694d50f49 100644
--- a/drivers/media/rc/keymaps/rc-real-audio-220-32-keys.c
+++ b/drivers/media/rc/keymaps/rc-real-audio-220-32-keys.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* Zogis Real Audio 220 - 32 keys IR */ 16/* Zogis Real Audio 220 - 32 keys IR */
16 17
diff --git a/drivers/media/rc/keymaps/rc-streamzap.c b/drivers/media/rc/keymaps/rc-streamzap.c
index 92cc10d2f9cd..f9a07578d985 100644
--- a/drivers/media/rc/keymaps/rc-streamzap.c
+++ b/drivers/media/rc/keymaps/rc-streamzap.c
@@ -10,6 +10,7 @@
10 */ 10 */
11 11
12#include <media/rc-map.h> 12#include <media/rc-map.h>
13#include <linux/module.h>
13 14
14static struct rc_map_table streamzap[] = { 15static struct rc_map_table streamzap[] = {
15/* 16/*
diff --git a/drivers/media/rc/keymaps/rc-tbs-nec.c b/drivers/media/rc/keymaps/rc-tbs-nec.c
index 7242ee66f6e0..5039be782bc5 100644
--- a/drivers/media/rc/keymaps/rc-tbs-nec.c
+++ b/drivers/media/rc/keymaps/rc-tbs-nec.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15static struct rc_map_table tbs_nec[] = { 16static struct rc_map_table tbs_nec[] = {
16 { 0x84, KEY_POWER2}, /* power */ 17 { 0x84, KEY_POWER2}, /* power */
diff --git a/drivers/media/rc/keymaps/rc-technisat-usb2.c b/drivers/media/rc/keymaps/rc-technisat-usb2.c
index 4afe5774f192..f9733bb289d6 100644
--- a/drivers/media/rc/keymaps/rc-technisat-usb2.c
+++ b/drivers/media/rc/keymaps/rc-technisat-usb2.c
@@ -30,6 +30,7 @@
30 */ 30 */
31 31
32#include <media/rc-map.h> 32#include <media/rc-map.h>
33#include <linux/module.h>
33 34
34static struct rc_map_table technisat_usb2[] = { 35static struct rc_map_table technisat_usb2[] = {
35 {0x0a0c, KEY_POWER}, 36 {0x0a0c, KEY_POWER},
diff --git a/drivers/media/rc/keymaps/rc-terratec-cinergy-xs.c b/drivers/media/rc/keymaps/rc-terratec-cinergy-xs.c
index bc38e34b9fda..53629fb0151f 100644
--- a/drivers/media/rc/keymaps/rc-terratec-cinergy-xs.c
+++ b/drivers/media/rc/keymaps/rc-terratec-cinergy-xs.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* Terratec Cinergy Hybrid T USB XS 16/* Terratec Cinergy Hybrid T USB XS
16 Devin Heitmueller <dheitmueller@linuxtv.org> 17 Devin Heitmueller <dheitmueller@linuxtv.org>
diff --git a/drivers/media/rc/keymaps/rc-terratec-slim-2.c b/drivers/media/rc/keymaps/rc-terratec-slim-2.c
index 44093918cf03..4c149ef712dc 100644
--- a/drivers/media/rc/keymaps/rc-terratec-slim-2.c
+++ b/drivers/media/rc/keymaps/rc-terratec-slim-2.c
@@ -20,6 +20,7 @@
20 */ 20 */
21 21
22#include <media/rc-map.h> 22#include <media/rc-map.h>
23#include <linux/module.h>
23 24
24/* 25/*
25 * TerraTec slim remote, 6 rows, 3 columns. 26 * TerraTec slim remote, 6 rows, 3 columns.
diff --git a/drivers/media/rc/keymaps/rc-terratec-slim.c b/drivers/media/rc/keymaps/rc-terratec-slim.c
index 1abafa5fd303..3d8a19cdb5a2 100644
--- a/drivers/media/rc/keymaps/rc-terratec-slim.c
+++ b/drivers/media/rc/keymaps/rc-terratec-slim.c
@@ -19,6 +19,7 @@
19 */ 19 */
20 20
21#include <media/rc-map.h> 21#include <media/rc-map.h>
22#include <linux/module.h>
22 23
23/* TerraTec slim remote, 7 rows, 4 columns. */ 24/* TerraTec slim remote, 7 rows, 4 columns. */
24/* Uses NEC extended 0x02bd. */ 25/* Uses NEC extended 0x02bd. */
diff --git a/drivers/media/rc/keymaps/rc-tevii-nec.c b/drivers/media/rc/keymaps/rc-tevii-nec.c
index ef5ba3f32735..f2c3b75d8580 100644
--- a/drivers/media/rc/keymaps/rc-tevii-nec.c
+++ b/drivers/media/rc/keymaps/rc-tevii-nec.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15static struct rc_map_table tevii_nec[] = { 16static struct rc_map_table tevii_nec[] = {
16 { 0x0a, KEY_POWER2}, 17 { 0x0a, KEY_POWER2},
diff --git a/drivers/media/rc/keymaps/rc-tivo.c b/drivers/media/rc/keymaps/rc-tivo.c
index 98ad085531fd..454e06295692 100644
--- a/drivers/media/rc/keymaps/rc-tivo.c
+++ b/drivers/media/rc/keymaps/rc-tivo.c
@@ -9,6 +9,7 @@
9 */ 9 */
10 10
11#include <media/rc-map.h> 11#include <media/rc-map.h>
12#include <linux/module.h>
12 13
13/* 14/*
14 * Initial mapping is for the TiVo remote included in the Nero LiquidTV bundle, 15 * Initial mapping is for the TiVo remote included in the Nero LiquidTV bundle,
diff --git a/drivers/media/rc/keymaps/rc-total-media-in-hand.c b/drivers/media/rc/keymaps/rc-total-media-in-hand.c
index 20ac4e19fb3f..5b9f9ec13680 100644
--- a/drivers/media/rc/keymaps/rc-total-media-in-hand.c
+++ b/drivers/media/rc/keymaps/rc-total-media-in-hand.c
@@ -19,6 +19,7 @@
19 */ 19 */
20 20
21#include <media/rc-map.h> 21#include <media/rc-map.h>
22#include <linux/module.h>
22 23
23/* Uses NEC extended 0x02bd */ 24/* Uses NEC extended 0x02bd */
24static struct rc_map_table total_media_in_hand[] = { 25static struct rc_map_table total_media_in_hand[] = {
diff --git a/drivers/media/rc/keymaps/rc-trekstor.c b/drivers/media/rc/keymaps/rc-trekstor.c
index f8190ead2e32..f9a2e0fabb9f 100644
--- a/drivers/media/rc/keymaps/rc-trekstor.c
+++ b/drivers/media/rc/keymaps/rc-trekstor.c
@@ -19,6 +19,7 @@
19 */ 19 */
20 20
21#include <media/rc-map.h> 21#include <media/rc-map.h>
22#include <linux/module.h>
22 23
23/* TrekStor DVB-T USB Stick remote controller. */ 24/* TrekStor DVB-T USB Stick remote controller. */
24/* Imported from af9015.h. 25/* Imported from af9015.h.
diff --git a/drivers/media/rc/keymaps/rc-tt-1500.c b/drivers/media/rc/keymaps/rc-tt-1500.c
index 295f3738e301..caeff85603e3 100644
--- a/drivers/media/rc/keymaps/rc-tt-1500.c
+++ b/drivers/media/rc/keymaps/rc-tt-1500.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* for the Technotrend 1500 bundled remotes (grey and black): */ 16/* for the Technotrend 1500 bundled remotes (grey and black): */
16 17
diff --git a/drivers/media/rc/keymaps/rc-twinhan1027.c b/drivers/media/rc/keymaps/rc-twinhan1027.c
index 8bf8df64b081..509299b90c90 100644
--- a/drivers/media/rc/keymaps/rc-twinhan1027.c
+++ b/drivers/media/rc/keymaps/rc-twinhan1027.c
@@ -1,4 +1,5 @@
1#include <media/rc-map.h> 1#include <media/rc-map.h>
2#include <linux/module.h>
2 3
3static struct rc_map_table twinhan_vp1027[] = { 4static struct rc_map_table twinhan_vp1027[] = {
4 { 0x16, KEY_POWER2 }, 5 { 0x16, KEY_POWER2 },
diff --git a/drivers/media/rc/keymaps/rc-videomate-m1f.c b/drivers/media/rc/keymaps/rc-videomate-m1f.c
index 4994d405c0a1..3bd1de1f585c 100644
--- a/drivers/media/rc/keymaps/rc-videomate-m1f.c
+++ b/drivers/media/rc/keymaps/rc-videomate-m1f.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15static struct rc_map_table videomate_m1f[] = { 16static struct rc_map_table videomate_m1f[] = {
16 { 0x01, KEY_POWER }, 17 { 0x01, KEY_POWER },
diff --git a/drivers/media/rc/keymaps/rc-videomate-s350.c b/drivers/media/rc/keymaps/rc-videomate-s350.c
index 9e474a6024e5..8bfc3e8d909d 100644
--- a/drivers/media/rc/keymaps/rc-videomate-s350.c
+++ b/drivers/media/rc/keymaps/rc-videomate-s350.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15static struct rc_map_table videomate_s350[] = { 16static struct rc_map_table videomate_s350[] = {
16 { 0x00, KEY_TV}, 17 { 0x00, KEY_TV},
diff --git a/drivers/media/rc/keymaps/rc-videomate-tv-pvr.c b/drivers/media/rc/keymaps/rc-videomate-tv-pvr.c
index 5f2a46e1f8f6..390ce9431b35 100644
--- a/drivers/media/rc/keymaps/rc-videomate-tv-pvr.c
+++ b/drivers/media/rc/keymaps/rc-videomate-tv-pvr.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15static struct rc_map_table videomate_tv_pvr[] = { 16static struct rc_map_table videomate_tv_pvr[] = {
16 { 0x14, KEY_MUTE }, 17 { 0x14, KEY_MUTE },
diff --git a/drivers/media/rc/keymaps/rc-winfast-usbii-deluxe.c b/drivers/media/rc/keymaps/rc-winfast-usbii-deluxe.c
index bd8d021f40aa..2852bf705064 100644
--- a/drivers/media/rc/keymaps/rc-winfast-usbii-deluxe.c
+++ b/drivers/media/rc/keymaps/rc-winfast-usbii-deluxe.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* Leadtek Winfast TV USB II Deluxe remote 16/* Leadtek Winfast TV USB II Deluxe remote
16 Magnus Alm <magnus.alm@gmail.com> 17 Magnus Alm <magnus.alm@gmail.com>
diff --git a/drivers/media/rc/keymaps/rc-winfast.c b/drivers/media/rc/keymaps/rc-winfast.c
index d8a34c14676a..2df1cba23600 100644
--- a/drivers/media/rc/keymaps/rc-winfast.c
+++ b/drivers/media/rc/keymaps/rc-winfast.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <media/rc-map.h> 13#include <media/rc-map.h>
14#include <linux/module.h>
14 15
15/* Table for Leadtek Winfast Remote Controls - used by both bttv and cx88 */ 16/* Table for Leadtek Winfast Remote Controls - used by both bttv and cx88 */
16 17
diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index 666d4bb5b1fb..29f900065d8a 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -18,6 +18,7 @@
18#include <linux/input.h> 18#include <linux/input.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/device.h> 20#include <linux/device.h>
21#include <linux/module.h>
21#include "rc-core-priv.h" 22#include "rc-core-priv.h"
22 23
23/* Sizes are in bytes, 256 bytes allows for 32 entries on x64 */ 24/* Sizes are in bytes, 256 bytes allows for 32 entries on x64 */
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index d285c8c92819..b303a3f8a9f8 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -517,6 +517,13 @@ config VIDEO_NOON010PC30
517 517
518source "drivers/media/video/m5mols/Kconfig" 518source "drivers/media/video/m5mols/Kconfig"
519 519
520config VIDEO_S5K6AA
521 tristate "Samsung S5K6AAFX sensor support"
522 depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
523 ---help---
524 This is a V4L2 sensor-level driver for Samsung S5K6AA(FX) 1.3M
525 camera sensor with an embedded SoC image signal processor.
526
520comment "Flash devices" 527comment "Flash devices"
521 528
522config VIDEO_ADP1653 529config VIDEO_ADP1653
@@ -736,6 +743,8 @@ source "drivers/media/video/cx88/Kconfig"
736 743
737source "drivers/media/video/cx23885/Kconfig" 744source "drivers/media/video/cx23885/Kconfig"
738 745
746source "drivers/media/video/cx25821/Kconfig"
747
739source "drivers/media/video/au0828/Kconfig" 748source "drivers/media/video/au0828/Kconfig"
740 749
741source "drivers/media/video/ivtv/Kconfig" 750source "drivers/media/video/ivtv/Kconfig"
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index 11fff97e7196..117f9c4b4cb9 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -72,6 +72,7 @@ obj-$(CONFIG_VIDEO_MT9V032) += mt9v032.o
72obj-$(CONFIG_VIDEO_SR030PC30) += sr030pc30.o 72obj-$(CONFIG_VIDEO_SR030PC30) += sr030pc30.o
73obj-$(CONFIG_VIDEO_NOON010PC30) += noon010pc30.o 73obj-$(CONFIG_VIDEO_NOON010PC30) += noon010pc30.o
74obj-$(CONFIG_VIDEO_M5MOLS) += m5mols/ 74obj-$(CONFIG_VIDEO_M5MOLS) += m5mols/
75obj-$(CONFIG_VIDEO_S5K6AA) += s5k6aa.o
75obj-$(CONFIG_VIDEO_ADP1653) += adp1653.o 76obj-$(CONFIG_VIDEO_ADP1653) += adp1653.o
76 77
77obj-$(CONFIG_SOC_CAMERA_IMX074) += imx074.o 78obj-$(CONFIG_SOC_CAMERA_IMX074) += imx074.o
@@ -104,6 +105,7 @@ obj-$(CONFIG_VIDEO_CX88) += cx88/
104obj-$(CONFIG_VIDEO_EM28XX) += em28xx/ 105obj-$(CONFIG_VIDEO_EM28XX) += em28xx/
105obj-$(CONFIG_VIDEO_TLG2300) += tlg2300/ 106obj-$(CONFIG_VIDEO_TLG2300) += tlg2300/
106obj-$(CONFIG_VIDEO_CX231XX) += cx231xx/ 107obj-$(CONFIG_VIDEO_CX231XX) += cx231xx/
108obj-$(CONFIG_VIDEO_CX25821) += cx25821/
107obj-$(CONFIG_VIDEO_USBVISION) += usbvision/ 109obj-$(CONFIG_VIDEO_USBVISION) += usbvision/
108obj-$(CONFIG_VIDEO_PVRUSB2) += pvrusb2/ 110obj-$(CONFIG_VIDEO_PVRUSB2) += pvrusb2/
109obj-$(CONFIG_VIDEO_CPIA2) += cpia2/ 111obj-$(CONFIG_VIDEO_CPIA2) += cpia2/
diff --git a/drivers/media/video/adp1653.c b/drivers/media/video/adp1653.c
index 5914390211ff..12eedf4d515a 100644
--- a/drivers/media/video/adp1653.c
+++ b/drivers/media/video/adp1653.c
@@ -31,6 +31,7 @@
31 */ 31 */
32 32
33#include <linux/delay.h> 33#include <linux/delay.h>
34#include <linux/module.h>
34#include <linux/i2c.h> 35#include <linux/i2c.h>
35#include <linux/module.h> 36#include <linux/module.h>
36#include <linux/slab.h> 37#include <linux/slab.h>
diff --git a/drivers/media/video/ak881x.c b/drivers/media/video/ak881x.c
index b388654d48cd..53c496c00fb6 100644
--- a/drivers/media/video/ak881x.c
+++ b/drivers/media/video/ak881x.c
@@ -13,6 +13,7 @@
13#include <linux/platform_device.h> 13#include <linux/platform_device.h>
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/videodev2.h> 15#include <linux/videodev2.h>
16#include <linux/module.h>
16 17
17#include <media/ak881x.h> 18#include <media/ak881x.h>
18#include <media/v4l2-chip-ident.h> 19#include <media/v4l2-chip-ident.h>
diff --git a/drivers/media/video/atmel-isi.c b/drivers/media/video/atmel-isi.c
index 774715d2f84f..8c775c59e120 100644
--- a/drivers/media/video/atmel-isi.c
+++ b/drivers/media/video/atmel-isi.c
@@ -94,6 +94,7 @@ struct atmel_isi {
94 unsigned int irq; 94 unsigned int irq;
95 95
96 struct isi_platform_data *pdata; 96 struct isi_platform_data *pdata;
97 u16 width_flags; /* max 12 bits */
97 98
98 struct list_head video_buffer_list; 99 struct list_head video_buffer_list;
99 struct frame_buffer *active; 100 struct frame_buffer *active;
@@ -248,9 +249,9 @@ static int atmel_isi_wait_status(struct atmel_isi *isi, int wait_reset)
248/* ------------------------------------------------------------------ 249/* ------------------------------------------------------------------
249 Videobuf operations 250 Videobuf operations
250 ------------------------------------------------------------------*/ 251 ------------------------------------------------------------------*/
251static int queue_setup(struct vb2_queue *vq, unsigned int *nbuffers, 252static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
252 unsigned int *nplanes, unsigned int sizes[], 253 unsigned int *nbuffers, unsigned int *nplanes,
253 void *alloc_ctxs[]) 254 unsigned int sizes[], void *alloc_ctxs[])
254{ 255{
255 struct soc_camera_device *icd = soc_camera_from_vb2q(vq); 256 struct soc_camera_device *icd = soc_camera_from_vb2q(vq);
256 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 257 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
@@ -647,50 +648,42 @@ static bool isi_camera_packing_supported(const struct soc_mbus_pixelfmt *fmt)
647 fmt->packing == SOC_MBUS_PACKING_EXTEND16); 648 fmt->packing == SOC_MBUS_PACKING_EXTEND16);
648} 649}
649 650
650static unsigned long make_bus_param(struct atmel_isi *isi) 651#define ISI_BUS_PARAM (V4L2_MBUS_MASTER | \
651{ 652 V4L2_MBUS_HSYNC_ACTIVE_HIGH | \
652 unsigned long flags; 653 V4L2_MBUS_HSYNC_ACTIVE_LOW | \
653 /* 654 V4L2_MBUS_VSYNC_ACTIVE_HIGH | \
654 * Platform specified synchronization and pixel clock polarities are 655 V4L2_MBUS_VSYNC_ACTIVE_LOW | \
655 * only a recommendation and are only used during probing. Atmel ISI 656 V4L2_MBUS_PCLK_SAMPLE_RISING | \
656 * camera interface only works in master mode, i.e., uses HSYNC and 657 V4L2_MBUS_PCLK_SAMPLE_FALLING | \
657 * VSYNC signals from the sensor 658 V4L2_MBUS_DATA_ACTIVE_HIGH)
658 */
659 flags = SOCAM_MASTER |
660 SOCAM_HSYNC_ACTIVE_HIGH |
661 SOCAM_HSYNC_ACTIVE_LOW |
662 SOCAM_VSYNC_ACTIVE_HIGH |
663 SOCAM_VSYNC_ACTIVE_LOW |
664 SOCAM_PCLK_SAMPLE_RISING |
665 SOCAM_PCLK_SAMPLE_FALLING |
666 SOCAM_DATA_ACTIVE_HIGH;
667
668 if (isi->pdata->data_width_flags & ISI_DATAWIDTH_10)
669 flags |= SOCAM_DATAWIDTH_10;
670
671 if (isi->pdata->data_width_flags & ISI_DATAWIDTH_8)
672 flags |= SOCAM_DATAWIDTH_8;
673
674 if (flags & SOCAM_DATAWIDTH_MASK)
675 return flags;
676
677 return 0;
678}
679 659
680static int isi_camera_try_bus_param(struct soc_camera_device *icd, 660static int isi_camera_try_bus_param(struct soc_camera_device *icd,
681 unsigned char buswidth) 661 unsigned char buswidth)
682{ 662{
663 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
683 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 664 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
684 struct atmel_isi *isi = ici->priv; 665 struct atmel_isi *isi = ici->priv;
685 unsigned long camera_flags; 666 struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,};
667 unsigned long common_flags;
686 int ret; 668 int ret;
687 669
688 camera_flags = icd->ops->query_bus_param(icd); 670 ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg);
689 ret = soc_camera_bus_param_compatible(camera_flags, 671 if (!ret) {
690 make_bus_param(isi)); 672 common_flags = soc_mbus_config_compatible(&cfg,
691 if (!ret) 673 ISI_BUS_PARAM);
692 return -EINVAL; 674 if (!common_flags) {
693 return 0; 675 dev_warn(icd->parent,
676 "Flags incompatible: camera 0x%x, host 0x%x\n",
677 cfg.flags, ISI_BUS_PARAM);
678 return -EINVAL;
679 }
680 } else if (ret != -ENOIOCTLCMD) {
681 return ret;
682 }
683
684 if ((1 << (buswidth - 1)) & isi->width_flags)
685 return 0;
686 return -EINVAL;
694} 687}
695 688
696 689
@@ -812,59 +805,71 @@ static int isi_camera_querycap(struct soc_camera_host *ici,
812 805
813static int isi_camera_set_bus_param(struct soc_camera_device *icd, u32 pixfmt) 806static int isi_camera_set_bus_param(struct soc_camera_device *icd, u32 pixfmt)
814{ 807{
808 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
815 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 809 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
816 struct atmel_isi *isi = ici->priv; 810 struct atmel_isi *isi = ici->priv;
817 unsigned long bus_flags, camera_flags, common_flags; 811 struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,};
812 unsigned long common_flags;
818 int ret; 813 int ret;
819 u32 cfg1 = 0; 814 u32 cfg1 = 0;
820 815
821 camera_flags = icd->ops->query_bus_param(icd); 816 ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg);
822 817 if (!ret) {
823 bus_flags = make_bus_param(isi); 818 common_flags = soc_mbus_config_compatible(&cfg,
824 common_flags = soc_camera_bus_param_compatible(camera_flags, bus_flags); 819 ISI_BUS_PARAM);
825 dev_dbg(icd->parent, "Flags cam: 0x%lx host: 0x%lx common: 0x%lx\n", 820 if (!common_flags) {
826 camera_flags, bus_flags, common_flags); 821 dev_warn(icd->parent,
827 if (!common_flags) 822 "Flags incompatible: camera 0x%x, host 0x%x\n",
828 return -EINVAL; 823 cfg.flags, ISI_BUS_PARAM);
824 return -EINVAL;
825 }
826 } else if (ret != -ENOIOCTLCMD) {
827 return ret;
828 } else {
829 common_flags = ISI_BUS_PARAM;
830 }
831 dev_dbg(icd->parent, "Flags cam: 0x%x host: 0x%x common: 0x%lx\n",
832 cfg.flags, ISI_BUS_PARAM, common_flags);
829 833
830 /* Make choises, based on platform preferences */ 834 /* Make choises, based on platform preferences */
831 if ((common_flags & SOCAM_HSYNC_ACTIVE_HIGH) && 835 if ((common_flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) &&
832 (common_flags & SOCAM_HSYNC_ACTIVE_LOW)) { 836 (common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)) {
833 if (isi->pdata->hsync_act_low) 837 if (isi->pdata->hsync_act_low)
834 common_flags &= ~SOCAM_HSYNC_ACTIVE_HIGH; 838 common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_HIGH;
835 else 839 else
836 common_flags &= ~SOCAM_HSYNC_ACTIVE_LOW; 840 common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_LOW;
837 } 841 }
838 842
839 if ((common_flags & SOCAM_VSYNC_ACTIVE_HIGH) && 843 if ((common_flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) &&
840 (common_flags & SOCAM_VSYNC_ACTIVE_LOW)) { 844 (common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)) {
841 if (isi->pdata->vsync_act_low) 845 if (isi->pdata->vsync_act_low)
842 common_flags &= ~SOCAM_VSYNC_ACTIVE_HIGH; 846 common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_HIGH;
843 else 847 else
844 common_flags &= ~SOCAM_VSYNC_ACTIVE_LOW; 848 common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_LOW;
845 } 849 }
846 850
847 if ((common_flags & SOCAM_PCLK_SAMPLE_RISING) && 851 if ((common_flags & V4L2_MBUS_PCLK_SAMPLE_RISING) &&
848 (common_flags & SOCAM_PCLK_SAMPLE_FALLING)) { 852 (common_flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)) {
849 if (isi->pdata->pclk_act_falling) 853 if (isi->pdata->pclk_act_falling)
850 common_flags &= ~SOCAM_PCLK_SAMPLE_RISING; 854 common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_RISING;
851 else 855 else
852 common_flags &= ~SOCAM_PCLK_SAMPLE_FALLING; 856 common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_FALLING;
853 } 857 }
854 858
855 ret = icd->ops->set_bus_param(icd, common_flags); 859 cfg.flags = common_flags;
856 if (ret < 0) { 860 ret = v4l2_subdev_call(sd, video, s_mbus_config, &cfg);
857 dev_dbg(icd->parent, "Camera set_bus_param(%lx) returned %d\n", 861 if (ret < 0 && ret != -ENOIOCTLCMD) {
862 dev_dbg(icd->parent, "camera s_mbus_config(0x%lx) returned %d\n",
858 common_flags, ret); 863 common_flags, ret);
859 return ret; 864 return ret;
860 } 865 }
861 866
862 /* set bus param for ISI */ 867 /* set bus param for ISI */
863 if (common_flags & SOCAM_HSYNC_ACTIVE_LOW) 868 if (common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)
864 cfg1 |= ISI_CFG1_HSYNC_POL_ACTIVE_LOW; 869 cfg1 |= ISI_CFG1_HSYNC_POL_ACTIVE_LOW;
865 if (common_flags & SOCAM_VSYNC_ACTIVE_LOW) 870 if (common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)
866 cfg1 |= ISI_CFG1_VSYNC_POL_ACTIVE_LOW; 871 cfg1 |= ISI_CFG1_VSYNC_POL_ACTIVE_LOW;
867 if (common_flags & SOCAM_PCLK_SAMPLE_FALLING) 872 if (common_flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)
868 cfg1 |= ISI_CFG1_PIXCLK_POL_ACTIVE_FALLING; 873 cfg1 |= ISI_CFG1_PIXCLK_POL_ACTIVE_FALLING;
869 874
870 if (isi->pdata->has_emb_sync) 875 if (isi->pdata->has_emb_sync)
@@ -983,6 +988,11 @@ static int __devinit atmel_isi_probe(struct platform_device *pdev)
983 goto err_ioremap; 988 goto err_ioremap;
984 } 989 }
985 990
991 if (pdata->data_width_flags & ISI_DATAWIDTH_8)
992 isi->width_flags = 1 << 7;
993 if (pdata->data_width_flags & ISI_DATAWIDTH_10)
994 isi->width_flags |= 1 << 9;
995
986 isi_writel(isi, ISI_CTRL, ISI_CTRL_DIS); 996 isi_writel(isi, ISI_CTRL, ISI_CTRL_DIS);
987 997
988 irq = platform_get_irq(pdev, 0); 998 irq = platform_get_irq(pdev, 0);
diff --git a/drivers/media/video/cpia2/cpia2_usb.c b/drivers/media/video/cpia2/cpia2_usb.c
index dc5b07a20f69..59c797c15277 100644
--- a/drivers/media/video/cpia2/cpia2_usb.c
+++ b/drivers/media/video/cpia2/cpia2_usb.c
@@ -31,6 +31,7 @@
31#include <linux/kernel.h> 31#include <linux/kernel.h>
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/usb.h> 33#include <linux/usb.h>
34#include <linux/module.h>
34 35
35#include "cpia2.h" 36#include "cpia2.h"
36 37
diff --git a/drivers/media/video/cx18/cx18-driver.c b/drivers/media/video/cx18/cx18-driver.c
index 9e2f870f4258..c6ff32a6137c 100644
--- a/drivers/media/video/cx18/cx18-driver.c
+++ b/drivers/media/video/cx18/cx18-driver.c
@@ -1085,6 +1085,8 @@ static int __devinit cx18_probe(struct pci_dev *pci_dev,
1085 setup.addr = ADDR_UNSET; 1085 setup.addr = ADDR_UNSET;
1086 setup.type = cx->options.tuner; 1086 setup.type = cx->options.tuner;
1087 setup.mode_mask = T_ANALOG_TV; /* matches TV tuners */ 1087 setup.mode_mask = T_ANALOG_TV; /* matches TV tuners */
1088 if (cx->options.radio > 0)
1089 setup.mode_mask |= T_RADIO;
1088 setup.tuner_callback = (setup.type == TUNER_XC2028) ? 1090 setup.tuner_callback = (setup.type == TUNER_XC2028) ?
1089 cx18_reset_tuner_gpio : NULL; 1091 cx18_reset_tuner_gpio : NULL;
1090 cx18_call_all(cx, tuner, s_type_addr, &setup); 1092 cx18_call_all(cx, tuner, s_type_addr, &setup);
diff --git a/drivers/staging/cx25821/Kconfig b/drivers/media/video/cx25821/Kconfig
index 5f6b54213713..5f6b54213713 100644
--- a/drivers/staging/cx25821/Kconfig
+++ b/drivers/media/video/cx25821/Kconfig
diff --git a/drivers/staging/cx25821/Makefile b/drivers/media/video/cx25821/Makefile
index aedde18c68f9..aedde18c68f9 100644
--- a/drivers/staging/cx25821/Makefile
+++ b/drivers/media/video/cx25821/Makefile
diff --git a/drivers/staging/cx25821/cx25821-alsa.c b/drivers/media/video/cx25821/cx25821-alsa.c
index 09e99de5fd21..09e99de5fd21 100644
--- a/drivers/staging/cx25821/cx25821-alsa.c
+++ b/drivers/media/video/cx25821/cx25821-alsa.c
diff --git a/drivers/staging/cx25821/cx25821-audio-upstream.c b/drivers/media/video/cx25821/cx25821-audio-upstream.c
index c20d6dece154..c20d6dece154 100644
--- a/drivers/staging/cx25821/cx25821-audio-upstream.c
+++ b/drivers/media/video/cx25821/cx25821-audio-upstream.c
diff --git a/drivers/staging/cx25821/cx25821-audio-upstream.h b/drivers/media/video/cx25821/cx25821-audio-upstream.h
index af2ae7c5815a..af2ae7c5815a 100644
--- a/drivers/staging/cx25821/cx25821-audio-upstream.h
+++ b/drivers/media/video/cx25821/cx25821-audio-upstream.h
diff --git a/drivers/staging/cx25821/cx25821-audio.h b/drivers/media/video/cx25821/cx25821-audio.h
index 8eb55b7b88cb..8eb55b7b88cb 100644
--- a/drivers/staging/cx25821/cx25821-audio.h
+++ b/drivers/media/video/cx25821/cx25821-audio.h
diff --git a/drivers/staging/cx25821/cx25821-biffuncs.h b/drivers/media/video/cx25821/cx25821-biffuncs.h
index 9326a7c729ec..9326a7c729ec 100644
--- a/drivers/staging/cx25821/cx25821-biffuncs.h
+++ b/drivers/media/video/cx25821/cx25821-biffuncs.h
diff --git a/drivers/staging/cx25821/cx25821-cards.c b/drivers/media/video/cx25821/cx25821-cards.c
index 6ace60313b49..6ace60313b49 100644
--- a/drivers/staging/cx25821/cx25821-cards.c
+++ b/drivers/media/video/cx25821/cx25821-cards.c
diff --git a/drivers/staging/cx25821/cx25821-core.c b/drivers/media/video/cx25821/cx25821-core.c
index a7fa38f9594e..a7fa38f9594e 100644
--- a/drivers/staging/cx25821/cx25821-core.c
+++ b/drivers/media/video/cx25821/cx25821-core.c
diff --git a/drivers/staging/cx25821/cx25821-gpio.c b/drivers/media/video/cx25821/cx25821-gpio.c
index 29e43b03c85e..29e43b03c85e 100644
--- a/drivers/staging/cx25821/cx25821-gpio.c
+++ b/drivers/media/video/cx25821/cx25821-gpio.c
diff --git a/drivers/staging/cx25821/cx25821-i2c.c b/drivers/media/video/cx25821/cx25821-i2c.c
index 4d3d0ce40785..4d3d0ce40785 100644
--- a/drivers/staging/cx25821/cx25821-i2c.c
+++ b/drivers/media/video/cx25821/cx25821-i2c.c
diff --git a/drivers/staging/cx25821/cx25821-medusa-defines.h b/drivers/media/video/cx25821/cx25821-medusa-defines.h
index 60d197f57556..60d197f57556 100644
--- a/drivers/staging/cx25821/cx25821-medusa-defines.h
+++ b/drivers/media/video/cx25821/cx25821-medusa-defines.h
diff --git a/drivers/staging/cx25821/cx25821-medusa-reg.h b/drivers/media/video/cx25821/cx25821-medusa-reg.h
index 1c1c228352d1..1c1c228352d1 100644
--- a/drivers/staging/cx25821/cx25821-medusa-reg.h
+++ b/drivers/media/video/cx25821/cx25821-medusa-reg.h
diff --git a/drivers/staging/cx25821/cx25821-medusa-video.c b/drivers/media/video/cx25821/cx25821-medusa-video.c
index fc780d0908dc..fc780d0908dc 100644
--- a/drivers/staging/cx25821/cx25821-medusa-video.c
+++ b/drivers/media/video/cx25821/cx25821-medusa-video.c
diff --git a/drivers/staging/cx25821/cx25821-medusa-video.h b/drivers/media/video/cx25821/cx25821-medusa-video.h
index 6175e0961855..6175e0961855 100644
--- a/drivers/staging/cx25821/cx25821-medusa-video.h
+++ b/drivers/media/video/cx25821/cx25821-medusa-video.h
diff --git a/drivers/staging/cx25821/cx25821-reg.h b/drivers/media/video/cx25821/cx25821-reg.h
index a3fc25a4dc0b..a3fc25a4dc0b 100644
--- a/drivers/staging/cx25821/cx25821-reg.h
+++ b/drivers/media/video/cx25821/cx25821-reg.h
diff --git a/drivers/staging/cx25821/cx25821-sram.h b/drivers/media/video/cx25821/cx25821-sram.h
index 5f05d153bc4d..5f05d153bc4d 100644
--- a/drivers/staging/cx25821/cx25821-sram.h
+++ b/drivers/media/video/cx25821/cx25821-sram.h
diff --git a/drivers/staging/cx25821/cx25821-video-upstream-ch2.c b/drivers/media/video/cx25821/cx25821-video-upstream-ch2.c
index 2a724ddfa53f..2a724ddfa53f 100644
--- a/drivers/staging/cx25821/cx25821-video-upstream-ch2.c
+++ b/drivers/media/video/cx25821/cx25821-video-upstream-ch2.c
diff --git a/drivers/staging/cx25821/cx25821-video-upstream-ch2.h b/drivers/media/video/cx25821/cx25821-video-upstream-ch2.h
index d42dab59b663..d42dab59b663 100644
--- a/drivers/staging/cx25821/cx25821-video-upstream-ch2.h
+++ b/drivers/media/video/cx25821/cx25821-video-upstream-ch2.h
diff --git a/drivers/staging/cx25821/cx25821-video-upstream.c b/drivers/media/video/cx25821/cx25821-video-upstream.c
index c0b80068f468..c0b80068f468 100644
--- a/drivers/staging/cx25821/cx25821-video-upstream.c
+++ b/drivers/media/video/cx25821/cx25821-video-upstream.c
diff --git a/drivers/staging/cx25821/cx25821-video-upstream.h b/drivers/media/video/cx25821/cx25821-video-upstream.h
index 268ec8aa6a61..268ec8aa6a61 100644
--- a/drivers/staging/cx25821/cx25821-video-upstream.h
+++ b/drivers/media/video/cx25821/cx25821-video-upstream.h
diff --git a/drivers/staging/cx25821/cx25821-video.c b/drivers/media/video/cx25821/cx25821-video.c
index 084fc0899e13..4d6907cda75b 100644
--- a/drivers/staging/cx25821/cx25821-video.c
+++ b/drivers/media/video/cx25821/cx25821-video.c
@@ -1312,7 +1312,7 @@ int cx25821_vidioc_s_input(struct file *file, void *priv, unsigned int i)
1312 return err; 1312 return err;
1313 } 1313 }
1314 1314
1315 if (i > 2) { 1315 if (i >= CX25821_NR_INPUT) {
1316 dprintk(1, "%s(): -EINVAL\n", __func__); 1316 dprintk(1, "%s(): -EINVAL\n", __func__);
1317 return -EINVAL; 1317 return -EINVAL;
1318 } 1318 }
diff --git a/drivers/staging/cx25821/cx25821-video.h b/drivers/media/video/cx25821/cx25821-video.h
index d0d9538ca5b3..d0d9538ca5b3 100644
--- a/drivers/staging/cx25821/cx25821-video.h
+++ b/drivers/media/video/cx25821/cx25821-video.h
diff --git a/drivers/staging/cx25821/cx25821.h b/drivers/media/video/cx25821/cx25821.h
index db2615b2bac3..2d2d00932823 100644
--- a/drivers/staging/cx25821/cx25821.h
+++ b/drivers/media/video/cx25821/cx25821.h
@@ -98,6 +98,7 @@
98#define CX25821_BOARD_CONEXANT_ATHENA10 1 98#define CX25821_BOARD_CONEXANT_ATHENA10 1
99#define MAX_VID_CHANNEL_NUM 12 99#define MAX_VID_CHANNEL_NUM 12
100#define VID_CHANNEL_NUM 8 100#define VID_CHANNEL_NUM 8
101#define CX25821_NR_INPUT 2
101 102
102struct cx25821_fmt { 103struct cx25821_fmt {
103 char *name; 104 char *name;
@@ -196,7 +197,7 @@ struct cx25821_board {
196 unsigned char radio_addr; 197 unsigned char radio_addr;
197 198
198 u32 clk_freq; 199 u32 clk_freq;
199 struct cx25821_input input[2]; 200 struct cx25821_input input[CX25821_NR_INPUT];
200}; 201};
201 202
202struct cx25821_subid { 203struct cx25821_subid {
diff --git a/drivers/media/video/cx25840/cx25840-ir.c b/drivers/media/video/cx25840/cx25840-ir.c
index b718a3a4bed3..13c380ebb562 100644
--- a/drivers/media/video/cx25840/cx25840-ir.c
+++ b/drivers/media/video/cx25840/cx25840-ir.c
@@ -23,6 +23,7 @@
23 23
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/kfifo.h> 25#include <linux/kfifo.h>
26#include <linux/module.h>
26#include <media/cx25840.h> 27#include <media/cx25840.h>
27#include <media/rc-core.h> 28#include <media/rc-core.h>
28 29
diff --git a/drivers/media/video/davinci/dm355_ccdc.c b/drivers/media/video/davinci/dm355_ccdc.c
index c29ac88ffd78..bd443ee76fff 100644
--- a/drivers/media/video/davinci/dm355_ccdc.c
+++ b/drivers/media/video/davinci/dm355_ccdc.c
@@ -39,6 +39,7 @@
39#include <linux/videodev2.h> 39#include <linux/videodev2.h>
40#include <linux/clk.h> 40#include <linux/clk.h>
41#include <linux/err.h> 41#include <linux/err.h>
42#include <linux/module.h>
42 43
43#include <media/davinci/dm355_ccdc.h> 44#include <media/davinci/dm355_ccdc.h>
44#include <media/davinci/vpss.h> 45#include <media/davinci/vpss.h>
diff --git a/drivers/media/video/davinci/dm644x_ccdc.c b/drivers/media/video/davinci/dm644x_ccdc.c
index c8b32c1c7386..8051c2956478 100644
--- a/drivers/media/video/davinci/dm644x_ccdc.c
+++ b/drivers/media/video/davinci/dm644x_ccdc.c
@@ -40,6 +40,7 @@
40#include <linux/gfp.h> 40#include <linux/gfp.h>
41#include <linux/clk.h> 41#include <linux/clk.h>
42#include <linux/err.h> 42#include <linux/err.h>
43#include <linux/module.h>
43 44
44#include <media/davinci/dm644x_ccdc.h> 45#include <media/davinci/dm644x_ccdc.h>
45#include <media/davinci/vpss.h> 46#include <media/davinci/vpss.h>
diff --git a/drivers/media/video/em28xx/em28xx-cards.c b/drivers/media/video/em28xx/em28xx-cards.c
index 4240f0b720fa..9b747c266afa 100644
--- a/drivers/media/video/em28xx/em28xx-cards.c
+++ b/drivers/media/video/em28xx/em28xx-cards.c
@@ -1923,6 +1923,8 @@ struct usb_device_id em28xx_id_table[] = {
1923 .driver_info = EM2860_BOARD_TERRATEC_AV350 }, 1923 .driver_info = EM2860_BOARD_TERRATEC_AV350 },
1924 { USB_DEVICE(0x0ccd, 0x0096), 1924 { USB_DEVICE(0x0ccd, 0x0096),
1925 .driver_info = EM2860_BOARD_TERRATEC_GRABBY }, 1925 .driver_info = EM2860_BOARD_TERRATEC_GRABBY },
1926 { USB_DEVICE(0x0ccd, 0x10AF),
1927 .driver_info = EM2860_BOARD_TERRATEC_GRABBY },
1926 { USB_DEVICE(0x0fd9, 0x0033), 1928 { USB_DEVICE(0x0fd9, 0x0033),
1927 .driver_info = EM2860_BOARD_ELGATO_VIDEO_CAPTURE}, 1929 .driver_info = EM2860_BOARD_ELGATO_VIDEO_CAPTURE},
1928 { USB_DEVICE(0x185b, 0x2870), 1930 { USB_DEVICE(0x185b, 0x2870),
diff --git a/drivers/media/video/hdpvr/hdpvr-i2c.c b/drivers/media/video/hdpvr/hdpvr-i2c.c
index 2a1ac287591d..82e819fa91c0 100644
--- a/drivers/media/video/hdpvr/hdpvr-i2c.c
+++ b/drivers/media/video/hdpvr/hdpvr-i2c.c
@@ -17,6 +17,7 @@
17 17
18#include <linux/i2c.h> 18#include <linux/i2c.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/export.h>
20 21
21#include "hdpvr.h" 22#include "hdpvr.h"
22 23
diff --git a/drivers/media/video/hexium_gemini.c b/drivers/media/video/hexium_gemini.c
index 9cb039e593db..a62322d5c0d8 100644
--- a/drivers/media/video/hexium_gemini.c
+++ b/drivers/media/video/hexium_gemini.c
@@ -26,6 +26,7 @@
26#define DEBUG_VARIABLE debug 26#define DEBUG_VARIABLE debug
27 27
28#include <media/saa7146_vv.h> 28#include <media/saa7146_vv.h>
29#include <linux/module.h>
29 30
30static int debug; 31static int debug;
31module_param(debug, int, 0); 32module_param(debug, int, 0);
diff --git a/drivers/media/video/hexium_orion.c b/drivers/media/video/hexium_orion.c
index 74861a4b601a..23debc967d94 100644
--- a/drivers/media/video/hexium_orion.c
+++ b/drivers/media/video/hexium_orion.c
@@ -26,6 +26,7 @@
26#define DEBUG_VARIABLE debug 26#define DEBUG_VARIABLE debug
27 27
28#include <media/saa7146_vv.h> 28#include <media/saa7146_vv.h>
29#include <linux/module.h>
29 30
30static int debug; 31static int debug;
31module_param(debug, int, 0); 32module_param(debug, int, 0);
diff --git a/drivers/media/video/imx074.c b/drivers/media/video/imx074.c
index 0382ea752e6f..eec75bb57203 100644
--- a/drivers/media/video/imx074.c
+++ b/drivers/media/video/imx074.c
@@ -12,11 +12,12 @@
12 12
13#include <linux/delay.h> 13#include <linux/delay.h>
14#include <linux/i2c.h> 14#include <linux/i2c.h>
15#include <linux/v4l2-mediabus.h>
15#include <linux/slab.h> 16#include <linux/slab.h>
16#include <linux/videodev2.h> 17#include <linux/videodev2.h>
18#include <linux/module.h>
17 19
18#include <media/soc_camera.h> 20#include <media/soc_camera.h>
19#include <media/soc_mediabus.h>
20#include <media/v4l2-subdev.h> 21#include <media/v4l2-subdev.h>
21#include <media/v4l2-chip-ident.h> 22#include <media/v4l2-chip-ident.h>
22 23
@@ -267,6 +268,17 @@ static int imx074_g_chip_ident(struct v4l2_subdev *sd,
267 return 0; 268 return 0;
268} 269}
269 270
271static int imx074_g_mbus_config(struct v4l2_subdev *sd,
272 struct v4l2_mbus_config *cfg)
273{
274 cfg->type = V4L2_MBUS_CSI2;
275 cfg->flags = V4L2_MBUS_CSI2_2_LANE |
276 V4L2_MBUS_CSI2_CHANNEL_0 |
277 V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
278
279 return 0;
280}
281
270static struct v4l2_subdev_video_ops imx074_subdev_video_ops = { 282static struct v4l2_subdev_video_ops imx074_subdev_video_ops = {
271 .s_stream = imx074_s_stream, 283 .s_stream = imx074_s_stream,
272 .s_mbus_fmt = imx074_s_fmt, 284 .s_mbus_fmt = imx074_s_fmt,
@@ -275,6 +287,7 @@ static struct v4l2_subdev_video_ops imx074_subdev_video_ops = {
275 .enum_mbus_fmt = imx074_enum_fmt, 287 .enum_mbus_fmt = imx074_enum_fmt,
276 .g_crop = imx074_g_crop, 288 .g_crop = imx074_g_crop,
277 .cropcap = imx074_cropcap, 289 .cropcap = imx074_cropcap,
290 .g_mbus_config = imx074_g_mbus_config,
278}; 291};
279 292
280static struct v4l2_subdev_core_ops imx074_subdev_core_ops = { 293static struct v4l2_subdev_core_ops imx074_subdev_core_ops = {
@@ -286,28 +299,7 @@ static struct v4l2_subdev_ops imx074_subdev_ops = {
286 .video = &imx074_subdev_video_ops, 299 .video = &imx074_subdev_video_ops,
287}; 300};
288 301
289/* 302static int imx074_video_probe(struct i2c_client *client)
290 * We have to provide soc-camera operations, but we don't have anything to say
291 * there. The MIPI CSI2 driver will provide .query_bus_param and .set_bus_param
292 */
293static unsigned long imx074_query_bus_param(struct soc_camera_device *icd)
294{
295 return 0;
296}
297
298static int imx074_set_bus_param(struct soc_camera_device *icd,
299 unsigned long flags)
300{
301 return -EINVAL;
302}
303
304static struct soc_camera_ops imx074_ops = {
305 .query_bus_param = imx074_query_bus_param,
306 .set_bus_param = imx074_set_bus_param,
307};
308
309static int imx074_video_probe(struct soc_camera_device *icd,
310 struct i2c_client *client)
311{ 303{
312 int ret; 304 int ret;
313 u16 id; 305 u16 id;
@@ -417,17 +409,10 @@ static int imx074_probe(struct i2c_client *client,
417 const struct i2c_device_id *did) 409 const struct i2c_device_id *did)
418{ 410{
419 struct imx074 *priv; 411 struct imx074 *priv;
420 struct soc_camera_device *icd = client->dev.platform_data;
421 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 412 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
422 struct soc_camera_link *icl; 413 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
423 int ret; 414 int ret;
424 415
425 if (!icd) {
426 dev_err(&client->dev, "IMX074: missing soc-camera data!\n");
427 return -EINVAL;
428 }
429
430 icl = to_soc_camera_link(icd);
431 if (!icl) { 416 if (!icl) {
432 dev_err(&client->dev, "IMX074: missing platform data!\n"); 417 dev_err(&client->dev, "IMX074: missing platform data!\n");
433 return -EINVAL; 418 return -EINVAL;
@@ -445,12 +430,10 @@ static int imx074_probe(struct i2c_client *client,
445 430
446 v4l2_i2c_subdev_init(&priv->subdev, client, &imx074_subdev_ops); 431 v4l2_i2c_subdev_init(&priv->subdev, client, &imx074_subdev_ops);
447 432
448 icd->ops = &imx074_ops;
449 priv->fmt = &imx074_colour_fmts[0]; 433 priv->fmt = &imx074_colour_fmts[0];
450 434
451 ret = imx074_video_probe(icd, client); 435 ret = imx074_video_probe(client);
452 if (ret < 0) { 436 if (ret < 0) {
453 icd->ops = NULL;
454 kfree(priv); 437 kfree(priv);
455 return ret; 438 return ret;
456 } 439 }
@@ -461,10 +444,8 @@ static int imx074_probe(struct i2c_client *client,
461static int imx074_remove(struct i2c_client *client) 444static int imx074_remove(struct i2c_client *client)
462{ 445{
463 struct imx074 *priv = to_imx074(client); 446 struct imx074 *priv = to_imx074(client);
464 struct soc_camera_device *icd = client->dev.platform_data; 447 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
465 struct soc_camera_link *icl = to_soc_camera_link(icd);
466 448
467 icd->ops = NULL;
468 if (icl->free_bus) 449 if (icl->free_bus)
469 icl->free_bus(icl); 450 icl->free_bus(icl);
470 kfree(priv); 451 kfree(priv);
diff --git a/drivers/media/video/ivtv/ivtv-driver.c b/drivers/media/video/ivtv/ivtv-driver.c
index 0fb75524484d..41108a9a195e 100644
--- a/drivers/media/video/ivtv/ivtv-driver.c
+++ b/drivers/media/video/ivtv/ivtv-driver.c
@@ -1180,6 +1180,8 @@ static int __devinit ivtv_probe(struct pci_dev *pdev,
1180 setup.addr = ADDR_UNSET; 1180 setup.addr = ADDR_UNSET;
1181 setup.type = itv->options.tuner; 1181 setup.type = itv->options.tuner;
1182 setup.mode_mask = T_ANALOG_TV; /* matches TV tuners */ 1182 setup.mode_mask = T_ANALOG_TV; /* matches TV tuners */
1183 if (itv->options.radio > 0)
1184 setup.mode_mask |= T_RADIO;
1183 setup.tuner_callback = (setup.type == TUNER_XC2028) ? 1185 setup.tuner_callback = (setup.type == TUNER_XC2028) ?
1184 ivtv_reset_tuner_gpio : NULL; 1186 ivtv_reset_tuner_gpio : NULL;
1185 ivtv_call_all(itv, tuner, s_type_addr, &setup); 1187 ivtv_call_all(itv, tuner, s_type_addr, &setup);
diff --git a/drivers/media/video/m5mols/m5mols_core.c b/drivers/media/video/m5mols/m5mols_core.c
index 5d21d056d6a3..05ab3700647e 100644
--- a/drivers/media/video/m5mols/m5mols_core.c
+++ b/drivers/media/video/m5mols/m5mols_core.c
@@ -21,6 +21,7 @@
21#include <linux/gpio.h> 21#include <linux/gpio.h>
22#include <linux/regulator/consumer.h> 22#include <linux/regulator/consumer.h>
23#include <linux/videodev2.h> 23#include <linux/videodev2.h>
24#include <linux/module.h>
24#include <media/v4l2-ctrls.h> 25#include <media/v4l2-ctrls.h>
25#include <media/v4l2-device.h> 26#include <media/v4l2-device.h>
26#include <media/v4l2-subdev.h> 27#include <media/v4l2-subdev.h>
diff --git a/drivers/media/video/marvell-ccic/mcam-core.c b/drivers/media/video/marvell-ccic/mcam-core.c
index 1141b976dff4..80ec64d2d6d8 100644
--- a/drivers/media/video/marvell-ccic/mcam-core.c
+++ b/drivers/media/video/marvell-ccic/mcam-core.c
@@ -883,7 +883,8 @@ static int mcam_read_setup(struct mcam_camera *cam)
883 * Videobuf2 interface code. 883 * Videobuf2 interface code.
884 */ 884 */
885 885
886static int mcam_vb_queue_setup(struct vb2_queue *vq, unsigned int *nbufs, 886static int mcam_vb_queue_setup(struct vb2_queue *vq,
887 const struct v4l2_format *fmt, unsigned int *nbufs,
887 unsigned int *num_planes, unsigned int sizes[], 888 unsigned int *num_planes, unsigned int sizes[],
888 void *alloc_ctxs[]) 889 void *alloc_ctxs[])
889{ 890{
diff --git a/drivers/media/video/mem2mem_testdev.c b/drivers/media/video/mem2mem_testdev.c
index 9594b52f8605..12897e8a3314 100644
--- a/drivers/media/video/mem2mem_testdev.c
+++ b/drivers/media/video/mem2mem_testdev.c
@@ -738,9 +738,10 @@ static const struct v4l2_ioctl_ops m2mtest_ioctl_ops = {
738 * Queue operations 738 * Queue operations
739 */ 739 */
740 740
741static int m2mtest_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers, 741static int m2mtest_queue_setup(struct vb2_queue *vq,
742 unsigned int *nplanes, unsigned int sizes[], 742 const struct v4l2_format *fmt,
743 void *alloc_ctxs[]) 743 unsigned int *nbuffers, unsigned int *nplanes,
744 unsigned int sizes[], void *alloc_ctxs[])
744{ 745{
745 struct m2mtest_ctx *ctx = vb2_get_drv_priv(vq); 746 struct m2mtest_ctx *ctx = vb2_get_drv_priv(vq);
746 struct m2mtest_q_data *q_data; 747 struct m2mtest_q_data *q_data;
diff --git a/drivers/media/video/mt9m001.c b/drivers/media/video/mt9m001.c
index 4da9cca939c1..e2b1029b16cd 100644
--- a/drivers/media/video/mt9m001.c
+++ b/drivers/media/video/mt9m001.c
@@ -12,10 +12,13 @@
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/i2c.h> 13#include <linux/i2c.h>
14#include <linux/log2.h> 14#include <linux/log2.h>
15#include <linux/module.h>
15 16
17#include <media/soc_camera.h>
18#include <media/soc_mediabus.h>
16#include <media/v4l2-subdev.h> 19#include <media/v4l2-subdev.h>
17#include <media/v4l2-chip-ident.h> 20#include <media/v4l2-chip-ident.h>
18#include <media/soc_camera.h> 21#include <media/v4l2-ctrls.h>
19 22
20/* 23/*
21 * mt9m001 i2c address 0x5d 24 * mt9m001 i2c address 0x5d
@@ -84,15 +87,19 @@ static const struct mt9m001_datafmt mt9m001_monochrome_fmts[] = {
84 87
85struct mt9m001 { 88struct mt9m001 {
86 struct v4l2_subdev subdev; 89 struct v4l2_subdev subdev;
90 struct v4l2_ctrl_handler hdl;
91 struct {
92 /* exposure/auto-exposure cluster */
93 struct v4l2_ctrl *autoexposure;
94 struct v4l2_ctrl *exposure;
95 };
87 struct v4l2_rect rect; /* Sensor window */ 96 struct v4l2_rect rect; /* Sensor window */
88 const struct mt9m001_datafmt *fmt; 97 const struct mt9m001_datafmt *fmt;
89 const struct mt9m001_datafmt *fmts; 98 const struct mt9m001_datafmt *fmts;
90 int num_fmts; 99 int num_fmts;
91 int model; /* V4L2_IDENT_MT9M001* codes from v4l2-chip-ident.h */ 100 int model; /* V4L2_IDENT_MT9M001* codes from v4l2-chip-ident.h */
92 unsigned int gain; 101 unsigned int total_h;
93 unsigned int exposure;
94 unsigned short y_skip_top; /* Lines to skip at the top */ 102 unsigned short y_skip_top; /* Lines to skip at the top */
95 unsigned char autoexposure;
96}; 103};
97 104
98static struct mt9m001 *to_mt9m001(const struct i2c_client *client) 105static struct mt9m001 *to_mt9m001(const struct i2c_client *client)
@@ -165,54 +172,13 @@ static int mt9m001_s_stream(struct v4l2_subdev *sd, int enable)
165 return 0; 172 return 0;
166} 173}
167 174
168static int mt9m001_set_bus_param(struct soc_camera_device *icd,
169 unsigned long flags)
170{
171 struct soc_camera_link *icl = to_soc_camera_link(icd);
172 unsigned long width_flag = flags & SOCAM_DATAWIDTH_MASK;
173
174 /* Only one width bit may be set */
175 if (!is_power_of_2(width_flag))
176 return -EINVAL;
177
178 if (icl->set_bus_param)
179 return icl->set_bus_param(icl, width_flag);
180
181 /*
182 * Without board specific bus width settings we only support the
183 * sensors native bus width
184 */
185 if (width_flag == SOCAM_DATAWIDTH_10)
186 return 0;
187
188 return -EINVAL;
189}
190
191static unsigned long mt9m001_query_bus_param(struct soc_camera_device *icd)
192{
193 struct soc_camera_link *icl = to_soc_camera_link(icd);
194 /* MT9M001 has all capture_format parameters fixed */
195 unsigned long flags = SOCAM_PCLK_SAMPLE_FALLING |
196 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH |
197 SOCAM_DATA_ACTIVE_HIGH | SOCAM_MASTER;
198
199 if (icl->query_bus_param)
200 flags |= icl->query_bus_param(icl) & SOCAM_DATAWIDTH_MASK;
201 else
202 flags |= SOCAM_DATAWIDTH_10;
203
204 return soc_camera_apply_sensor_flags(icl, flags);
205}
206
207static int mt9m001_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) 175static int mt9m001_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
208{ 176{
209 struct i2c_client *client = v4l2_get_subdevdata(sd); 177 struct i2c_client *client = v4l2_get_subdevdata(sd);
210 struct mt9m001 *mt9m001 = to_mt9m001(client); 178 struct mt9m001 *mt9m001 = to_mt9m001(client);
211 struct v4l2_rect rect = a->c; 179 struct v4l2_rect rect = a->c;
212 struct soc_camera_device *icd = client->dev.platform_data;
213 int ret; 180 int ret;
214 const u16 hblank = 9, vblank = 25; 181 const u16 hblank = 9, vblank = 25;
215 unsigned int total_h;
216 182
217 if (mt9m001->fmts == mt9m001_colour_fmts) 183 if (mt9m001->fmts == mt9m001_colour_fmts)
218 /* 184 /*
@@ -231,7 +197,7 @@ static int mt9m001_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
231 soc_camera_limit_side(&rect.top, &rect.height, 197 soc_camera_limit_side(&rect.top, &rect.height,
232 MT9M001_ROW_SKIP, MT9M001_MIN_HEIGHT, MT9M001_MAX_HEIGHT); 198 MT9M001_ROW_SKIP, MT9M001_MIN_HEIGHT, MT9M001_MAX_HEIGHT);
233 199
234 total_h = rect.height + mt9m001->y_skip_top + vblank; 200 mt9m001->total_h = rect.height + mt9m001->y_skip_top + vblank;
235 201
236 /* Blanking and start values - default... */ 202 /* Blanking and start values - default... */
237 ret = reg_write(client, MT9M001_HORIZONTAL_BLANKING, hblank); 203 ret = reg_write(client, MT9M001_HORIZONTAL_BLANKING, hblank);
@@ -240,7 +206,7 @@ static int mt9m001_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
240 206
241 /* 207 /*
242 * The caller provides a supported format, as verified per 208 * The caller provides a supported format, as verified per
243 * call to icd->try_fmt() 209 * call to .try_mbus_fmt()
244 */ 210 */
245 if (!ret) 211 if (!ret)
246 ret = reg_write(client, MT9M001_COLUMN_START, rect.left); 212 ret = reg_write(client, MT9M001_COLUMN_START, rect.left);
@@ -251,17 +217,8 @@ static int mt9m001_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
251 if (!ret) 217 if (!ret)
252 ret = reg_write(client, MT9M001_WINDOW_HEIGHT, 218 ret = reg_write(client, MT9M001_WINDOW_HEIGHT,
253 rect.height + mt9m001->y_skip_top - 1); 219 rect.height + mt9m001->y_skip_top - 1);
254 if (!ret && mt9m001->autoexposure) { 220 if (!ret && v4l2_ctrl_g_ctrl(mt9m001->autoexposure) == V4L2_EXPOSURE_AUTO)
255 ret = reg_write(client, MT9M001_SHUTTER_WIDTH, total_h); 221 ret = reg_write(client, MT9M001_SHUTTER_WIDTH, mt9m001->total_h);
256 if (!ret) {
257 const struct v4l2_queryctrl *qctrl =
258 soc_camera_find_qctrl(icd->ops,
259 V4L2_CID_EXPOSURE);
260 mt9m001->exposure = (524 + (total_h - 1) *
261 (qctrl->maximum - qctrl->minimum)) /
262 1048 + qctrl->minimum;
263 }
264 }
265 222
266 if (!ret) 223 if (!ret)
267 mt9m001->rect = rect; 224 mt9m001->rect = rect;
@@ -421,107 +378,48 @@ static int mt9m001_s_register(struct v4l2_subdev *sd,
421} 378}
422#endif 379#endif
423 380
424static const struct v4l2_queryctrl mt9m001_controls[] = { 381static int mt9m001_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
425 {
426 .id = V4L2_CID_VFLIP,
427 .type = V4L2_CTRL_TYPE_BOOLEAN,
428 .name = "Flip Vertically",
429 .minimum = 0,
430 .maximum = 1,
431 .step = 1,
432 .default_value = 0,
433 }, {
434 .id = V4L2_CID_GAIN,
435 .type = V4L2_CTRL_TYPE_INTEGER,
436 .name = "Gain",
437 .minimum = 0,
438 .maximum = 127,
439 .step = 1,
440 .default_value = 64,
441 .flags = V4L2_CTRL_FLAG_SLIDER,
442 }, {
443 .id = V4L2_CID_EXPOSURE,
444 .type = V4L2_CTRL_TYPE_INTEGER,
445 .name = "Exposure",
446 .minimum = 1,
447 .maximum = 255,
448 .step = 1,
449 .default_value = 255,
450 .flags = V4L2_CTRL_FLAG_SLIDER,
451 }, {
452 .id = V4L2_CID_EXPOSURE_AUTO,
453 .type = V4L2_CTRL_TYPE_BOOLEAN,
454 .name = "Automatic Exposure",
455 .minimum = 0,
456 .maximum = 1,
457 .step = 1,
458 .default_value = 1,
459 }
460};
461
462static struct soc_camera_ops mt9m001_ops = {
463 .set_bus_param = mt9m001_set_bus_param,
464 .query_bus_param = mt9m001_query_bus_param,
465 .controls = mt9m001_controls,
466 .num_controls = ARRAY_SIZE(mt9m001_controls),
467};
468
469static int mt9m001_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
470{ 382{
471 struct i2c_client *client = v4l2_get_subdevdata(sd); 383 struct mt9m001 *mt9m001 = container_of(ctrl->handler,
472 struct mt9m001 *mt9m001 = to_mt9m001(client); 384 struct mt9m001, hdl);
473 int data; 385 s32 min, max;
474 386
475 switch (ctrl->id) { 387 switch (ctrl->id) {
476 case V4L2_CID_VFLIP:
477 data = reg_read(client, MT9M001_READ_OPTIONS2);
478 if (data < 0)
479 return -EIO;
480 ctrl->value = !!(data & 0x8000);
481 break;
482 case V4L2_CID_EXPOSURE_AUTO: 388 case V4L2_CID_EXPOSURE_AUTO:
483 ctrl->value = mt9m001->autoexposure; 389 min = mt9m001->exposure->minimum;
484 break; 390 max = mt9m001->exposure->maximum;
485 case V4L2_CID_GAIN: 391 mt9m001->exposure->val =
486 ctrl->value = mt9m001->gain; 392 (524 + (mt9m001->total_h - 1) * (max - min)) / 1048 + min;
487 break;
488 case V4L2_CID_EXPOSURE:
489 ctrl->value = mt9m001->exposure;
490 break; 393 break;
491 } 394 }
492 return 0; 395 return 0;
493} 396}
494 397
495static int mt9m001_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 398static int mt9m001_s_ctrl(struct v4l2_ctrl *ctrl)
496{ 399{
400 struct mt9m001 *mt9m001 = container_of(ctrl->handler,
401 struct mt9m001, hdl);
402 struct v4l2_subdev *sd = &mt9m001->subdev;
497 struct i2c_client *client = v4l2_get_subdevdata(sd); 403 struct i2c_client *client = v4l2_get_subdevdata(sd);
498 struct mt9m001 *mt9m001 = to_mt9m001(client); 404 struct v4l2_ctrl *exp = mt9m001->exposure;
499 struct soc_camera_device *icd = client->dev.platform_data;
500 const struct v4l2_queryctrl *qctrl;
501 int data; 405 int data;
502 406
503 qctrl = soc_camera_find_qctrl(&mt9m001_ops, ctrl->id);
504
505 if (!qctrl)
506 return -EINVAL;
507
508 switch (ctrl->id) { 407 switch (ctrl->id) {
509 case V4L2_CID_VFLIP: 408 case V4L2_CID_VFLIP:
510 if (ctrl->value) 409 if (ctrl->val)
511 data = reg_set(client, MT9M001_READ_OPTIONS2, 0x8000); 410 data = reg_set(client, MT9M001_READ_OPTIONS2, 0x8000);
512 else 411 else
513 data = reg_clear(client, MT9M001_READ_OPTIONS2, 0x8000); 412 data = reg_clear(client, MT9M001_READ_OPTIONS2, 0x8000);
514 if (data < 0) 413 if (data < 0)
515 return -EIO; 414 return -EIO;
516 break; 415 return 0;
416
517 case V4L2_CID_GAIN: 417 case V4L2_CID_GAIN:
518 if (ctrl->value > qctrl->maximum || ctrl->value < qctrl->minimum)
519 return -EINVAL;
520 /* See Datasheet Table 7, Gain settings. */ 418 /* See Datasheet Table 7, Gain settings. */
521 if (ctrl->value <= qctrl->default_value) { 419 if (ctrl->val <= ctrl->default_value) {
522 /* Pack it into 0..1 step 0.125, register values 0..8 */ 420 /* Pack it into 0..1 step 0.125, register values 0..8 */
523 unsigned long range = qctrl->default_value - qctrl->minimum; 421 unsigned long range = ctrl->default_value - ctrl->minimum;
524 data = ((ctrl->value - qctrl->minimum) * 8 + range / 2) / range; 422 data = ((ctrl->val - ctrl->minimum) * 8 + range / 2) / range;
525 423
526 dev_dbg(&client->dev, "Setting gain %d\n", data); 424 dev_dbg(&client->dev, "Setting gain %d\n", data);
527 data = reg_write(client, MT9M001_GLOBAL_GAIN, data); 425 data = reg_write(client, MT9M001_GLOBAL_GAIN, data);
@@ -530,8 +428,8 @@ static int mt9m001_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
530 } else { 428 } else {
531 /* Pack it into 1.125..15 variable step, register values 9..67 */ 429 /* Pack it into 1.125..15 variable step, register values 9..67 */
532 /* We assume qctrl->maximum - qctrl->default_value - 1 > 0 */ 430 /* We assume qctrl->maximum - qctrl->default_value - 1 > 0 */
533 unsigned long range = qctrl->maximum - qctrl->default_value - 1; 431 unsigned long range = ctrl->maximum - ctrl->default_value - 1;
534 unsigned long gain = ((ctrl->value - qctrl->default_value - 1) * 432 unsigned long gain = ((ctrl->val - ctrl->default_value - 1) *
535 111 + range / 2) / range + 9; 433 111 + range / 2) / range + 9;
536 434
537 if (gain <= 32) 435 if (gain <= 32)
@@ -547,66 +445,44 @@ static int mt9m001_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
547 if (data < 0) 445 if (data < 0)
548 return -EIO; 446 return -EIO;
549 } 447 }
448 return 0;
550 449
551 /* Success */ 450 case V4L2_CID_EXPOSURE_AUTO:
552 mt9m001->gain = ctrl->value; 451 if (ctrl->val == V4L2_EXPOSURE_MANUAL) {
553 break; 452 unsigned long range = exp->maximum - exp->minimum;
554 case V4L2_CID_EXPOSURE: 453 unsigned long shutter = ((exp->val - exp->minimum) * 1048 +
555 /* mt9m001 has maximum == default */
556 if (ctrl->value > qctrl->maximum || ctrl->value < qctrl->minimum)
557 return -EINVAL;
558 else {
559 unsigned long range = qctrl->maximum - qctrl->minimum;
560 unsigned long shutter = ((ctrl->value - qctrl->minimum) * 1048 +
561 range / 2) / range + 1; 454 range / 2) / range + 1;
562 455
563 dev_dbg(&client->dev, 456 dev_dbg(&client->dev,
564 "Setting shutter width from %d to %lu\n", 457 "Setting shutter width from %d to %lu\n",
565 reg_read(client, MT9M001_SHUTTER_WIDTH), 458 reg_read(client, MT9M001_SHUTTER_WIDTH), shutter);
566 shutter);
567 if (reg_write(client, MT9M001_SHUTTER_WIDTH, shutter) < 0) 459 if (reg_write(client, MT9M001_SHUTTER_WIDTH, shutter) < 0)
568 return -EIO; 460 return -EIO;
569 mt9m001->exposure = ctrl->value; 461 } else {
570 mt9m001->autoexposure = 0;
571 }
572 break;
573 case V4L2_CID_EXPOSURE_AUTO:
574 if (ctrl->value) {
575 const u16 vblank = 25; 462 const u16 vblank = 25;
576 unsigned int total_h = mt9m001->rect.height + 463
464 mt9m001->total_h = mt9m001->rect.height +
577 mt9m001->y_skip_top + vblank; 465 mt9m001->y_skip_top + vblank;
578 if (reg_write(client, MT9M001_SHUTTER_WIDTH, 466 if (reg_write(client, MT9M001_SHUTTER_WIDTH, mt9m001->total_h) < 0)
579 total_h) < 0)
580 return -EIO; 467 return -EIO;
581 qctrl = soc_camera_find_qctrl(icd->ops, V4L2_CID_EXPOSURE); 468 }
582 mt9m001->exposure = (524 + (total_h - 1) * 469 return 0;
583 (qctrl->maximum - qctrl->minimum)) /
584 1048 + qctrl->minimum;
585 mt9m001->autoexposure = 1;
586 } else
587 mt9m001->autoexposure = 0;
588 break;
589 } 470 }
590 return 0; 471 return -EINVAL;
591} 472}
592 473
593/* 474/*
594 * Interface active, can use i2c. If it fails, it can indeed mean, that 475 * Interface active, can use i2c. If it fails, it can indeed mean, that
595 * this wasn't our capture interface, so, we wait for the right one 476 * this wasn't our capture interface, so, we wait for the right one
596 */ 477 */
597static int mt9m001_video_probe(struct soc_camera_device *icd, 478static int mt9m001_video_probe(struct soc_camera_link *icl,
598 struct i2c_client *client) 479 struct i2c_client *client)
599{ 480{
600 struct mt9m001 *mt9m001 = to_mt9m001(client); 481 struct mt9m001 *mt9m001 = to_mt9m001(client);
601 struct soc_camera_link *icl = to_soc_camera_link(icd);
602 s32 data; 482 s32 data;
603 unsigned long flags; 483 unsigned long flags;
604 int ret; 484 int ret;
605 485
606 /* We must have a parent by now. And it cannot be a wrong one. */
607 BUG_ON(!icd->parent ||
608 to_soc_camera_host(icd->parent)->nr != icd->iface);
609
610 /* Enable the chip */ 486 /* Enable the chip */
611 data = reg_write(client, MT9M001_CHIP_ENABLE, 1); 487 data = reg_write(client, MT9M001_CHIP_ENABLE, 1);
612 dev_dbg(&client->dev, "write: %d\n", data); 488 dev_dbg(&client->dev, "write: %d\n", data);
@@ -661,18 +537,11 @@ static int mt9m001_video_probe(struct soc_camera_device *icd,
661 dev_err(&client->dev, "Failed to initialise the camera\n"); 537 dev_err(&client->dev, "Failed to initialise the camera\n");
662 538
663 /* mt9m001_init() has reset the chip, returning registers to defaults */ 539 /* mt9m001_init() has reset the chip, returning registers to defaults */
664 mt9m001->gain = 64; 540 return v4l2_ctrl_handler_setup(&mt9m001->hdl);
665 mt9m001->exposure = 255;
666
667 return ret;
668} 541}
669 542
670static void mt9m001_video_remove(struct soc_camera_device *icd) 543static void mt9m001_video_remove(struct soc_camera_link *icl)
671{ 544{
672 struct soc_camera_link *icl = to_soc_camera_link(icd);
673
674 dev_dbg(icd->pdev, "Video removed: %p, %p\n",
675 icd->parent, icd->vdev);
676 if (icl->free_bus) 545 if (icl->free_bus)
677 icl->free_bus(icl); 546 icl->free_bus(icl);
678} 547}
@@ -687,9 +556,12 @@ static int mt9m001_g_skip_top_lines(struct v4l2_subdev *sd, u32 *lines)
687 return 0; 556 return 0;
688} 557}
689 558
559static const struct v4l2_ctrl_ops mt9m001_ctrl_ops = {
560 .g_volatile_ctrl = mt9m001_g_volatile_ctrl,
561 .s_ctrl = mt9m001_s_ctrl,
562};
563
690static struct v4l2_subdev_core_ops mt9m001_subdev_core_ops = { 564static struct v4l2_subdev_core_ops mt9m001_subdev_core_ops = {
691 .g_ctrl = mt9m001_g_ctrl,
692 .s_ctrl = mt9m001_s_ctrl,
693 .g_chip_ident = mt9m001_g_chip_ident, 565 .g_chip_ident = mt9m001_g_chip_ident,
694#ifdef CONFIG_VIDEO_ADV_DEBUG 566#ifdef CONFIG_VIDEO_ADV_DEBUG
695 .g_register = mt9m001_g_register, 567 .g_register = mt9m001_g_register,
@@ -710,6 +582,40 @@ static int mt9m001_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
710 return 0; 582 return 0;
711} 583}
712 584
585static int mt9m001_g_mbus_config(struct v4l2_subdev *sd,
586 struct v4l2_mbus_config *cfg)
587{
588 struct i2c_client *client = v4l2_get_subdevdata(sd);
589 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
590
591 /* MT9M001 has all capture_format parameters fixed */
592 cfg->flags = V4L2_MBUS_PCLK_SAMPLE_FALLING |
593 V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_HIGH |
594 V4L2_MBUS_DATA_ACTIVE_HIGH | V4L2_MBUS_MASTER;
595 cfg->type = V4L2_MBUS_PARALLEL;
596 cfg->flags = soc_camera_apply_board_flags(icl, cfg);
597
598 return 0;
599}
600
601static int mt9m001_s_mbus_config(struct v4l2_subdev *sd,
602 const struct v4l2_mbus_config *cfg)
603{
604 const struct i2c_client *client = v4l2_get_subdevdata(sd);
605 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
606 struct mt9m001 *mt9m001 = to_mt9m001(client);
607 unsigned int bps = soc_mbus_get_fmtdesc(mt9m001->fmt->code)->bits_per_sample;
608
609 if (icl->set_bus_param)
610 return icl->set_bus_param(icl, 1 << (bps - 1));
611
612 /*
613 * Without board specific bus width settings we only support the
614 * sensors native bus width
615 */
616 return bps == 10 ? 0 : -EINVAL;
617}
618
713static struct v4l2_subdev_video_ops mt9m001_subdev_video_ops = { 619static struct v4l2_subdev_video_ops mt9m001_subdev_video_ops = {
714 .s_stream = mt9m001_s_stream, 620 .s_stream = mt9m001_s_stream,
715 .s_mbus_fmt = mt9m001_s_fmt, 621 .s_mbus_fmt = mt9m001_s_fmt,
@@ -719,6 +625,8 @@ static struct v4l2_subdev_video_ops mt9m001_subdev_video_ops = {
719 .g_crop = mt9m001_g_crop, 625 .g_crop = mt9m001_g_crop,
720 .cropcap = mt9m001_cropcap, 626 .cropcap = mt9m001_cropcap,
721 .enum_mbus_fmt = mt9m001_enum_fmt, 627 .enum_mbus_fmt = mt9m001_enum_fmt,
628 .g_mbus_config = mt9m001_g_mbus_config,
629 .s_mbus_config = mt9m001_s_mbus_config,
722}; 630};
723 631
724static struct v4l2_subdev_sensor_ops mt9m001_subdev_sensor_ops = { 632static struct v4l2_subdev_sensor_ops mt9m001_subdev_sensor_ops = {
@@ -735,17 +643,10 @@ static int mt9m001_probe(struct i2c_client *client,
735 const struct i2c_device_id *did) 643 const struct i2c_device_id *did)
736{ 644{
737 struct mt9m001 *mt9m001; 645 struct mt9m001 *mt9m001;
738 struct soc_camera_device *icd = client->dev.platform_data;
739 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 646 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
740 struct soc_camera_link *icl; 647 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
741 int ret; 648 int ret;
742 649
743 if (!icd) {
744 dev_err(&client->dev, "MT9M001: missing soc-camera data!\n");
745 return -EINVAL;
746 }
747
748 icl = to_soc_camera_link(icd);
749 if (!icl) { 650 if (!icl) {
750 dev_err(&client->dev, "MT9M001 driver needs platform data\n"); 651 dev_err(&client->dev, "MT9M001 driver needs platform data\n");
751 return -EINVAL; 652 return -EINVAL;
@@ -762,25 +663,40 @@ static int mt9m001_probe(struct i2c_client *client,
762 return -ENOMEM; 663 return -ENOMEM;
763 664
764 v4l2_i2c_subdev_init(&mt9m001->subdev, client, &mt9m001_subdev_ops); 665 v4l2_i2c_subdev_init(&mt9m001->subdev, client, &mt9m001_subdev_ops);
666 v4l2_ctrl_handler_init(&mt9m001->hdl, 4);
667 v4l2_ctrl_new_std(&mt9m001->hdl, &mt9m001_ctrl_ops,
668 V4L2_CID_VFLIP, 0, 1, 1, 0);
669 v4l2_ctrl_new_std(&mt9m001->hdl, &mt9m001_ctrl_ops,
670 V4L2_CID_GAIN, 0, 127, 1, 64);
671 mt9m001->exposure = v4l2_ctrl_new_std(&mt9m001->hdl, &mt9m001_ctrl_ops,
672 V4L2_CID_EXPOSURE, 1, 255, 1, 255);
673 /*
674 * Simulated autoexposure. If enabled, we calculate shutter width
675 * ourselves in the driver based on vertical blanking and frame width
676 */
677 mt9m001->autoexposure = v4l2_ctrl_new_std_menu(&mt9m001->hdl,
678 &mt9m001_ctrl_ops, V4L2_CID_EXPOSURE_AUTO, 1, 0,
679 V4L2_EXPOSURE_AUTO);
680 mt9m001->subdev.ctrl_handler = &mt9m001->hdl;
681 if (mt9m001->hdl.error) {
682 int err = mt9m001->hdl.error;
765 683
766 /* Second stage probe - when a capture adapter is there */ 684 kfree(mt9m001);
767 icd->ops = &mt9m001_ops; 685 return err;
686 }
687 v4l2_ctrl_auto_cluster(2, &mt9m001->autoexposure,
688 V4L2_EXPOSURE_MANUAL, true);
768 689
690 /* Second stage probe - when a capture adapter is there */
769 mt9m001->y_skip_top = 0; 691 mt9m001->y_skip_top = 0;
770 mt9m001->rect.left = MT9M001_COLUMN_SKIP; 692 mt9m001->rect.left = MT9M001_COLUMN_SKIP;
771 mt9m001->rect.top = MT9M001_ROW_SKIP; 693 mt9m001->rect.top = MT9M001_ROW_SKIP;
772 mt9m001->rect.width = MT9M001_MAX_WIDTH; 694 mt9m001->rect.width = MT9M001_MAX_WIDTH;
773 mt9m001->rect.height = MT9M001_MAX_HEIGHT; 695 mt9m001->rect.height = MT9M001_MAX_HEIGHT;
774 696
775 /* 697 ret = mt9m001_video_probe(icl, client);
776 * Simulated autoexposure. If enabled, we calculate shutter width
777 * ourselves in the driver based on vertical blanking and frame width
778 */
779 mt9m001->autoexposure = 1;
780
781 ret = mt9m001_video_probe(icd, client);
782 if (ret) { 698 if (ret) {
783 icd->ops = NULL; 699 v4l2_ctrl_handler_free(&mt9m001->hdl);
784 kfree(mt9m001); 700 kfree(mt9m001);
785 } 701 }
786 702
@@ -790,10 +706,11 @@ static int mt9m001_probe(struct i2c_client *client,
790static int mt9m001_remove(struct i2c_client *client) 706static int mt9m001_remove(struct i2c_client *client)
791{ 707{
792 struct mt9m001 *mt9m001 = to_mt9m001(client); 708 struct mt9m001 *mt9m001 = to_mt9m001(client);
793 struct soc_camera_device *icd = client->dev.platform_data; 709 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
794 710
795 icd->ops = NULL; 711 v4l2_device_unregister_subdev(&mt9m001->subdev);
796 mt9m001_video_remove(icd); 712 v4l2_ctrl_handler_free(&mt9m001->hdl);
713 mt9m001_video_remove(icl);
797 kfree(mt9m001); 714 kfree(mt9m001);
798 715
799 return 0; 716 return 0;
diff --git a/drivers/media/video/mt9m111.c b/drivers/media/video/mt9m111.c
index 07af26e6bebd..cf2c0fb95f2f 100644
--- a/drivers/media/video/mt9m111.c
+++ b/drivers/media/video/mt9m111.c
@@ -13,10 +13,13 @@
13#include <linux/log2.h> 13#include <linux/log2.h>
14#include <linux/gpio.h> 14#include <linux/gpio.h>
15#include <linux/delay.h> 15#include <linux/delay.h>
16#include <linux/v4l2-mediabus.h>
17#include <linux/module.h>
16 18
19#include <media/soc_camera.h>
17#include <media/v4l2-common.h> 20#include <media/v4l2-common.h>
21#include <media/v4l2-ctrls.h>
18#include <media/v4l2-chip-ident.h> 22#include <media/v4l2-chip-ident.h>
19#include <media/soc_camera.h>
20 23
21/* 24/*
22 * MT9M111, MT9M112 and MT9M131: 25 * MT9M111, MT9M112 and MT9M131:
@@ -177,6 +180,8 @@ enum mt9m111_context {
177 180
178struct mt9m111 { 181struct mt9m111 {
179 struct v4l2_subdev subdev; 182 struct v4l2_subdev subdev;
183 struct v4l2_ctrl_handler hdl;
184 struct v4l2_ctrl *gain;
180 int model; /* V4L2_IDENT_MT9M111 or V4L2_IDENT_MT9M112 code 185 int model; /* V4L2_IDENT_MT9M111 or V4L2_IDENT_MT9M112 code
181 * from v4l2-chip-ident.h */ 186 * from v4l2-chip-ident.h */
182 enum mt9m111_context context; 187 enum mt9m111_context context;
@@ -185,13 +190,8 @@ struct mt9m111 {
185 int power_count; 190 int power_count;
186 const struct mt9m111_datafmt *fmt; 191 const struct mt9m111_datafmt *fmt;
187 int lastpage; /* PageMap cache value */ 192 int lastpage; /* PageMap cache value */
188 unsigned int gain;
189 unsigned char autoexposure;
190 unsigned char datawidth; 193 unsigned char datawidth;
191 unsigned int powered:1; 194 unsigned int powered:1;
192 unsigned int hflip:1;
193 unsigned int vflip:1;
194 unsigned int autowhitebalance:1;
195}; 195};
196 196
197static struct mt9m111 *to_mt9m111(const struct i2c_client *client) 197static struct mt9m111 *to_mt9m111(const struct i2c_client *client)
@@ -363,21 +363,6 @@ static int mt9m111_reset(struct mt9m111 *mt9m111)
363 return ret; 363 return ret;
364} 364}
365 365
366static unsigned long mt9m111_query_bus_param(struct soc_camera_device *icd)
367{
368 struct soc_camera_link *icl = to_soc_camera_link(icd);
369 unsigned long flags = SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING |
370 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH |
371 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8;
372
373 return soc_camera_apply_sensor_flags(icl, flags);
374}
375
376static int mt9m111_set_bus_param(struct soc_camera_device *icd, unsigned long f)
377{
378 return 0;
379}
380
381static int mt9m111_make_rect(struct mt9m111 *mt9m111, 366static int mt9m111_make_rect(struct mt9m111 *mt9m111,
382 struct v4l2_rect *rect) 367 struct v4l2_rect *rect)
383{ 368{
@@ -660,50 +645,6 @@ static int mt9m111_s_register(struct v4l2_subdev *sd,
660} 645}
661#endif 646#endif
662 647
663static const struct v4l2_queryctrl mt9m111_controls[] = {
664 {
665 .id = V4L2_CID_VFLIP,
666 .type = V4L2_CTRL_TYPE_BOOLEAN,
667 .name = "Flip Verticaly",
668 .minimum = 0,
669 .maximum = 1,
670 .step = 1,
671 .default_value = 0,
672 }, {
673 .id = V4L2_CID_HFLIP,
674 .type = V4L2_CTRL_TYPE_BOOLEAN,
675 .name = "Flip Horizontaly",
676 .minimum = 0,
677 .maximum = 1,
678 .step = 1,
679 .default_value = 0,
680 }, { /* gain = 1/32*val (=>gain=1 if val==32) */
681 .id = V4L2_CID_GAIN,
682 .type = V4L2_CTRL_TYPE_INTEGER,
683 .name = "Gain",
684 .minimum = 0,
685 .maximum = 63 * 2 * 2,
686 .step = 1,
687 .default_value = 32,
688 .flags = V4L2_CTRL_FLAG_SLIDER,
689 }, {
690 .id = V4L2_CID_EXPOSURE_AUTO,
691 .type = V4L2_CTRL_TYPE_BOOLEAN,
692 .name = "Auto Exposure",
693 .minimum = 0,
694 .maximum = 1,
695 .step = 1,
696 .default_value = 1,
697 }
698};
699
700static struct soc_camera_ops mt9m111_ops = {
701 .query_bus_param = mt9m111_query_bus_param,
702 .set_bus_param = mt9m111_set_bus_param,
703 .controls = mt9m111_controls,
704 .num_controls = ARRAY_SIZE(mt9m111_controls),
705};
706
707static int mt9m111_set_flip(struct mt9m111 *mt9m111, int flip, int mask) 648static int mt9m111_set_flip(struct mt9m111 *mt9m111, int flip, int mask)
708{ 649{
709 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); 650 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
@@ -744,7 +685,6 @@ static int mt9m111_set_global_gain(struct mt9m111 *mt9m111, int gain)
744 if (gain > 63 * 2 * 2) 685 if (gain > 63 * 2 * 2)
745 return -EINVAL; 686 return -EINVAL;
746 687
747 mt9m111->gain = gain;
748 if ((gain >= 64 * 2) && (gain < 63 * 2 * 2)) 688 if ((gain >= 64 * 2) && (gain < 63 * 2 * 2))
749 val = (1 << 10) | (1 << 9) | (gain / 4); 689 val = (1 << 10) | (1 << 9) | (gain / 4);
750 else if ((gain >= 64) && (gain < 64 * 2)) 690 else if ((gain >= 64) && (gain < 64 * 2))
@@ -758,118 +698,47 @@ static int mt9m111_set_global_gain(struct mt9m111 *mt9m111, int gain)
758static int mt9m111_set_autoexposure(struct mt9m111 *mt9m111, int on) 698static int mt9m111_set_autoexposure(struct mt9m111 *mt9m111, int on)
759{ 699{
760 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); 700 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
761 int ret;
762 701
763 if (on) 702 if (on)
764 ret = reg_set(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOEXPO_EN); 703 return reg_set(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOEXPO_EN);
765 else 704 return reg_clear(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOEXPO_EN);
766 ret = reg_clear(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOEXPO_EN);
767
768 if (!ret)
769 mt9m111->autoexposure = on;
770
771 return ret;
772} 705}
773 706
774static int mt9m111_set_autowhitebalance(struct mt9m111 *mt9m111, int on) 707static int mt9m111_set_autowhitebalance(struct mt9m111 *mt9m111, int on)
775{ 708{
776 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev); 709 struct i2c_client *client = v4l2_get_subdevdata(&mt9m111->subdev);
777 int ret;
778 710
779 if (on) 711 if (on)
780 ret = reg_set(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOWHITEBAL_EN); 712 return reg_set(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOWHITEBAL_EN);
781 else 713 return reg_clear(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOWHITEBAL_EN);
782 ret = reg_clear(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOWHITEBAL_EN);
783
784 if (!ret)
785 mt9m111->autowhitebalance = on;
786
787 return ret;
788}
789
790static int mt9m111_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
791{
792 struct i2c_client *client = v4l2_get_subdevdata(sd);
793 struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev);
794 int data;
795
796 switch (ctrl->id) {
797 case V4L2_CID_VFLIP:
798 if (mt9m111->context == HIGHPOWER)
799 data = reg_read(READ_MODE_B);
800 else
801 data = reg_read(READ_MODE_A);
802
803 if (data < 0)
804 return -EIO;
805 ctrl->value = !!(data & MT9M111_RMB_MIRROR_ROWS);
806 break;
807 case V4L2_CID_HFLIP:
808 if (mt9m111->context == HIGHPOWER)
809 data = reg_read(READ_MODE_B);
810 else
811 data = reg_read(READ_MODE_A);
812
813 if (data < 0)
814 return -EIO;
815 ctrl->value = !!(data & MT9M111_RMB_MIRROR_COLS);
816 break;
817 case V4L2_CID_GAIN:
818 data = mt9m111_get_global_gain(mt9m111);
819 if (data < 0)
820 return data;
821 ctrl->value = data;
822 break;
823 case V4L2_CID_EXPOSURE_AUTO:
824 ctrl->value = mt9m111->autoexposure;
825 break;
826 case V4L2_CID_AUTO_WHITE_BALANCE:
827 ctrl->value = mt9m111->autowhitebalance;
828 break;
829 }
830 return 0;
831} 714}
832 715
833static int mt9m111_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 716static int mt9m111_s_ctrl(struct v4l2_ctrl *ctrl)
834{ 717{
835 struct mt9m111 *mt9m111 = container_of(sd, struct mt9m111, subdev); 718 struct mt9m111 *mt9m111 = container_of(ctrl->handler,
836 const struct v4l2_queryctrl *qctrl; 719 struct mt9m111, hdl);
837 int ret;
838
839 qctrl = soc_camera_find_qctrl(&mt9m111_ops, ctrl->id);
840 if (!qctrl)
841 return -EINVAL;
842 720
843 switch (ctrl->id) { 721 switch (ctrl->id) {
844 case V4L2_CID_VFLIP: 722 case V4L2_CID_VFLIP:
845 mt9m111->vflip = ctrl->value; 723 return mt9m111_set_flip(mt9m111, ctrl->val,
846 ret = mt9m111_set_flip(mt9m111, ctrl->value,
847 MT9M111_RMB_MIRROR_ROWS); 724 MT9M111_RMB_MIRROR_ROWS);
848 break;
849 case V4L2_CID_HFLIP: 725 case V4L2_CID_HFLIP:
850 mt9m111->hflip = ctrl->value; 726 return mt9m111_set_flip(mt9m111, ctrl->val,
851 ret = mt9m111_set_flip(mt9m111, ctrl->value,
852 MT9M111_RMB_MIRROR_COLS); 727 MT9M111_RMB_MIRROR_COLS);
853 break;
854 case V4L2_CID_GAIN: 728 case V4L2_CID_GAIN:
855 ret = mt9m111_set_global_gain(mt9m111, ctrl->value); 729 return mt9m111_set_global_gain(mt9m111, ctrl->val);
856 break;
857 case V4L2_CID_EXPOSURE_AUTO: 730 case V4L2_CID_EXPOSURE_AUTO:
858 ret = mt9m111_set_autoexposure(mt9m111, ctrl->value); 731 return mt9m111_set_autoexposure(mt9m111, ctrl->val);
859 break;
860 case V4L2_CID_AUTO_WHITE_BALANCE: 732 case V4L2_CID_AUTO_WHITE_BALANCE:
861 ret = mt9m111_set_autowhitebalance(mt9m111, ctrl->value); 733 return mt9m111_set_autowhitebalance(mt9m111, ctrl->val);
862 break;
863 default:
864 ret = -EINVAL;
865 } 734 }
866 735
867 return ret; 736 return -EINVAL;
868} 737}
869 738
870static int mt9m111_suspend(struct mt9m111 *mt9m111) 739static int mt9m111_suspend(struct mt9m111 *mt9m111)
871{ 740{
872 mt9m111->gain = mt9m111_get_global_gain(mt9m111); 741 v4l2_ctrl_s_ctrl(mt9m111->gain, mt9m111_get_global_gain(mt9m111));
873 742
874 return 0; 743 return 0;
875} 744}
@@ -879,11 +748,7 @@ static void mt9m111_restore_state(struct mt9m111 *mt9m111)
879 mt9m111_set_context(mt9m111, mt9m111->context); 748 mt9m111_set_context(mt9m111, mt9m111->context);
880 mt9m111_set_pixfmt(mt9m111, mt9m111->fmt->code); 749 mt9m111_set_pixfmt(mt9m111, mt9m111->fmt->code);
881 mt9m111_setup_rect(mt9m111, &mt9m111->rect); 750 mt9m111_setup_rect(mt9m111, &mt9m111->rect);
882 mt9m111_set_flip(mt9m111, mt9m111->hflip, MT9M111_RMB_MIRROR_COLS); 751 v4l2_ctrl_handler_setup(&mt9m111->hdl);
883 mt9m111_set_flip(mt9m111, mt9m111->vflip, MT9M111_RMB_MIRROR_ROWS);
884 mt9m111_set_global_gain(mt9m111, mt9m111->gain);
885 mt9m111_set_autoexposure(mt9m111, mt9m111->autoexposure);
886 mt9m111_set_autowhitebalance(mt9m111, mt9m111->autowhitebalance);
887} 752}
888 753
889static int mt9m111_resume(struct mt9m111 *mt9m111) 754static int mt9m111_resume(struct mt9m111 *mt9m111)
@@ -911,8 +776,6 @@ static int mt9m111_init(struct mt9m111 *mt9m111)
911 ret = mt9m111_reset(mt9m111); 776 ret = mt9m111_reset(mt9m111);
912 if (!ret) 777 if (!ret)
913 ret = mt9m111_set_context(mt9m111, mt9m111->context); 778 ret = mt9m111_set_context(mt9m111, mt9m111->context);
914 if (!ret)
915 ret = mt9m111_set_autoexposure(mt9m111, mt9m111->autoexposure);
916 if (ret) 779 if (ret)
917 dev_err(&client->dev, "mt9m111 init failed: %d\n", ret); 780 dev_err(&client->dev, "mt9m111 init failed: %d\n", ret);
918 return ret; 781 return ret;
@@ -922,22 +785,12 @@ static int mt9m111_init(struct mt9m111 *mt9m111)
922 * Interface active, can use i2c. If it fails, it can indeed mean, that 785 * Interface active, can use i2c. If it fails, it can indeed mean, that
923 * this wasn't our capture interface, so, we wait for the right one 786 * this wasn't our capture interface, so, we wait for the right one
924 */ 787 */
925static int mt9m111_video_probe(struct soc_camera_device *icd, 788static int mt9m111_video_probe(struct i2c_client *client)
926 struct i2c_client *client)
927{ 789{
928 struct mt9m111 *mt9m111 = to_mt9m111(client); 790 struct mt9m111 *mt9m111 = to_mt9m111(client);
929 s32 data; 791 s32 data;
930 int ret; 792 int ret;
931 793
932 /* We must have a parent by now. And it cannot be a wrong one. */
933 BUG_ON(!icd->parent ||
934 to_soc_camera_host(icd->parent)->nr != icd->iface);
935
936 mt9m111->lastpage = -1;
937
938 mt9m111->autoexposure = 1;
939 mt9m111->autowhitebalance = 1;
940
941 data = reg_read(CHIP_VERSION); 794 data = reg_read(CHIP_VERSION);
942 795
943 switch (data) { 796 switch (data) {
@@ -951,17 +804,16 @@ static int mt9m111_video_probe(struct soc_camera_device *icd,
951 dev_info(&client->dev, "Detected a MT9M112 chip ID %x\n", data); 804 dev_info(&client->dev, "Detected a MT9M112 chip ID %x\n", data);
952 break; 805 break;
953 default: 806 default:
954 ret = -ENODEV;
955 dev_err(&client->dev, 807 dev_err(&client->dev,
956 "No MT9M111/MT9M112/MT9M131 chip detected register read %x\n", 808 "No MT9M111/MT9M112/MT9M131 chip detected register read %x\n",
957 data); 809 data);
958 goto ei2c; 810 return -ENODEV;
959 } 811 }
960 812
961 ret = mt9m111_init(mt9m111); 813 ret = mt9m111_init(mt9m111);
962 814 if (ret)
963ei2c: 815 return ret;
964 return ret; 816 return v4l2_ctrl_handler_setup(&mt9m111->hdl);
965} 817}
966 818
967static int mt9m111_s_power(struct v4l2_subdev *sd, int on) 819static int mt9m111_s_power(struct v4l2_subdev *sd, int on)
@@ -998,9 +850,11 @@ out:
998 return ret; 850 return ret;
999} 851}
1000 852
853static const struct v4l2_ctrl_ops mt9m111_ctrl_ops = {
854 .s_ctrl = mt9m111_s_ctrl,
855};
856
1001static struct v4l2_subdev_core_ops mt9m111_subdev_core_ops = { 857static struct v4l2_subdev_core_ops mt9m111_subdev_core_ops = {
1002 .g_ctrl = mt9m111_g_ctrl,
1003 .s_ctrl = mt9m111_s_ctrl,
1004 .g_chip_ident = mt9m111_g_chip_ident, 858 .g_chip_ident = mt9m111_g_chip_ident,
1005 .s_power = mt9m111_s_power, 859 .s_power = mt9m111_s_power,
1006#ifdef CONFIG_VIDEO_ADV_DEBUG 860#ifdef CONFIG_VIDEO_ADV_DEBUG
@@ -1019,6 +873,21 @@ static int mt9m111_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
1019 return 0; 873 return 0;
1020} 874}
1021 875
876static int mt9m111_g_mbus_config(struct v4l2_subdev *sd,
877 struct v4l2_mbus_config *cfg)
878{
879 struct i2c_client *client = v4l2_get_subdevdata(sd);
880 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
881
882 cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_PCLK_SAMPLE_RISING |
883 V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_HIGH |
884 V4L2_MBUS_DATA_ACTIVE_HIGH;
885 cfg->type = V4L2_MBUS_PARALLEL;
886 cfg->flags = soc_camera_apply_board_flags(icl, cfg);
887
888 return 0;
889}
890
1022static struct v4l2_subdev_video_ops mt9m111_subdev_video_ops = { 891static struct v4l2_subdev_video_ops mt9m111_subdev_video_ops = {
1023 .s_mbus_fmt = mt9m111_s_fmt, 892 .s_mbus_fmt = mt9m111_s_fmt,
1024 .g_mbus_fmt = mt9m111_g_fmt, 893 .g_mbus_fmt = mt9m111_g_fmt,
@@ -1027,6 +896,7 @@ static struct v4l2_subdev_video_ops mt9m111_subdev_video_ops = {
1027 .g_crop = mt9m111_g_crop, 896 .g_crop = mt9m111_g_crop,
1028 .cropcap = mt9m111_cropcap, 897 .cropcap = mt9m111_cropcap,
1029 .enum_mbus_fmt = mt9m111_enum_fmt, 898 .enum_mbus_fmt = mt9m111_enum_fmt,
899 .g_mbus_config = mt9m111_g_mbus_config,
1030}; 900};
1031 901
1032static struct v4l2_subdev_ops mt9m111_subdev_ops = { 902static struct v4l2_subdev_ops mt9m111_subdev_ops = {
@@ -1038,17 +908,10 @@ static int mt9m111_probe(struct i2c_client *client,
1038 const struct i2c_device_id *did) 908 const struct i2c_device_id *did)
1039{ 909{
1040 struct mt9m111 *mt9m111; 910 struct mt9m111 *mt9m111;
1041 struct soc_camera_device *icd = client->dev.platform_data;
1042 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 911 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
1043 struct soc_camera_link *icl; 912 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
1044 int ret; 913 int ret;
1045 914
1046 if (!icd) {
1047 dev_err(&client->dev, "mt9m111: soc-camera data missing!\n");
1048 return -EINVAL;
1049 }
1050
1051 icl = to_soc_camera_link(icd);
1052 if (!icl) { 915 if (!icl) {
1053 dev_err(&client->dev, "mt9m111: driver needs platform data\n"); 916 dev_err(&client->dev, "mt9m111: driver needs platform data\n");
1054 return -EINVAL; 917 return -EINVAL;
@@ -1065,19 +928,37 @@ static int mt9m111_probe(struct i2c_client *client,
1065 return -ENOMEM; 928 return -ENOMEM;
1066 929
1067 v4l2_i2c_subdev_init(&mt9m111->subdev, client, &mt9m111_subdev_ops); 930 v4l2_i2c_subdev_init(&mt9m111->subdev, client, &mt9m111_subdev_ops);
931 v4l2_ctrl_handler_init(&mt9m111->hdl, 5);
932 v4l2_ctrl_new_std(&mt9m111->hdl, &mt9m111_ctrl_ops,
933 V4L2_CID_VFLIP, 0, 1, 1, 0);
934 v4l2_ctrl_new_std(&mt9m111->hdl, &mt9m111_ctrl_ops,
935 V4L2_CID_HFLIP, 0, 1, 1, 0);
936 v4l2_ctrl_new_std(&mt9m111->hdl, &mt9m111_ctrl_ops,
937 V4L2_CID_AUTO_WHITE_BALANCE, 0, 1, 1, 1);
938 mt9m111->gain = v4l2_ctrl_new_std(&mt9m111->hdl, &mt9m111_ctrl_ops,
939 V4L2_CID_GAIN, 0, 63 * 2 * 2, 1, 32);
940 v4l2_ctrl_new_std_menu(&mt9m111->hdl,
941 &mt9m111_ctrl_ops, V4L2_CID_EXPOSURE_AUTO, 1, 0,
942 V4L2_EXPOSURE_AUTO);
943 mt9m111->subdev.ctrl_handler = &mt9m111->hdl;
944 if (mt9m111->hdl.error) {
945 int err = mt9m111->hdl.error;
1068 946
1069 /* Second stage probe - when a capture adapter is there */ 947 kfree(mt9m111);
1070 icd->ops = &mt9m111_ops; 948 return err;
949 }
1071 950
951 /* Second stage probe - when a capture adapter is there */
1072 mt9m111->rect.left = MT9M111_MIN_DARK_COLS; 952 mt9m111->rect.left = MT9M111_MIN_DARK_COLS;
1073 mt9m111->rect.top = MT9M111_MIN_DARK_ROWS; 953 mt9m111->rect.top = MT9M111_MIN_DARK_ROWS;
1074 mt9m111->rect.width = MT9M111_MAX_WIDTH; 954 mt9m111->rect.width = MT9M111_MAX_WIDTH;
1075 mt9m111->rect.height = MT9M111_MAX_HEIGHT; 955 mt9m111->rect.height = MT9M111_MAX_HEIGHT;
1076 mt9m111->fmt = &mt9m111_colour_fmts[0]; 956 mt9m111->fmt = &mt9m111_colour_fmts[0];
957 mt9m111->lastpage = -1;
1077 958
1078 ret = mt9m111_video_probe(icd, client); 959 ret = mt9m111_video_probe(client);
1079 if (ret) { 960 if (ret) {
1080 icd->ops = NULL; 961 v4l2_ctrl_handler_free(&mt9m111->hdl);
1081 kfree(mt9m111); 962 kfree(mt9m111);
1082 } 963 }
1083 964
@@ -1087,9 +968,9 @@ static int mt9m111_probe(struct i2c_client *client,
1087static int mt9m111_remove(struct i2c_client *client) 968static int mt9m111_remove(struct i2c_client *client)
1088{ 969{
1089 struct mt9m111 *mt9m111 = to_mt9m111(client); 970 struct mt9m111 *mt9m111 = to_mt9m111(client);
1090 struct soc_camera_device *icd = client->dev.platform_data;
1091 971
1092 icd->ops = NULL; 972 v4l2_device_unregister_subdev(&mt9m111->subdev);
973 v4l2_ctrl_handler_free(&mt9m111->hdl);
1093 kfree(mt9m111); 974 kfree(mt9m111);
1094 975
1095 return 0; 976 return 0;
diff --git a/drivers/media/video/mt9t031.c b/drivers/media/video/mt9t031.c
index 30547cc3f89b..0e78477452ff 100644
--- a/drivers/media/video/mt9t031.c
+++ b/drivers/media/video/mt9t031.c
@@ -13,11 +13,21 @@
13#include <linux/log2.h> 13#include <linux/log2.h>
14#include <linux/pm.h> 14#include <linux/pm.h>
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/v4l2-mediabus.h>
16#include <linux/videodev2.h> 17#include <linux/videodev2.h>
18#include <linux/module.h>
17 19
18#include <media/soc_camera.h> 20#include <media/soc_camera.h>
19#include <media/v4l2-chip-ident.h> 21#include <media/v4l2-chip-ident.h>
20#include <media/v4l2-subdev.h> 22#include <media/v4l2-subdev.h>
23#include <media/v4l2-ctrls.h>
24
25/*
26 * ATTENTION: this driver still cannot be used outside of the soc-camera
27 * framework because of its PM implementation, using the video_device node.
28 * If hardware becomes available for testing, alternative PM approaches shall
29 * be considered and tested.
30 */
21 31
22/* 32/*
23 * mt9t031 i2c address 0x5d 33 * mt9t031 i2c address 0x5d
@@ -57,21 +67,20 @@
57#define MT9T031_COLUMN_SKIP 32 67#define MT9T031_COLUMN_SKIP 32
58#define MT9T031_ROW_SKIP 20 68#define MT9T031_ROW_SKIP 20
59 69
60#define MT9T031_BUS_PARAM (SOCAM_PCLK_SAMPLE_RISING | \
61 SOCAM_PCLK_SAMPLE_FALLING | SOCAM_HSYNC_ACTIVE_HIGH | \
62 SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_DATA_ACTIVE_HIGH | \
63 SOCAM_MASTER | SOCAM_DATAWIDTH_10)
64
65struct mt9t031 { 70struct mt9t031 {
66 struct v4l2_subdev subdev; 71 struct v4l2_subdev subdev;
72 struct v4l2_ctrl_handler hdl;
73 struct {
74 /* exposure/auto-exposure cluster */
75 struct v4l2_ctrl *autoexposure;
76 struct v4l2_ctrl *exposure;
77 };
67 struct v4l2_rect rect; /* Sensor window */ 78 struct v4l2_rect rect; /* Sensor window */
68 int model; /* V4L2_IDENT_MT9T031* codes from v4l2-chip-ident.h */ 79 int model; /* V4L2_IDENT_MT9T031* codes from v4l2-chip-ident.h */
69 u16 xskip; 80 u16 xskip;
70 u16 yskip; 81 u16 yskip;
71 unsigned int gain; 82 unsigned int total_h;
72 unsigned short y_skip_top; /* Lines to skip at the top */ 83 unsigned short y_skip_top; /* Lines to skip at the top */
73 unsigned int exposure;
74 unsigned char autoexposure;
75}; 84};
76 85
77static struct mt9t031 *to_mt9t031(const struct i2c_client *client) 86static struct mt9t031 *to_mt9t031(const struct i2c_client *client)
@@ -179,95 +188,6 @@ static int mt9t031_s_stream(struct v4l2_subdev *sd, int enable)
179 return 0; 188 return 0;
180} 189}
181 190
182static int mt9t031_set_bus_param(struct soc_camera_device *icd,
183 unsigned long flags)
184{
185 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
186
187 /* The caller should have queried our parameters, check anyway */
188 if (flags & ~MT9T031_BUS_PARAM)
189 return -EINVAL;
190
191 if (flags & SOCAM_PCLK_SAMPLE_FALLING)
192 reg_clear(client, MT9T031_PIXEL_CLOCK_CONTROL, 0x8000);
193 else
194 reg_set(client, MT9T031_PIXEL_CLOCK_CONTROL, 0x8000);
195
196 return 0;
197}
198
199static unsigned long mt9t031_query_bus_param(struct soc_camera_device *icd)
200{
201 struct soc_camera_link *icl = to_soc_camera_link(icd);
202
203 return soc_camera_apply_sensor_flags(icl, MT9T031_BUS_PARAM);
204}
205
206enum {
207 MT9T031_CTRL_VFLIP,
208 MT9T031_CTRL_HFLIP,
209 MT9T031_CTRL_GAIN,
210 MT9T031_CTRL_EXPOSURE,
211 MT9T031_CTRL_EXPOSURE_AUTO,
212};
213
214static const struct v4l2_queryctrl mt9t031_controls[] = {
215 [MT9T031_CTRL_VFLIP] = {
216 .id = V4L2_CID_VFLIP,
217 .type = V4L2_CTRL_TYPE_BOOLEAN,
218 .name = "Flip Vertically",
219 .minimum = 0,
220 .maximum = 1,
221 .step = 1,
222 .default_value = 0,
223 },
224 [MT9T031_CTRL_HFLIP] = {
225 .id = V4L2_CID_HFLIP,
226 .type = V4L2_CTRL_TYPE_BOOLEAN,
227 .name = "Flip Horizontally",
228 .minimum = 0,
229 .maximum = 1,
230 .step = 1,
231 .default_value = 0,
232 },
233 [MT9T031_CTRL_GAIN] = {
234 .id = V4L2_CID_GAIN,
235 .type = V4L2_CTRL_TYPE_INTEGER,
236 .name = "Gain",
237 .minimum = 0,
238 .maximum = 127,
239 .step = 1,
240 .default_value = 64,
241 .flags = V4L2_CTRL_FLAG_SLIDER,
242 },
243 [MT9T031_CTRL_EXPOSURE] = {
244 .id = V4L2_CID_EXPOSURE,
245 .type = V4L2_CTRL_TYPE_INTEGER,
246 .name = "Exposure",
247 .minimum = 1,
248 .maximum = 255,
249 .step = 1,
250 .default_value = 255,
251 .flags = V4L2_CTRL_FLAG_SLIDER,
252 },
253 [MT9T031_CTRL_EXPOSURE_AUTO] = {
254 .id = V4L2_CID_EXPOSURE_AUTO,
255 .type = V4L2_CTRL_TYPE_BOOLEAN,
256 .name = "Automatic Exposure",
257 .minimum = 0,
258 .maximum = 1,
259 .step = 1,
260 .default_value = 1,
261 }
262};
263
264static struct soc_camera_ops mt9t031_ops = {
265 .set_bus_param = mt9t031_set_bus_param,
266 .query_bus_param = mt9t031_query_bus_param,
267 .controls = mt9t031_controls,
268 .num_controls = ARRAY_SIZE(mt9t031_controls),
269};
270
271/* target must be _even_ */ 191/* target must be _even_ */
272static u16 mt9t031_skip(s32 *source, s32 target, s32 max) 192static u16 mt9t031_skip(s32 *source, s32 target, s32 max)
273{ 193{
@@ -353,7 +273,7 @@ static int mt9t031_set_params(struct i2c_client *client,
353 273
354 /* 274 /*
355 * The caller provides a supported format, as guaranteed by 275 * The caller provides a supported format, as guaranteed by
356 * icd->try_fmt_cap(), soc_camera_s_crop() and soc_camera_cropcap() 276 * .try_mbus_fmt(), soc_camera_s_crop() and soc_camera_cropcap()
357 */ 277 */
358 if (ret >= 0) 278 if (ret >= 0)
359 ret = reg_write(client, MT9T031_COLUMN_START, rect->left); 279 ret = reg_write(client, MT9T031_COLUMN_START, rect->left);
@@ -364,17 +284,10 @@ static int mt9t031_set_params(struct i2c_client *client,
364 if (ret >= 0) 284 if (ret >= 0)
365 ret = reg_write(client, MT9T031_WINDOW_HEIGHT, 285 ret = reg_write(client, MT9T031_WINDOW_HEIGHT,
366 rect->height + mt9t031->y_skip_top - 1); 286 rect->height + mt9t031->y_skip_top - 1);
367 if (ret >= 0 && mt9t031->autoexposure) { 287 if (ret >= 0 && v4l2_ctrl_g_ctrl(mt9t031->autoexposure) == V4L2_EXPOSURE_AUTO) {
368 unsigned int total_h = rect->height + mt9t031->y_skip_top + vblank; 288 mt9t031->total_h = rect->height + mt9t031->y_skip_top + vblank;
369 ret = set_shutter(client, total_h); 289
370 if (ret >= 0) { 290 ret = set_shutter(client, mt9t031->total_h);
371 const u32 shutter_max = MT9T031_MAX_HEIGHT + vblank;
372 const struct v4l2_queryctrl *qctrl =
373 &mt9t031_controls[MT9T031_CTRL_EXPOSURE];
374 mt9t031->exposure = (shutter_max / 2 + (total_h - 1) *
375 (qctrl->maximum - qctrl->minimum)) /
376 shutter_max + qctrl->minimum;
377 }
378 } 291 }
379 292
380 /* Re-enable register update, commit all changes */ 293 /* Re-enable register update, commit all changes */
@@ -543,71 +456,57 @@ static int mt9t031_s_register(struct v4l2_subdev *sd,
543} 456}
544#endif 457#endif
545 458
546static int mt9t031_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 459static int mt9t031_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
547{ 460{
548 struct i2c_client *client = v4l2_get_subdevdata(sd); 461 struct mt9t031 *mt9t031 = container_of(ctrl->handler,
549 struct mt9t031 *mt9t031 = to_mt9t031(client); 462 struct mt9t031, hdl);
550 int data; 463 const u32 shutter_max = MT9T031_MAX_HEIGHT + MT9T031_VERTICAL_BLANK;
464 s32 min, max;
551 465
552 switch (ctrl->id) { 466 switch (ctrl->id) {
553 case V4L2_CID_VFLIP:
554 data = reg_read(client, MT9T031_READ_MODE_2);
555 if (data < 0)
556 return -EIO;
557 ctrl->value = !!(data & 0x8000);
558 break;
559 case V4L2_CID_HFLIP:
560 data = reg_read(client, MT9T031_READ_MODE_2);
561 if (data < 0)
562 return -EIO;
563 ctrl->value = !!(data & 0x4000);
564 break;
565 case V4L2_CID_EXPOSURE_AUTO: 467 case V4L2_CID_EXPOSURE_AUTO:
566 ctrl->value = mt9t031->autoexposure; 468 min = mt9t031->exposure->minimum;
567 break; 469 max = mt9t031->exposure->maximum;
568 case V4L2_CID_GAIN: 470 mt9t031->exposure->val =
569 ctrl->value = mt9t031->gain; 471 (shutter_max / 2 + (mt9t031->total_h - 1) * (max - min))
570 break; 472 / shutter_max + min;
571 case V4L2_CID_EXPOSURE:
572 ctrl->value = mt9t031->exposure;
573 break; 473 break;
574 } 474 }
575 return 0; 475 return 0;
576} 476}
577 477
578static int mt9t031_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 478static int mt9t031_s_ctrl(struct v4l2_ctrl *ctrl)
579{ 479{
480 struct mt9t031 *mt9t031 = container_of(ctrl->handler,
481 struct mt9t031, hdl);
482 struct v4l2_subdev *sd = &mt9t031->subdev;
580 struct i2c_client *client = v4l2_get_subdevdata(sd); 483 struct i2c_client *client = v4l2_get_subdevdata(sd);
581 struct mt9t031 *mt9t031 = to_mt9t031(client); 484 struct v4l2_ctrl *exp = mt9t031->exposure;
582 const struct v4l2_queryctrl *qctrl;
583 int data; 485 int data;
584 486
585 switch (ctrl->id) { 487 switch (ctrl->id) {
586 case V4L2_CID_VFLIP: 488 case V4L2_CID_VFLIP:
587 if (ctrl->value) 489 if (ctrl->val)
588 data = reg_set(client, MT9T031_READ_MODE_2, 0x8000); 490 data = reg_set(client, MT9T031_READ_MODE_2, 0x8000);
589 else 491 else
590 data = reg_clear(client, MT9T031_READ_MODE_2, 0x8000); 492 data = reg_clear(client, MT9T031_READ_MODE_2, 0x8000);
591 if (data < 0) 493 if (data < 0)
592 return -EIO; 494 return -EIO;
593 break; 495 return 0;
594 case V4L2_CID_HFLIP: 496 case V4L2_CID_HFLIP:
595 if (ctrl->value) 497 if (ctrl->val)
596 data = reg_set(client, MT9T031_READ_MODE_2, 0x4000); 498 data = reg_set(client, MT9T031_READ_MODE_2, 0x4000);
597 else 499 else
598 data = reg_clear(client, MT9T031_READ_MODE_2, 0x4000); 500 data = reg_clear(client, MT9T031_READ_MODE_2, 0x4000);
599 if (data < 0) 501 if (data < 0)
600 return -EIO; 502 return -EIO;
601 break; 503 return 0;
602 case V4L2_CID_GAIN: 504 case V4L2_CID_GAIN:
603 qctrl = &mt9t031_controls[MT9T031_CTRL_GAIN];
604 if (ctrl->value > qctrl->maximum || ctrl->value < qctrl->minimum)
605 return -EINVAL;
606 /* See Datasheet Table 7, Gain settings. */ 505 /* See Datasheet Table 7, Gain settings. */
607 if (ctrl->value <= qctrl->default_value) { 506 if (ctrl->val <= ctrl->default_value) {
608 /* Pack it into 0..1 step 0.125, register values 0..8 */ 507 /* Pack it into 0..1 step 0.125, register values 0..8 */
609 unsigned long range = qctrl->default_value - qctrl->minimum; 508 unsigned long range = ctrl->default_value - ctrl->minimum;
610 data = ((ctrl->value - qctrl->minimum) * 8 + range / 2) / range; 509 data = ((ctrl->val - ctrl->minimum) * 8 + range / 2) / range;
611 510
612 dev_dbg(&client->dev, "Setting gain %d\n", data); 511 dev_dbg(&client->dev, "Setting gain %d\n", data);
613 data = reg_write(client, MT9T031_GLOBAL_GAIN, data); 512 data = reg_write(client, MT9T031_GLOBAL_GAIN, data);
@@ -616,9 +515,9 @@ static int mt9t031_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
616 } else { 515 } else {
617 /* Pack it into 1.125..128 variable step, register values 9..0x7860 */ 516 /* Pack it into 1.125..128 variable step, register values 9..0x7860 */
618 /* We assume qctrl->maximum - qctrl->default_value - 1 > 0 */ 517 /* We assume qctrl->maximum - qctrl->default_value - 1 > 0 */
619 unsigned long range = qctrl->maximum - qctrl->default_value - 1; 518 unsigned long range = ctrl->maximum - ctrl->default_value - 1;
620 /* calculated gain: map 65..127 to 9..1024 step 0.125 */ 519 /* calculated gain: map 65..127 to 9..1024 step 0.125 */
621 unsigned long gain = ((ctrl->value - qctrl->default_value - 1) * 520 unsigned long gain = ((ctrl->val - ctrl->default_value - 1) *
622 1015 + range / 2) / range + 9; 521 1015 + range / 2) / range + 9;
623 522
624 if (gain <= 32) /* calculated gain 9..32 -> 9..32 */ 523 if (gain <= 32) /* calculated gain 9..32 -> 9..32 */
@@ -635,19 +534,13 @@ static int mt9t031_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
635 if (data < 0) 534 if (data < 0)
636 return -EIO; 535 return -EIO;
637 } 536 }
537 return 0;
638 538
639 /* Success */ 539 case V4L2_CID_EXPOSURE_AUTO:
640 mt9t031->gain = ctrl->value; 540 if (ctrl->val == V4L2_EXPOSURE_MANUAL) {
641 break; 541 unsigned int range = exp->maximum - exp->minimum;
642 case V4L2_CID_EXPOSURE: 542 unsigned int shutter = ((exp->val - exp->minimum) * 1048 +
643 qctrl = &mt9t031_controls[MT9T031_CTRL_EXPOSURE]; 543 range / 2) / range + 1;
644 /* mt9t031 has maximum == default */
645 if (ctrl->value > qctrl->maximum || ctrl->value < qctrl->minimum)
646 return -EINVAL;
647 else {
648 const unsigned long range = qctrl->maximum - qctrl->minimum;
649 const u32 shutter = ((ctrl->value - qctrl->minimum) * 1048 +
650 range / 2) / range + 1;
651 u32 old; 544 u32 old;
652 545
653 get_shutter(client, &old); 546 get_shutter(client, &old);
@@ -655,27 +548,15 @@ static int mt9t031_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
655 old, shutter); 548 old, shutter);
656 if (set_shutter(client, shutter) < 0) 549 if (set_shutter(client, shutter) < 0)
657 return -EIO; 550 return -EIO;
658 mt9t031->exposure = ctrl->value; 551 } else {
659 mt9t031->autoexposure = 0;
660 }
661 break;
662 case V4L2_CID_EXPOSURE_AUTO:
663 if (ctrl->value) {
664 const u16 vblank = MT9T031_VERTICAL_BLANK; 552 const u16 vblank = MT9T031_VERTICAL_BLANK;
665 const u32 shutter_max = MT9T031_MAX_HEIGHT + vblank; 553 mt9t031->total_h = mt9t031->rect.height +
666 unsigned int total_h = mt9t031->rect.height +
667 mt9t031->y_skip_top + vblank; 554 mt9t031->y_skip_top + vblank;
668 555
669 if (set_shutter(client, total_h) < 0) 556 if (set_shutter(client, mt9t031->total_h) < 0)
670 return -EIO; 557 return -EIO;
671 qctrl = &mt9t031_controls[MT9T031_CTRL_EXPOSURE]; 558 }
672 mt9t031->exposure = (shutter_max / 2 + (total_h - 1) * 559 return 0;
673 (qctrl->maximum - qctrl->minimum)) /
674 shutter_max + qctrl->minimum;
675 mt9t031->autoexposure = 1;
676 } else
677 mt9t031->autoexposure = 0;
678 break;
679 default: 560 default:
680 return -EINVAL; 561 return -EINVAL;
681 } 562 }
@@ -700,8 +581,7 @@ static int mt9t031_runtime_suspend(struct device *dev)
700static int mt9t031_runtime_resume(struct device *dev) 581static int mt9t031_runtime_resume(struct device *dev)
701{ 582{
702 struct video_device *vdev = to_video_device(dev); 583 struct video_device *vdev = to_video_device(dev);
703 struct soc_camera_device *icd = dev_get_drvdata(vdev->parent); 584 struct v4l2_subdev *sd = soc_camera_vdev_to_subdev(vdev);
704 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
705 struct i2c_client *client = v4l2_get_subdevdata(sd); 585 struct i2c_client *client = v4l2_get_subdevdata(sd);
706 struct mt9t031 *mt9t031 = to_mt9t031(client); 586 struct mt9t031 *mt9t031 = to_mt9t031(client);
707 587
@@ -734,6 +614,19 @@ static struct device_type mt9t031_dev_type = {
734 .pm = &mt9t031_dev_pm_ops, 614 .pm = &mt9t031_dev_pm_ops,
735}; 615};
736 616
617static int mt9t031_s_power(struct v4l2_subdev *sd, int on)
618{
619 struct i2c_client *client = v4l2_get_subdevdata(sd);
620 struct video_device *vdev = soc_camera_i2c_to_vdev(client);
621
622 if (on)
623 vdev->dev.type = &mt9t031_dev_type;
624 else
625 vdev->dev.type = NULL;
626
627 return 0;
628}
629
737/* 630/*
738 * Interface active, can use i2c. If it fails, it can indeed mean, that 631 * Interface active, can use i2c. If it fails, it can indeed mean, that
739 * this wasn't our capture interface, so, we wait for the right one 632 * this wasn't our capture interface, so, we wait for the right one
@@ -741,7 +634,6 @@ static struct device_type mt9t031_dev_type = {
741static int mt9t031_video_probe(struct i2c_client *client) 634static int mt9t031_video_probe(struct i2c_client *client)
742{ 635{
743 struct mt9t031 *mt9t031 = to_mt9t031(client); 636 struct mt9t031 *mt9t031 = to_mt9t031(client);
744 struct video_device *vdev = soc_camera_i2c_to_vdev(client);
745 s32 data; 637 s32 data;
746 int ret; 638 int ret;
747 639
@@ -768,11 +660,7 @@ static int mt9t031_video_probe(struct i2c_client *client)
768 if (ret < 0) 660 if (ret < 0)
769 dev_err(&client->dev, "Failed to initialise the camera\n"); 661 dev_err(&client->dev, "Failed to initialise the camera\n");
770 else 662 else
771 vdev->dev.type = &mt9t031_dev_type; 663 v4l2_ctrl_handler_setup(&mt9t031->hdl);
772
773 /* mt9t031_idle() has reset the chip to default. */
774 mt9t031->exposure = 255;
775 mt9t031->gain = 64;
776 664
777 return ret; 665 return ret;
778} 666}
@@ -787,10 +675,14 @@ static int mt9t031_g_skip_top_lines(struct v4l2_subdev *sd, u32 *lines)
787 return 0; 675 return 0;
788} 676}
789 677
678static const struct v4l2_ctrl_ops mt9t031_ctrl_ops = {
679 .g_volatile_ctrl = mt9t031_g_volatile_ctrl,
680 .s_ctrl = mt9t031_s_ctrl,
681};
682
790static struct v4l2_subdev_core_ops mt9t031_subdev_core_ops = { 683static struct v4l2_subdev_core_ops mt9t031_subdev_core_ops = {
791 .g_ctrl = mt9t031_g_ctrl,
792 .s_ctrl = mt9t031_s_ctrl,
793 .g_chip_ident = mt9t031_g_chip_ident, 684 .g_chip_ident = mt9t031_g_chip_ident,
685 .s_power = mt9t031_s_power,
794#ifdef CONFIG_VIDEO_ADV_DEBUG 686#ifdef CONFIG_VIDEO_ADV_DEBUG
795 .g_register = mt9t031_g_register, 687 .g_register = mt9t031_g_register,
796 .s_register = mt9t031_s_register, 688 .s_register = mt9t031_s_register,
@@ -807,6 +699,34 @@ static int mt9t031_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
807 return 0; 699 return 0;
808} 700}
809 701
702static int mt9t031_g_mbus_config(struct v4l2_subdev *sd,
703 struct v4l2_mbus_config *cfg)
704{
705 struct i2c_client *client = v4l2_get_subdevdata(sd);
706 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
707
708 cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_PCLK_SAMPLE_RISING |
709 V4L2_MBUS_PCLK_SAMPLE_FALLING | V4L2_MBUS_HSYNC_ACTIVE_HIGH |
710 V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_DATA_ACTIVE_HIGH;
711 cfg->type = V4L2_MBUS_PARALLEL;
712 cfg->flags = soc_camera_apply_board_flags(icl, cfg);
713
714 return 0;
715}
716
717static int mt9t031_s_mbus_config(struct v4l2_subdev *sd,
718 const struct v4l2_mbus_config *cfg)
719{
720 struct i2c_client *client = v4l2_get_subdevdata(sd);
721 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
722
723 if (soc_camera_apply_board_flags(icl, cfg) &
724 V4L2_MBUS_PCLK_SAMPLE_FALLING)
725 return reg_clear(client, MT9T031_PIXEL_CLOCK_CONTROL, 0x8000);
726 else
727 return reg_set(client, MT9T031_PIXEL_CLOCK_CONTROL, 0x8000);
728}
729
810static struct v4l2_subdev_video_ops mt9t031_subdev_video_ops = { 730static struct v4l2_subdev_video_ops mt9t031_subdev_video_ops = {
811 .s_stream = mt9t031_s_stream, 731 .s_stream = mt9t031_s_stream,
812 .s_mbus_fmt = mt9t031_s_fmt, 732 .s_mbus_fmt = mt9t031_s_fmt,
@@ -816,6 +736,8 @@ static struct v4l2_subdev_video_ops mt9t031_subdev_video_ops = {
816 .g_crop = mt9t031_g_crop, 736 .g_crop = mt9t031_g_crop,
817 .cropcap = mt9t031_cropcap, 737 .cropcap = mt9t031_cropcap,
818 .enum_mbus_fmt = mt9t031_enum_fmt, 738 .enum_mbus_fmt = mt9t031_enum_fmt,
739 .g_mbus_config = mt9t031_g_mbus_config,
740 .s_mbus_config = mt9t031_s_mbus_config,
819}; 741};
820 742
821static struct v4l2_subdev_sensor_ops mt9t031_subdev_sensor_ops = { 743static struct v4l2_subdev_sensor_ops mt9t031_subdev_sensor_ops = {
@@ -832,18 +754,13 @@ static int mt9t031_probe(struct i2c_client *client,
832 const struct i2c_device_id *did) 754 const struct i2c_device_id *did)
833{ 755{
834 struct mt9t031 *mt9t031; 756 struct mt9t031 *mt9t031;
835 struct soc_camera_device *icd = client->dev.platform_data; 757 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
836 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 758 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
837 int ret; 759 int ret;
838 760
839 if (icd) { 761 if (!icl) {
840 struct soc_camera_link *icl = to_soc_camera_link(icd); 762 dev_err(&client->dev, "MT9T031 driver needs platform data\n");
841 if (!icl) { 763 return -EINVAL;
842 dev_err(&client->dev, "MT9T031 driver needs platform data\n");
843 return -EINVAL;
844 }
845
846 icd->ops = &mt9t031_ops;
847 } 764 }
848 765
849 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) { 766 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) {
@@ -857,6 +774,33 @@ static int mt9t031_probe(struct i2c_client *client,
857 return -ENOMEM; 774 return -ENOMEM;
858 775
859 v4l2_i2c_subdev_init(&mt9t031->subdev, client, &mt9t031_subdev_ops); 776 v4l2_i2c_subdev_init(&mt9t031->subdev, client, &mt9t031_subdev_ops);
777 v4l2_ctrl_handler_init(&mt9t031->hdl, 5);
778 v4l2_ctrl_new_std(&mt9t031->hdl, &mt9t031_ctrl_ops,
779 V4L2_CID_VFLIP, 0, 1, 1, 0);
780 v4l2_ctrl_new_std(&mt9t031->hdl, &mt9t031_ctrl_ops,
781 V4L2_CID_HFLIP, 0, 1, 1, 0);
782 v4l2_ctrl_new_std(&mt9t031->hdl, &mt9t031_ctrl_ops,
783 V4L2_CID_GAIN, 0, 127, 1, 64);
784
785 /*
786 * Simulated autoexposure. If enabled, we calculate shutter width
787 * ourselves in the driver based on vertical blanking and frame width
788 */
789 mt9t031->autoexposure = v4l2_ctrl_new_std_menu(&mt9t031->hdl,
790 &mt9t031_ctrl_ops, V4L2_CID_EXPOSURE_AUTO, 1, 0,
791 V4L2_EXPOSURE_AUTO);
792 mt9t031->exposure = v4l2_ctrl_new_std(&mt9t031->hdl, &mt9t031_ctrl_ops,
793 V4L2_CID_EXPOSURE, 1, 255, 1, 255);
794
795 mt9t031->subdev.ctrl_handler = &mt9t031->hdl;
796 if (mt9t031->hdl.error) {
797 int err = mt9t031->hdl.error;
798
799 kfree(mt9t031);
800 return err;
801 }
802 v4l2_ctrl_auto_cluster(2, &mt9t031->autoexposure,
803 V4L2_EXPOSURE_MANUAL, true);
860 804
861 mt9t031->y_skip_top = 0; 805 mt9t031->y_skip_top = 0;
862 mt9t031->rect.left = MT9T031_COLUMN_SKIP; 806 mt9t031->rect.left = MT9T031_COLUMN_SKIP;
@@ -864,12 +808,6 @@ static int mt9t031_probe(struct i2c_client *client,
864 mt9t031->rect.width = MT9T031_MAX_WIDTH; 808 mt9t031->rect.width = MT9T031_MAX_WIDTH;
865 mt9t031->rect.height = MT9T031_MAX_HEIGHT; 809 mt9t031->rect.height = MT9T031_MAX_HEIGHT;
866 810
867 /*
868 * Simulated autoexposure. If enabled, we calculate shutter width
869 * ourselves in the driver based on vertical blanking and frame width
870 */
871 mt9t031->autoexposure = 1;
872
873 mt9t031->xskip = 1; 811 mt9t031->xskip = 1;
874 mt9t031->yskip = 1; 812 mt9t031->yskip = 1;
875 813
@@ -880,8 +818,7 @@ static int mt9t031_probe(struct i2c_client *client,
880 mt9t031_disable(client); 818 mt9t031_disable(client);
881 819
882 if (ret) { 820 if (ret) {
883 if (icd) 821 v4l2_ctrl_handler_free(&mt9t031->hdl);
884 icd->ops = NULL;
885 kfree(mt9t031); 822 kfree(mt9t031);
886 } 823 }
887 824
@@ -891,10 +828,9 @@ static int mt9t031_probe(struct i2c_client *client,
891static int mt9t031_remove(struct i2c_client *client) 828static int mt9t031_remove(struct i2c_client *client)
892{ 829{
893 struct mt9t031 *mt9t031 = to_mt9t031(client); 830 struct mt9t031 *mt9t031 = to_mt9t031(client);
894 struct soc_camera_device *icd = client->dev.platform_data;
895 831
896 if (icd) 832 v4l2_device_unregister_subdev(&mt9t031->subdev);
897 icd->ops = NULL; 833 v4l2_ctrl_handler_free(&mt9t031->hdl);
898 kfree(mt9t031); 834 kfree(mt9t031);
899 835
900 return 0; 836 return 0;
diff --git a/drivers/media/video/mt9t112.c b/drivers/media/video/mt9t112.c
index d2e0a50063a2..32114a3c0ca7 100644
--- a/drivers/media/video/mt9t112.c
+++ b/drivers/media/video/mt9t112.c
@@ -22,11 +22,11 @@
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/v4l2-mediabus.h>
25#include <linux/videodev2.h> 26#include <linux/videodev2.h>
26 27
27#include <media/mt9t112.h> 28#include <media/mt9t112.h>
28#include <media/soc_camera.h> 29#include <media/soc_camera.h>
29#include <media/soc_mediabus.h>
30#include <media/v4l2-chip-ident.h> 30#include <media/v4l2-chip-ident.h>
31#include <media/v4l2-common.h> 31#include <media/v4l2-common.h>
32 32
@@ -34,11 +34,7 @@
34/* #define EXT_CLOCK 24000000 */ 34/* #define EXT_CLOCK 24000000 */
35 35
36/************************************************************************ 36/************************************************************************
37
38
39 macro 37 macro
40
41
42************************************************************************/ 38************************************************************************/
43/* 39/*
44 * frame size 40 * frame size
@@ -80,17 +76,8 @@
80#define VAR8(id, offset) _VAR(id, offset, 0x8000) 76#define VAR8(id, offset) _VAR(id, offset, 0x8000)
81 77
82/************************************************************************ 78/************************************************************************
83
84
85 struct 79 struct
86
87
88************************************************************************/ 80************************************************************************/
89struct mt9t112_frame_size {
90 u16 width;
91 u16 height;
92};
93
94struct mt9t112_format { 81struct mt9t112_format {
95 enum v4l2_mbus_pixelcode code; 82 enum v4l2_mbus_pixelcode code;
96 enum v4l2_colorspace colorspace; 83 enum v4l2_colorspace colorspace;
@@ -102,21 +89,17 @@ struct mt9t112_priv {
102 struct v4l2_subdev subdev; 89 struct v4l2_subdev subdev;
103 struct mt9t112_camera_info *info; 90 struct mt9t112_camera_info *info;
104 struct i2c_client *client; 91 struct i2c_client *client;
105 struct soc_camera_device icd; 92 struct v4l2_rect frame;
106 struct mt9t112_frame_size frame;
107 const struct mt9t112_format *format; 93 const struct mt9t112_format *format;
108 int model; 94 int model;
109 u32 flags; 95 u32 flags;
110/* for flags */ 96/* for flags */
111#define INIT_DONE (1<<0) 97#define INIT_DONE (1 << 0)
98#define PCLK_RISING (1 << 1)
112}; 99};
113 100
114/************************************************************************ 101/************************************************************************
115
116
117 supported format 102 supported format
118
119
120************************************************************************/ 103************************************************************************/
121 104
122static const struct mt9t112_format mt9t112_cfmts[] = { 105static const struct mt9t112_format mt9t112_cfmts[] = {
@@ -154,11 +137,7 @@ static const struct mt9t112_format mt9t112_cfmts[] = {
154}; 137};
155 138
156/************************************************************************ 139/************************************************************************
157
158
159 general function 140 general function
160
161
162************************************************************************/ 141************************************************************************/
163static struct mt9t112_priv *to_mt9t112(const struct i2c_client *client) 142static struct mt9t112_priv *to_mt9t112(const struct i2c_client *client)
164{ 143{
@@ -326,50 +305,47 @@ static int mt9t112_clock_info(const struct i2c_client *client, u32 ext)
326 n = (n >> 8) & 0x003f; 305 n = (n >> 8) & 0x003f;
327 306
328 enable = ((6000 > ext) || (54000 < ext)) ? "X" : ""; 307 enable = ((6000 > ext) || (54000 < ext)) ? "X" : "";
329 dev_info(&client->dev, "EXTCLK : %10u K %s\n", ext, enable); 308 dev_dbg(&client->dev, "EXTCLK : %10u K %s\n", ext, enable);
330 309
331 vco = 2 * m * ext / (n+1); 310 vco = 2 * m * ext / (n+1);
332 enable = ((384000 > vco) || (768000 < vco)) ? "X" : ""; 311 enable = ((384000 > vco) || (768000 < vco)) ? "X" : "";
333 dev_info(&client->dev, "VCO : %10u K %s\n", vco, enable); 312 dev_dbg(&client->dev, "VCO : %10u K %s\n", vco, enable);
334 313
335 clk = vco / (p1+1) / (p2+1); 314 clk = vco / (p1+1) / (p2+1);
336 enable = (96000 < clk) ? "X" : ""; 315 enable = (96000 < clk) ? "X" : "";
337 dev_info(&client->dev, "PIXCLK : %10u K %s\n", clk, enable); 316 dev_dbg(&client->dev, "PIXCLK : %10u K %s\n", clk, enable);
338 317
339 clk = vco / (p3+1); 318 clk = vco / (p3+1);
340 enable = (768000 < clk) ? "X" : ""; 319 enable = (768000 < clk) ? "X" : "";
341 dev_info(&client->dev, "MIPICLK : %10u K %s\n", clk, enable); 320 dev_dbg(&client->dev, "MIPICLK : %10u K %s\n", clk, enable);
342 321
343 clk = vco / (p6+1); 322 clk = vco / (p6+1);
344 enable = (96000 < clk) ? "X" : ""; 323 enable = (96000 < clk) ? "X" : "";
345 dev_info(&client->dev, "MCU CLK : %10u K %s\n", clk, enable); 324 dev_dbg(&client->dev, "MCU CLK : %10u K %s\n", clk, enable);
346 325
347 clk = vco / (p5+1); 326 clk = vco / (p5+1);
348 enable = (54000 < clk) ? "X" : ""; 327 enable = (54000 < clk) ? "X" : "";
349 dev_info(&client->dev, "SOC CLK : %10u K %s\n", clk, enable); 328 dev_dbg(&client->dev, "SOC CLK : %10u K %s\n", clk, enable);
350 329
351 clk = vco / (p4+1); 330 clk = vco / (p4+1);
352 enable = (70000 < clk) ? "X" : ""; 331 enable = (70000 < clk) ? "X" : "";
353 dev_info(&client->dev, "Sensor CLK : %10u K %s\n", clk, enable); 332 dev_dbg(&client->dev, "Sensor CLK : %10u K %s\n", clk, enable);
354 333
355 clk = vco / (p7+1); 334 clk = vco / (p7+1);
356 dev_info(&client->dev, "External sensor : %10u K\n", clk); 335 dev_dbg(&client->dev, "External sensor : %10u K\n", clk);
357 336
358 clk = ext / (n+1); 337 clk = ext / (n+1);
359 enable = ((2000 > clk) || (24000 < clk)) ? "X" : ""; 338 enable = ((2000 > clk) || (24000 < clk)) ? "X" : "";
360 dev_info(&client->dev, "PFD : %10u K %s\n", clk, enable); 339 dev_dbg(&client->dev, "PFD : %10u K %s\n", clk, enable);
361 340
362 return 0; 341 return 0;
363} 342}
364#endif 343#endif
365 344
366static void mt9t112_frame_check(u32 *width, u32 *height) 345static void mt9t112_frame_check(u32 *width, u32 *height, u32 *left, u32 *top)
367{ 346{
368 if (*width > MAX_WIDTH) 347 soc_camera_limit_side(left, width, 0, 0, MAX_WIDTH);
369 *width = MAX_WIDTH; 348 soc_camera_limit_side(top, height, 0, 0, MAX_HEIGHT);
370
371 if (*height > MAX_HEIGHT)
372 *height = MAX_HEIGHT;
373} 349}
374 350
375static int mt9t112_set_a_frame_size(const struct i2c_client *client, 351static int mt9t112_set_a_frame_size(const struct i2c_client *client,
@@ -758,48 +734,7 @@ static int mt9t112_init_camera(const struct i2c_client *client)
758} 734}
759 735
760/************************************************************************ 736/************************************************************************
761
762
763 soc_camera_ops
764
765
766************************************************************************/
767static int mt9t112_set_bus_param(struct soc_camera_device *icd,
768 unsigned long flags)
769{
770 return 0;
771}
772
773static unsigned long mt9t112_query_bus_param(struct soc_camera_device *icd)
774{
775 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
776 struct mt9t112_priv *priv = to_mt9t112(client);
777 struct soc_camera_link *icl = to_soc_camera_link(icd);
778 unsigned long flags = SOCAM_MASTER | SOCAM_VSYNC_ACTIVE_HIGH |
779 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_DATA_ACTIVE_HIGH;
780
781 flags |= (priv->info->flags & MT9T112_FLAG_PCLK_RISING_EDGE) ?
782 SOCAM_PCLK_SAMPLE_RISING : SOCAM_PCLK_SAMPLE_FALLING;
783
784 if (priv->info->flags & MT9T112_FLAG_DATAWIDTH_8)
785 flags |= SOCAM_DATAWIDTH_8;
786 else
787 flags |= SOCAM_DATAWIDTH_10;
788
789 return soc_camera_apply_sensor_flags(icl, flags);
790}
791
792static struct soc_camera_ops mt9t112_ops = {
793 .set_bus_param = mt9t112_set_bus_param,
794 .query_bus_param = mt9t112_query_bus_param,
795};
796
797/************************************************************************
798
799
800 v4l2_subdev_core_ops 737 v4l2_subdev_core_ops
801
802
803************************************************************************/ 738************************************************************************/
804static int mt9t112_g_chip_ident(struct v4l2_subdev *sd, 739static int mt9t112_g_chip_ident(struct v4l2_subdev *sd,
805 struct v4l2_dbg_chip_ident *id) 740 struct v4l2_dbg_chip_ident *id)
@@ -850,11 +785,7 @@ static struct v4l2_subdev_core_ops mt9t112_subdev_core_ops = {
850 785
851 786
852/************************************************************************ 787/************************************************************************
853
854
855 v4l2_subdev_video_ops 788 v4l2_subdev_video_ops
856
857
858************************************************************************/ 789************************************************************************/
859static int mt9t112_s_stream(struct v4l2_subdev *sd, int enable) 790static int mt9t112_s_stream(struct v4l2_subdev *sd, int enable)
860{ 791{
@@ -877,8 +808,7 @@ static int mt9t112_s_stream(struct v4l2_subdev *sd, int enable)
877 } 808 }
878 809
879 if (!(priv->flags & INIT_DONE)) { 810 if (!(priv->flags & INIT_DONE)) {
880 u16 param = (MT9T112_FLAG_PCLK_RISING_EDGE & 811 u16 param = PCLK_RISING & priv->flags ? 0x0001 : 0x0000;
881 priv->info->flags) ? 0x0001 : 0x0000;
882 812
883 ECHECKER(ret, mt9t112_init_camera(client)); 813 ECHECKER(ret, mt9t112_init_camera(client));
884 814
@@ -910,19 +840,12 @@ static int mt9t112_s_stream(struct v4l2_subdev *sd, int enable)
910 return ret; 840 return ret;
911} 841}
912 842
913static int mt9t112_set_params(struct i2c_client *client, u32 width, u32 height, 843static int mt9t112_set_params(struct mt9t112_priv *priv,
844 const struct v4l2_rect *rect,
914 enum v4l2_mbus_pixelcode code) 845 enum v4l2_mbus_pixelcode code)
915{ 846{
916 struct mt9t112_priv *priv = to_mt9t112(client);
917 int i; 847 int i;
918 848
919 priv->format = NULL;
920
921 /*
922 * frame size check
923 */
924 mt9t112_frame_check(&width, &height);
925
926 /* 849 /*
927 * get color format 850 * get color format
928 */ 851 */
@@ -933,8 +856,13 @@ static int mt9t112_set_params(struct i2c_client *client, u32 width, u32 height,
933 if (i == ARRAY_SIZE(mt9t112_cfmts)) 856 if (i == ARRAY_SIZE(mt9t112_cfmts))
934 return -EINVAL; 857 return -EINVAL;
935 858
936 priv->frame.width = (u16)width; 859 priv->frame = *rect;
937 priv->frame.height = (u16)height; 860
861 /*
862 * frame size check
863 */
864 mt9t112_frame_check(&priv->frame.width, &priv->frame.height,
865 &priv->frame.left, &priv->frame.top);
938 866
939 priv->format = mt9t112_cfmts + i; 867 priv->format = mt9t112_cfmts + i;
940 868
@@ -945,9 +873,12 @@ static int mt9t112_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a)
945{ 873{
946 a->bounds.left = 0; 874 a->bounds.left = 0;
947 a->bounds.top = 0; 875 a->bounds.top = 0;
948 a->bounds.width = VGA_WIDTH; 876 a->bounds.width = MAX_WIDTH;
949 a->bounds.height = VGA_HEIGHT; 877 a->bounds.height = MAX_HEIGHT;
950 a->defrect = a->bounds; 878 a->defrect.left = 0;
879 a->defrect.top = 0;
880 a->defrect.width = VGA_WIDTH;
881 a->defrect.height = VGA_HEIGHT;
951 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 882 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
952 a->pixelaspect.numerator = 1; 883 a->pixelaspect.numerator = 1;
953 a->pixelaspect.denominator = 1; 884 a->pixelaspect.denominator = 1;
@@ -957,11 +888,11 @@ static int mt9t112_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a)
957 888
958static int mt9t112_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) 889static int mt9t112_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
959{ 890{
960 a->c.left = 0; 891 struct i2c_client *client = v4l2_get_subdevdata(sd);
961 a->c.top = 0; 892 struct mt9t112_priv *priv = to_mt9t112(client);
962 a->c.width = VGA_WIDTH; 893
963 a->c.height = VGA_HEIGHT; 894 a->c = priv->frame;
964 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 895 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
965 896
966 return 0; 897 return 0;
967} 898}
@@ -969,10 +900,10 @@ static int mt9t112_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
969static int mt9t112_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) 900static int mt9t112_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
970{ 901{
971 struct i2c_client *client = v4l2_get_subdevdata(sd); 902 struct i2c_client *client = v4l2_get_subdevdata(sd);
903 struct mt9t112_priv *priv = to_mt9t112(client);
972 struct v4l2_rect *rect = &a->c; 904 struct v4l2_rect *rect = &a->c;
973 905
974 return mt9t112_set_params(client, rect->width, rect->height, 906 return mt9t112_set_params(priv, rect, priv->format->code);
975 V4L2_MBUS_FMT_UYVY8_2X8);
976} 907}
977 908
978static int mt9t112_g_fmt(struct v4l2_subdev *sd, 909static int mt9t112_g_fmt(struct v4l2_subdev *sd,
@@ -981,16 +912,9 @@ static int mt9t112_g_fmt(struct v4l2_subdev *sd,
981 struct i2c_client *client = v4l2_get_subdevdata(sd); 912 struct i2c_client *client = v4l2_get_subdevdata(sd);
982 struct mt9t112_priv *priv = to_mt9t112(client); 913 struct mt9t112_priv *priv = to_mt9t112(client);
983 914
984 if (!priv->format) {
985 int ret = mt9t112_set_params(client, VGA_WIDTH, VGA_HEIGHT,
986 V4L2_MBUS_FMT_UYVY8_2X8);
987 if (ret < 0)
988 return ret;
989 }
990
991 mf->width = priv->frame.width; 915 mf->width = priv->frame.width;
992 mf->height = priv->frame.height; 916 mf->height = priv->frame.height;
993 /* TODO: set colorspace */ 917 mf->colorspace = priv->format->colorspace;
994 mf->code = priv->format->code; 918 mf->code = priv->format->code;
995 mf->field = V4L2_FIELD_NONE; 919 mf->field = V4L2_FIELD_NONE;
996 920
@@ -1001,17 +925,42 @@ static int mt9t112_s_fmt(struct v4l2_subdev *sd,
1001 struct v4l2_mbus_framefmt *mf) 925 struct v4l2_mbus_framefmt *mf)
1002{ 926{
1003 struct i2c_client *client = v4l2_get_subdevdata(sd); 927 struct i2c_client *client = v4l2_get_subdevdata(sd);
928 struct mt9t112_priv *priv = to_mt9t112(client);
929 struct v4l2_rect rect = {
930 .width = mf->width,
931 .height = mf->height,
932 .left = priv->frame.left,
933 .top = priv->frame.top,
934 };
935 int ret;
936
937 ret = mt9t112_set_params(priv, &rect, mf->code);
938
939 if (!ret)
940 mf->colorspace = priv->format->colorspace;
1004 941
1005 /* TODO: set colorspace */ 942 return ret;
1006 return mt9t112_set_params(client, mf->width, mf->height, mf->code);
1007} 943}
1008 944
1009static int mt9t112_try_fmt(struct v4l2_subdev *sd, 945static int mt9t112_try_fmt(struct v4l2_subdev *sd,
1010 struct v4l2_mbus_framefmt *mf) 946 struct v4l2_mbus_framefmt *mf)
1011{ 947{
1012 mt9t112_frame_check(&mf->width, &mf->height); 948 unsigned int top, left;
949 int i;
950
951 for (i = 0; i < ARRAY_SIZE(mt9t112_cfmts); i++)
952 if (mt9t112_cfmts[i].code == mf->code)
953 break;
954
955 if (i == ARRAY_SIZE(mt9t112_cfmts)) {
956 mf->code = V4L2_MBUS_FMT_UYVY8_2X8;
957 mf->colorspace = V4L2_COLORSPACE_JPEG;
958 } else {
959 mf->colorspace = mt9t112_cfmts[i].colorspace;
960 }
961
962 mt9t112_frame_check(&mf->width, &mf->height, &left, &top);
1013 963
1014 /* TODO: set colorspace */
1015 mf->field = V4L2_FIELD_NONE; 964 mf->field = V4L2_FIELD_NONE;
1016 965
1017 return 0; 966 return 0;
@@ -1024,6 +973,35 @@ static int mt9t112_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
1024 return -EINVAL; 973 return -EINVAL;
1025 974
1026 *code = mt9t112_cfmts[index].code; 975 *code = mt9t112_cfmts[index].code;
976
977 return 0;
978}
979
980static int mt9t112_g_mbus_config(struct v4l2_subdev *sd,
981 struct v4l2_mbus_config *cfg)
982{
983 struct i2c_client *client = v4l2_get_subdevdata(sd);
984 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
985
986 cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_VSYNC_ACTIVE_HIGH |
987 V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_DATA_ACTIVE_HIGH |
988 V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING;
989 cfg->type = V4L2_MBUS_PARALLEL;
990 cfg->flags = soc_camera_apply_board_flags(icl, cfg);
991
992 return 0;
993}
994
995static int mt9t112_s_mbus_config(struct v4l2_subdev *sd,
996 const struct v4l2_mbus_config *cfg)
997{
998 struct i2c_client *client = v4l2_get_subdevdata(sd);
999 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
1000 struct mt9t112_priv *priv = to_mt9t112(client);
1001
1002 if (soc_camera_apply_board_flags(icl, cfg) & V4L2_MBUS_PCLK_SAMPLE_RISING)
1003 priv->flags |= PCLK_RISING;
1004
1027 return 0; 1005 return 0;
1028} 1006}
1029 1007
@@ -1036,31 +1014,24 @@ static struct v4l2_subdev_video_ops mt9t112_subdev_video_ops = {
1036 .g_crop = mt9t112_g_crop, 1014 .g_crop = mt9t112_g_crop,
1037 .s_crop = mt9t112_s_crop, 1015 .s_crop = mt9t112_s_crop,
1038 .enum_mbus_fmt = mt9t112_enum_fmt, 1016 .enum_mbus_fmt = mt9t112_enum_fmt,
1017 .g_mbus_config = mt9t112_g_mbus_config,
1018 .s_mbus_config = mt9t112_s_mbus_config,
1039}; 1019};
1040 1020
1041/************************************************************************ 1021/************************************************************************
1042
1043
1044 i2c driver 1022 i2c driver
1045
1046
1047************************************************************************/ 1023************************************************************************/
1048static struct v4l2_subdev_ops mt9t112_subdev_ops = { 1024static struct v4l2_subdev_ops mt9t112_subdev_ops = {
1049 .core = &mt9t112_subdev_core_ops, 1025 .core = &mt9t112_subdev_core_ops,
1050 .video = &mt9t112_subdev_video_ops, 1026 .video = &mt9t112_subdev_video_ops,
1051}; 1027};
1052 1028
1053static int mt9t112_camera_probe(struct soc_camera_device *icd, 1029static int mt9t112_camera_probe(struct i2c_client *client)
1054 struct i2c_client *client)
1055{ 1030{
1056 struct mt9t112_priv *priv = to_mt9t112(client); 1031 struct mt9t112_priv *priv = to_mt9t112(client);
1057 const char *devname; 1032 const char *devname;
1058 int chipid; 1033 int chipid;
1059 1034
1060 /* We must have a parent by now. And it cannot be a wrong one. */
1061 BUG_ON(!icd->parent ||
1062 to_soc_camera_host(icd->parent)->nr != icd->iface);
1063
1064 /* 1035 /*
1065 * check and show chip ID 1036 * check and show chip ID
1066 */ 1037 */
@@ -1088,20 +1059,21 @@ static int mt9t112_camera_probe(struct soc_camera_device *icd,
1088static int mt9t112_probe(struct i2c_client *client, 1059static int mt9t112_probe(struct i2c_client *client,
1089 const struct i2c_device_id *did) 1060 const struct i2c_device_id *did)
1090{ 1061{
1091 struct mt9t112_priv *priv; 1062 struct mt9t112_priv *priv;
1092 struct soc_camera_device *icd = client->dev.platform_data; 1063 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
1093 struct soc_camera_link *icl; 1064 struct v4l2_rect rect = {
1094 int ret; 1065 .width = VGA_WIDTH,
1066 .height = VGA_HEIGHT,
1067 .left = (MAX_WIDTH - VGA_WIDTH) / 2,
1068 .top = (MAX_HEIGHT - VGA_HEIGHT) / 2,
1069 };
1070 int ret;
1095 1071
1096 if (!icd) { 1072 if (!icl || !icl->priv) {
1097 dev_err(&client->dev, "mt9t112: missing soc-camera data!\n"); 1073 dev_err(&client->dev, "mt9t112: missing platform data!\n");
1098 return -EINVAL; 1074 return -EINVAL;
1099 } 1075 }
1100 1076
1101 icl = to_soc_camera_link(icd);
1102 if (!icl || !icl->priv)
1103 return -EINVAL;
1104
1105 priv = kzalloc(sizeof(*priv), GFP_KERNEL); 1077 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
1106 if (!priv) 1078 if (!priv)
1107 return -ENOMEM; 1079 return -ENOMEM;
@@ -1110,13 +1082,12 @@ static int mt9t112_probe(struct i2c_client *client,
1110 1082
1111 v4l2_i2c_subdev_init(&priv->subdev, client, &mt9t112_subdev_ops); 1083 v4l2_i2c_subdev_init(&priv->subdev, client, &mt9t112_subdev_ops);
1112 1084
1113 icd->ops = &mt9t112_ops; 1085 ret = mt9t112_camera_probe(client);
1114 1086 if (ret)
1115 ret = mt9t112_camera_probe(icd, client);
1116 if (ret) {
1117 icd->ops = NULL;
1118 kfree(priv); 1087 kfree(priv);
1119 } 1088
1089 /* Cannot fail: using the default supported pixel code */
1090 mt9t112_set_params(priv, &rect, V4L2_MBUS_FMT_UYVY8_2X8);
1120 1091
1121 return ret; 1092 return ret;
1122} 1093}
@@ -1124,9 +1095,7 @@ static int mt9t112_probe(struct i2c_client *client,
1124static int mt9t112_remove(struct i2c_client *client) 1095static int mt9t112_remove(struct i2c_client *client)
1125{ 1096{
1126 struct mt9t112_priv *priv = to_mt9t112(client); 1097 struct mt9t112_priv *priv = to_mt9t112(client);
1127 struct soc_camera_device *icd = client->dev.platform_data;
1128 1098
1129 icd->ops = NULL;
1130 kfree(priv); 1099 kfree(priv);
1131 return 0; 1100 return 0;
1132} 1101}
@@ -1147,11 +1116,7 @@ static struct i2c_driver mt9t112_i2c_driver = {
1147}; 1116};
1148 1117
1149/************************************************************************ 1118/************************************************************************
1150
1151
1152 module function 1119 module function
1153
1154
1155************************************************************************/ 1120************************************************************************/
1156static int __init mt9t112_module_init(void) 1121static int __init mt9t112_module_init(void)
1157{ 1122{
diff --git a/drivers/media/video/mt9v011.c b/drivers/media/video/mt9v011.c
index 893a8b8f5141..db74dd27c722 100644
--- a/drivers/media/video/mt9v011.c
+++ b/drivers/media/video/mt9v011.c
@@ -9,6 +9,7 @@
9#include <linux/slab.h> 9#include <linux/slab.h>
10#include <linux/videodev2.h> 10#include <linux/videodev2.h>
11#include <linux/delay.h> 11#include <linux/delay.h>
12#include <linux/module.h>
12#include <asm/div64.h> 13#include <asm/div64.h>
13#include <media/v4l2-device.h> 14#include <media/v4l2-device.h>
14#include <media/v4l2-chip-ident.h> 15#include <media/v4l2-chip-ident.h>
diff --git a/drivers/media/video/mt9v022.c b/drivers/media/video/mt9v022.c
index 51b0fccbfe70..690ee0d42eeb 100644
--- a/drivers/media/video/mt9v022.c
+++ b/drivers/media/video/mt9v022.c
@@ -13,10 +13,13 @@
13#include <linux/i2c.h> 13#include <linux/i2c.h>
14#include <linux/delay.h> 14#include <linux/delay.h>
15#include <linux/log2.h> 15#include <linux/log2.h>
16#include <linux/module.h>
16 17
18#include <media/soc_camera.h>
19#include <media/soc_mediabus.h>
17#include <media/v4l2-subdev.h> 20#include <media/v4l2-subdev.h>
18#include <media/v4l2-chip-ident.h> 21#include <media/v4l2-chip-ident.h>
19#include <media/soc_camera.h> 22#include <media/v4l2-ctrls.h>
20 23
21/* 24/*
22 * mt9v022 i2c address 0x48, 0x4c, 0x58, 0x5c 25 * mt9v022 i2c address 0x48, 0x4c, 0x58, 0x5c
@@ -100,6 +103,17 @@ static const struct mt9v022_datafmt mt9v022_monochrome_fmts[] = {
100 103
101struct mt9v022 { 104struct mt9v022 {
102 struct v4l2_subdev subdev; 105 struct v4l2_subdev subdev;
106 struct v4l2_ctrl_handler hdl;
107 struct {
108 /* exposure/auto-exposure cluster */
109 struct v4l2_ctrl *autoexposure;
110 struct v4l2_ctrl *exposure;
111 };
112 struct {
113 /* gain/auto-gain cluster */
114 struct v4l2_ctrl *autogain;
115 struct v4l2_ctrl *gain;
116 };
103 struct v4l2_rect rect; /* Sensor window */ 117 struct v4l2_rect rect; /* Sensor window */
104 const struct mt9v022_datafmt *fmt; 118 const struct mt9v022_datafmt *fmt;
105 const struct mt9v022_datafmt *fmts; 119 const struct mt9v022_datafmt *fmts;
@@ -178,6 +192,8 @@ static int mt9v022_init(struct i2c_client *client)
178 ret = reg_clear(client, MT9V022_BLACK_LEVEL_CALIB_CTRL, 1); 192 ret = reg_clear(client, MT9V022_BLACK_LEVEL_CALIB_CTRL, 1);
179 if (!ret) 193 if (!ret)
180 ret = reg_write(client, MT9V022_DIGITAL_TEST_PATTERN, 0); 194 ret = reg_write(client, MT9V022_DIGITAL_TEST_PATTERN, 0);
195 if (!ret)
196 return v4l2_ctrl_handler_setup(&mt9v022->hdl);
181 197
182 return ret; 198 return ret;
183} 199}
@@ -199,78 +215,6 @@ static int mt9v022_s_stream(struct v4l2_subdev *sd, int enable)
199 return 0; 215 return 0;
200} 216}
201 217
202static int mt9v022_set_bus_param(struct soc_camera_device *icd,
203 unsigned long flags)
204{
205 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
206 struct mt9v022 *mt9v022 = to_mt9v022(client);
207 struct soc_camera_link *icl = to_soc_camera_link(icd);
208 unsigned int width_flag = flags & SOCAM_DATAWIDTH_MASK;
209 int ret;
210 u16 pixclk = 0;
211
212 /* Only one width bit may be set */
213 if (!is_power_of_2(width_flag))
214 return -EINVAL;
215
216 if (icl->set_bus_param) {
217 ret = icl->set_bus_param(icl, width_flag);
218 if (ret)
219 return ret;
220 } else {
221 /*
222 * Without board specific bus width settings we only support the
223 * sensors native bus width
224 */
225 if (width_flag != SOCAM_DATAWIDTH_10)
226 return -EINVAL;
227 }
228
229 flags = soc_camera_apply_sensor_flags(icl, flags);
230
231 if (flags & SOCAM_PCLK_SAMPLE_FALLING)
232 pixclk |= 0x10;
233
234 if (!(flags & SOCAM_HSYNC_ACTIVE_HIGH))
235 pixclk |= 0x1;
236
237 if (!(flags & SOCAM_VSYNC_ACTIVE_HIGH))
238 pixclk |= 0x2;
239
240 ret = reg_write(client, MT9V022_PIXCLK_FV_LV, pixclk);
241 if (ret < 0)
242 return ret;
243
244 if (!(flags & SOCAM_MASTER))
245 mt9v022->chip_control &= ~0x8;
246
247 ret = reg_write(client, MT9V022_CHIP_CONTROL, mt9v022->chip_control);
248 if (ret < 0)
249 return ret;
250
251 dev_dbg(&client->dev, "Calculated pixclk 0x%x, chip control 0x%x\n",
252 pixclk, mt9v022->chip_control);
253
254 return 0;
255}
256
257static unsigned long mt9v022_query_bus_param(struct soc_camera_device *icd)
258{
259 struct soc_camera_link *icl = to_soc_camera_link(icd);
260 unsigned int flags = SOCAM_MASTER | SOCAM_SLAVE |
261 SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING |
262 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW |
263 SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |
264 SOCAM_DATA_ACTIVE_HIGH;
265
266 if (icl->query_bus_param)
267 flags |= icl->query_bus_param(icl) & SOCAM_DATAWIDTH_MASK;
268 else
269 flags |= SOCAM_DATAWIDTH_10;
270
271 return soc_camera_apply_sensor_flags(icl, flags);
272}
273
274static int mt9v022_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) 218static int mt9v022_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
275{ 219{
276 struct i2c_client *client = v4l2_get_subdevdata(sd); 220 struct i2c_client *client = v4l2_get_subdevdata(sd);
@@ -389,7 +333,7 @@ static int mt9v022_s_fmt(struct v4l2_subdev *sd,
389 333
390 /* 334 /*
391 * The caller provides a supported format, as verified per call to 335 * The caller provides a supported format, as verified per call to
392 * icd->try_fmt(), datawidth is from our supported format list 336 * .try_mbus_fmt(), datawidth is from our supported format list
393 */ 337 */
394 switch (mf->code) { 338 switch (mf->code) {
395 case V4L2_MBUS_FMT_Y8_1X8: 339 case V4L2_MBUS_FMT_Y8_1X8:
@@ -502,236 +446,131 @@ static int mt9v022_s_register(struct v4l2_subdev *sd,
502} 446}
503#endif 447#endif
504 448
505static const struct v4l2_queryctrl mt9v022_controls[] = { 449static int mt9v022_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
506 {
507 .id = V4L2_CID_VFLIP,
508 .type = V4L2_CTRL_TYPE_BOOLEAN,
509 .name = "Flip Vertically",
510 .minimum = 0,
511 .maximum = 1,
512 .step = 1,
513 .default_value = 0,
514 }, {
515 .id = V4L2_CID_HFLIP,
516 .type = V4L2_CTRL_TYPE_BOOLEAN,
517 .name = "Flip Horizontally",
518 .minimum = 0,
519 .maximum = 1,
520 .step = 1,
521 .default_value = 0,
522 }, {
523 .id = V4L2_CID_GAIN,
524 .type = V4L2_CTRL_TYPE_INTEGER,
525 .name = "Analog Gain",
526 .minimum = 64,
527 .maximum = 127,
528 .step = 1,
529 .default_value = 64,
530 .flags = V4L2_CTRL_FLAG_SLIDER,
531 }, {
532 .id = V4L2_CID_EXPOSURE,
533 .type = V4L2_CTRL_TYPE_INTEGER,
534 .name = "Exposure",
535 .minimum = 1,
536 .maximum = 255,
537 .step = 1,
538 .default_value = 255,
539 .flags = V4L2_CTRL_FLAG_SLIDER,
540 }, {
541 .id = V4L2_CID_AUTOGAIN,
542 .type = V4L2_CTRL_TYPE_BOOLEAN,
543 .name = "Automatic Gain",
544 .minimum = 0,
545 .maximum = 1,
546 .step = 1,
547 .default_value = 1,
548 }, {
549 .id = V4L2_CID_EXPOSURE_AUTO,
550 .type = V4L2_CTRL_TYPE_BOOLEAN,
551 .name = "Automatic Exposure",
552 .minimum = 0,
553 .maximum = 1,
554 .step = 1,
555 .default_value = 1,
556 }
557};
558
559static struct soc_camera_ops mt9v022_ops = {
560 .set_bus_param = mt9v022_set_bus_param,
561 .query_bus_param = mt9v022_query_bus_param,
562 .controls = mt9v022_controls,
563 .num_controls = ARRAY_SIZE(mt9v022_controls),
564};
565
566static int mt9v022_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
567{ 450{
451 struct mt9v022 *mt9v022 = container_of(ctrl->handler,
452 struct mt9v022, hdl);
453 struct v4l2_subdev *sd = &mt9v022->subdev;
568 struct i2c_client *client = v4l2_get_subdevdata(sd); 454 struct i2c_client *client = v4l2_get_subdevdata(sd);
569 const struct v4l2_queryctrl *qctrl; 455 struct v4l2_ctrl *gain = mt9v022->gain;
456 struct v4l2_ctrl *exp = mt9v022->exposure;
570 unsigned long range; 457 unsigned long range;
571 int data; 458 int data;
572 459
573 qctrl = soc_camera_find_qctrl(&mt9v022_ops, ctrl->id);
574
575 switch (ctrl->id) { 460 switch (ctrl->id) {
576 case V4L2_CID_VFLIP:
577 data = reg_read(client, MT9V022_READ_MODE);
578 if (data < 0)
579 return -EIO;
580 ctrl->value = !!(data & 0x10);
581 break;
582 case V4L2_CID_HFLIP:
583 data = reg_read(client, MT9V022_READ_MODE);
584 if (data < 0)
585 return -EIO;
586 ctrl->value = !!(data & 0x20);
587 break;
588 case V4L2_CID_EXPOSURE_AUTO:
589 data = reg_read(client, MT9V022_AEC_AGC_ENABLE);
590 if (data < 0)
591 return -EIO;
592 ctrl->value = !!(data & 0x1);
593 break;
594 case V4L2_CID_AUTOGAIN: 461 case V4L2_CID_AUTOGAIN:
595 data = reg_read(client, MT9V022_AEC_AGC_ENABLE);
596 if (data < 0)
597 return -EIO;
598 ctrl->value = !!(data & 0x2);
599 break;
600 case V4L2_CID_GAIN:
601 data = reg_read(client, MT9V022_ANALOG_GAIN); 462 data = reg_read(client, MT9V022_ANALOG_GAIN);
602 if (data < 0) 463 if (data < 0)
603 return -EIO; 464 return -EIO;
604 465
605 range = qctrl->maximum - qctrl->minimum; 466 range = gain->maximum - gain->minimum;
606 ctrl->value = ((data - 16) * range + 24) / 48 + qctrl->minimum; 467 gain->val = ((data - 16) * range + 24) / 48 + gain->minimum;
607 468 return 0;
608 break; 469 case V4L2_CID_EXPOSURE_AUTO:
609 case V4L2_CID_EXPOSURE:
610 data = reg_read(client, MT9V022_TOTAL_SHUTTER_WIDTH); 470 data = reg_read(client, MT9V022_TOTAL_SHUTTER_WIDTH);
611 if (data < 0) 471 if (data < 0)
612 return -EIO; 472 return -EIO;
613 473
614 range = qctrl->maximum - qctrl->minimum; 474 range = exp->maximum - exp->minimum;
615 ctrl->value = ((data - 1) * range + 239) / 479 + qctrl->minimum; 475 exp->val = ((data - 1) * range + 239) / 479 + exp->minimum;
616 476 return 0;
617 break;
618 } 477 }
619 return 0; 478 return -EINVAL;
620} 479}
621 480
622static int mt9v022_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 481static int mt9v022_s_ctrl(struct v4l2_ctrl *ctrl)
623{ 482{
624 int data; 483 struct mt9v022 *mt9v022 = container_of(ctrl->handler,
484 struct mt9v022, hdl);
485 struct v4l2_subdev *sd = &mt9v022->subdev;
625 struct i2c_client *client = v4l2_get_subdevdata(sd); 486 struct i2c_client *client = v4l2_get_subdevdata(sd);
626 const struct v4l2_queryctrl *qctrl; 487 int data;
627
628 qctrl = soc_camera_find_qctrl(&mt9v022_ops, ctrl->id);
629 if (!qctrl)
630 return -EINVAL;
631 488
632 switch (ctrl->id) { 489 switch (ctrl->id) {
633 case V4L2_CID_VFLIP: 490 case V4L2_CID_VFLIP:
634 if (ctrl->value) 491 if (ctrl->val)
635 data = reg_set(client, MT9V022_READ_MODE, 0x10); 492 data = reg_set(client, MT9V022_READ_MODE, 0x10);
636 else 493 else
637 data = reg_clear(client, MT9V022_READ_MODE, 0x10); 494 data = reg_clear(client, MT9V022_READ_MODE, 0x10);
638 if (data < 0) 495 if (data < 0)
639 return -EIO; 496 return -EIO;
640 break; 497 return 0;
641 case V4L2_CID_HFLIP: 498 case V4L2_CID_HFLIP:
642 if (ctrl->value) 499 if (ctrl->val)
643 data = reg_set(client, MT9V022_READ_MODE, 0x20); 500 data = reg_set(client, MT9V022_READ_MODE, 0x20);
644 else 501 else
645 data = reg_clear(client, MT9V022_READ_MODE, 0x20); 502 data = reg_clear(client, MT9V022_READ_MODE, 0x20);
646 if (data < 0) 503 if (data < 0)
647 return -EIO; 504 return -EIO;
648 break; 505 return 0;
649 case V4L2_CID_GAIN: 506 case V4L2_CID_AUTOGAIN:
650 /* mt9v022 has minimum == default */ 507 if (ctrl->val) {
651 if (ctrl->value > qctrl->maximum || ctrl->value < qctrl->minimum) 508 if (reg_set(client, MT9V022_AEC_AGC_ENABLE, 0x2) < 0)
652 return -EINVAL; 509 return -EIO;
653 else { 510 } else {
654 unsigned long range = qctrl->maximum - qctrl->minimum; 511 struct v4l2_ctrl *gain = mt9v022->gain;
512 /* mt9v022 has minimum == default */
513 unsigned long range = gain->maximum - gain->minimum;
655 /* Valid values 16 to 64, 32 to 64 must be even. */ 514 /* Valid values 16 to 64, 32 to 64 must be even. */
656 unsigned long gain = ((ctrl->value - qctrl->minimum) * 515 unsigned long gain_val = ((gain->val - gain->minimum) *
657 48 + range / 2) / range + 16; 516 48 + range / 2) / range + 16;
658 if (gain >= 32) 517
659 gain &= ~1; 518 if (gain_val >= 32)
519 gain_val &= ~1;
520
660 /* 521 /*
661 * The user wants to set gain manually, hope, she 522 * The user wants to set gain manually, hope, she
662 * knows, what she's doing... Switch AGC off. 523 * knows, what she's doing... Switch AGC off.
663 */ 524 */
664
665 if (reg_clear(client, MT9V022_AEC_AGC_ENABLE, 0x2) < 0) 525 if (reg_clear(client, MT9V022_AEC_AGC_ENABLE, 0x2) < 0)
666 return -EIO; 526 return -EIO;
667 527
668 dev_dbg(&client->dev, "Setting gain from %d to %lu\n", 528 dev_dbg(&client->dev, "Setting gain from %d to %lu\n",
669 reg_read(client, MT9V022_ANALOG_GAIN), gain); 529 reg_read(client, MT9V022_ANALOG_GAIN), gain_val);
670 if (reg_write(client, MT9V022_ANALOG_GAIN, gain) < 0) 530 if (reg_write(client, MT9V022_ANALOG_GAIN, gain_val) < 0)
671 return -EIO; 531 return -EIO;
672 } 532 }
673 break; 533 return 0;
674 case V4L2_CID_EXPOSURE: 534 case V4L2_CID_EXPOSURE_AUTO:
675 /* mt9v022 has maximum == default */ 535 if (ctrl->val == V4L2_EXPOSURE_AUTO) {
676 if (ctrl->value > qctrl->maximum || ctrl->value < qctrl->minimum) 536 data = reg_set(client, MT9V022_AEC_AGC_ENABLE, 0x1);
677 return -EINVAL; 537 } else {
678 else { 538 struct v4l2_ctrl *exp = mt9v022->exposure;
679 unsigned long range = qctrl->maximum - qctrl->minimum; 539 unsigned long range = exp->maximum - exp->minimum;
680 unsigned long shutter = ((ctrl->value - qctrl->minimum) * 540 unsigned long shutter = ((exp->val - exp->minimum) *
681 479 + range / 2) / range + 1; 541 479 + range / 2) / range + 1;
542
682 /* 543 /*
683 * The user wants to set shutter width manually, hope, 544 * The user wants to set shutter width manually, hope,
684 * she knows, what she's doing... Switch AEC off. 545 * she knows, what she's doing... Switch AEC off.
685 */ 546 */
686 547 data = reg_clear(client, MT9V022_AEC_AGC_ENABLE, 0x1);
687 if (reg_clear(client, MT9V022_AEC_AGC_ENABLE, 0x1) < 0) 548 if (data < 0)
688 return -EIO; 549 return -EIO;
689
690 dev_dbg(&client->dev, "Shutter width from %d to %lu\n", 550 dev_dbg(&client->dev, "Shutter width from %d to %lu\n",
691 reg_read(client, MT9V022_TOTAL_SHUTTER_WIDTH), 551 reg_read(client, MT9V022_TOTAL_SHUTTER_WIDTH),
692 shutter); 552 shutter);
693 if (reg_write(client, MT9V022_TOTAL_SHUTTER_WIDTH, 553 if (reg_write(client, MT9V022_TOTAL_SHUTTER_WIDTH,
694 shutter) < 0) 554 shutter) < 0)
695 return -EIO; 555 return -EIO;
696 } 556 }
697 break; 557 return 0;
698 case V4L2_CID_AUTOGAIN:
699 if (ctrl->value)
700 data = reg_set(client, MT9V022_AEC_AGC_ENABLE, 0x2);
701 else
702 data = reg_clear(client, MT9V022_AEC_AGC_ENABLE, 0x2);
703 if (data < 0)
704 return -EIO;
705 break;
706 case V4L2_CID_EXPOSURE_AUTO:
707 if (ctrl->value)
708 data = reg_set(client, MT9V022_AEC_AGC_ENABLE, 0x1);
709 else
710 data = reg_clear(client, MT9V022_AEC_AGC_ENABLE, 0x1);
711 if (data < 0)
712 return -EIO;
713 break;
714 } 558 }
715 return 0; 559 return -EINVAL;
716} 560}
717 561
718/* 562/*
719 * Interface active, can use i2c. If it fails, it can indeed mean, that 563 * Interface active, can use i2c. If it fails, it can indeed mean, that
720 * this wasn't our capture interface, so, we wait for the right one 564 * this wasn't our capture interface, so, we wait for the right one
721 */ 565 */
722static int mt9v022_video_probe(struct soc_camera_device *icd, 566static int mt9v022_video_probe(struct i2c_client *client)
723 struct i2c_client *client)
724{ 567{
725 struct mt9v022 *mt9v022 = to_mt9v022(client); 568 struct mt9v022 *mt9v022 = to_mt9v022(client);
726 struct soc_camera_link *icl = to_soc_camera_link(icd); 569 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
727 s32 data; 570 s32 data;
728 int ret; 571 int ret;
729 unsigned long flags; 572 unsigned long flags;
730 573
731 /* We must have a parent by now. And it cannot be a wrong one. */
732 BUG_ON(!icd->parent ||
733 to_soc_camera_host(icd->parent)->nr != icd->iface);
734
735 /* Read out the chip version register */ 574 /* Read out the chip version register */
736 data = reg_read(client, MT9V022_CHIP_VERSION); 575 data = reg_read(client, MT9V022_CHIP_VERSION);
737 576
@@ -805,16 +644,6 @@ ei2c:
805 return ret; 644 return ret;
806} 645}
807 646
808static void mt9v022_video_remove(struct soc_camera_device *icd)
809{
810 struct soc_camera_link *icl = to_soc_camera_link(icd);
811
812 dev_dbg(icd->pdev, "Video removed: %p, %p\n",
813 icd->parent, icd->vdev);
814 if (icl->free_bus)
815 icl->free_bus(icl);
816}
817
818static int mt9v022_g_skip_top_lines(struct v4l2_subdev *sd, u32 *lines) 647static int mt9v022_g_skip_top_lines(struct v4l2_subdev *sd, u32 *lines)
819{ 648{
820 struct i2c_client *client = v4l2_get_subdevdata(sd); 649 struct i2c_client *client = v4l2_get_subdevdata(sd);
@@ -825,9 +654,12 @@ static int mt9v022_g_skip_top_lines(struct v4l2_subdev *sd, u32 *lines)
825 return 0; 654 return 0;
826} 655}
827 656
657static const struct v4l2_ctrl_ops mt9v022_ctrl_ops = {
658 .g_volatile_ctrl = mt9v022_g_volatile_ctrl,
659 .s_ctrl = mt9v022_s_ctrl,
660};
661
828static struct v4l2_subdev_core_ops mt9v022_subdev_core_ops = { 662static struct v4l2_subdev_core_ops mt9v022_subdev_core_ops = {
829 .g_ctrl = mt9v022_g_ctrl,
830 .s_ctrl = mt9v022_s_ctrl,
831 .g_chip_ident = mt9v022_g_chip_ident, 663 .g_chip_ident = mt9v022_g_chip_ident,
832#ifdef CONFIG_VIDEO_ADV_DEBUG 664#ifdef CONFIG_VIDEO_ADV_DEBUG
833 .g_register = mt9v022_g_register, 665 .g_register = mt9v022_g_register,
@@ -848,6 +680,72 @@ static int mt9v022_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
848 return 0; 680 return 0;
849} 681}
850 682
683static int mt9v022_g_mbus_config(struct v4l2_subdev *sd,
684 struct v4l2_mbus_config *cfg)
685{
686 struct i2c_client *client = v4l2_get_subdevdata(sd);
687 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
688
689 cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_SLAVE |
690 V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING |
691 V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_LOW |
692 V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW |
693 V4L2_MBUS_DATA_ACTIVE_HIGH;
694 cfg->type = V4L2_MBUS_PARALLEL;
695 cfg->flags = soc_camera_apply_board_flags(icl, cfg);
696
697 return 0;
698}
699
700static int mt9v022_s_mbus_config(struct v4l2_subdev *sd,
701 const struct v4l2_mbus_config *cfg)
702{
703 struct i2c_client *client = v4l2_get_subdevdata(sd);
704 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
705 struct mt9v022 *mt9v022 = to_mt9v022(client);
706 unsigned long flags = soc_camera_apply_board_flags(icl, cfg);
707 unsigned int bps = soc_mbus_get_fmtdesc(mt9v022->fmt->code)->bits_per_sample;
708 int ret;
709 u16 pixclk = 0;
710
711 if (icl->set_bus_param) {
712 ret = icl->set_bus_param(icl, 1 << (bps - 1));
713 if (ret)
714 return ret;
715 } else if (bps != 10) {
716 /*
717 * Without board specific bus width settings we only support the
718 * sensors native bus width
719 */
720 return -EINVAL;
721 }
722
723 if (flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)
724 pixclk |= 0x10;
725
726 if (!(flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH))
727 pixclk |= 0x1;
728
729 if (!(flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH))
730 pixclk |= 0x2;
731
732 ret = reg_write(client, MT9V022_PIXCLK_FV_LV, pixclk);
733 if (ret < 0)
734 return ret;
735
736 if (!(flags & V4L2_MBUS_MASTER))
737 mt9v022->chip_control &= ~0x8;
738
739 ret = reg_write(client, MT9V022_CHIP_CONTROL, mt9v022->chip_control);
740 if (ret < 0)
741 return ret;
742
743 dev_dbg(&client->dev, "Calculated pixclk 0x%x, chip control 0x%x\n",
744 pixclk, mt9v022->chip_control);
745
746 return 0;
747}
748
851static struct v4l2_subdev_video_ops mt9v022_subdev_video_ops = { 749static struct v4l2_subdev_video_ops mt9v022_subdev_video_ops = {
852 .s_stream = mt9v022_s_stream, 750 .s_stream = mt9v022_s_stream,
853 .s_mbus_fmt = mt9v022_s_fmt, 751 .s_mbus_fmt = mt9v022_s_fmt,
@@ -857,6 +755,8 @@ static struct v4l2_subdev_video_ops mt9v022_subdev_video_ops = {
857 .g_crop = mt9v022_g_crop, 755 .g_crop = mt9v022_g_crop,
858 .cropcap = mt9v022_cropcap, 756 .cropcap = mt9v022_cropcap,
859 .enum_mbus_fmt = mt9v022_enum_fmt, 757 .enum_mbus_fmt = mt9v022_enum_fmt,
758 .g_mbus_config = mt9v022_g_mbus_config,
759 .s_mbus_config = mt9v022_s_mbus_config,
860}; 760};
861 761
862static struct v4l2_subdev_sensor_ops mt9v022_subdev_sensor_ops = { 762static struct v4l2_subdev_sensor_ops mt9v022_subdev_sensor_ops = {
@@ -873,17 +773,10 @@ static int mt9v022_probe(struct i2c_client *client,
873 const struct i2c_device_id *did) 773 const struct i2c_device_id *did)
874{ 774{
875 struct mt9v022 *mt9v022; 775 struct mt9v022 *mt9v022;
876 struct soc_camera_device *icd = client->dev.platform_data; 776 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
877 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 777 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
878 struct soc_camera_link *icl;
879 int ret; 778 int ret;
880 779
881 if (!icd) {
882 dev_err(&client->dev, "MT9V022: missing soc-camera data!\n");
883 return -EINVAL;
884 }
885
886 icl = to_soc_camera_link(icd);
887 if (!icl) { 780 if (!icl) {
888 dev_err(&client->dev, "MT9V022 driver needs platform data\n"); 781 dev_err(&client->dev, "MT9V022 driver needs platform data\n");
889 return -EINVAL; 782 return -EINVAL;
@@ -900,10 +793,39 @@ static int mt9v022_probe(struct i2c_client *client,
900 return -ENOMEM; 793 return -ENOMEM;
901 794
902 v4l2_i2c_subdev_init(&mt9v022->subdev, client, &mt9v022_subdev_ops); 795 v4l2_i2c_subdev_init(&mt9v022->subdev, client, &mt9v022_subdev_ops);
796 v4l2_ctrl_handler_init(&mt9v022->hdl, 6);
797 v4l2_ctrl_new_std(&mt9v022->hdl, &mt9v022_ctrl_ops,
798 V4L2_CID_VFLIP, 0, 1, 1, 0);
799 v4l2_ctrl_new_std(&mt9v022->hdl, &mt9v022_ctrl_ops,
800 V4L2_CID_HFLIP, 0, 1, 1, 0);
801 mt9v022->autogain = v4l2_ctrl_new_std(&mt9v022->hdl, &mt9v022_ctrl_ops,
802 V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
803 mt9v022->gain = v4l2_ctrl_new_std(&mt9v022->hdl, &mt9v022_ctrl_ops,
804 V4L2_CID_GAIN, 0, 127, 1, 64);
805
806 /*
807 * Simulated autoexposure. If enabled, we calculate shutter width
808 * ourselves in the driver based on vertical blanking and frame width
809 */
810 mt9v022->autoexposure = v4l2_ctrl_new_std_menu(&mt9v022->hdl,
811 &mt9v022_ctrl_ops, V4L2_CID_EXPOSURE_AUTO, 1, 0,
812 V4L2_EXPOSURE_AUTO);
813 mt9v022->exposure = v4l2_ctrl_new_std(&mt9v022->hdl, &mt9v022_ctrl_ops,
814 V4L2_CID_EXPOSURE, 1, 255, 1, 255);
815
816 mt9v022->subdev.ctrl_handler = &mt9v022->hdl;
817 if (mt9v022->hdl.error) {
818 int err = mt9v022->hdl.error;
819
820 kfree(mt9v022);
821 return err;
822 }
823 v4l2_ctrl_auto_cluster(2, &mt9v022->autoexposure,
824 V4L2_EXPOSURE_MANUAL, true);
825 v4l2_ctrl_auto_cluster(2, &mt9v022->autogain, 0, true);
903 826
904 mt9v022->chip_control = MT9V022_CHIP_CONTROL_DEFAULT; 827 mt9v022->chip_control = MT9V022_CHIP_CONTROL_DEFAULT;
905 828
906 icd->ops = &mt9v022_ops;
907 /* 829 /*
908 * MT9V022 _really_ corrupts the first read out line. 830 * MT9V022 _really_ corrupts the first read out line.
909 * TODO: verify on i.MX31 831 * TODO: verify on i.MX31
@@ -914,9 +836,9 @@ static int mt9v022_probe(struct i2c_client *client,
914 mt9v022->rect.width = MT9V022_MAX_WIDTH; 836 mt9v022->rect.width = MT9V022_MAX_WIDTH;
915 mt9v022->rect.height = MT9V022_MAX_HEIGHT; 837 mt9v022->rect.height = MT9V022_MAX_HEIGHT;
916 838
917 ret = mt9v022_video_probe(icd, client); 839 ret = mt9v022_video_probe(client);
918 if (ret) { 840 if (ret) {
919 icd->ops = NULL; 841 v4l2_ctrl_handler_free(&mt9v022->hdl);
920 kfree(mt9v022); 842 kfree(mt9v022);
921 } 843 }
922 844
@@ -926,10 +848,12 @@ static int mt9v022_probe(struct i2c_client *client,
926static int mt9v022_remove(struct i2c_client *client) 848static int mt9v022_remove(struct i2c_client *client)
927{ 849{
928 struct mt9v022 *mt9v022 = to_mt9v022(client); 850 struct mt9v022 *mt9v022 = to_mt9v022(client);
929 struct soc_camera_device *icd = client->dev.platform_data; 851 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
930 852
931 icd->ops = NULL; 853 v4l2_device_unregister_subdev(&mt9v022->subdev);
932 mt9v022_video_remove(icd); 854 if (icl->free_bus)
855 icl->free_bus(icl);
856 v4l2_ctrl_handler_free(&mt9v022->hdl);
933 kfree(mt9v022); 857 kfree(mt9v022);
934 858
935 return 0; 859 return 0;
diff --git a/drivers/media/video/mt9v032.c b/drivers/media/video/mt9v032.c
index c64e1dc4cb4e..f080c162123f 100644
--- a/drivers/media/video/mt9v032.c
+++ b/drivers/media/video/mt9v032.c
@@ -19,6 +19,7 @@
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/videodev2.h> 20#include <linux/videodev2.h>
21#include <linux/v4l2-mediabus.h> 21#include <linux/v4l2-mediabus.h>
22#include <linux/module.h>
22 23
23#include <media/mt9v032.h> 24#include <media/mt9v032.h>
24#include <media/v4l2-ctrls.h> 25#include <media/v4l2-ctrls.h>
diff --git a/drivers/media/video/mx1_camera.c b/drivers/media/video/mx1_camera.c
index 087db12a3a67..18e94c7d2be8 100644
--- a/drivers/media/video/mx1_camera.c
+++ b/drivers/media/video/mx1_camera.c
@@ -78,11 +78,10 @@
78#define CSI_IRQ_MASK (CSISR_SFF_OR_INT | CSISR_RFF_OR_INT | \ 78#define CSI_IRQ_MASK (CSISR_SFF_OR_INT | CSISR_RFF_OR_INT | \
79 CSISR_STATFF_INT | CSISR_RXFF_INT | CSISR_SOF_INT) 79 CSISR_STATFF_INT | CSISR_RXFF_INT | CSISR_SOF_INT)
80 80
81#define CSI_BUS_FLAGS (SOCAM_MASTER | SOCAM_HSYNC_ACTIVE_HIGH | \ 81#define CSI_BUS_FLAGS (V4L2_MBUS_MASTER | V4L2_MBUS_HSYNC_ACTIVE_HIGH | \
82 SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW | \ 82 V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW | \
83 SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING | \ 83 V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING | \
84 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATA_ACTIVE_LOW | \ 84 V4L2_MBUS_DATA_ACTIVE_HIGH | V4L2_MBUS_DATA_ACTIVE_LOW)
85 SOCAM_DATAWIDTH_8)
86 85
87#define MAX_VIDEO_MEM 16 /* Video memory limit in megabytes */ 86#define MAX_VIDEO_MEM 16 /* Video memory limit in megabytes */
88 87
@@ -490,59 +489,73 @@ static int mx1_camera_set_crop(struct soc_camera_device *icd,
490 489
491static int mx1_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt) 490static int mx1_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt)
492{ 491{
492 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
493 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 493 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
494 struct mx1_camera_dev *pcdev = ici->priv; 494 struct mx1_camera_dev *pcdev = ici->priv;
495 unsigned long camera_flags, common_flags; 495 struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,};
496 unsigned long common_flags;
496 unsigned int csicr1; 497 unsigned int csicr1;
497 int ret; 498 int ret;
498 499
499 camera_flags = icd->ops->query_bus_param(icd);
500
501 /* MX1 supports only 8bit buswidth */ 500 /* MX1 supports only 8bit buswidth */
502 common_flags = soc_camera_bus_param_compatible(camera_flags, 501 ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg);
503 CSI_BUS_FLAGS); 502 if (!ret) {
504 if (!common_flags) 503 common_flags = soc_mbus_config_compatible(&cfg, CSI_BUS_FLAGS);
505 return -EINVAL; 504 if (!common_flags) {
505 dev_warn(icd->parent,
506 "Flags incompatible: camera 0x%x, host 0x%x\n",
507 cfg.flags, CSI_BUS_FLAGS);
508 return -EINVAL;
509 }
510 } else if (ret != -ENOIOCTLCMD) {
511 return ret;
512 } else {
513 common_flags = CSI_BUS_FLAGS;
514 }
506 515
507 /* Make choises, based on platform choice */ 516 /* Make choises, based on platform choice */
508 if ((common_flags & SOCAM_VSYNC_ACTIVE_HIGH) && 517 if ((common_flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) &&
509 (common_flags & SOCAM_VSYNC_ACTIVE_LOW)) { 518 (common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)) {
510 if (!pcdev->pdata || 519 if (!pcdev->pdata ||
511 pcdev->pdata->flags & MX1_CAMERA_VSYNC_HIGH) 520 pcdev->pdata->flags & MX1_CAMERA_VSYNC_HIGH)
512 common_flags &= ~SOCAM_VSYNC_ACTIVE_LOW; 521 common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_LOW;
513 else 522 else
514 common_flags &= ~SOCAM_VSYNC_ACTIVE_HIGH; 523 common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_HIGH;
515 } 524 }
516 525
517 if ((common_flags & SOCAM_PCLK_SAMPLE_RISING) && 526 if ((common_flags & V4L2_MBUS_PCLK_SAMPLE_RISING) &&
518 (common_flags & SOCAM_PCLK_SAMPLE_FALLING)) { 527 (common_flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)) {
519 if (!pcdev->pdata || 528 if (!pcdev->pdata ||
520 pcdev->pdata->flags & MX1_CAMERA_PCLK_RISING) 529 pcdev->pdata->flags & MX1_CAMERA_PCLK_RISING)
521 common_flags &= ~SOCAM_PCLK_SAMPLE_FALLING; 530 common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_FALLING;
522 else 531 else
523 common_flags &= ~SOCAM_PCLK_SAMPLE_RISING; 532 common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_RISING;
524 } 533 }
525 534
526 if ((common_flags & SOCAM_DATA_ACTIVE_HIGH) && 535 if ((common_flags & V4L2_MBUS_DATA_ACTIVE_HIGH) &&
527 (common_flags & SOCAM_DATA_ACTIVE_LOW)) { 536 (common_flags & V4L2_MBUS_DATA_ACTIVE_LOW)) {
528 if (!pcdev->pdata || 537 if (!pcdev->pdata ||
529 pcdev->pdata->flags & MX1_CAMERA_DATA_HIGH) 538 pcdev->pdata->flags & MX1_CAMERA_DATA_HIGH)
530 common_flags &= ~SOCAM_DATA_ACTIVE_LOW; 539 common_flags &= ~V4L2_MBUS_DATA_ACTIVE_LOW;
531 else 540 else
532 common_flags &= ~SOCAM_DATA_ACTIVE_HIGH; 541 common_flags &= ~V4L2_MBUS_DATA_ACTIVE_HIGH;
533 } 542 }
534 543
535 ret = icd->ops->set_bus_param(icd, common_flags); 544 cfg.flags = common_flags;
536 if (ret < 0) 545 ret = v4l2_subdev_call(sd, video, s_mbus_config, &cfg);
546 if (ret < 0 && ret != -ENOIOCTLCMD) {
547 dev_dbg(icd->parent, "camera s_mbus_config(0x%lx) returned %d\n",
548 common_flags, ret);
537 return ret; 549 return ret;
550 }
538 551
539 csicr1 = __raw_readl(pcdev->base + CSICR1); 552 csicr1 = __raw_readl(pcdev->base + CSICR1);
540 553
541 if (common_flags & SOCAM_PCLK_SAMPLE_RISING) 554 if (common_flags & V4L2_MBUS_PCLK_SAMPLE_RISING)
542 csicr1 |= CSICR1_REDGE; 555 csicr1 |= CSICR1_REDGE;
543 if (common_flags & SOCAM_VSYNC_ACTIVE_HIGH) 556 if (common_flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH)
544 csicr1 |= CSICR1_SOF_POL; 557 csicr1 |= CSICR1_SOF_POL;
545 if (common_flags & SOCAM_DATA_ACTIVE_LOW) 558 if (common_flags & V4L2_MBUS_DATA_ACTIVE_LOW)
546 csicr1 |= CSICR1_DATA_POL; 559 csicr1 |= CSICR1_DATA_POL;
547 560
548 __raw_writel(csicr1, pcdev->base + CSICR1); 561 __raw_writel(csicr1, pcdev->base + CSICR1);
diff --git a/drivers/media/video/mx2_camera.c b/drivers/media/video/mx2_camera.c
index ec2410c0c806..a803d9ea8fd6 100644
--- a/drivers/media/video/mx2_camera.c
+++ b/drivers/media/video/mx2_camera.c
@@ -686,16 +686,15 @@ static void mx2_camera_init_videobuf(struct videobuf_queue *q,
686 icd, &icd->video_lock); 686 icd, &icd->video_lock);
687} 687}
688 688
689#define MX2_BUS_FLAGS (SOCAM_DATAWIDTH_8 | \ 689#define MX2_BUS_FLAGS (V4L2_MBUS_MASTER | \
690 SOCAM_MASTER | \ 690 V4L2_MBUS_VSYNC_ACTIVE_HIGH | \
691 SOCAM_VSYNC_ACTIVE_HIGH | \ 691 V4L2_MBUS_VSYNC_ACTIVE_LOW | \
692 SOCAM_VSYNC_ACTIVE_LOW | \ 692 V4L2_MBUS_HSYNC_ACTIVE_HIGH | \
693 SOCAM_HSYNC_ACTIVE_HIGH | \ 693 V4L2_MBUS_HSYNC_ACTIVE_LOW | \
694 SOCAM_HSYNC_ACTIVE_LOW | \ 694 V4L2_MBUS_PCLK_SAMPLE_RISING | \
695 SOCAM_PCLK_SAMPLE_RISING | \ 695 V4L2_MBUS_PCLK_SAMPLE_FALLING | \
696 SOCAM_PCLK_SAMPLE_FALLING | \ 696 V4L2_MBUS_DATA_ACTIVE_HIGH | \
697 SOCAM_DATA_ACTIVE_HIGH | \ 697 V4L2_MBUS_DATA_ACTIVE_LOW)
698 SOCAM_DATA_ACTIVE_LOW)
699 698
700static int mx27_camera_emma_prp_reset(struct mx2_camera_dev *pcdev) 699static int mx27_camera_emma_prp_reset(struct mx2_camera_dev *pcdev)
701{ 700{
@@ -770,46 +769,59 @@ static void mx27_camera_emma_buf_init(struct soc_camera_device *icd,
770static int mx2_camera_set_bus_param(struct soc_camera_device *icd, 769static int mx2_camera_set_bus_param(struct soc_camera_device *icd,
771 __u32 pixfmt) 770 __u32 pixfmt)
772{ 771{
773 struct soc_camera_host *ici = 772 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
774 to_soc_camera_host(icd->parent); 773 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
775 struct mx2_camera_dev *pcdev = ici->priv; 774 struct mx2_camera_dev *pcdev = ici->priv;
776 unsigned long camera_flags, common_flags; 775 struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,};
777 int ret = 0; 776 unsigned long common_flags;
777 int ret;
778 int bytesperline; 778 int bytesperline;
779 u32 csicr1 = pcdev->csicr1; 779 u32 csicr1 = pcdev->csicr1;
780 780
781 camera_flags = icd->ops->query_bus_param(icd); 781 ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg);
782 782 if (!ret) {
783 common_flags = soc_camera_bus_param_compatible(camera_flags, 783 common_flags = soc_mbus_config_compatible(&cfg, MX2_BUS_FLAGS);
784 MX2_BUS_FLAGS); 784 if (!common_flags) {
785 if (!common_flags) 785 dev_warn(icd->parent,
786 return -EINVAL; 786 "Flags incompatible: camera 0x%x, host 0x%x\n",
787 cfg.flags, MX2_BUS_FLAGS);
788 return -EINVAL;
789 }
790 } else if (ret != -ENOIOCTLCMD) {
791 return ret;
792 } else {
793 common_flags = MX2_BUS_FLAGS;
794 }
787 795
788 if ((common_flags & SOCAM_HSYNC_ACTIVE_HIGH) && 796 if ((common_flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) &&
789 (common_flags & SOCAM_HSYNC_ACTIVE_LOW)) { 797 (common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)) {
790 if (pcdev->platform_flags & MX2_CAMERA_HSYNC_HIGH) 798 if (pcdev->platform_flags & MX2_CAMERA_HSYNC_HIGH)
791 common_flags &= ~SOCAM_HSYNC_ACTIVE_LOW; 799 common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_LOW;
792 else 800 else
793 common_flags &= ~SOCAM_HSYNC_ACTIVE_HIGH; 801 common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_HIGH;
794 } 802 }
795 803
796 if ((common_flags & SOCAM_PCLK_SAMPLE_RISING) && 804 if ((common_flags & V4L2_MBUS_PCLK_SAMPLE_RISING) &&
797 (common_flags & SOCAM_PCLK_SAMPLE_FALLING)) { 805 (common_flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)) {
798 if (pcdev->platform_flags & MX2_CAMERA_PCLK_SAMPLE_RISING) 806 if (pcdev->platform_flags & MX2_CAMERA_PCLK_SAMPLE_RISING)
799 common_flags &= ~SOCAM_PCLK_SAMPLE_FALLING; 807 common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_FALLING;
800 else 808 else
801 common_flags &= ~SOCAM_PCLK_SAMPLE_RISING; 809 common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_RISING;
802 } 810 }
803 811
804 ret = icd->ops->set_bus_param(icd, common_flags); 812 cfg.flags = common_flags;
805 if (ret < 0) 813 ret = v4l2_subdev_call(sd, video, s_mbus_config, &cfg);
814 if (ret < 0 && ret != -ENOIOCTLCMD) {
815 dev_dbg(icd->parent, "camera s_mbus_config(0x%lx) returned %d\n",
816 common_flags, ret);
806 return ret; 817 return ret;
818 }
807 819
808 if (common_flags & SOCAM_PCLK_SAMPLE_RISING) 820 if (common_flags & V4L2_MBUS_PCLK_SAMPLE_RISING)
809 csicr1 |= CSICR1_REDGE; 821 csicr1 |= CSICR1_REDGE;
810 if (common_flags & SOCAM_VSYNC_ACTIVE_HIGH) 822 if (common_flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH)
811 csicr1 |= CSICR1_SOF_POL; 823 csicr1 |= CSICR1_SOF_POL;
812 if (common_flags & SOCAM_HSYNC_ACTIVE_HIGH) 824 if (common_flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH)
813 csicr1 |= CSICR1_HSYNC_POL; 825 csicr1 |= CSICR1_HSYNC_POL;
814 if (pcdev->platform_flags & MX2_CAMERA_SWAP16) 826 if (pcdev->platform_flags & MX2_CAMERA_SWAP16)
815 csicr1 |= CSICR1_SWAP16_EN; 827 csicr1 |= CSICR1_SWAP16_EN;
diff --git a/drivers/media/video/mx3_camera.c b/drivers/media/video/mx3_camera.c
index c8e958a07e91..f96f92f00f92 100644
--- a/drivers/media/video/mx3_camera.c
+++ b/drivers/media/video/mx3_camera.c
@@ -109,10 +109,12 @@ struct mx3_camera_dev {
109 109
110 unsigned long platform_flags; 110 unsigned long platform_flags;
111 unsigned long mclk; 111 unsigned long mclk;
112 u16 width_flags; /* max 15 bits */
112 113
113 struct list_head capture; 114 struct list_head capture;
114 spinlock_t lock; /* Protects video buffer lists */ 115 spinlock_t lock; /* Protects video buffer lists */
115 struct mx3_camera_buffer *active; 116 struct mx3_camera_buffer *active;
117 size_t buf_total;
116 struct vb2_alloc_ctx *alloc_ctx; 118 struct vb2_alloc_ctx *alloc_ctx;
117 enum v4l2_field field; 119 enum v4l2_field field;
118 int sequence; 120 int sequence;
@@ -190,79 +192,53 @@ static void mx3_cam_dma_done(void *arg)
190 * Calculate the __buffer__ (not data) size and number of buffers. 192 * Calculate the __buffer__ (not data) size and number of buffers.
191 */ 193 */
192static int mx3_videobuf_setup(struct vb2_queue *vq, 194static int mx3_videobuf_setup(struct vb2_queue *vq,
195 const struct v4l2_format *fmt,
193 unsigned int *count, unsigned int *num_planes, 196 unsigned int *count, unsigned int *num_planes,
194 unsigned int sizes[], void *alloc_ctxs[]) 197 unsigned int sizes[], void *alloc_ctxs[])
195{ 198{
196 struct soc_camera_device *icd = soc_camera_from_vb2q(vq); 199 struct soc_camera_device *icd = soc_camera_from_vb2q(vq);
197 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 200 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
198 struct mx3_camera_dev *mx3_cam = ici->priv; 201 struct mx3_camera_dev *mx3_cam = ici->priv;
199 int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width, 202 int bytes_per_line;
200 icd->current_fmt->host_fmt); 203 unsigned int height;
201
202 if (bytes_per_line < 0)
203 return bytes_per_line;
204 204
205 if (!mx3_cam->idmac_channel[0]) 205 if (!mx3_cam->idmac_channel[0])
206 return -EINVAL; 206 return -EINVAL;
207 207
208 *num_planes = 1; 208 if (fmt) {
209 209 const struct soc_camera_format_xlate *xlate = soc_camera_xlate_by_fourcc(icd,
210 mx3_cam->sequence = 0; 210 fmt->fmt.pix.pixelformat);
211 sizes[0] = bytes_per_line * icd->user_height; 211 if (!xlate)
212 alloc_ctxs[0] = mx3_cam->alloc_ctx; 212 return -EINVAL;
213 213 bytes_per_line = soc_mbus_bytes_per_line(fmt->fmt.pix.width,
214 if (!*count) 214 xlate->host_fmt);
215 *count = 32; 215 height = fmt->fmt.pix.height;
216 216 } else {
217 if (sizes[0] * *count > MAX_VIDEO_MEM * 1024 * 1024) 217 /* Called from VIDIOC_REQBUFS or in compatibility mode */
218 *count = MAX_VIDEO_MEM * 1024 * 1024 / sizes[0]; 218 bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
219
220 return 0;
221}
222
223static int mx3_videobuf_prepare(struct vb2_buffer *vb)
224{
225 struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue);
226 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
227 struct mx3_camera_dev *mx3_cam = ici->priv;
228 struct idmac_channel *ichan = mx3_cam->idmac_channel[0];
229 struct scatterlist *sg;
230 struct mx3_camera_buffer *buf;
231 size_t new_size;
232 int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
233 icd->current_fmt->host_fmt); 219 icd->current_fmt->host_fmt);
234 220 height = icd->user_height;
221 }
235 if (bytes_per_line < 0) 222 if (bytes_per_line < 0)
236 return bytes_per_line; 223 return bytes_per_line;
237 224
238 buf = to_mx3_vb(vb); 225 sizes[0] = bytes_per_line * height;
239 sg = &buf->sg;
240
241 new_size = bytes_per_line * icd->user_height;
242 226
243 if (vb2_plane_size(vb, 0) < new_size) { 227 alloc_ctxs[0] = mx3_cam->alloc_ctx;
244 dev_err(icd->parent, "Buffer too small (%lu < %zu)\n",
245 vb2_plane_size(vb, 0), new_size);
246 return -ENOBUFS;
247 }
248 228
249 if (buf->state == CSI_BUF_NEEDS_INIT) { 229 if (!vq->num_buffers)
250 sg_dma_address(sg) = vb2_dma_contig_plane_dma_addr(vb, 0); 230 mx3_cam->sequence = 0;
251 sg_dma_len(sg) = new_size;
252 231
253 buf->txd = ichan->dma_chan.device->device_prep_slave_sg( 232 if (!*count)
254 &ichan->dma_chan, sg, 1, DMA_FROM_DEVICE, 233 *count = 2;
255 DMA_PREP_INTERRUPT);
256 if (!buf->txd)
257 return -EIO;
258
259 buf->txd->callback_param = buf->txd;
260 buf->txd->callback = mx3_cam_dma_done;
261 234
262 buf->state = CSI_BUF_PREPARED; 235 /* If *num_planes != 0, we have already verified *count. */
263 } 236 if (!*num_planes &&
237 sizes[0] * *count + mx3_cam->buf_total > MAX_VIDEO_MEM * 1024 * 1024)
238 *count = (MAX_VIDEO_MEM * 1024 * 1024 - mx3_cam->buf_total) /
239 sizes[0];
264 240
265 vb2_set_plane_payload(vb, 0, new_size); 241 *num_planes = 1;
266 242
267 return 0; 243 return 0;
268} 244}
@@ -286,28 +262,58 @@ static void mx3_videobuf_queue(struct vb2_buffer *vb)
286 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 262 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
287 struct mx3_camera_dev *mx3_cam = ici->priv; 263 struct mx3_camera_dev *mx3_cam = ici->priv;
288 struct mx3_camera_buffer *buf = to_mx3_vb(vb); 264 struct mx3_camera_buffer *buf = to_mx3_vb(vb);
289 struct dma_async_tx_descriptor *txd = buf->txd; 265 struct scatterlist *sg = &buf->sg;
290 struct idmac_channel *ichan = to_idmac_chan(txd->chan); 266 struct dma_async_tx_descriptor *txd;
267 struct idmac_channel *ichan = mx3_cam->idmac_channel[0];
291 struct idmac_video_param *video = &ichan->params.video; 268 struct idmac_video_param *video = &ichan->params.video;
292 dma_cookie_t cookie; 269 const struct soc_mbus_pixelfmt *host_fmt = icd->current_fmt->host_fmt;
293 u32 fourcc = icd->current_fmt->host_fmt->fourcc; 270 int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width, host_fmt);
294 unsigned long flags; 271 unsigned long flags;
272 dma_cookie_t cookie;
273 size_t new_size;
274
275 BUG_ON(bytes_per_line <= 0);
276
277 new_size = bytes_per_line * icd->user_height;
278
279 if (vb2_plane_size(vb, 0) < new_size) {
280 dev_err(icd->parent, "Buffer #%d too small (%lu < %zu)\n",
281 vb->v4l2_buf.index, vb2_plane_size(vb, 0), new_size);
282 goto error;
283 }
284
285 if (buf->state == CSI_BUF_NEEDS_INIT) {
286 sg_dma_address(sg) = vb2_dma_contig_plane_dma_addr(vb, 0);
287 sg_dma_len(sg) = new_size;
288
289 txd = ichan->dma_chan.device->device_prep_slave_sg(
290 &ichan->dma_chan, sg, 1, DMA_FROM_DEVICE,
291 DMA_PREP_INTERRUPT);
292 if (!txd)
293 goto error;
294
295 txd->callback_param = txd;
296 txd->callback = mx3_cam_dma_done;
297
298 buf->state = CSI_BUF_PREPARED;
299 buf->txd = txd;
300 } else {
301 txd = buf->txd;
302 }
303
304 vb2_set_plane_payload(vb, 0, new_size);
295 305
296 /* This is the configuration of one sg-element */ 306 /* This is the configuration of one sg-element */
297 video->out_pixel_fmt = fourcc_to_ipu_pix(fourcc); 307 video->out_pixel_fmt = fourcc_to_ipu_pix(host_fmt->fourcc);
298 308
299 if (video->out_pixel_fmt == IPU_PIX_FMT_GENERIC) { 309 if (video->out_pixel_fmt == IPU_PIX_FMT_GENERIC) {
300 /* 310 /*
301 * If the IPU DMA channel is configured to transport 311 * If the IPU DMA channel is configured to transfer generic
302 * generic 8-bit data, we have to set up correctly the 312 * 8-bit data, we have to set up the geometry parameters
303 * geometry parameters upon the current pixel format. 313 * correctly, according to the current pixel format. The DMA
304 * So, since the DMA horizontal parameters are expressed 314 * horizontal parameters in this case are expressed in bytes,
305 * in bytes not pixels, convert these in the right unit. 315 * not in pixels.
306 */ 316 */
307 int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
308 icd->current_fmt->host_fmt);
309 BUG_ON(bytes_per_line <= 0);
310
311 video->out_width = bytes_per_line; 317 video->out_width = bytes_per_line;
312 video->out_height = icd->user_height; 318 video->out_height = icd->user_height;
313 video->out_stride = bytes_per_line; 319 video->out_stride = bytes_per_line;
@@ -351,6 +357,7 @@ static void mx3_videobuf_queue(struct vb2_buffer *vb)
351 mx3_cam->active = NULL; 357 mx3_cam->active = NULL;
352 358
353 spin_unlock_irqrestore(&mx3_cam->lock, flags); 359 spin_unlock_irqrestore(&mx3_cam->lock, flags);
360error:
354 vb2_buffer_done(vb, VB2_BUF_STATE_ERROR); 361 vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
355} 362}
356 363
@@ -384,17 +391,24 @@ static void mx3_videobuf_release(struct vb2_buffer *vb)
384 } 391 }
385 392
386 spin_unlock_irqrestore(&mx3_cam->lock, flags); 393 spin_unlock_irqrestore(&mx3_cam->lock, flags);
394
395 mx3_cam->buf_total -= vb2_plane_size(vb, 0);
387} 396}
388 397
389static int mx3_videobuf_init(struct vb2_buffer *vb) 398static int mx3_videobuf_init(struct vb2_buffer *vb)
390{ 399{
400 struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue);
401 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
402 struct mx3_camera_dev *mx3_cam = ici->priv;
391 struct mx3_camera_buffer *buf = to_mx3_vb(vb); 403 struct mx3_camera_buffer *buf = to_mx3_vb(vb);
404
392 /* This is for locking debugging only */ 405 /* This is for locking debugging only */
393 INIT_LIST_HEAD(&buf->queue); 406 INIT_LIST_HEAD(&buf->queue);
394 sg_init_table(&buf->sg, 1); 407 sg_init_table(&buf->sg, 1);
395 408
396 buf->state = CSI_BUF_NEEDS_INIT; 409 buf->state = CSI_BUF_NEEDS_INIT;
397 buf->txd = NULL; 410
411 mx3_cam->buf_total += vb2_plane_size(vb, 0);
398 412
399 return 0; 413 return 0;
400} 414}
@@ -405,13 +419,12 @@ static int mx3_stop_streaming(struct vb2_queue *q)
405 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 419 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
406 struct mx3_camera_dev *mx3_cam = ici->priv; 420 struct mx3_camera_dev *mx3_cam = ici->priv;
407 struct idmac_channel *ichan = mx3_cam->idmac_channel[0]; 421 struct idmac_channel *ichan = mx3_cam->idmac_channel[0];
408 struct dma_chan *chan;
409 struct mx3_camera_buffer *buf, *tmp; 422 struct mx3_camera_buffer *buf, *tmp;
410 unsigned long flags; 423 unsigned long flags;
411 424
412 if (ichan) { 425 if (ichan) {
413 chan = &ichan->dma_chan; 426 struct dma_chan *chan = &ichan->dma_chan;
414 chan->device->device_control(chan, DMA_TERMINATE_ALL, 0); 427 chan->device->device_control(chan, DMA_PAUSE, 0);
415 } 428 }
416 429
417 spin_lock_irqsave(&mx3_cam->lock, flags); 430 spin_lock_irqsave(&mx3_cam->lock, flags);
@@ -419,8 +432,8 @@ static int mx3_stop_streaming(struct vb2_queue *q)
419 mx3_cam->active = NULL; 432 mx3_cam->active = NULL;
420 433
421 list_for_each_entry_safe(buf, tmp, &mx3_cam->capture, queue) { 434 list_for_each_entry_safe(buf, tmp, &mx3_cam->capture, queue) {
422 buf->state = CSI_BUF_NEEDS_INIT;
423 list_del_init(&buf->queue); 435 list_del_init(&buf->queue);
436 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
424 } 437 }
425 438
426 spin_unlock_irqrestore(&mx3_cam->lock, flags); 439 spin_unlock_irqrestore(&mx3_cam->lock, flags);
@@ -430,7 +443,6 @@ static int mx3_stop_streaming(struct vb2_queue *q)
430 443
431static struct vb2_ops mx3_videobuf_ops = { 444static struct vb2_ops mx3_videobuf_ops = {
432 .queue_setup = mx3_videobuf_setup, 445 .queue_setup = mx3_videobuf_setup,
433 .buf_prepare = mx3_videobuf_prepare,
434 .buf_queue = mx3_videobuf_queue, 446 .buf_queue = mx3_videobuf_queue,
435 .buf_cleanup = mx3_videobuf_release, 447 .buf_cleanup = mx3_videobuf_release,
436 .buf_init = mx3_videobuf_init, 448 .buf_init = mx3_videobuf_init,
@@ -514,6 +526,7 @@ static int mx3_camera_add_device(struct soc_camera_device *icd)
514 526
515 mx3_camera_activate(mx3_cam, icd); 527 mx3_camera_activate(mx3_cam, icd);
516 528
529 mx3_cam->buf_total = 0;
517 mx3_cam->icd = icd; 530 mx3_cam->icd = icd;
518 531
519 dev_info(icd->parent, "MX3 Camera driver attached to camera %d\n", 532 dev_info(icd->parent, "MX3 Camera driver attached to camera %d\n",
@@ -548,58 +561,27 @@ static int test_platform_param(struct mx3_camera_dev *mx3_cam,
548 unsigned char buswidth, unsigned long *flags) 561 unsigned char buswidth, unsigned long *flags)
549{ 562{
550 /* 563 /*
564 * If requested data width is supported by the platform, use it or any
565 * possible lower value - i.MX31 is smart enough to shift bits
566 */
567 if (buswidth > fls(mx3_cam->width_flags))
568 return -EINVAL;
569
570 /*
551 * Platform specified synchronization and pixel clock polarities are 571 * Platform specified synchronization and pixel clock polarities are
552 * only a recommendation and are only used during probing. MX3x 572 * only a recommendation and are only used during probing. MX3x
553 * camera interface only works in master mode, i.e., uses HSYNC and 573 * camera interface only works in master mode, i.e., uses HSYNC and
554 * VSYNC signals from the sensor 574 * VSYNC signals from the sensor
555 */ 575 */
556 *flags = SOCAM_MASTER | 576 *flags = V4L2_MBUS_MASTER |
557 SOCAM_HSYNC_ACTIVE_HIGH | 577 V4L2_MBUS_HSYNC_ACTIVE_HIGH |
558 SOCAM_HSYNC_ACTIVE_LOW | 578 V4L2_MBUS_HSYNC_ACTIVE_LOW |
559 SOCAM_VSYNC_ACTIVE_HIGH | 579 V4L2_MBUS_VSYNC_ACTIVE_HIGH |
560 SOCAM_VSYNC_ACTIVE_LOW | 580 V4L2_MBUS_VSYNC_ACTIVE_LOW |
561 SOCAM_PCLK_SAMPLE_RISING | 581 V4L2_MBUS_PCLK_SAMPLE_RISING |
562 SOCAM_PCLK_SAMPLE_FALLING | 582 V4L2_MBUS_PCLK_SAMPLE_FALLING |
563 SOCAM_DATA_ACTIVE_HIGH | 583 V4L2_MBUS_DATA_ACTIVE_HIGH |
564 SOCAM_DATA_ACTIVE_LOW; 584 V4L2_MBUS_DATA_ACTIVE_LOW;
565
566 /*
567 * If requested data width is supported by the platform, use it or any
568 * possible lower value - i.MX31 is smart enough to schift bits
569 */
570 if (mx3_cam->platform_flags & MX3_CAMERA_DATAWIDTH_15)
571 *flags |= SOCAM_DATAWIDTH_15 | SOCAM_DATAWIDTH_10 |
572 SOCAM_DATAWIDTH_8 | SOCAM_DATAWIDTH_4;
573 else if (mx3_cam->platform_flags & MX3_CAMERA_DATAWIDTH_10)
574 *flags |= SOCAM_DATAWIDTH_10 | SOCAM_DATAWIDTH_8 |
575 SOCAM_DATAWIDTH_4;
576 else if (mx3_cam->platform_flags & MX3_CAMERA_DATAWIDTH_8)
577 *flags |= SOCAM_DATAWIDTH_8 | SOCAM_DATAWIDTH_4;
578 else if (mx3_cam->platform_flags & MX3_CAMERA_DATAWIDTH_4)
579 *flags |= SOCAM_DATAWIDTH_4;
580
581 switch (buswidth) {
582 case 15:
583 if (!(*flags & SOCAM_DATAWIDTH_15))
584 return -EINVAL;
585 break;
586 case 10:
587 if (!(*flags & SOCAM_DATAWIDTH_10))
588 return -EINVAL;
589 break;
590 case 8:
591 if (!(*flags & SOCAM_DATAWIDTH_8))
592 return -EINVAL;
593 break;
594 case 4:
595 if (!(*flags & SOCAM_DATAWIDTH_4))
596 return -EINVAL;
597 break;
598 default:
599 dev_warn(mx3_cam->soc_host.v4l2_dev.dev,
600 "Unsupported bus width %d\n", buswidth);
601 return -EINVAL;
602 }
603 585
604 return 0; 586 return 0;
605} 587}
@@ -607,9 +589,11 @@ static int test_platform_param(struct mx3_camera_dev *mx3_cam,
607static int mx3_camera_try_bus_param(struct soc_camera_device *icd, 589static int mx3_camera_try_bus_param(struct soc_camera_device *icd,
608 const unsigned int depth) 590 const unsigned int depth)
609{ 591{
592 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
610 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 593 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
611 struct mx3_camera_dev *mx3_cam = ici->priv; 594 struct mx3_camera_dev *mx3_cam = ici->priv;
612 unsigned long bus_flags, camera_flags; 595 struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,};
596 unsigned long bus_flags, common_flags;
613 int ret = test_platform_param(mx3_cam, depth, &bus_flags); 597 int ret = test_platform_param(mx3_cam, depth, &bus_flags);
614 598
615 dev_dbg(icd->parent, "request bus width %d bit: %d\n", depth, ret); 599 dev_dbg(icd->parent, "request bus width %d bit: %d\n", depth, ret);
@@ -617,15 +601,21 @@ static int mx3_camera_try_bus_param(struct soc_camera_device *icd,
617 if (ret < 0) 601 if (ret < 0)
618 return ret; 602 return ret;
619 603
620 camera_flags = icd->ops->query_bus_param(icd); 604 ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg);
621 605 if (!ret) {
622 ret = soc_camera_bus_param_compatible(camera_flags, bus_flags); 606 common_flags = soc_mbus_config_compatible(&cfg,
623 if (ret < 0) 607 bus_flags);
624 dev_warn(icd->parent, 608 if (!common_flags) {
625 "Flags incompatible: camera %lx, host %lx\n", 609 dev_warn(icd->parent,
626 camera_flags, bus_flags); 610 "Flags incompatible: camera 0x%x, host 0x%lx\n",
611 cfg.flags, bus_flags);
612 return -EINVAL;
613 }
614 } else if (ret != -ENOIOCTLCMD) {
615 return ret;
616 }
627 617
628 return ret; 618 return 0;
629} 619}
630 620
631static bool chan_filter(struct dma_chan *chan, void *arg) 621static bool chan_filter(struct dma_chan *chan, void *arg)
@@ -994,9 +984,11 @@ static int mx3_camera_querycap(struct soc_camera_host *ici,
994 984
995static int mx3_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt) 985static int mx3_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt)
996{ 986{
987 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
997 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 988 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
998 struct mx3_camera_dev *mx3_cam = ici->priv; 989 struct mx3_camera_dev *mx3_cam = ici->priv;
999 unsigned long bus_flags, camera_flags, common_flags; 990 struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,};
991 unsigned long bus_flags, common_flags;
1000 u32 dw, sens_conf; 992 u32 dw, sens_conf;
1001 const struct soc_mbus_pixelfmt *fmt; 993 const struct soc_mbus_pixelfmt *fmt;
1002 int buswidth; 994 int buswidth;
@@ -1008,83 +1000,76 @@ static int mx3_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt)
1008 if (!fmt) 1000 if (!fmt)
1009 return -EINVAL; 1001 return -EINVAL;
1010 1002
1011 buswidth = fmt->bits_per_sample;
1012 ret = test_platform_param(mx3_cam, buswidth, &bus_flags);
1013
1014 xlate = soc_camera_xlate_by_fourcc(icd, pixfmt); 1003 xlate = soc_camera_xlate_by_fourcc(icd, pixfmt);
1015 if (!xlate) { 1004 if (!xlate) {
1016 dev_warn(dev, "Format %x not found\n", pixfmt); 1005 dev_warn(dev, "Format %x not found\n", pixfmt);
1017 return -EINVAL; 1006 return -EINVAL;
1018 } 1007 }
1019 1008
1009 buswidth = fmt->bits_per_sample;
1010 ret = test_platform_param(mx3_cam, buswidth, &bus_flags);
1011
1020 dev_dbg(dev, "requested bus width %d bit: %d\n", buswidth, ret); 1012 dev_dbg(dev, "requested bus width %d bit: %d\n", buswidth, ret);
1021 1013
1022 if (ret < 0) 1014 if (ret < 0)
1023 return ret; 1015 return ret;
1024 1016
1025 camera_flags = icd->ops->query_bus_param(icd); 1017 ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg);
1026 1018 if (!ret) {
1027 common_flags = soc_camera_bus_param_compatible(camera_flags, bus_flags); 1019 common_flags = soc_mbus_config_compatible(&cfg,
1028 dev_dbg(dev, "Flags cam: 0x%lx host: 0x%lx common: 0x%lx\n", 1020 bus_flags);
1029 camera_flags, bus_flags, common_flags); 1021 if (!common_flags) {
1030 if (!common_flags) { 1022 dev_warn(icd->parent,
1031 dev_dbg(dev, "no common flags"); 1023 "Flags incompatible: camera 0x%x, host 0x%lx\n",
1032 return -EINVAL; 1024 cfg.flags, bus_flags);
1025 return -EINVAL;
1026 }
1027 } else if (ret != -ENOIOCTLCMD) {
1028 return ret;
1029 } else {
1030 common_flags = bus_flags;
1033 } 1031 }
1034 1032
1033 dev_dbg(dev, "Flags cam: 0x%x host: 0x%lx common: 0x%lx\n",
1034 cfg.flags, bus_flags, common_flags);
1035
1035 /* Make choices, based on platform preferences */ 1036 /* Make choices, based on platform preferences */
1036 if ((common_flags & SOCAM_HSYNC_ACTIVE_HIGH) && 1037 if ((common_flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) &&
1037 (common_flags & SOCAM_HSYNC_ACTIVE_LOW)) { 1038 (common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)) {
1038 if (mx3_cam->platform_flags & MX3_CAMERA_HSP) 1039 if (mx3_cam->platform_flags & MX3_CAMERA_HSP)
1039 common_flags &= ~SOCAM_HSYNC_ACTIVE_HIGH; 1040 common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_HIGH;
1040 else 1041 else
1041 common_flags &= ~SOCAM_HSYNC_ACTIVE_LOW; 1042 common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_LOW;
1042 } 1043 }
1043 1044
1044 if ((common_flags & SOCAM_VSYNC_ACTIVE_HIGH) && 1045 if ((common_flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) &&
1045 (common_flags & SOCAM_VSYNC_ACTIVE_LOW)) { 1046 (common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)) {
1046 if (mx3_cam->platform_flags & MX3_CAMERA_VSP) 1047 if (mx3_cam->platform_flags & MX3_CAMERA_VSP)
1047 common_flags &= ~SOCAM_VSYNC_ACTIVE_HIGH; 1048 common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_HIGH;
1048 else 1049 else
1049 common_flags &= ~SOCAM_VSYNC_ACTIVE_LOW; 1050 common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_LOW;
1050 } 1051 }
1051 1052
1052 if ((common_flags & SOCAM_DATA_ACTIVE_HIGH) && 1053 if ((common_flags & V4L2_MBUS_DATA_ACTIVE_HIGH) &&
1053 (common_flags & SOCAM_DATA_ACTIVE_LOW)) { 1054 (common_flags & V4L2_MBUS_DATA_ACTIVE_LOW)) {
1054 if (mx3_cam->platform_flags & MX3_CAMERA_DP) 1055 if (mx3_cam->platform_flags & MX3_CAMERA_DP)
1055 common_flags &= ~SOCAM_DATA_ACTIVE_HIGH; 1056 common_flags &= ~V4L2_MBUS_DATA_ACTIVE_HIGH;
1056 else 1057 else
1057 common_flags &= ~SOCAM_DATA_ACTIVE_LOW; 1058 common_flags &= ~V4L2_MBUS_DATA_ACTIVE_LOW;
1058 } 1059 }
1059 1060
1060 if ((common_flags & SOCAM_PCLK_SAMPLE_RISING) && 1061 if ((common_flags & V4L2_MBUS_PCLK_SAMPLE_RISING) &&
1061 (common_flags & SOCAM_PCLK_SAMPLE_FALLING)) { 1062 (common_flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)) {
1062 if (mx3_cam->platform_flags & MX3_CAMERA_PCP) 1063 if (mx3_cam->platform_flags & MX3_CAMERA_PCP)
1063 common_flags &= ~SOCAM_PCLK_SAMPLE_RISING; 1064 common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_RISING;
1064 else 1065 else
1065 common_flags &= ~SOCAM_PCLK_SAMPLE_FALLING; 1066 common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_FALLING;
1066 } 1067 }
1067 1068
1068 /* 1069 cfg.flags = common_flags;
1069 * Make the camera work in widest common mode, we'll take care of 1070 ret = v4l2_subdev_call(sd, video, s_mbus_config, &cfg);
1070 * the rest 1071 if (ret < 0 && ret != -ENOIOCTLCMD) {
1071 */ 1072 dev_dbg(dev, "camera s_mbus_config(0x%lx) returned %d\n",
1072 if (common_flags & SOCAM_DATAWIDTH_15)
1073 common_flags = (common_flags & ~SOCAM_DATAWIDTH_MASK) |
1074 SOCAM_DATAWIDTH_15;
1075 else if (common_flags & SOCAM_DATAWIDTH_10)
1076 common_flags = (common_flags & ~SOCAM_DATAWIDTH_MASK) |
1077 SOCAM_DATAWIDTH_10;
1078 else if (common_flags & SOCAM_DATAWIDTH_8)
1079 common_flags = (common_flags & ~SOCAM_DATAWIDTH_MASK) |
1080 SOCAM_DATAWIDTH_8;
1081 else
1082 common_flags = (common_flags & ~SOCAM_DATAWIDTH_MASK) |
1083 SOCAM_DATAWIDTH_4;
1084
1085 ret = icd->ops->set_bus_param(icd, common_flags);
1086 if (ret < 0) {
1087 dev_dbg(dev, "camera set_bus_param(%lx) returned %d\n",
1088 common_flags, ret); 1073 common_flags, ret);
1089 return ret; 1074 return ret;
1090 } 1075 }
@@ -1108,13 +1093,13 @@ static int mx3_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt)
1108 /* This has been set in mx3_camera_activate(), but we clear it above */ 1093 /* This has been set in mx3_camera_activate(), but we clear it above */
1109 sens_conf |= CSI_SENS_CONF_DATA_FMT_BAYER; 1094 sens_conf |= CSI_SENS_CONF_DATA_FMT_BAYER;
1110 1095
1111 if (common_flags & SOCAM_PCLK_SAMPLE_FALLING) 1096 if (common_flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)
1112 sens_conf |= 1 << CSI_SENS_CONF_PIX_CLK_POL_SHIFT; 1097 sens_conf |= 1 << CSI_SENS_CONF_PIX_CLK_POL_SHIFT;
1113 if (common_flags & SOCAM_HSYNC_ACTIVE_LOW) 1098 if (common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)
1114 sens_conf |= 1 << CSI_SENS_CONF_HSYNC_POL_SHIFT; 1099 sens_conf |= 1 << CSI_SENS_CONF_HSYNC_POL_SHIFT;
1115 if (common_flags & SOCAM_VSYNC_ACTIVE_LOW) 1100 if (common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)
1116 sens_conf |= 1 << CSI_SENS_CONF_VSYNC_POL_SHIFT; 1101 sens_conf |= 1 << CSI_SENS_CONF_VSYNC_POL_SHIFT;
1117 if (common_flags & SOCAM_DATA_ACTIVE_LOW) 1102 if (common_flags & V4L2_MBUS_DATA_ACTIVE_LOW)
1118 sens_conf |= 1 << CSI_SENS_CONF_DATA_POL_SHIFT; 1103 sens_conf |= 1 << CSI_SENS_CONF_DATA_POL_SHIFT;
1119 1104
1120 /* Just do what we're asked to do */ 1105 /* Just do what we're asked to do */
@@ -1199,6 +1184,14 @@ static int __devinit mx3_camera_probe(struct platform_device *pdev)
1199 "data widths, using default 8 bit\n"); 1184 "data widths, using default 8 bit\n");
1200 mx3_cam->platform_flags |= MX3_CAMERA_DATAWIDTH_8; 1185 mx3_cam->platform_flags |= MX3_CAMERA_DATAWIDTH_8;
1201 } 1186 }
1187 if (mx3_cam->platform_flags & MX3_CAMERA_DATAWIDTH_4)
1188 mx3_cam->width_flags = 1 << 3;
1189 if (mx3_cam->platform_flags & MX3_CAMERA_DATAWIDTH_8)
1190 mx3_cam->width_flags |= 1 << 7;
1191 if (mx3_cam->platform_flags & MX3_CAMERA_DATAWIDTH_10)
1192 mx3_cam->width_flags |= 1 << 9;
1193 if (mx3_cam->platform_flags & MX3_CAMERA_DATAWIDTH_15)
1194 mx3_cam->width_flags |= 1 << 14;
1202 1195
1203 mx3_cam->mclk = mx3_cam->pdata->mclk_10khz * 10000; 1196 mx3_cam->mclk = mx3_cam->pdata->mclk_10khz * 10000;
1204 if (!mx3_cam->mclk) { 1197 if (!mx3_cam->mclk) {
@@ -1281,8 +1274,6 @@ static int __devexit mx3_camera_remove(struct platform_device *pdev)
1281 1274
1282 dmaengine_put(); 1275 dmaengine_put();
1283 1276
1284 dev_info(&pdev->dev, "i.MX3x Camera driver unloaded\n");
1285
1286 return 0; 1277 return 0;
1287} 1278}
1288 1279
diff --git a/drivers/media/video/mxb.c b/drivers/media/video/mxb.c
index f0c3968ac7eb..2e4131748438 100644
--- a/drivers/media/video/mxb.c
+++ b/drivers/media/video/mxb.c
@@ -29,6 +29,7 @@
29#include <media/tuner.h> 29#include <media/tuner.h>
30#include <media/v4l2-common.h> 30#include <media/v4l2-common.h>
31#include <media/saa7115.h> 31#include <media/saa7115.h>
32#include <linux/module.h>
32 33
33#include "mxb.h" 34#include "mxb.h"
34#include "tea6415c.h" 35#include "tea6415c.h"
diff --git a/drivers/media/video/noon010pc30.c b/drivers/media/video/noon010pc30.c
index 6cd21cf91b44..50838bf84204 100644
--- a/drivers/media/video/noon010pc30.c
+++ b/drivers/media/video/noon010pc30.c
@@ -21,6 +21,7 @@
21#include <media/noon010pc30.h> 21#include <media/noon010pc30.h>
22#include <media/v4l2-chip-ident.h> 22#include <media/v4l2-chip-ident.h>
23#include <linux/videodev2.h> 23#include <linux/videodev2.h>
24#include <linux/module.h>
24#include <media/v4l2-ctrls.h> 25#include <media/v4l2-ctrls.h>
25#include <media/v4l2-device.h> 26#include <media/v4l2-device.h>
26#include <media/v4l2-mediabus.h> 27#include <media/v4l2-mediabus.h>
diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
index 30d8896bb710..9c5c19f142de 100644
--- a/drivers/media/video/omap/omap_vout.c
+++ b/drivers/media/video/omap/omap_vout.c
@@ -833,6 +833,15 @@ static void omap_vout_buffer_release(struct videobuf_queue *q,
833/* 833/*
834 * File operations 834 * File operations
835 */ 835 */
836static unsigned int omap_vout_poll(struct file *file,
837 struct poll_table_struct *wait)
838{
839 struct omap_vout_device *vout = file->private_data;
840 struct videobuf_queue *q = &vout->vbq;
841
842 return videobuf_poll_stream(file, q, wait);
843}
844
836static void omap_vout_vm_open(struct vm_area_struct *vma) 845static void omap_vout_vm_open(struct vm_area_struct *vma)
837{ 846{
838 struct omap_vout_device *vout = vma->vm_private_data; 847 struct omap_vout_device *vout = vma->vm_private_data;
@@ -1861,6 +1870,7 @@ static const struct v4l2_ioctl_ops vout_ioctl_ops = {
1861 1870
1862static const struct v4l2_file_operations omap_vout_fops = { 1871static const struct v4l2_file_operations omap_vout_fops = {
1863 .owner = THIS_MODULE, 1872 .owner = THIS_MODULE,
1873 .poll = omap_vout_poll,
1864 .unlocked_ioctl = video_ioctl2, 1874 .unlocked_ioctl = video_ioctl2,
1865 .mmap = omap_vout_mmap, 1875 .mmap = omap_vout_mmap,
1866 .open = omap_vout_open, 1876 .open = omap_vout_open,
diff --git a/drivers/media/video/omap1_camera.c b/drivers/media/video/omap1_camera.c
index 8a947e603aca..e87ae2f634b2 100644
--- a/drivers/media/video/omap1_camera.c
+++ b/drivers/media/video/omap1_camera.c
@@ -102,10 +102,10 @@
102/* end of OMAP1 Camera Interface registers */ 102/* end of OMAP1 Camera Interface registers */
103 103
104 104
105#define SOCAM_BUS_FLAGS (SOCAM_MASTER | \ 105#define SOCAM_BUS_FLAGS (V4L2_MBUS_MASTER | \
106 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH | \ 106 V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_HIGH | \
107 SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING | \ 107 V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING | \
108 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8) 108 V4L2_MBUS_DATA_ACTIVE_HIGH)
109 109
110 110
111#define FIFO_SIZE ((THRESHOLD_MASK >> THRESHOLD_SHIFT) + 1) 111#define FIFO_SIZE ((THRESHOLD_MASK >> THRESHOLD_SHIFT) + 1)
@@ -1438,41 +1438,55 @@ static int omap1_cam_querycap(struct soc_camera_host *ici,
1438static int omap1_cam_set_bus_param(struct soc_camera_device *icd, 1438static int omap1_cam_set_bus_param(struct soc_camera_device *icd,
1439 __u32 pixfmt) 1439 __u32 pixfmt)
1440{ 1440{
1441 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
1441 struct device *dev = icd->parent; 1442 struct device *dev = icd->parent;
1442 struct soc_camera_host *ici = to_soc_camera_host(dev); 1443 struct soc_camera_host *ici = to_soc_camera_host(dev);
1443 struct omap1_cam_dev *pcdev = ici->priv; 1444 struct omap1_cam_dev *pcdev = ici->priv;
1444 const struct soc_camera_format_xlate *xlate; 1445 const struct soc_camera_format_xlate *xlate;
1445 const struct soc_mbus_pixelfmt *fmt; 1446 const struct soc_mbus_pixelfmt *fmt;
1446 unsigned long camera_flags, common_flags; 1447 struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,};
1448 unsigned long common_flags;
1447 u32 ctrlclock, mode; 1449 u32 ctrlclock, mode;
1448 int ret; 1450 int ret;
1449 1451
1450 camera_flags = icd->ops->query_bus_param(icd); 1452 ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg);
1451 1453 if (!ret) {
1452 common_flags = soc_camera_bus_param_compatible(camera_flags, 1454 common_flags = soc_mbus_config_compatible(&cfg, SOCAM_BUS_FLAGS);
1453 SOCAM_BUS_FLAGS); 1455 if (!common_flags) {
1454 if (!common_flags) 1456 dev_warn(dev,
1455 return -EINVAL; 1457 "Flags incompatible: camera 0x%x, host 0x%x\n",
1458 cfg.flags, SOCAM_BUS_FLAGS);
1459 return -EINVAL;
1460 }
1461 } else if (ret != -ENOIOCTLCMD) {
1462 return ret;
1463 } else {
1464 common_flags = SOCAM_BUS_FLAGS;
1465 }
1456 1466
1457 /* Make choices, possibly based on platform configuration */ 1467 /* Make choices, possibly based on platform configuration */
1458 if ((common_flags & SOCAM_PCLK_SAMPLE_RISING) && 1468 if ((common_flags & V4L2_MBUS_PCLK_SAMPLE_RISING) &&
1459 (common_flags & SOCAM_PCLK_SAMPLE_FALLING)) { 1469 (common_flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)) {
1460 if (!pcdev->pdata || 1470 if (!pcdev->pdata ||
1461 pcdev->pdata->flags & OMAP1_CAMERA_LCLK_RISING) 1471 pcdev->pdata->flags & OMAP1_CAMERA_LCLK_RISING)
1462 common_flags &= ~SOCAM_PCLK_SAMPLE_FALLING; 1472 common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_FALLING;
1463 else 1473 else
1464 common_flags &= ~SOCAM_PCLK_SAMPLE_RISING; 1474 common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_RISING;
1465 } 1475 }
1466 1476
1467 ret = icd->ops->set_bus_param(icd, common_flags); 1477 cfg.flags = common_flags;
1468 if (ret < 0) 1478 ret = v4l2_subdev_call(sd, video, s_mbus_config, &cfg);
1479 if (ret < 0 && ret != -ENOIOCTLCMD) {
1480 dev_dbg(dev, "camera s_mbus_config(0x%lx) returned %d\n",
1481 common_flags, ret);
1469 return ret; 1482 return ret;
1483 }
1470 1484
1471 ctrlclock = CAM_READ_CACHE(pcdev, CTRLCLOCK); 1485 ctrlclock = CAM_READ_CACHE(pcdev, CTRLCLOCK);
1472 if (ctrlclock & LCLK_EN) 1486 if (ctrlclock & LCLK_EN)
1473 CAM_WRITE(pcdev, CTRLCLOCK, ctrlclock & ~LCLK_EN); 1487 CAM_WRITE(pcdev, CTRLCLOCK, ctrlclock & ~LCLK_EN);
1474 1488
1475 if (common_flags & SOCAM_PCLK_SAMPLE_RISING) { 1489 if (common_flags & V4L2_MBUS_PCLK_SAMPLE_RISING) {
1476 dev_dbg(dev, "CTRLCLOCK_REG |= POLCLK\n"); 1490 dev_dbg(dev, "CTRLCLOCK_REG |= POLCLK\n");
1477 ctrlclock |= POLCLK; 1491 ctrlclock |= POLCLK;
1478 } else { 1492 } else {
@@ -1565,10 +1579,10 @@ static int __init omap1_cam_probe(struct platform_device *pdev)
1565 pcdev->clk = clk; 1579 pcdev->clk = clk;
1566 1580
1567 pcdev->pdata = pdev->dev.platform_data; 1581 pcdev->pdata = pdev->dev.platform_data;
1568 pcdev->pflags = pcdev->pdata->flags; 1582 if (pcdev->pdata) {
1569 1583 pcdev->pflags = pcdev->pdata->flags;
1570 if (pcdev->pdata)
1571 pcdev->camexclk = pcdev->pdata->camexclk_khz * 1000; 1584 pcdev->camexclk = pcdev->pdata->camexclk_khz * 1000;
1585 }
1572 1586
1573 switch (pcdev->camexclk) { 1587 switch (pcdev->camexclk) {
1574 case 6000000: 1588 case 6000000:
@@ -1578,6 +1592,7 @@ static int __init omap1_cam_probe(struct platform_device *pdev)
1578 case 24000000: 1592 case 24000000:
1579 break; 1593 break;
1580 default: 1594 default:
1595 /* pcdev->camexclk != 0 => pcdev->pdata != NULL */
1581 dev_warn(&pdev->dev, 1596 dev_warn(&pdev->dev,
1582 "Incorrect sensor clock frequency %ld kHz, " 1597 "Incorrect sensor clock frequency %ld kHz, "
1583 "should be one of 0, 6, 8, 9.6, 12 or 24 MHz, " 1598 "should be one of 0, 6, 8, 9.6, 12 or 24 MHz, "
@@ -1585,8 +1600,7 @@ static int __init omap1_cam_probe(struct platform_device *pdev)
1585 pcdev->pdata->camexclk_khz); 1600 pcdev->pdata->camexclk_khz);
1586 pcdev->camexclk = 0; 1601 pcdev->camexclk = 0;
1587 case 0: 1602 case 0:
1588 dev_info(&pdev->dev, 1603 dev_info(&pdev->dev, "Not providing sensor clock\n");
1589 "Not providing sensor clock\n");
1590 } 1604 }
1591 1605
1592 INIT_LIST_HEAD(&pcdev->capture); 1606 INIT_LIST_HEAD(&pcdev->capture);
@@ -1716,5 +1730,5 @@ MODULE_PARM_DESC(sg_mode, "videobuf mode, 0: dma-contig (default), 1: dma-sg");
1716MODULE_DESCRIPTION("OMAP1 Camera Interface driver"); 1730MODULE_DESCRIPTION("OMAP1 Camera Interface driver");
1717MODULE_AUTHOR("Janusz Krzysztofik <jkrzyszt@tis.icnet.pl>"); 1731MODULE_AUTHOR("Janusz Krzysztofik <jkrzyszt@tis.icnet.pl>");
1718MODULE_LICENSE("GPL v2"); 1732MODULE_LICENSE("GPL v2");
1719MODULE_LICENSE(DRIVER_VERSION); 1733MODULE_VERSION(DRIVER_VERSION);
1720MODULE_ALIAS("platform:" DRIVER_NAME); 1734MODULE_ALIAS("platform:" DRIVER_NAME);
diff --git a/drivers/media/video/omap24xxcam.c b/drivers/media/video/omap24xxcam.c
index eb97bff7116f..45522e603185 100644
--- a/drivers/media/video/omap24xxcam.c
+++ b/drivers/media/video/omap24xxcam.c
@@ -36,6 +36,7 @@
36#include <linux/io.h> 36#include <linux/io.h>
37#include <linux/slab.h> 37#include <linux/slab.h>
38#include <linux/sched.h> 38#include <linux/sched.h>
39#include <linux/module.h>
39 40
40#include <media/v4l2-common.h> 41#include <media/v4l2-common.h>
41#include <media/v4l2-ioctl.h> 42#include <media/v4l2-ioctl.h>
diff --git a/drivers/media/video/omap3isp/isp.c b/drivers/media/video/omap3isp/isp.c
index 678e1252047a..b818cacf420f 100644
--- a/drivers/media/video/omap3isp/isp.c
+++ b/drivers/media/video/omap3isp/isp.c
@@ -1704,6 +1704,7 @@ static int isp_register_entities(struct isp_device *isp)
1704 isp->media_dev.dev = isp->dev; 1704 isp->media_dev.dev = isp->dev;
1705 strlcpy(isp->media_dev.model, "TI OMAP3 ISP", 1705 strlcpy(isp->media_dev.model, "TI OMAP3 ISP",
1706 sizeof(isp->media_dev.model)); 1706 sizeof(isp->media_dev.model));
1707 isp->media_dev.hw_revision = isp->revision;
1707 isp->media_dev.link_notify = isp_pipeline_link_notify; 1708 isp->media_dev.link_notify = isp_pipeline_link_notify;
1708 ret = media_device_register(&isp->media_dev); 1709 ret = media_device_register(&isp->media_dev);
1709 if (ret < 0) { 1710 if (ret < 0) {
@@ -2210,6 +2211,8 @@ error:
2210 regulator_put(isp->isp_csiphy2.vdd); 2211 regulator_put(isp->isp_csiphy2.vdd);
2211 regulator_put(isp->isp_csiphy1.vdd); 2212 regulator_put(isp->isp_csiphy1.vdd);
2212 platform_set_drvdata(pdev, NULL); 2213 platform_set_drvdata(pdev, NULL);
2214
2215 mutex_destroy(&isp->isp_mutex);
2213 kfree(isp); 2216 kfree(isp);
2214 2217
2215 return ret; 2218 return ret;
diff --git a/drivers/media/video/omap3isp/ispccdc.c b/drivers/media/video/omap3isp/ispccdc.c
index 253fdcce2df2..b0b0fa5a3572 100644
--- a/drivers/media/video/omap3isp/ispccdc.c
+++ b/drivers/media/video/omap3isp/ispccdc.c
@@ -1836,7 +1836,7 @@ ccdc_try_format(struct isp_ccdc_device *ccdc, struct v4l2_subdev_fh *fh,
1836 * callers to request an output size bigger than the input size 1836 * callers to request an output size bigger than the input size
1837 * up to the nearest multiple of 16. 1837 * up to the nearest multiple of 16.
1838 */ 1838 */
1839 fmt->width = clamp_t(u32, width, 32, (fmt->width + 15) & ~15); 1839 fmt->width = clamp_t(u32, width, 32, fmt->width + 15);
1840 fmt->width &= ~15; 1840 fmt->width &= ~15;
1841 fmt->height = clamp_t(u32, height, 32, fmt->height); 1841 fmt->height = clamp_t(u32, height, 32, fmt->height);
1842 break; 1842 break;
@@ -2152,6 +2152,37 @@ static const struct media_entity_operations ccdc_media_ops = {
2152 .link_setup = ccdc_link_setup, 2152 .link_setup = ccdc_link_setup,
2153}; 2153};
2154 2154
2155void omap3isp_ccdc_unregister_entities(struct isp_ccdc_device *ccdc)
2156{
2157 v4l2_device_unregister_subdev(&ccdc->subdev);
2158 omap3isp_video_unregister(&ccdc->video_out);
2159}
2160
2161int omap3isp_ccdc_register_entities(struct isp_ccdc_device *ccdc,
2162 struct v4l2_device *vdev)
2163{
2164 int ret;
2165
2166 /* Register the subdev and video node. */
2167 ret = v4l2_device_register_subdev(vdev, &ccdc->subdev);
2168 if (ret < 0)
2169 goto error;
2170
2171 ret = omap3isp_video_register(&ccdc->video_out, vdev);
2172 if (ret < 0)
2173 goto error;
2174
2175 return 0;
2176
2177error:
2178 omap3isp_ccdc_unregister_entities(ccdc);
2179 return ret;
2180}
2181
2182/* -----------------------------------------------------------------------------
2183 * ISP CCDC initialisation and cleanup
2184 */
2185
2155/* 2186/*
2156 * ccdc_init_entities - Initialize V4L2 subdev and media entity 2187 * ccdc_init_entities - Initialize V4L2 subdev and media entity
2157 * @ccdc: ISP CCDC module 2188 * @ccdc: ISP CCDC module
@@ -2193,50 +2224,23 @@ static int ccdc_init_entities(struct isp_ccdc_device *ccdc)
2193 2224
2194 ret = omap3isp_video_init(&ccdc->video_out, "CCDC"); 2225 ret = omap3isp_video_init(&ccdc->video_out, "CCDC");
2195 if (ret < 0) 2226 if (ret < 0)
2196 return ret; 2227 goto error_video;
2197 2228
2198 /* Connect the CCDC subdev to the video node. */ 2229 /* Connect the CCDC subdev to the video node. */
2199 ret = media_entity_create_link(&ccdc->subdev.entity, CCDC_PAD_SOURCE_OF, 2230 ret = media_entity_create_link(&ccdc->subdev.entity, CCDC_PAD_SOURCE_OF,
2200 &ccdc->video_out.video.entity, 0, 0); 2231 &ccdc->video_out.video.entity, 0, 0);
2201 if (ret < 0) 2232 if (ret < 0)
2202 return ret; 2233 goto error_link;
2203
2204 return 0;
2205}
2206
2207void omap3isp_ccdc_unregister_entities(struct isp_ccdc_device *ccdc)
2208{
2209 media_entity_cleanup(&ccdc->subdev.entity);
2210
2211 v4l2_device_unregister_subdev(&ccdc->subdev);
2212 omap3isp_video_unregister(&ccdc->video_out);
2213}
2214
2215int omap3isp_ccdc_register_entities(struct isp_ccdc_device *ccdc,
2216 struct v4l2_device *vdev)
2217{
2218 int ret;
2219
2220 /* Register the subdev and video node. */
2221 ret = v4l2_device_register_subdev(vdev, &ccdc->subdev);
2222 if (ret < 0)
2223 goto error;
2224
2225 ret = omap3isp_video_register(&ccdc->video_out, vdev);
2226 if (ret < 0)
2227 goto error;
2228 2234
2229 return 0; 2235 return 0;
2230 2236
2231error: 2237error_link:
2232 omap3isp_ccdc_unregister_entities(ccdc); 2238 omap3isp_video_cleanup(&ccdc->video_out);
2239error_video:
2240 media_entity_cleanup(me);
2233 return ret; 2241 return ret;
2234} 2242}
2235 2243
2236/* -----------------------------------------------------------------------------
2237 * ISP CCDC initialisation and cleanup
2238 */
2239
2240/* 2244/*
2241 * omap3isp_ccdc_init - CCDC module initialization. 2245 * omap3isp_ccdc_init - CCDC module initialization.
2242 * @dev: Device pointer specific to the OMAP3 ISP. 2246 * @dev: Device pointer specific to the OMAP3 ISP.
@@ -2248,6 +2252,7 @@ error:
2248int omap3isp_ccdc_init(struct isp_device *isp) 2252int omap3isp_ccdc_init(struct isp_device *isp)
2249{ 2253{
2250 struct isp_ccdc_device *ccdc = &isp->isp_ccdc; 2254 struct isp_ccdc_device *ccdc = &isp->isp_ccdc;
2255 int ret;
2251 2256
2252 spin_lock_init(&ccdc->lock); 2257 spin_lock_init(&ccdc->lock);
2253 init_waitqueue_head(&ccdc->wait); 2258 init_waitqueue_head(&ccdc->wait);
@@ -2276,7 +2281,13 @@ int omap3isp_ccdc_init(struct isp_device *isp)
2276 ccdc->update = OMAP3ISP_CCDC_BLCLAMP; 2281 ccdc->update = OMAP3ISP_CCDC_BLCLAMP;
2277 ccdc_apply_controls(ccdc); 2282 ccdc_apply_controls(ccdc);
2278 2283
2279 return ccdc_init_entities(ccdc); 2284 ret = ccdc_init_entities(ccdc);
2285 if (ret < 0) {
2286 mutex_destroy(&ccdc->ioctl_lock);
2287 return ret;
2288 }
2289
2290 return 0;
2280} 2291}
2281 2292
2282/* 2293/*
@@ -2287,6 +2298,9 @@ void omap3isp_ccdc_cleanup(struct isp_device *isp)
2287{ 2298{
2288 struct isp_ccdc_device *ccdc = &isp->isp_ccdc; 2299 struct isp_ccdc_device *ccdc = &isp->isp_ccdc;
2289 2300
2301 omap3isp_video_cleanup(&ccdc->video_out);
2302 media_entity_cleanup(&ccdc->subdev.entity);
2303
2290 /* Free LSC requests. As the CCDC is stopped there's no active request, 2304 /* Free LSC requests. As the CCDC is stopped there's no active request,
2291 * so only the pending request and the free queue need to be handled. 2305 * so only the pending request and the free queue need to be handled.
2292 */ 2306 */
@@ -2296,4 +2310,6 @@ void omap3isp_ccdc_cleanup(struct isp_device *isp)
2296 2310
2297 if (ccdc->fpc.fpcaddr != 0) 2311 if (ccdc->fpc.fpcaddr != 0)
2298 omap_iommu_vfree(isp->domain, isp->iommu, ccdc->fpc.fpcaddr); 2312 omap_iommu_vfree(isp->domain, isp->iommu, ccdc->fpc.fpcaddr);
2313
2314 mutex_destroy(&ccdc->ioctl_lock);
2299} 2315}
diff --git a/drivers/media/video/omap3isp/ispccp2.c b/drivers/media/video/omap3isp/ispccp2.c
index fa1d09b0ad98..904ca8c8b17f 100644
--- a/drivers/media/video/omap3isp/ispccp2.c
+++ b/drivers/media/video/omap3isp/ispccp2.c
@@ -1032,6 +1032,48 @@ static const struct media_entity_operations ccp2_media_ops = {
1032}; 1032};
1033 1033
1034/* 1034/*
1035 * omap3isp_ccp2_unregister_entities - Unregister media entities: subdev
1036 * @ccp2: Pointer to ISP CCP2 device
1037 */
1038void omap3isp_ccp2_unregister_entities(struct isp_ccp2_device *ccp2)
1039{
1040 v4l2_device_unregister_subdev(&ccp2->subdev);
1041 omap3isp_video_unregister(&ccp2->video_in);
1042}
1043
1044/*
1045 * omap3isp_ccp2_register_entities - Register the subdev media entity
1046 * @ccp2: Pointer to ISP CCP2 device
1047 * @vdev: Pointer to v4l device
1048 * return negative error code or zero on success
1049 */
1050
1051int omap3isp_ccp2_register_entities(struct isp_ccp2_device *ccp2,
1052 struct v4l2_device *vdev)
1053{
1054 int ret;
1055
1056 /* Register the subdev and video nodes. */
1057 ret = v4l2_device_register_subdev(vdev, &ccp2->subdev);
1058 if (ret < 0)
1059 goto error;
1060
1061 ret = omap3isp_video_register(&ccp2->video_in, vdev);
1062 if (ret < 0)
1063 goto error;
1064
1065 return 0;
1066
1067error:
1068 omap3isp_ccp2_unregister_entities(ccp2);
1069 return ret;
1070}
1071
1072/* -----------------------------------------------------------------------------
1073 * ISP ccp2 initialisation and cleanup
1074 */
1075
1076/*
1035 * ccp2_init_entities - Initialize ccp2 subdev and media entity. 1077 * ccp2_init_entities - Initialize ccp2 subdev and media entity.
1036 * @ccp2: Pointer to ISP CCP2 device 1078 * @ccp2: Pointer to ISP CCP2 device
1037 * return negative error code or zero on success 1079 * return negative error code or zero on success
@@ -1083,72 +1125,23 @@ static int ccp2_init_entities(struct isp_ccp2_device *ccp2)
1083 1125
1084 ret = omap3isp_video_init(&ccp2->video_in, "CCP2"); 1126 ret = omap3isp_video_init(&ccp2->video_in, "CCP2");
1085 if (ret < 0) 1127 if (ret < 0)
1086 return ret; 1128 goto error_video;
1087 1129
1088 /* Connect the video node to the ccp2 subdev. */ 1130 /* Connect the video node to the ccp2 subdev. */
1089 ret = media_entity_create_link(&ccp2->video_in.video.entity, 0, 1131 ret = media_entity_create_link(&ccp2->video_in.video.entity, 0,
1090 &ccp2->subdev.entity, CCP2_PAD_SINK, 0); 1132 &ccp2->subdev.entity, CCP2_PAD_SINK, 0);
1091 if (ret < 0) 1133 if (ret < 0)
1092 return ret; 1134 goto error_link;
1093 1135
1094 return 0; 1136 return 0;
1095}
1096 1137
1097/* 1138error_link:
1098 * omap3isp_ccp2_unregister_entities - Unregister media entities: subdev 1139 omap3isp_video_cleanup(&ccp2->video_in);
1099 * @ccp2: Pointer to ISP CCP2 device 1140error_video:
1100 */
1101void omap3isp_ccp2_unregister_entities(struct isp_ccp2_device *ccp2)
1102{
1103 media_entity_cleanup(&ccp2->subdev.entity); 1141 media_entity_cleanup(&ccp2->subdev.entity);
1104
1105 v4l2_device_unregister_subdev(&ccp2->subdev);
1106 omap3isp_video_unregister(&ccp2->video_in);
1107}
1108
1109/*
1110 * omap3isp_ccp2_register_entities - Register the subdev media entity
1111 * @ccp2: Pointer to ISP CCP2 device
1112 * @vdev: Pointer to v4l device
1113 * return negative error code or zero on success
1114 */
1115
1116int omap3isp_ccp2_register_entities(struct isp_ccp2_device *ccp2,
1117 struct v4l2_device *vdev)
1118{
1119 int ret;
1120
1121 /* Register the subdev and video nodes. */
1122 ret = v4l2_device_register_subdev(vdev, &ccp2->subdev);
1123 if (ret < 0)
1124 goto error;
1125
1126 ret = omap3isp_video_register(&ccp2->video_in, vdev);
1127 if (ret < 0)
1128 goto error;
1129
1130 return 0;
1131
1132error:
1133 omap3isp_ccp2_unregister_entities(ccp2);
1134 return ret; 1142 return ret;
1135} 1143}
1136 1144
1137/* -----------------------------------------------------------------------------
1138 * ISP ccp2 initialisation and cleanup
1139 */
1140
1141/*
1142 * omap3isp_ccp2_cleanup - CCP2 un-initialization
1143 * @isp : Pointer to ISP device
1144 */
1145void omap3isp_ccp2_cleanup(struct isp_device *isp)
1146{
1147 struct isp_ccp2_device *ccp2 = &isp->isp_ccp2;
1148
1149 regulator_put(ccp2->vdds_csib);
1150}
1151
1152/* 1145/*
1153 * omap3isp_ccp2_init - CCP2 initialization. 1146 * omap3isp_ccp2_init - CCP2 initialization.
1154 * @isp : Pointer to ISP device 1147 * @isp : Pointer to ISP device
@@ -1184,13 +1177,25 @@ int omap3isp_ccp2_init(struct isp_device *isp)
1184 } 1177 }
1185 1178
1186 ret = ccp2_init_entities(ccp2); 1179 ret = ccp2_init_entities(ccp2);
1187 if (ret < 0) 1180 if (ret < 0) {
1188 goto out; 1181 regulator_put(ccp2->vdds_csib);
1182 return ret;
1183 }
1189 1184
1190 ccp2_reset(ccp2); 1185 ccp2_reset(ccp2);
1191out: 1186 return 0;
1192 if (ret) 1187}
1193 omap3isp_ccp2_cleanup(isp);
1194 1188
1195 return ret; 1189/*
1190 * omap3isp_ccp2_cleanup - CCP2 un-initialization
1191 * @isp : Pointer to ISP device
1192 */
1193void omap3isp_ccp2_cleanup(struct isp_device *isp)
1194{
1195 struct isp_ccp2_device *ccp2 = &isp->isp_ccp2;
1196
1197 omap3isp_video_cleanup(&ccp2->video_in);
1198 media_entity_cleanup(&ccp2->subdev.entity);
1199
1200 regulator_put(ccp2->vdds_csib);
1196} 1201}
diff --git a/drivers/media/video/omap3isp/ispcsi2.c b/drivers/media/video/omap3isp/ispcsi2.c
index 69161a682b3d..0c5f1cb9d99d 100644
--- a/drivers/media/video/omap3isp/ispcsi2.c
+++ b/drivers/media/video/omap3isp/ispcsi2.c
@@ -1187,6 +1187,37 @@ static const struct media_entity_operations csi2_media_ops = {
1187 .link_setup = csi2_link_setup, 1187 .link_setup = csi2_link_setup,
1188}; 1188};
1189 1189
1190void omap3isp_csi2_unregister_entities(struct isp_csi2_device *csi2)
1191{
1192 v4l2_device_unregister_subdev(&csi2->subdev);
1193 omap3isp_video_unregister(&csi2->video_out);
1194}
1195
1196int omap3isp_csi2_register_entities(struct isp_csi2_device *csi2,
1197 struct v4l2_device *vdev)
1198{
1199 int ret;
1200
1201 /* Register the subdev and video nodes. */
1202 ret = v4l2_device_register_subdev(vdev, &csi2->subdev);
1203 if (ret < 0)
1204 goto error;
1205
1206 ret = omap3isp_video_register(&csi2->video_out, vdev);
1207 if (ret < 0)
1208 goto error;
1209
1210 return 0;
1211
1212error:
1213 omap3isp_csi2_unregister_entities(csi2);
1214 return ret;
1215}
1216
1217/* -----------------------------------------------------------------------------
1218 * ISP CSI2 initialisation and cleanup
1219 */
1220
1190/* 1221/*
1191 * csi2_init_entities - Initialize subdev and media entity. 1222 * csi2_init_entities - Initialize subdev and media entity.
1192 * @csi2: Pointer to csi2 structure. 1223 * @csi2: Pointer to csi2 structure.
@@ -1228,57 +1259,23 @@ static int csi2_init_entities(struct isp_csi2_device *csi2)
1228 1259
1229 ret = omap3isp_video_init(&csi2->video_out, "CSI2a"); 1260 ret = omap3isp_video_init(&csi2->video_out, "CSI2a");
1230 if (ret < 0) 1261 if (ret < 0)
1231 return ret; 1262 goto error_video;
1232 1263
1233 /* Connect the CSI2 subdev to the video node. */ 1264 /* Connect the CSI2 subdev to the video node. */
1234 ret = media_entity_create_link(&csi2->subdev.entity, CSI2_PAD_SOURCE, 1265 ret = media_entity_create_link(&csi2->subdev.entity, CSI2_PAD_SOURCE,
1235 &csi2->video_out.video.entity, 0, 0); 1266 &csi2->video_out.video.entity, 0, 0);
1236 if (ret < 0) 1267 if (ret < 0)
1237 return ret; 1268 goto error_link;
1238 1269
1239 return 0; 1270 return 0;
1240}
1241 1271
1242void omap3isp_csi2_unregister_entities(struct isp_csi2_device *csi2) 1272error_link:
1243{ 1273 omap3isp_video_cleanup(&csi2->video_out);
1274error_video:
1244 media_entity_cleanup(&csi2->subdev.entity); 1275 media_entity_cleanup(&csi2->subdev.entity);
1245
1246 v4l2_device_unregister_subdev(&csi2->subdev);
1247 omap3isp_video_unregister(&csi2->video_out);
1248}
1249
1250int omap3isp_csi2_register_entities(struct isp_csi2_device *csi2,
1251 struct v4l2_device *vdev)
1252{
1253 int ret;
1254
1255 /* Register the subdev and video nodes. */
1256 ret = v4l2_device_register_subdev(vdev, &csi2->subdev);
1257 if (ret < 0)
1258 goto error;
1259
1260 ret = omap3isp_video_register(&csi2->video_out, vdev);
1261 if (ret < 0)
1262 goto error;
1263
1264 return 0;
1265
1266error:
1267 omap3isp_csi2_unregister_entities(csi2);
1268 return ret; 1276 return ret;
1269} 1277}
1270 1278
1271/* -----------------------------------------------------------------------------
1272 * ISP CSI2 initialisation and cleanup
1273 */
1274
1275/*
1276 * omap3isp_csi2_cleanup - Routine for module driver cleanup
1277 */
1278void omap3isp_csi2_cleanup(struct isp_device *isp)
1279{
1280}
1281
1282/* 1279/*
1283 * omap3isp_csi2_init - Routine for module driver init 1280 * omap3isp_csi2_init - Routine for module driver init
1284 */ 1281 */
@@ -1298,7 +1295,7 @@ int omap3isp_csi2_init(struct isp_device *isp)
1298 1295
1299 ret = csi2_init_entities(csi2a); 1296 ret = csi2_init_entities(csi2a);
1300 if (ret < 0) 1297 if (ret < 0)
1301 goto fail; 1298 return ret;
1302 1299
1303 if (isp->revision == ISP_REVISION_15_0) { 1300 if (isp->revision == ISP_REVISION_15_0) {
1304 csi2c->isp = isp; 1301 csi2c->isp = isp;
@@ -1311,7 +1308,15 @@ int omap3isp_csi2_init(struct isp_device *isp)
1311 } 1308 }
1312 1309
1313 return 0; 1310 return 0;
1314fail: 1311}
1315 omap3isp_csi2_cleanup(isp); 1312
1316 return ret; 1313/*
1314 * omap3isp_csi2_cleanup - Routine for module driver cleanup
1315 */
1316void omap3isp_csi2_cleanup(struct isp_device *isp)
1317{
1318 struct isp_csi2_device *csi2a = &isp->isp_csi2a;
1319
1320 omap3isp_video_cleanup(&csi2a->video_out);
1321 media_entity_cleanup(&csi2a->subdev.entity);
1317} 1322}
diff --git a/drivers/media/video/omap3isp/isph3a_aewb.c b/drivers/media/video/omap3isp/isph3a_aewb.c
index 8068cefd8d89..a3c76bf18175 100644
--- a/drivers/media/video/omap3isp/isph3a_aewb.c
+++ b/drivers/media/video/omap3isp/isph3a_aewb.c
@@ -370,5 +370,5 @@ void omap3isp_h3a_aewb_cleanup(struct isp_device *isp)
370{ 370{
371 kfree(isp->isp_aewb.priv); 371 kfree(isp->isp_aewb.priv);
372 kfree(isp->isp_aewb.recover_priv); 372 kfree(isp->isp_aewb.recover_priv);
373 omap3isp_stat_free(&isp->isp_aewb); 373 omap3isp_stat_cleanup(&isp->isp_aewb);
374} 374}
diff --git a/drivers/media/video/omap3isp/isph3a_af.c b/drivers/media/video/omap3isp/isph3a_af.c
index ba54d0acdecf..58e0bc414899 100644
--- a/drivers/media/video/omap3isp/isph3a_af.c
+++ b/drivers/media/video/omap3isp/isph3a_af.c
@@ -425,5 +425,5 @@ void omap3isp_h3a_af_cleanup(struct isp_device *isp)
425{ 425{
426 kfree(isp->isp_af.priv); 426 kfree(isp->isp_af.priv);
427 kfree(isp->isp_af.recover_priv); 427 kfree(isp->isp_af.recover_priv);
428 omap3isp_stat_free(&isp->isp_af); 428 omap3isp_stat_cleanup(&isp->isp_af);
429} 429}
diff --git a/drivers/media/video/omap3isp/isphist.c b/drivers/media/video/omap3isp/isphist.c
index 1743856b30d1..1163907bcddc 100644
--- a/drivers/media/video/omap3isp/isphist.c
+++ b/drivers/media/video/omap3isp/isphist.c
@@ -516,5 +516,5 @@ void omap3isp_hist_cleanup(struct isp_device *isp)
516 if (HIST_USING_DMA(&isp->isp_hist)) 516 if (HIST_USING_DMA(&isp->isp_hist))
517 omap_free_dma(isp->isp_hist.dma_ch); 517 omap_free_dma(isp->isp_hist.dma_ch);
518 kfree(isp->isp_hist.priv); 518 kfree(isp->isp_hist.priv);
519 omap3isp_stat_free(&isp->isp_hist); 519 omap3isp_stat_cleanup(&isp->isp_hist);
520} 520}
diff --git a/drivers/media/video/omap3isp/isppreview.c b/drivers/media/video/omap3isp/isppreview.c
index aba537af87e4..ccb876fe023f 100644
--- a/drivers/media/video/omap3isp/isppreview.c
+++ b/drivers/media/video/omap3isp/isppreview.c
@@ -76,9 +76,51 @@ static struct omap3isp_prev_csc flr_prev_csc = {
76 76
77#define DEF_DETECT_CORRECT_VAL 0xe 77#define DEF_DETECT_CORRECT_VAL 0xe
78 78
79#define PREV_MIN_WIDTH 64 79/*
80#define PREV_MIN_HEIGHT 8 80 * Margins and image size limits.
81#define PREV_MAX_HEIGHT 16384 81 *
82 * The preview engine crops several rows and columns internally depending on
83 * which filters are enabled. To avoid format changes when the filters are
84 * enabled or disabled (which would prevent them from being turned on or off
85 * during streaming), the driver assumes all the filters are enabled when
86 * computing sink crop and source format limits.
87 *
88 * If a filter is disabled, additional cropping is automatically added at the
89 * preview engine input by the driver to avoid overflow at line and frame end.
90 * This is completely transparent for applications.
91 *
92 * Median filter 4 pixels
93 * Noise filter,
94 * Faulty pixels correction 4 pixels, 4 lines
95 * CFA filter 4 pixels, 4 lines in Bayer mode
96 * 2 lines in other modes
97 * Color suppression 2 pixels
98 * or luma enhancement
99 * -------------------------------------------------------------
100 * Maximum total 14 pixels, 8 lines
101 *
102 * The color suppression and luma enhancement filters are applied after bayer to
103 * YUV conversion. They thus can crop one pixel on the left and one pixel on the
104 * right side of the image without changing the color pattern. When both those
105 * filters are disabled, the driver must crop the two pixels on the same side of
106 * the image to avoid changing the bayer pattern. The left margin is thus set to
107 * 8 pixels and the right margin to 6 pixels.
108 */
109
110#define PREV_MARGIN_LEFT 8
111#define PREV_MARGIN_RIGHT 6
112#define PREV_MARGIN_TOP 4
113#define PREV_MARGIN_BOTTOM 4
114
115#define PREV_MIN_IN_WIDTH 64
116#define PREV_MIN_IN_HEIGHT 8
117#define PREV_MAX_IN_HEIGHT 16384
118
119#define PREV_MIN_OUT_WIDTH 0
120#define PREV_MIN_OUT_HEIGHT 0
121#define PREV_MAX_OUT_WIDTH 1280
122#define PREV_MAX_OUT_WIDTH_ES2 3300
123#define PREV_MAX_OUT_WIDTH_3630 4096
82 124
83/* 125/*
84 * Coeficient Tables for the submodules in Preview. 126 * Coeficient Tables for the submodules in Preview.
@@ -979,52 +1021,36 @@ static void preview_config_averager(struct isp_prev_device *prev, u8 average)
979 * enabled when reporting source pad formats to userspace. If this assumption is 1021 * enabled when reporting source pad formats to userspace. If this assumption is
980 * not true, rows and columns must be manually cropped at the preview engine 1022 * not true, rows and columns must be manually cropped at the preview engine
981 * input to avoid overflows at the end of lines and frames. 1023 * input to avoid overflows at the end of lines and frames.
1024 *
1025 * See the explanation at the PREV_MARGIN_* definitions for more details.
982 */ 1026 */
983static void preview_config_input_size(struct isp_prev_device *prev) 1027static void preview_config_input_size(struct isp_prev_device *prev)
984{ 1028{
985 struct isp_device *isp = to_isp_device(prev); 1029 struct isp_device *isp = to_isp_device(prev);
986 struct prev_params *params = &prev->params; 1030 struct prev_params *params = &prev->params;
987 struct v4l2_mbus_framefmt *format = &prev->formats[PREV_PAD_SINK]; 1031 unsigned int sph = prev->crop.left;
988 unsigned int sph = 0; 1032 unsigned int eph = prev->crop.left + prev->crop.width - 1;
989 unsigned int eph = format->width - 1; 1033 unsigned int slv = prev->crop.top;
990 unsigned int slv = 0; 1034 unsigned int elv = prev->crop.top + prev->crop.height - 1;
991 unsigned int elv = format->height - 1; 1035
992 1036 if (params->features & PREV_CFA) {
993 if (prev->input == PREVIEW_INPUT_CCDC) { 1037 sph -= 2;
994 sph += 2; 1038 eph += 2;
995 eph -= 2; 1039 slv -= 2;
1040 elv += 2;
996 } 1041 }
997 1042 if (params->features & (PREV_DEFECT_COR | PREV_NOISE_FILTER)) {
998 /* 1043 sph -= 2;
999 * Median filter 4 pixels 1044 eph += 2;
1000 * Noise filter 4 pixels, 4 lines 1045 slv -= 2;
1001 * or faulty pixels correction 1046 elv += 2;
1002 * CFA filter 4 pixels, 4 lines in Bayer mode
1003 * 2 lines in other modes
1004 * Color suppression 2 pixels
1005 * or luma enhancement
1006 * -------------------------------------------------------------
1007 * Maximum total 14 pixels, 8 lines
1008 */
1009
1010 if (!(params->features & PREV_CFA)) {
1011 sph += 2;
1012 eph -= 2;
1013 slv += 2;
1014 elv -= 2;
1015 } 1047 }
1016 if (!(params->features & (PREV_DEFECT_COR | PREV_NOISE_FILTER))) { 1048 if (params->features & PREV_HORZ_MEDIAN_FILTER) {
1017 sph += 2; 1049 sph -= 2;
1018 eph -= 2; 1050 eph += 2;
1019 slv += 2;
1020 elv -= 2;
1021 } 1051 }
1022 if (!(params->features & PREV_HORZ_MEDIAN_FILTER)) { 1052 if (params->features & (PREV_CHROMA_SUPPRESS | PREV_LUMA_ENHANCE))
1023 sph += 2; 1053 sph -= 2;
1024 eph -= 2;
1025 }
1026 if (!(params->features & (PREV_CHROMA_SUPPRESS | PREV_LUMA_ENHANCE)))
1027 sph += 2;
1028 1054
1029 isp_reg_writel(isp, (sph << ISPPRV_HORZ_INFO_SPH_SHIFT) | eph, 1055 isp_reg_writel(isp, (sph << ISPPRV_HORZ_INFO_SPH_SHIFT) | eph,
1030 OMAP3_ISP_IOMEM_PREV, ISPPRV_HORZ_INFO); 1056 OMAP3_ISP_IOMEM_PREV, ISPPRV_HORZ_INFO);
@@ -1228,7 +1254,6 @@ static void preview_init_params(struct isp_prev_device *prev)
1228 /* Init values */ 1254 /* Init values */
1229 params->contrast = ISPPRV_CONTRAST_DEF * ISPPRV_CONTRAST_UNITS; 1255 params->contrast = ISPPRV_CONTRAST_DEF * ISPPRV_CONTRAST_UNITS;
1230 params->brightness = ISPPRV_BRIGHT_DEF * ISPPRV_BRIGHT_UNITS; 1256 params->brightness = ISPPRV_BRIGHT_DEF * ISPPRV_BRIGHT_UNITS;
1231 params->average = NO_AVE;
1232 params->cfa.format = OMAP3ISP_CFAFMT_BAYER; 1257 params->cfa.format = OMAP3ISP_CFAFMT_BAYER;
1233 memcpy(params->cfa.table, cfa_coef_table, 1258 memcpy(params->cfa.table, cfa_coef_table,
1234 sizeof(params->cfa.table)); 1259 sizeof(params->cfa.table));
@@ -1281,14 +1306,14 @@ static unsigned int preview_max_out_width(struct isp_prev_device *prev)
1281 1306
1282 switch (isp->revision) { 1307 switch (isp->revision) {
1283 case ISP_REVISION_1_0: 1308 case ISP_REVISION_1_0:
1284 return ISPPRV_MAXOUTPUT_WIDTH; 1309 return PREV_MAX_OUT_WIDTH;
1285 1310
1286 case ISP_REVISION_2_0: 1311 case ISP_REVISION_2_0:
1287 default: 1312 default:
1288 return ISPPRV_MAXOUTPUT_WIDTH_ES2; 1313 return PREV_MAX_OUT_WIDTH_ES2;
1289 1314
1290 case ISP_REVISION_15_0: 1315 case ISP_REVISION_15_0:
1291 return ISPPRV_MAXOUTPUT_WIDTH_3630; 1316 return PREV_MAX_OUT_WIDTH_3630;
1292 } 1317 }
1293} 1318}
1294 1319
@@ -1296,8 +1321,6 @@ static void preview_configure(struct isp_prev_device *prev)
1296{ 1321{
1297 struct isp_device *isp = to_isp_device(prev); 1322 struct isp_device *isp = to_isp_device(prev);
1298 struct v4l2_mbus_framefmt *format; 1323 struct v4l2_mbus_framefmt *format;
1299 unsigned int max_out_width;
1300 unsigned int format_avg;
1301 1324
1302 preview_setup_hw(prev); 1325 preview_setup_hw(prev);
1303 1326
@@ -1335,10 +1358,7 @@ static void preview_configure(struct isp_prev_device *prev)
1335 preview_config_outlineoffset(prev, 1358 preview_config_outlineoffset(prev,
1336 ALIGN(format->width, 0x10) * 2); 1359 ALIGN(format->width, 0x10) * 2);
1337 1360
1338 max_out_width = preview_max_out_width(prev); 1361 preview_config_averager(prev, 0);
1339
1340 format_avg = fls(DIV_ROUND_UP(format->width, max_out_width) - 1);
1341 preview_config_averager(prev, format_avg);
1342 preview_config_ycpos(prev, format->code); 1362 preview_config_ycpos(prev, format->code);
1343} 1363}
1344 1364
@@ -1597,6 +1617,16 @@ __preview_get_format(struct isp_prev_device *prev, struct v4l2_subdev_fh *fh,
1597 return &prev->formats[pad]; 1617 return &prev->formats[pad];
1598} 1618}
1599 1619
1620static struct v4l2_rect *
1621__preview_get_crop(struct isp_prev_device *prev, struct v4l2_subdev_fh *fh,
1622 enum v4l2_subdev_format_whence which)
1623{
1624 if (which == V4L2_SUBDEV_FORMAT_TRY)
1625 return v4l2_subdev_get_try_crop(fh, PREV_PAD_SINK);
1626 else
1627 return &prev->crop;
1628}
1629
1600/* previewer format descriptions */ 1630/* previewer format descriptions */
1601static const unsigned int preview_input_fmts[] = { 1631static const unsigned int preview_input_fmts[] = {
1602 V4L2_MBUS_FMT_SGRBG10_1X10, 1632 V4L2_MBUS_FMT_SGRBG10_1X10,
@@ -1611,24 +1641,25 @@ static const unsigned int preview_output_fmts[] = {
1611}; 1641};
1612 1642
1613/* 1643/*
1614 * preview_try_format - Handle try format by pad subdev method 1644 * preview_try_format - Validate a format
1615 * @prev: ISP preview device 1645 * @prev: ISP preview engine
1616 * @fh : V4L2 subdev file handle 1646 * @fh: V4L2 subdev file handle
1617 * @pad: pad num 1647 * @pad: pad number
1618 * @fmt: pointer to v4l2 format structure 1648 * @fmt: format to be validated
1649 * @which: try/active format selector
1650 *
1651 * Validate and adjust the given format for the given pad based on the preview
1652 * engine limits and the format and crop rectangles on other pads.
1619 */ 1653 */
1620static void preview_try_format(struct isp_prev_device *prev, 1654static void preview_try_format(struct isp_prev_device *prev,
1621 struct v4l2_subdev_fh *fh, unsigned int pad, 1655 struct v4l2_subdev_fh *fh, unsigned int pad,
1622 struct v4l2_mbus_framefmt *fmt, 1656 struct v4l2_mbus_framefmt *fmt,
1623 enum v4l2_subdev_format_whence which) 1657 enum v4l2_subdev_format_whence which)
1624{ 1658{
1625 struct v4l2_mbus_framefmt *format;
1626 unsigned int max_out_width;
1627 enum v4l2_mbus_pixelcode pixelcode; 1659 enum v4l2_mbus_pixelcode pixelcode;
1660 struct v4l2_rect *crop;
1628 unsigned int i; 1661 unsigned int i;
1629 1662
1630 max_out_width = preview_max_out_width(prev);
1631
1632 switch (pad) { 1663 switch (pad) {
1633 case PREV_PAD_SINK: 1664 case PREV_PAD_SINK:
1634 /* When reading data from the CCDC, the input size has already 1665 /* When reading data from the CCDC, the input size has already
@@ -1641,10 +1672,11 @@ static void preview_try_format(struct isp_prev_device *prev,
1641 * filter array interpolation. 1672 * filter array interpolation.
1642 */ 1673 */
1643 if (prev->input == PREVIEW_INPUT_MEMORY) { 1674 if (prev->input == PREVIEW_INPUT_MEMORY) {
1644 fmt->width = clamp_t(u32, fmt->width, PREV_MIN_WIDTH, 1675 fmt->width = clamp_t(u32, fmt->width, PREV_MIN_IN_WIDTH,
1645 max_out_width * 8); 1676 preview_max_out_width(prev));
1646 fmt->height = clamp_t(u32, fmt->height, PREV_MIN_HEIGHT, 1677 fmt->height = clamp_t(u32, fmt->height,
1647 PREV_MAX_HEIGHT); 1678 PREV_MIN_IN_HEIGHT,
1679 PREV_MAX_IN_HEIGHT);
1648 } 1680 }
1649 1681
1650 fmt->colorspace = V4L2_COLORSPACE_SRGB; 1682 fmt->colorspace = V4L2_COLORSPACE_SRGB;
@@ -1661,15 +1693,8 @@ static void preview_try_format(struct isp_prev_device *prev,
1661 1693
1662 case PREV_PAD_SOURCE: 1694 case PREV_PAD_SOURCE:
1663 pixelcode = fmt->code; 1695 pixelcode = fmt->code;
1664 format = __preview_get_format(prev, fh, PREV_PAD_SINK, which); 1696 *fmt = *__preview_get_format(prev, fh, PREV_PAD_SINK, which);
1665 memcpy(fmt, format, sizeof(*fmt));
1666 1697
1667 /* The preview module output size is configurable through the
1668 * input interface (horizontal and vertical cropping) and the
1669 * averager (horizontal scaling by 1/1, 1/2, 1/4 or 1/8). In
1670 * spite of this, hardcode the output size to the biggest
1671 * possible value for simplicity reasons.
1672 */
1673 switch (pixelcode) { 1698 switch (pixelcode) {
1674 case V4L2_MBUS_FMT_YUYV8_1X16: 1699 case V4L2_MBUS_FMT_YUYV8_1X16:
1675 case V4L2_MBUS_FMT_UYVY8_1X16: 1700 case V4L2_MBUS_FMT_UYVY8_1X16:
@@ -1681,31 +1706,14 @@ static void preview_try_format(struct isp_prev_device *prev,
1681 break; 1706 break;
1682 } 1707 }
1683 1708
1684 /* The TRM states (12.1.4.7.1.2) that 2 pixels must be cropped 1709 /* The preview module output size is configurable through the
1685 * from the left and right sides when the input source is the 1710 * averager (horizontal scaling by 1/1, 1/2, 1/4 or 1/8). This
1686 * CCDC. This seems not to be needed in practice, investigation 1711 * is not supported yet, hardcode the output size to the crop
1687 * is required. 1712 * rectangle size.
1688 */
1689 if (prev->input == PREVIEW_INPUT_CCDC)
1690 fmt->width -= 4;
1691
1692 /* The preview module can output a maximum of 3312 pixels
1693 * horizontally due to fixed memory-line sizes. Compute the
1694 * horizontal averaging factor accordingly. Note that the limit
1695 * applies to the noise filter and CFA interpolation blocks, so
1696 * it doesn't take cropping by further blocks into account.
1697 *
1698 * ES 1.0 hardware revision is limited to 1280 pixels
1699 * horizontally.
1700 */
1701 fmt->width >>= fls(DIV_ROUND_UP(fmt->width, max_out_width) - 1);
1702
1703 /* Assume that all blocks are enabled and crop pixels and lines
1704 * accordingly. See preview_config_input_size() for more
1705 * information.
1706 */ 1713 */
1707 fmt->width -= 14; 1714 crop = __preview_get_crop(prev, fh, which);
1708 fmt->height -= 8; 1715 fmt->width = crop->width;
1716 fmt->height = crop->height;
1709 1717
1710 fmt->colorspace = V4L2_COLORSPACE_JPEG; 1718 fmt->colorspace = V4L2_COLORSPACE_JPEG;
1711 break; 1719 break;
@@ -1715,6 +1723,49 @@ static void preview_try_format(struct isp_prev_device *prev,
1715} 1723}
1716 1724
1717/* 1725/*
1726 * preview_try_crop - Validate a crop rectangle
1727 * @prev: ISP preview engine
1728 * @sink: format on the sink pad
1729 * @crop: crop rectangle to be validated
1730 *
1731 * The preview engine crops lines and columns for its internal operation,
1732 * depending on which filters are enabled. Enforce minimum crop margins to
1733 * handle that transparently for userspace.
1734 *
1735 * See the explanation at the PREV_MARGIN_* definitions for more details.
1736 */
1737static void preview_try_crop(struct isp_prev_device *prev,
1738 const struct v4l2_mbus_framefmt *sink,
1739 struct v4l2_rect *crop)
1740{
1741 unsigned int left = PREV_MARGIN_LEFT;
1742 unsigned int right = sink->width - PREV_MARGIN_RIGHT;
1743 unsigned int top = PREV_MARGIN_TOP;
1744 unsigned int bottom = sink->height - PREV_MARGIN_BOTTOM;
1745
1746 /* When processing data on-the-fly from the CCDC, at least 2 pixels must
1747 * be cropped from the left and right sides of the image. As we don't
1748 * know which filters will be enabled, increase the left and right
1749 * margins by two.
1750 */
1751 if (prev->input == PREVIEW_INPUT_CCDC) {
1752 left += 2;
1753 right -= 2;
1754 }
1755
1756 /* Restrict left/top to even values to keep the Bayer pattern. */
1757 crop->left &= ~1;
1758 crop->top &= ~1;
1759
1760 crop->left = clamp_t(u32, crop->left, left, right - PREV_MIN_OUT_WIDTH);
1761 crop->top = clamp_t(u32, crop->top, top, bottom - PREV_MIN_OUT_HEIGHT);
1762 crop->width = clamp_t(u32, crop->width, PREV_MIN_OUT_WIDTH,
1763 right - crop->left);
1764 crop->height = clamp_t(u32, crop->height, PREV_MIN_OUT_HEIGHT,
1765 bottom - crop->top);
1766}
1767
1768/*
1718 * preview_enum_mbus_code - Handle pixel format enumeration 1769 * preview_enum_mbus_code - Handle pixel format enumeration
1719 * @sd : pointer to v4l2 subdev structure 1770 * @sd : pointer to v4l2 subdev structure
1720 * @fh : V4L2 subdev file handle 1771 * @fh : V4L2 subdev file handle
@@ -1776,6 +1827,60 @@ static int preview_enum_frame_size(struct v4l2_subdev *sd,
1776} 1827}
1777 1828
1778/* 1829/*
1830 * preview_get_crop - Retrieve the crop rectangle on a pad
1831 * @sd: ISP preview V4L2 subdevice
1832 * @fh: V4L2 subdev file handle
1833 * @crop: crop rectangle
1834 *
1835 * Return 0 on success or a negative error code otherwise.
1836 */
1837static int preview_get_crop(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1838 struct v4l2_subdev_crop *crop)
1839{
1840 struct isp_prev_device *prev = v4l2_get_subdevdata(sd);
1841
1842 /* Cropping is only supported on the sink pad. */
1843 if (crop->pad != PREV_PAD_SINK)
1844 return -EINVAL;
1845
1846 crop->rect = *__preview_get_crop(prev, fh, crop->which);
1847 return 0;
1848}
1849
1850/*
1851 * preview_set_crop - Retrieve the crop rectangle on a pad
1852 * @sd: ISP preview V4L2 subdevice
1853 * @fh: V4L2 subdev file handle
1854 * @crop: crop rectangle
1855 *
1856 * Return 0 on success or a negative error code otherwise.
1857 */
1858static int preview_set_crop(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1859 struct v4l2_subdev_crop *crop)
1860{
1861 struct isp_prev_device *prev = v4l2_get_subdevdata(sd);
1862 struct v4l2_mbus_framefmt *format;
1863
1864 /* Cropping is only supported on the sink pad. */
1865 if (crop->pad != PREV_PAD_SINK)
1866 return -EINVAL;
1867
1868 /* The crop rectangle can't be changed while streaming. */
1869 if (prev->state != ISP_PIPELINE_STREAM_STOPPED)
1870 return -EBUSY;
1871
1872 format = __preview_get_format(prev, fh, PREV_PAD_SINK, crop->which);
1873 preview_try_crop(prev, format, &crop->rect);
1874 *__preview_get_crop(prev, fh, crop->which) = crop->rect;
1875
1876 /* Update the source format. */
1877 format = __preview_get_format(prev, fh, PREV_PAD_SOURCE, crop->which);
1878 preview_try_format(prev, fh, PREV_PAD_SOURCE, format, crop->which);
1879
1880 return 0;
1881}
1882
1883/*
1779 * preview_get_format - Handle get format by pads subdev method 1884 * preview_get_format - Handle get format by pads subdev method
1780 * @sd : pointer to v4l2 subdev structure 1885 * @sd : pointer to v4l2 subdev structure
1781 * @fh : V4L2 subdev file handle 1886 * @fh : V4L2 subdev file handle
@@ -1808,6 +1913,7 @@ static int preview_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1808{ 1913{
1809 struct isp_prev_device *prev = v4l2_get_subdevdata(sd); 1914 struct isp_prev_device *prev = v4l2_get_subdevdata(sd);
1810 struct v4l2_mbus_framefmt *format; 1915 struct v4l2_mbus_framefmt *format;
1916 struct v4l2_rect *crop;
1811 1917
1812 format = __preview_get_format(prev, fh, fmt->pad, fmt->which); 1918 format = __preview_get_format(prev, fh, fmt->pad, fmt->which);
1813 if (format == NULL) 1919 if (format == NULL)
@@ -1818,9 +1924,18 @@ static int preview_set_format(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1818 1924
1819 /* Propagate the format from sink to source */ 1925 /* Propagate the format from sink to source */
1820 if (fmt->pad == PREV_PAD_SINK) { 1926 if (fmt->pad == PREV_PAD_SINK) {
1927 /* Reset the crop rectangle. */
1928 crop = __preview_get_crop(prev, fh, fmt->which);
1929 crop->left = 0;
1930 crop->top = 0;
1931 crop->width = fmt->format.width;
1932 crop->height = fmt->format.height;
1933
1934 preview_try_crop(prev, &fmt->format, crop);
1935
1936 /* Update the source format. */
1821 format = __preview_get_format(prev, fh, PREV_PAD_SOURCE, 1937 format = __preview_get_format(prev, fh, PREV_PAD_SOURCE,
1822 fmt->which); 1938 fmt->which);
1823 *format = fmt->format;
1824 preview_try_format(prev, fh, PREV_PAD_SOURCE, format, 1939 preview_try_format(prev, fh, PREV_PAD_SOURCE, format,
1825 fmt->which); 1940 fmt->which);
1826 } 1941 }
@@ -1869,6 +1984,8 @@ static const struct v4l2_subdev_pad_ops preview_v4l2_pad_ops = {
1869 .enum_frame_size = preview_enum_frame_size, 1984 .enum_frame_size = preview_enum_frame_size,
1870 .get_fmt = preview_get_format, 1985 .get_fmt = preview_get_format,
1871 .set_fmt = preview_set_format, 1986 .set_fmt = preview_set_format,
1987 .get_crop = preview_get_crop,
1988 .set_crop = preview_set_crop,
1872}; 1989};
1873 1990
1874/* subdev operations */ 1991/* subdev operations */
@@ -1966,8 +2083,44 @@ static const struct media_entity_operations preview_media_ops = {
1966 .link_setup = preview_link_setup, 2083 .link_setup = preview_link_setup,
1967}; 2084};
1968 2085
2086void omap3isp_preview_unregister_entities(struct isp_prev_device *prev)
2087{
2088 v4l2_device_unregister_subdev(&prev->subdev);
2089 omap3isp_video_unregister(&prev->video_in);
2090 omap3isp_video_unregister(&prev->video_out);
2091}
2092
2093int omap3isp_preview_register_entities(struct isp_prev_device *prev,
2094 struct v4l2_device *vdev)
2095{
2096 int ret;
2097
2098 /* Register the subdev and video nodes. */
2099 ret = v4l2_device_register_subdev(vdev, &prev->subdev);
2100 if (ret < 0)
2101 goto error;
2102
2103 ret = omap3isp_video_register(&prev->video_in, vdev);
2104 if (ret < 0)
2105 goto error;
2106
2107 ret = omap3isp_video_register(&prev->video_out, vdev);
2108 if (ret < 0)
2109 goto error;
2110
2111 return 0;
2112
2113error:
2114 omap3isp_preview_unregister_entities(prev);
2115 return ret;
2116}
2117
2118/* -----------------------------------------------------------------------------
2119 * ISP previewer initialisation and cleanup
2120 */
2121
1969/* 2122/*
1970 * review_init_entities - Initialize subdev and media entity. 2123 * preview_init_entities - Initialize subdev and media entity.
1971 * @prev : Pointer to preview structure 2124 * @prev : Pointer to preview structure
1972 * return -ENOMEM or zero on success 2125 * return -ENOMEM or zero on success
1973 */ 2126 */
@@ -2024,69 +2177,34 @@ static int preview_init_entities(struct isp_prev_device *prev)
2024 2177
2025 ret = omap3isp_video_init(&prev->video_in, "preview"); 2178 ret = omap3isp_video_init(&prev->video_in, "preview");
2026 if (ret < 0) 2179 if (ret < 0)
2027 return ret; 2180 goto error_video_in;
2028 2181
2029 ret = omap3isp_video_init(&prev->video_out, "preview"); 2182 ret = omap3isp_video_init(&prev->video_out, "preview");
2030 if (ret < 0) 2183 if (ret < 0)
2031 return ret; 2184 goto error_video_out;
2032 2185
2033 /* Connect the video nodes to the previewer subdev. */ 2186 /* Connect the video nodes to the previewer subdev. */
2034 ret = media_entity_create_link(&prev->video_in.video.entity, 0, 2187 ret = media_entity_create_link(&prev->video_in.video.entity, 0,
2035 &prev->subdev.entity, PREV_PAD_SINK, 0); 2188 &prev->subdev.entity, PREV_PAD_SINK, 0);
2036 if (ret < 0) 2189 if (ret < 0)
2037 return ret; 2190 goto error_link;
2038 2191
2039 ret = media_entity_create_link(&prev->subdev.entity, PREV_PAD_SOURCE, 2192 ret = media_entity_create_link(&prev->subdev.entity, PREV_PAD_SOURCE,
2040 &prev->video_out.video.entity, 0, 0); 2193 &prev->video_out.video.entity, 0, 0);
2041 if (ret < 0) 2194 if (ret < 0)
2042 return ret; 2195 goto error_link;
2043 2196
2044 return 0; 2197 return 0;
2045}
2046 2198
2047void omap3isp_preview_unregister_entities(struct isp_prev_device *prev) 2199error_link:
2048{ 2200 omap3isp_video_cleanup(&prev->video_out);
2201error_video_out:
2202 omap3isp_video_cleanup(&prev->video_in);
2203error_video_in:
2049 media_entity_cleanup(&prev->subdev.entity); 2204 media_entity_cleanup(&prev->subdev.entity);
2050
2051 v4l2_device_unregister_subdev(&prev->subdev);
2052 v4l2_ctrl_handler_free(&prev->ctrls);
2053 omap3isp_video_unregister(&prev->video_in);
2054 omap3isp_video_unregister(&prev->video_out);
2055}
2056
2057int omap3isp_preview_register_entities(struct isp_prev_device *prev,
2058 struct v4l2_device *vdev)
2059{
2060 int ret;
2061
2062 /* Register the subdev and video nodes. */
2063 ret = v4l2_device_register_subdev(vdev, &prev->subdev);
2064 if (ret < 0)
2065 goto error;
2066
2067 ret = omap3isp_video_register(&prev->video_in, vdev);
2068 if (ret < 0)
2069 goto error;
2070
2071 ret = omap3isp_video_register(&prev->video_out, vdev);
2072 if (ret < 0)
2073 goto error;
2074
2075 return 0;
2076
2077error:
2078 omap3isp_preview_unregister_entities(prev);
2079 return ret; 2205 return ret;
2080} 2206}
2081 2207
2082/* -----------------------------------------------------------------------------
2083 * ISP previewer initialisation and cleanup
2084 */
2085
2086void omap3isp_preview_cleanup(struct isp_device *isp)
2087{
2088}
2089
2090/* 2208/*
2091 * isp_preview_init - Previewer initialization. 2209 * isp_preview_init - Previewer initialization.
2092 * @dev : Pointer to ISP device 2210 * @dev : Pointer to ISP device
@@ -2095,19 +2213,20 @@ void omap3isp_preview_cleanup(struct isp_device *isp)
2095int omap3isp_preview_init(struct isp_device *isp) 2213int omap3isp_preview_init(struct isp_device *isp)
2096{ 2214{
2097 struct isp_prev_device *prev = &isp->isp_prev; 2215 struct isp_prev_device *prev = &isp->isp_prev;
2098 int ret;
2099 2216
2100 spin_lock_init(&prev->lock); 2217 spin_lock_init(&prev->lock);
2101 init_waitqueue_head(&prev->wait); 2218 init_waitqueue_head(&prev->wait);
2102 preview_init_params(prev); 2219 preview_init_params(prev);
2103 2220
2104 ret = preview_init_entities(prev); 2221 return preview_init_entities(prev);
2105 if (ret < 0) 2222}
2106 goto out;
2107 2223
2108out: 2224void omap3isp_preview_cleanup(struct isp_device *isp)
2109 if (ret) 2225{
2110 omap3isp_preview_cleanup(isp); 2226 struct isp_prev_device *prev = &isp->isp_prev;
2111 2227
2112 return ret; 2228 v4l2_ctrl_handler_free(&prev->ctrls);
2229 omap3isp_video_cleanup(&prev->video_in);
2230 omap3isp_video_cleanup(&prev->video_out);
2231 media_entity_cleanup(&prev->subdev.entity);
2113} 2232}
diff --git a/drivers/media/video/omap3isp/isppreview.h b/drivers/media/video/omap3isp/isppreview.h
index fa943bd05c7f..f54e775c2df4 100644
--- a/drivers/media/video/omap3isp/isppreview.h
+++ b/drivers/media/video/omap3isp/isppreview.h
@@ -45,11 +45,6 @@
45#define ISPPRV_CONTRAST_HIGH 0xFF 45#define ISPPRV_CONTRAST_HIGH 0xFF
46#define ISPPRV_CONTRAST_UNITS 0x1 46#define ISPPRV_CONTRAST_UNITS 0x1
47 47
48#define NO_AVE 0x0
49#define AVE_2_PIX 0x1
50#define AVE_4_PIX 0x2
51#define AVE_8_PIX 0x3
52
53/* Features list */ 48/* Features list */
54#define PREV_LUMA_ENHANCE OMAP3ISP_PREV_LUMAENH 49#define PREV_LUMA_ENHANCE OMAP3ISP_PREV_LUMAENH
55#define PREV_INVERSE_ALAW OMAP3ISP_PREV_INVALAW 50#define PREV_INVERSE_ALAW OMAP3ISP_PREV_INVALAW
@@ -106,7 +101,6 @@ enum preview_ycpos_mode {
106 * @rgb2ycbcr: RGB to ycbcr parameters. 101 * @rgb2ycbcr: RGB to ycbcr parameters.
107 * @hmed: Horizontal median filter. 102 * @hmed: Horizontal median filter.
108 * @yclimit: YC limits parameters. 103 * @yclimit: YC limits parameters.
109 * @average: Downsampling rate for averager.
110 * @contrast: Contrast. 104 * @contrast: Contrast.
111 * @brightness: Brightness. 105 * @brightness: Brightness.
112 */ 106 */
@@ -124,7 +118,6 @@ struct prev_params {
124 struct omap3isp_prev_csc rgb2ycbcr; 118 struct omap3isp_prev_csc rgb2ycbcr;
125 struct omap3isp_prev_hmed hmed; 119 struct omap3isp_prev_hmed hmed;
126 struct omap3isp_prev_yclimit yclimit; 120 struct omap3isp_prev_yclimit yclimit;
127 u8 average;
128 u8 contrast; 121 u8 contrast;
129 u8 brightness; 122 u8 brightness;
130}; 123};
@@ -159,6 +152,7 @@ struct isptables_update {
159 * @subdev: V4L2 subdevice 152 * @subdev: V4L2 subdevice
160 * @pads: Media entity pads 153 * @pads: Media entity pads
161 * @formats: Active formats at the subdev pad 154 * @formats: Active formats at the subdev pad
155 * @crop: Active crop rectangle
162 * @input: Module currently connected to the input pad 156 * @input: Module currently connected to the input pad
163 * @output: Bitmask of the active output 157 * @output: Bitmask of the active output
164 * @video_in: Input video entity 158 * @video_in: Input video entity
@@ -177,6 +171,7 @@ struct isp_prev_device {
177 struct v4l2_subdev subdev; 171 struct v4l2_subdev subdev;
178 struct media_pad pads[PREV_PADS_NUM]; 172 struct media_pad pads[PREV_PADS_NUM];
179 struct v4l2_mbus_framefmt formats[PREV_PADS_NUM]; 173 struct v4l2_mbus_framefmt formats[PREV_PADS_NUM];
174 struct v4l2_rect crop;
180 175
181 struct v4l2_ctrl_handler ctrls; 176 struct v4l2_ctrl_handler ctrls;
182 177
diff --git a/drivers/media/video/omap3isp/ispreg.h b/drivers/media/video/omap3isp/ispreg.h
index 69f6af6f6b9c..084ea77d65a7 100644
--- a/drivers/media/video/omap3isp/ispreg.h
+++ b/drivers/media/video/omap3isp/ispreg.h
@@ -402,9 +402,6 @@
402#define ISPPRV_YENH_TABLE_ADDR 0x1000 402#define ISPPRV_YENH_TABLE_ADDR 0x1000
403#define ISPPRV_CFA_TABLE_ADDR 0x1400 403#define ISPPRV_CFA_TABLE_ADDR 0x1400
404 404
405#define ISPPRV_MAXOUTPUT_WIDTH 1280
406#define ISPPRV_MAXOUTPUT_WIDTH_ES2 3300
407#define ISPPRV_MAXOUTPUT_WIDTH_3630 4096
408#define ISPRSZ_MIN_OUTPUT 64 405#define ISPRSZ_MIN_OUTPUT 64
409#define ISPRSZ_MAX_OUTPUT 3312 406#define ISPRSZ_MAX_OUTPUT 3312
410 407
diff --git a/drivers/media/video/omap3isp/ispresizer.c b/drivers/media/video/omap3isp/ispresizer.c
index 0bb0f8cd36f5..50e593bfcfaf 100644
--- a/drivers/media/video/omap3isp/ispresizer.c
+++ b/drivers/media/video/omap3isp/ispresizer.c
@@ -1608,6 +1608,42 @@ static const struct media_entity_operations resizer_media_ops = {
1608 .link_setup = resizer_link_setup, 1608 .link_setup = resizer_link_setup,
1609}; 1609};
1610 1610
1611void omap3isp_resizer_unregister_entities(struct isp_res_device *res)
1612{
1613 v4l2_device_unregister_subdev(&res->subdev);
1614 omap3isp_video_unregister(&res->video_in);
1615 omap3isp_video_unregister(&res->video_out);
1616}
1617
1618int omap3isp_resizer_register_entities(struct isp_res_device *res,
1619 struct v4l2_device *vdev)
1620{
1621 int ret;
1622
1623 /* Register the subdev and video nodes. */
1624 ret = v4l2_device_register_subdev(vdev, &res->subdev);
1625 if (ret < 0)
1626 goto error;
1627
1628 ret = omap3isp_video_register(&res->video_in, vdev);
1629 if (ret < 0)
1630 goto error;
1631
1632 ret = omap3isp_video_register(&res->video_out, vdev);
1633 if (ret < 0)
1634 goto error;
1635
1636 return 0;
1637
1638error:
1639 omap3isp_resizer_unregister_entities(res);
1640 return ret;
1641}
1642
1643/* -----------------------------------------------------------------------------
1644 * ISP resizer initialization and cleanup
1645 */
1646
1611/* 1647/*
1612 * resizer_init_entities - Initialize resizer subdev and media entity. 1648 * resizer_init_entities - Initialize resizer subdev and media entity.
1613 * @res : Pointer to resizer device structure 1649 * @res : Pointer to resizer device structure
@@ -1652,68 +1688,34 @@ static int resizer_init_entities(struct isp_res_device *res)
1652 1688
1653 ret = omap3isp_video_init(&res->video_in, "resizer"); 1689 ret = omap3isp_video_init(&res->video_in, "resizer");
1654 if (ret < 0) 1690 if (ret < 0)
1655 return ret; 1691 goto error_video_in;
1656 1692
1657 ret = omap3isp_video_init(&res->video_out, "resizer"); 1693 ret = omap3isp_video_init(&res->video_out, "resizer");
1658 if (ret < 0) 1694 if (ret < 0)
1659 return ret; 1695 goto error_video_out;
1660 1696
1661 /* Connect the video nodes to the resizer subdev. */ 1697 /* Connect the video nodes to the resizer subdev. */
1662 ret = media_entity_create_link(&res->video_in.video.entity, 0, 1698 ret = media_entity_create_link(&res->video_in.video.entity, 0,
1663 &res->subdev.entity, RESZ_PAD_SINK, 0); 1699 &res->subdev.entity, RESZ_PAD_SINK, 0);
1664 if (ret < 0) 1700 if (ret < 0)
1665 return ret; 1701 goto error_link;
1666 1702
1667 ret = media_entity_create_link(&res->subdev.entity, RESZ_PAD_SOURCE, 1703 ret = media_entity_create_link(&res->subdev.entity, RESZ_PAD_SOURCE,
1668 &res->video_out.video.entity, 0, 0); 1704 &res->video_out.video.entity, 0, 0);
1669 if (ret < 0) 1705 if (ret < 0)
1670 return ret; 1706 goto error_link;
1671 1707
1672 return 0; 1708 return 0;
1673}
1674 1709
1675void omap3isp_resizer_unregister_entities(struct isp_res_device *res) 1710error_link:
1676{ 1711 omap3isp_video_cleanup(&res->video_out);
1712error_video_out:
1713 omap3isp_video_cleanup(&res->video_in);
1714error_video_in:
1677 media_entity_cleanup(&res->subdev.entity); 1715 media_entity_cleanup(&res->subdev.entity);
1678
1679 v4l2_device_unregister_subdev(&res->subdev);
1680 omap3isp_video_unregister(&res->video_in);
1681 omap3isp_video_unregister(&res->video_out);
1682}
1683
1684int omap3isp_resizer_register_entities(struct isp_res_device *res,
1685 struct v4l2_device *vdev)
1686{
1687 int ret;
1688
1689 /* Register the subdev and video nodes. */
1690 ret = v4l2_device_register_subdev(vdev, &res->subdev);
1691 if (ret < 0)
1692 goto error;
1693
1694 ret = omap3isp_video_register(&res->video_in, vdev);
1695 if (ret < 0)
1696 goto error;
1697
1698 ret = omap3isp_video_register(&res->video_out, vdev);
1699 if (ret < 0)
1700 goto error;
1701
1702 return 0;
1703
1704error:
1705 omap3isp_resizer_unregister_entities(res);
1706 return ret; 1716 return ret;
1707} 1717}
1708 1718
1709/* -----------------------------------------------------------------------------
1710 * ISP resizer initialization and cleanup
1711 */
1712
1713void omap3isp_resizer_cleanup(struct isp_device *isp)
1714{
1715}
1716
1717/* 1719/*
1718 * isp_resizer_init - Resizer initialization. 1720 * isp_resizer_init - Resizer initialization.
1719 * @isp : Pointer to ISP device 1721 * @isp : Pointer to ISP device
@@ -1722,17 +1724,17 @@ void omap3isp_resizer_cleanup(struct isp_device *isp)
1722int omap3isp_resizer_init(struct isp_device *isp) 1724int omap3isp_resizer_init(struct isp_device *isp)
1723{ 1725{
1724 struct isp_res_device *res = &isp->isp_res; 1726 struct isp_res_device *res = &isp->isp_res;
1725 int ret;
1726 1727
1727 init_waitqueue_head(&res->wait); 1728 init_waitqueue_head(&res->wait);
1728 atomic_set(&res->stopping, 0); 1729 atomic_set(&res->stopping, 0);
1729 ret = resizer_init_entities(res); 1730 return resizer_init_entities(res);
1730 if (ret < 0) 1731}
1731 goto out;
1732 1732
1733out: 1733void omap3isp_resizer_cleanup(struct isp_device *isp)
1734 if (ret) 1734{
1735 omap3isp_resizer_cleanup(isp); 1735 struct isp_res_device *res = &isp->isp_res;
1736 1736
1737 return ret; 1737 omap3isp_video_cleanup(&res->video_in);
1738 omap3isp_video_cleanup(&res->video_out);
1739 media_entity_cleanup(&res->subdev.entity);
1738} 1740}
diff --git a/drivers/media/video/omap3isp/ispstat.c b/drivers/media/video/omap3isp/ispstat.c
index 732905552261..68d539456c55 100644
--- a/drivers/media/video/omap3isp/ispstat.c
+++ b/drivers/media/video/omap3isp/ispstat.c
@@ -1023,24 +1023,6 @@ void omap3isp_stat_dma_isr(struct ispstat *stat)
1023 __stat_isr(stat, 1); 1023 __stat_isr(stat, 1);
1024} 1024}
1025 1025
1026static int isp_stat_init_entities(struct ispstat *stat, const char *name,
1027 const struct v4l2_subdev_ops *sd_ops)
1028{
1029 struct v4l2_subdev *subdev = &stat->subdev;
1030 struct media_entity *me = &subdev->entity;
1031
1032 v4l2_subdev_init(subdev, sd_ops);
1033 snprintf(subdev->name, V4L2_SUBDEV_NAME_SIZE, "OMAP3 ISP %s", name);
1034 subdev->grp_id = 1 << 16; /* group ID for isp subdevs */
1035 subdev->flags |= V4L2_SUBDEV_FL_HAS_EVENTS | V4L2_SUBDEV_FL_HAS_DEVNODE;
1036 v4l2_set_subdevdata(subdev, stat);
1037
1038 stat->pad.flags = MEDIA_PAD_FL_SINK;
1039 me->ops = NULL;
1040
1041 return media_entity_init(me, 1, &stat->pad, 0);
1042}
1043
1044int omap3isp_stat_subscribe_event(struct v4l2_subdev *subdev, 1026int omap3isp_stat_subscribe_event(struct v4l2_subdev *subdev,
1045 struct v4l2_fh *fh, 1027 struct v4l2_fh *fh,
1046 struct v4l2_event_subscription *sub) 1028 struct v4l2_event_subscription *sub)
@@ -1062,7 +1044,6 @@ int omap3isp_stat_unsubscribe_event(struct v4l2_subdev *subdev,
1062 1044
1063void omap3isp_stat_unregister_entities(struct ispstat *stat) 1045void omap3isp_stat_unregister_entities(struct ispstat *stat)
1064{ 1046{
1065 media_entity_cleanup(&stat->subdev.entity);
1066 v4l2_device_unregister_subdev(&stat->subdev); 1047 v4l2_device_unregister_subdev(&stat->subdev);
1067} 1048}
1068 1049
@@ -1072,21 +1053,50 @@ int omap3isp_stat_register_entities(struct ispstat *stat,
1072 return v4l2_device_register_subdev(vdev, &stat->subdev); 1053 return v4l2_device_register_subdev(vdev, &stat->subdev);
1073} 1054}
1074 1055
1056static int isp_stat_init_entities(struct ispstat *stat, const char *name,
1057 const struct v4l2_subdev_ops *sd_ops)
1058{
1059 struct v4l2_subdev *subdev = &stat->subdev;
1060 struct media_entity *me = &subdev->entity;
1061
1062 v4l2_subdev_init(subdev, sd_ops);
1063 snprintf(subdev->name, V4L2_SUBDEV_NAME_SIZE, "OMAP3 ISP %s", name);
1064 subdev->grp_id = 1 << 16; /* group ID for isp subdevs */
1065 subdev->flags |= V4L2_SUBDEV_FL_HAS_EVENTS | V4L2_SUBDEV_FL_HAS_DEVNODE;
1066 v4l2_set_subdevdata(subdev, stat);
1067
1068 stat->pad.flags = MEDIA_PAD_FL_SINK;
1069 me->ops = NULL;
1070
1071 return media_entity_init(me, 1, &stat->pad, 0);
1072}
1073
1075int omap3isp_stat_init(struct ispstat *stat, const char *name, 1074int omap3isp_stat_init(struct ispstat *stat, const char *name,
1076 const struct v4l2_subdev_ops *sd_ops) 1075 const struct v4l2_subdev_ops *sd_ops)
1077{ 1076{
1077 int ret;
1078
1078 stat->buf = kcalloc(STAT_MAX_BUFS, sizeof(*stat->buf), GFP_KERNEL); 1079 stat->buf = kcalloc(STAT_MAX_BUFS, sizeof(*stat->buf), GFP_KERNEL);
1079 if (!stat->buf) 1080 if (!stat->buf)
1080 return -ENOMEM; 1081 return -ENOMEM;
1082
1081 isp_stat_buf_clear(stat); 1083 isp_stat_buf_clear(stat);
1082 mutex_init(&stat->ioctl_lock); 1084 mutex_init(&stat->ioctl_lock);
1083 atomic_set(&stat->buf_err, 0); 1085 atomic_set(&stat->buf_err, 0);
1084 1086
1085 return isp_stat_init_entities(stat, name, sd_ops); 1087 ret = isp_stat_init_entities(stat, name, sd_ops);
1088 if (ret < 0) {
1089 mutex_destroy(&stat->ioctl_lock);
1090 kfree(stat->buf);
1091 }
1092
1093 return ret;
1086} 1094}
1087 1095
1088void omap3isp_stat_free(struct ispstat *stat) 1096void omap3isp_stat_cleanup(struct ispstat *stat)
1089{ 1097{
1098 media_entity_cleanup(&stat->subdev.entity);
1099 mutex_destroy(&stat->ioctl_lock);
1090 isp_stat_bufs_free(stat); 1100 isp_stat_bufs_free(stat);
1091 kfree(stat->buf); 1101 kfree(stat->buf);
1092} 1102}
diff --git a/drivers/media/video/omap3isp/ispstat.h b/drivers/media/video/omap3isp/ispstat.h
index d86da94fa50d..9b7c8654dc8a 100644
--- a/drivers/media/video/omap3isp/ispstat.h
+++ b/drivers/media/video/omap3isp/ispstat.h
@@ -144,7 +144,7 @@ int omap3isp_stat_request_statistics(struct ispstat *stat,
144 struct omap3isp_stat_data *data); 144 struct omap3isp_stat_data *data);
145int omap3isp_stat_init(struct ispstat *stat, const char *name, 145int omap3isp_stat_init(struct ispstat *stat, const char *name,
146 const struct v4l2_subdev_ops *sd_ops); 146 const struct v4l2_subdev_ops *sd_ops);
147void omap3isp_stat_free(struct ispstat *stat); 147void omap3isp_stat_cleanup(struct ispstat *stat);
148int omap3isp_stat_subscribe_event(struct v4l2_subdev *subdev, 148int omap3isp_stat_subscribe_event(struct v4l2_subdev *subdev,
149 struct v4l2_fh *fh, 149 struct v4l2_fh *fh,
150 struct v4l2_event_subscription *sub); 150 struct v4l2_event_subscription *sub);
diff --git a/drivers/media/video/omap3isp/ispvideo.c b/drivers/media/video/omap3isp/ispvideo.c
index 0cb8a9f9d675..d1000723c5ae 100644
--- a/drivers/media/video/omap3isp/ispvideo.c
+++ b/drivers/media/video/omap3isp/ispvideo.c
@@ -1325,6 +1325,13 @@ int omap3isp_video_init(struct isp_video *video, const char *name)
1325 return 0; 1325 return 0;
1326} 1326}
1327 1327
1328void omap3isp_video_cleanup(struct isp_video *video)
1329{
1330 media_entity_cleanup(&video->video.entity);
1331 mutex_destroy(&video->stream_lock);
1332 mutex_destroy(&video->mutex);
1333}
1334
1328int omap3isp_video_register(struct isp_video *video, struct v4l2_device *vdev) 1335int omap3isp_video_register(struct isp_video *video, struct v4l2_device *vdev)
1329{ 1336{
1330 int ret; 1337 int ret;
@@ -1341,8 +1348,6 @@ int omap3isp_video_register(struct isp_video *video, struct v4l2_device *vdev)
1341 1348
1342void omap3isp_video_unregister(struct isp_video *video) 1349void omap3isp_video_unregister(struct isp_video *video)
1343{ 1350{
1344 if (video_is_registered(&video->video)) { 1351 if (video_is_registered(&video->video))
1345 media_entity_cleanup(&video->video.entity);
1346 video_unregister_device(&video->video); 1352 video_unregister_device(&video->video);
1347 }
1348} 1353}
diff --git a/drivers/media/video/omap3isp/ispvideo.h b/drivers/media/video/omap3isp/ispvideo.h
index 53160aa24e6e..08cbfa144e6e 100644
--- a/drivers/media/video/omap3isp/ispvideo.h
+++ b/drivers/media/video/omap3isp/ispvideo.h
@@ -190,6 +190,7 @@ struct isp_video_fh {
190 container_of(q, struct isp_video_fh, queue) 190 container_of(q, struct isp_video_fh, queue)
191 191
192int omap3isp_video_init(struct isp_video *video, const char *name); 192int omap3isp_video_init(struct isp_video *video, const char *name);
193void omap3isp_video_cleanup(struct isp_video *video);
193int omap3isp_video_register(struct isp_video *video, 194int omap3isp_video_register(struct isp_video *video,
194 struct v4l2_device *vdev); 195 struct v4l2_device *vdev);
195void omap3isp_video_unregister(struct isp_video *video); 196void omap3isp_video_unregister(struct isp_video *video);
diff --git a/drivers/media/video/ov2640.c b/drivers/media/video/ov2640.c
index 9ce2fa037b94..b5247cb64fde 100644
--- a/drivers/media/video/ov2640.c
+++ b/drivers/media/video/ov2640.c
@@ -18,11 +18,13 @@
18#include <linux/i2c.h> 18#include <linux/i2c.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/delay.h> 20#include <linux/delay.h>
21#include <linux/v4l2-mediabus.h>
21#include <linux/videodev2.h> 22#include <linux/videodev2.h>
23
24#include <media/soc_camera.h>
22#include <media/v4l2-chip-ident.h> 25#include <media/v4l2-chip-ident.h>
23#include <media/v4l2-subdev.h> 26#include <media/v4l2-subdev.h>
24#include <media/soc_camera.h> 27#include <media/v4l2-ctrls.h>
25#include <media/soc_mediabus.h>
26 28
27#define VAL_SET(x, mask, rshift, lshift) \ 29#define VAL_SET(x, mask, rshift, lshift) \
28 ((((x) >> rshift) & mask) << lshift) 30 ((((x) >> rshift) & mask) << lshift)
@@ -299,12 +301,10 @@ struct ov2640_win_size {
299 301
300struct ov2640_priv { 302struct ov2640_priv {
301 struct v4l2_subdev subdev; 303 struct v4l2_subdev subdev;
302 struct ov2640_camera_info *info; 304 struct v4l2_ctrl_handler hdl;
303 enum v4l2_mbus_pixelcode cfmt_code; 305 enum v4l2_mbus_pixelcode cfmt_code;
304 const struct ov2640_win_size *win; 306 const struct ov2640_win_size *win;
305 int model; 307 int model;
306 u16 flag_vflip:1;
307 u16 flag_hflip:1;
308}; 308};
309 309
310/* 310/*
@@ -610,29 +610,6 @@ static enum v4l2_mbus_pixelcode ov2640_codes[] = {
610}; 610};
611 611
612/* 612/*
613 * Supported controls
614 */
615static const struct v4l2_queryctrl ov2640_controls[] = {
616 {
617 .id = V4L2_CID_VFLIP,
618 .type = V4L2_CTRL_TYPE_BOOLEAN,
619 .name = "Flip Vertically",
620 .minimum = 0,
621 .maximum = 1,
622 .step = 1,
623 .default_value = 0,
624 }, {
625 .id = V4L2_CID_HFLIP,
626 .type = V4L2_CTRL_TYPE_BOOLEAN,
627 .name = "Flip Horizontally",
628 .minimum = 0,
629 .maximum = 1,
630 .step = 1,
631 .default_value = 0,
632 },
633};
634
635/*
636 * General functions 613 * General functions
637 */ 614 */
638static struct ov2640_priv *to_ov2640(const struct i2c_client *client) 615static struct ov2640_priv *to_ov2640(const struct i2c_client *client)
@@ -701,81 +678,23 @@ static int ov2640_s_stream(struct v4l2_subdev *sd, int enable)
701 return 0; 678 return 0;
702} 679}
703 680
704static int ov2640_set_bus_param(struct soc_camera_device *icd, 681static int ov2640_s_ctrl(struct v4l2_ctrl *ctrl)
705 unsigned long flags)
706{
707 struct soc_camera_link *icl = to_soc_camera_link(icd);
708 unsigned long width_flag = flags & SOCAM_DATAWIDTH_MASK;
709
710 /* Only one width bit may be set */
711 if (!is_power_of_2(width_flag))
712 return -EINVAL;
713
714 if (icl->set_bus_param)
715 return icl->set_bus_param(icl, width_flag);
716
717 /*
718 * Without board specific bus width settings we support only the
719 * sensors native bus width witch are tested working
720 */
721 if (width_flag & (SOCAM_DATAWIDTH_10 | SOCAM_DATAWIDTH_8))
722 return 0;
723
724 return 0;
725}
726
727static unsigned long ov2640_query_bus_param(struct soc_camera_device *icd)
728{
729 struct soc_camera_link *icl = to_soc_camera_link(icd);
730 unsigned long flags = SOCAM_PCLK_SAMPLE_RISING | SOCAM_MASTER |
731 SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_HIGH |
732 SOCAM_DATA_ACTIVE_HIGH;
733
734 if (icl->query_bus_param)
735 flags |= icl->query_bus_param(icl) & SOCAM_DATAWIDTH_MASK;
736 else
737 flags |= SOCAM_DATAWIDTH_10;
738
739 return soc_camera_apply_sensor_flags(icl, flags);
740}
741
742static int ov2640_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
743{ 682{
683 struct v4l2_subdev *sd =
684 &container_of(ctrl->handler, struct ov2640_priv, hdl)->subdev;
744 struct i2c_client *client = v4l2_get_subdevdata(sd); 685 struct i2c_client *client = v4l2_get_subdevdata(sd);
745 struct ov2640_priv *priv = to_ov2640(client);
746
747 switch (ctrl->id) {
748 case V4L2_CID_VFLIP:
749 ctrl->value = priv->flag_vflip;
750 break;
751 case V4L2_CID_HFLIP:
752 ctrl->value = priv->flag_hflip;
753 break;
754 }
755 return 0;
756}
757
758static int ov2640_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
759{
760 struct i2c_client *client = v4l2_get_subdevdata(sd);
761 struct ov2640_priv *priv = to_ov2640(client);
762 int ret = 0;
763 u8 val; 686 u8 val;
764 687
765 switch (ctrl->id) { 688 switch (ctrl->id) {
766 case V4L2_CID_VFLIP: 689 case V4L2_CID_VFLIP:
767 val = ctrl->value ? REG04_VFLIP_IMG : 0x00; 690 val = ctrl->val ? REG04_VFLIP_IMG : 0x00;
768 priv->flag_vflip = ctrl->value ? 1 : 0; 691 return ov2640_mask_set(client, REG04, REG04_VFLIP_IMG, val);
769 ret = ov2640_mask_set(client, REG04, REG04_VFLIP_IMG, val);
770 break;
771 case V4L2_CID_HFLIP: 692 case V4L2_CID_HFLIP:
772 val = ctrl->value ? REG04_HFLIP_IMG : 0x00; 693 val = ctrl->val ? REG04_HFLIP_IMG : 0x00;
773 priv->flag_hflip = ctrl->value ? 1 : 0; 694 return ov2640_mask_set(client, REG04, REG04_HFLIP_IMG, val);
774 ret = ov2640_mask_set(client, REG04, REG04_HFLIP_IMG, val);
775 break;
776 } 695 }
777 696
778 return ret; 697 return -EINVAL;
779} 698}
780 699
781static int ov2640_g_chip_ident(struct v4l2_subdev *sd, 700static int ov2640_g_chip_ident(struct v4l2_subdev *sd,
@@ -1023,18 +942,13 @@ static int ov2640_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a)
1023 return 0; 942 return 0;
1024} 943}
1025 944
1026static int ov2640_video_probe(struct soc_camera_device *icd, 945static int ov2640_video_probe(struct i2c_client *client)
1027 struct i2c_client *client)
1028{ 946{
1029 struct ov2640_priv *priv = to_ov2640(client); 947 struct ov2640_priv *priv = to_ov2640(client);
1030 u8 pid, ver, midh, midl; 948 u8 pid, ver, midh, midl;
1031 const char *devname; 949 const char *devname;
1032 int ret; 950 int ret;
1033 951
1034 /* We must have a parent by now. And it cannot be a wrong one. */
1035 BUG_ON(!icd->parent ||
1036 to_soc_camera_host(icd->parent)->nr != icd->iface);
1037
1038 /* 952 /*
1039 * check and show product ID and manufacturer ID 953 * check and show product ID and manufacturer ID
1040 */ 954 */
@@ -1060,22 +974,17 @@ static int ov2640_video_probe(struct soc_camera_device *icd,
1060 "%s Product ID %0x:%0x Manufacturer ID %x:%x\n", 974 "%s Product ID %0x:%0x Manufacturer ID %x:%x\n",
1061 devname, pid, ver, midh, midl); 975 devname, pid, ver, midh, midl);
1062 976
1063 return 0; 977 return v4l2_ctrl_handler_setup(&priv->hdl);
1064 978
1065err: 979err:
1066 return ret; 980 return ret;
1067} 981}
1068 982
1069static struct soc_camera_ops ov2640_ops = { 983static const struct v4l2_ctrl_ops ov2640_ctrl_ops = {
1070 .set_bus_param = ov2640_set_bus_param, 984 .s_ctrl = ov2640_s_ctrl,
1071 .query_bus_param = ov2640_query_bus_param,
1072 .controls = ov2640_controls,
1073 .num_controls = ARRAY_SIZE(ov2640_controls),
1074}; 985};
1075 986
1076static struct v4l2_subdev_core_ops ov2640_subdev_core_ops = { 987static struct v4l2_subdev_core_ops ov2640_subdev_core_ops = {
1077 .g_ctrl = ov2640_g_ctrl,
1078 .s_ctrl = ov2640_s_ctrl,
1079 .g_chip_ident = ov2640_g_chip_ident, 988 .g_chip_ident = ov2640_g_chip_ident,
1080#ifdef CONFIG_VIDEO_ADV_DEBUG 989#ifdef CONFIG_VIDEO_ADV_DEBUG
1081 .g_register = ov2640_g_register, 990 .g_register = ov2640_g_register,
@@ -1083,6 +992,21 @@ static struct v4l2_subdev_core_ops ov2640_subdev_core_ops = {
1083#endif 992#endif
1084}; 993};
1085 994
995static int ov2640_g_mbus_config(struct v4l2_subdev *sd,
996 struct v4l2_mbus_config *cfg)
997{
998 struct i2c_client *client = v4l2_get_subdevdata(sd);
999 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
1000
1001 cfg->flags = V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_MASTER |
1002 V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_HIGH |
1003 V4L2_MBUS_DATA_ACTIVE_HIGH;
1004 cfg->type = V4L2_MBUS_PARALLEL;
1005 cfg->flags = soc_camera_apply_board_flags(icl, cfg);
1006
1007 return 0;
1008}
1009
1086static struct v4l2_subdev_video_ops ov2640_subdev_video_ops = { 1010static struct v4l2_subdev_video_ops ov2640_subdev_video_ops = {
1087 .s_stream = ov2640_s_stream, 1011 .s_stream = ov2640_s_stream,
1088 .g_mbus_fmt = ov2640_g_fmt, 1012 .g_mbus_fmt = ov2640_g_fmt,
@@ -1091,6 +1015,7 @@ static struct v4l2_subdev_video_ops ov2640_subdev_video_ops = {
1091 .cropcap = ov2640_cropcap, 1015 .cropcap = ov2640_cropcap,
1092 .g_crop = ov2640_g_crop, 1016 .g_crop = ov2640_g_crop,
1093 .enum_mbus_fmt = ov2640_enum_fmt, 1017 .enum_mbus_fmt = ov2640_enum_fmt,
1018 .g_mbus_config = ov2640_g_mbus_config,
1094}; 1019};
1095 1020
1096static struct v4l2_subdev_ops ov2640_subdev_ops = { 1021static struct v4l2_subdev_ops ov2640_subdev_ops = {
@@ -1104,18 +1029,11 @@ static struct v4l2_subdev_ops ov2640_subdev_ops = {
1104static int ov2640_probe(struct i2c_client *client, 1029static int ov2640_probe(struct i2c_client *client,
1105 const struct i2c_device_id *did) 1030 const struct i2c_device_id *did)
1106{ 1031{
1107 struct ov2640_priv *priv; 1032 struct ov2640_priv *priv;
1108 struct soc_camera_device *icd = client->dev.platform_data; 1033 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
1109 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 1034 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
1110 struct soc_camera_link *icl; 1035 int ret;
1111 int ret;
1112
1113 if (!icd) {
1114 dev_err(&adapter->dev, "OV2640: missing soc-camera data!\n");
1115 return -EINVAL;
1116 }
1117 1036
1118 icl = to_soc_camera_link(icd);
1119 if (!icl) { 1037 if (!icl) {
1120 dev_err(&adapter->dev, 1038 dev_err(&adapter->dev,
1121 "OV2640: Missing platform_data for driver\n"); 1039 "OV2640: Missing platform_data for driver\n");
@@ -1135,15 +1053,23 @@ static int ov2640_probe(struct i2c_client *client,
1135 return -ENOMEM; 1053 return -ENOMEM;
1136 } 1054 }
1137 1055
1138 priv->info = icl->priv;
1139
1140 v4l2_i2c_subdev_init(&priv->subdev, client, &ov2640_subdev_ops); 1056 v4l2_i2c_subdev_init(&priv->subdev, client, &ov2640_subdev_ops);
1057 v4l2_ctrl_handler_init(&priv->hdl, 2);
1058 v4l2_ctrl_new_std(&priv->hdl, &ov2640_ctrl_ops,
1059 V4L2_CID_VFLIP, 0, 1, 1, 0);
1060 v4l2_ctrl_new_std(&priv->hdl, &ov2640_ctrl_ops,
1061 V4L2_CID_HFLIP, 0, 1, 1, 0);
1062 priv->subdev.ctrl_handler = &priv->hdl;
1063 if (priv->hdl.error) {
1064 int err = priv->hdl.error;
1141 1065
1142 icd->ops = &ov2640_ops; 1066 kfree(priv);
1067 return err;
1068 }
1143 1069
1144 ret = ov2640_video_probe(icd, client); 1070 ret = ov2640_video_probe(client);
1145 if (ret) { 1071 if (ret) {
1146 icd->ops = NULL; 1072 v4l2_ctrl_handler_free(&priv->hdl);
1147 kfree(priv); 1073 kfree(priv);
1148 } else { 1074 } else {
1149 dev_info(&adapter->dev, "OV2640 Probed\n"); 1075 dev_info(&adapter->dev, "OV2640 Probed\n");
@@ -1155,9 +1081,9 @@ static int ov2640_probe(struct i2c_client *client,
1155static int ov2640_remove(struct i2c_client *client) 1081static int ov2640_remove(struct i2c_client *client)
1156{ 1082{
1157 struct ov2640_priv *priv = to_ov2640(client); 1083 struct ov2640_priv *priv = to_ov2640(client);
1158 struct soc_camera_device *icd = client->dev.platform_data;
1159 1084
1160 icd->ops = NULL; 1085 v4l2_device_unregister_subdev(&priv->subdev);
1086 v4l2_ctrl_handler_free(&priv->hdl);
1161 kfree(priv); 1087 kfree(priv);
1162 return 0; 1088 return 0;
1163} 1089}
diff --git a/drivers/media/video/ov5642.c b/drivers/media/video/ov5642.c
index 349a4ad3ccc1..bb37ec80f274 100644
--- a/drivers/media/video/ov5642.c
+++ b/drivers/media/video/ov5642.c
@@ -14,14 +14,16 @@
14 * published by the Free Software Foundation. 14 * published by the Free Software Foundation.
15 */ 15 */
16 16
17#include <linux/bitops.h>
17#include <linux/delay.h> 18#include <linux/delay.h>
18#include <linux/i2c.h> 19#include <linux/i2c.h>
20#include <linux/kernel.h>
19#include <linux/slab.h> 21#include <linux/slab.h>
20#include <linux/videodev2.h> 22#include <linux/videodev2.h>
21#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/v4l2-mediabus.h>
22 25
23#include <media/soc_camera.h> 26#include <media/soc_camera.h>
24#include <media/soc_mediabus.h>
25#include <media/v4l2-chip-ident.h> 27#include <media/v4l2-chip-ident.h>
26#include <media/v4l2-subdev.h> 28#include <media/v4l2-subdev.h>
27 29
@@ -35,7 +37,7 @@
35#define REG_WINDOW_START_Y_LOW 0x3803 37#define REG_WINDOW_START_Y_LOW 0x3803
36#define REG_WINDOW_WIDTH_HIGH 0x3804 38#define REG_WINDOW_WIDTH_HIGH 0x3804
37#define REG_WINDOW_WIDTH_LOW 0x3805 39#define REG_WINDOW_WIDTH_LOW 0x3805
38#define REG_WINDOW_HEIGHT_HIGH 0x3806 40#define REG_WINDOW_HEIGHT_HIGH 0x3806
39#define REG_WINDOW_HEIGHT_LOW 0x3807 41#define REG_WINDOW_HEIGHT_LOW 0x3807
40#define REG_OUT_WIDTH_HIGH 0x3808 42#define REG_OUT_WIDTH_HIGH 0x3808
41#define REG_OUT_WIDTH_LOW 0x3809 43#define REG_OUT_WIDTH_LOW 0x3809
@@ -45,19 +47,44 @@
45#define REG_OUT_TOTAL_WIDTH_LOW 0x380d 47#define REG_OUT_TOTAL_WIDTH_LOW 0x380d
46#define REG_OUT_TOTAL_HEIGHT_HIGH 0x380e 48#define REG_OUT_TOTAL_HEIGHT_HIGH 0x380e
47#define REG_OUT_TOTAL_HEIGHT_LOW 0x380f 49#define REG_OUT_TOTAL_HEIGHT_LOW 0x380f
50#define REG_OUTPUT_FORMAT 0x4300
51#define REG_ISP_CTRL_01 0x5001
52#define REG_AVG_WINDOW_END_X_HIGH 0x5682
53#define REG_AVG_WINDOW_END_X_LOW 0x5683
54#define REG_AVG_WINDOW_END_Y_HIGH 0x5686
55#define REG_AVG_WINDOW_END_Y_LOW 0x5687
56
57/* active pixel array size */
58#define OV5642_SENSOR_SIZE_X 2592
59#define OV5642_SENSOR_SIZE_Y 1944
48 60
49/* 61/*
50 * define standard resolution. 62 * About OV5642 resolution, cropping and binning:
51 * Works currently only for up to 720 lines 63 * This sensor supports it all, at least in the feature description.
52 * eg. 320x240, 640x480, 800x600, 1280x720, 2048x720 64 * Unfortunately, no combination of appropriate registers settings could make
65 * the chip work the intended way. As it works with predefined register lists,
66 * some undocumented registers are presumably changed there to achieve their
67 * goals.
68 * This driver currently only works for resolutions up to 720 lines with a
69 * 1:1 scale. Hopefully these restrictions will be removed in the future.
53 */ 70 */
71#define OV5642_MAX_WIDTH OV5642_SENSOR_SIZE_X
72#define OV5642_MAX_HEIGHT 720
54 73
55#define OV5642_WIDTH 1280 74/* default sizes */
56#define OV5642_HEIGHT 720 75#define OV5642_DEFAULT_WIDTH 1280
57#define OV5642_TOTAL_WIDTH 3200 76#define OV5642_DEFAULT_HEIGHT OV5642_MAX_HEIGHT
58#define OV5642_TOTAL_HEIGHT 2000 77
59#define OV5642_SENSOR_SIZE_X 2592 78/* minimum extra blanking */
60#define OV5642_SENSOR_SIZE_Y 1944 79#define BLANKING_EXTRA_WIDTH 500
80#define BLANKING_EXTRA_HEIGHT 20
81
82/*
83 * the sensor's autoexposure is buggy when setting total_height low.
84 * It tries to expose longer than 1 frame period without taking care of it
85 * and this leads to weird output. So we set 1000 lines as minimum.
86 */
87#define BLANKING_MIN_HEIGHT 1000
61 88
62struct regval_list { 89struct regval_list {
63 u16 reg_num; 90 u16 reg_num;
@@ -582,6 +609,11 @@ struct ov5642_datafmt {
582struct ov5642 { 609struct ov5642 {
583 struct v4l2_subdev subdev; 610 struct v4l2_subdev subdev;
584 const struct ov5642_datafmt *fmt; 611 const struct ov5642_datafmt *fmt;
612 struct v4l2_rect crop_rect;
613
614 /* blanking information */
615 int total_width;
616 int total_height;
585}; 617};
586 618
587static const struct ov5642_datafmt ov5642_colour_fmts[] = { 619static const struct ov5642_datafmt ov5642_colour_fmts[] = {
@@ -642,6 +674,21 @@ static int reg_write(struct i2c_client *client, u16 reg, u8 val)
642 674
643 return 0; 675 return 0;
644} 676}
677
678/*
679 * convenience function to write 16 bit register values that are split up
680 * into two consecutive high and low parts
681 */
682static int reg_write16(struct i2c_client *client, u16 reg, u16 val16)
683{
684 int ret;
685
686 ret = reg_write(client, reg, val16 >> 8);
687 if (ret)
688 return ret;
689 return reg_write(client, reg + 1, val16 & 0x00ff);
690}
691
645#ifdef CONFIG_VIDEO_ADV_DEBUG 692#ifdef CONFIG_VIDEO_ADV_DEBUG
646static int ov5642_get_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg) 693static int ov5642_get_register(struct v4l2_subdev *sd, struct v4l2_dbg_register *reg)
647{ 694{
@@ -685,58 +732,55 @@ static int ov5642_write_array(struct i2c_client *client,
685 return 0; 732 return 0;
686} 733}
687 734
688static int ov5642_set_resolution(struct i2c_client *client) 735static int ov5642_set_resolution(struct v4l2_subdev *sd)
689{ 736{
737 struct i2c_client *client = v4l2_get_subdevdata(sd);
738 struct ov5642 *priv = to_ov5642(client);
739 int width = priv->crop_rect.width;
740 int height = priv->crop_rect.height;
741 int total_width = priv->total_width;
742 int total_height = priv->total_height;
743 int start_x = (OV5642_SENSOR_SIZE_X - width) / 2;
744 int start_y = (OV5642_SENSOR_SIZE_Y - height) / 2;
690 int ret; 745 int ret;
691 u8 start_x_high = ((OV5642_SENSOR_SIZE_X - OV5642_WIDTH) / 2) >> 8;
692 u8 start_x_low = ((OV5642_SENSOR_SIZE_X - OV5642_WIDTH) / 2) & 0xff;
693 u8 start_y_high = ((OV5642_SENSOR_SIZE_Y - OV5642_HEIGHT) / 2) >> 8;
694 u8 start_y_low = ((OV5642_SENSOR_SIZE_Y - OV5642_HEIGHT) / 2) & 0xff;
695
696 u8 width_high = OV5642_WIDTH >> 8;
697 u8 width_low = OV5642_WIDTH & 0xff;
698 u8 height_high = OV5642_HEIGHT >> 8;
699 u8 height_low = OV5642_HEIGHT & 0xff;
700
701 u8 total_width_high = OV5642_TOTAL_WIDTH >> 8;
702 u8 total_width_low = OV5642_TOTAL_WIDTH & 0xff;
703 u8 total_height_high = OV5642_TOTAL_HEIGHT >> 8;
704 u8 total_height_low = OV5642_TOTAL_HEIGHT & 0xff;
705
706 ret = reg_write(client, REG_WINDOW_START_X_HIGH, start_x_high);
707 if (!ret)
708 ret = reg_write(client, REG_WINDOW_START_X_LOW, start_x_low);
709 if (!ret)
710 ret = reg_write(client, REG_WINDOW_START_Y_HIGH, start_y_high);
711 if (!ret)
712 ret = reg_write(client, REG_WINDOW_START_Y_LOW, start_y_low);
713 746
747 /*
748 * This should set the starting point for cropping.
749 * Doesn't work so far.
750 */
751 ret = reg_write16(client, REG_WINDOW_START_X_HIGH, start_x);
714 if (!ret) 752 if (!ret)
715 ret = reg_write(client, REG_WINDOW_WIDTH_HIGH, width_high); 753 ret = reg_write16(client, REG_WINDOW_START_Y_HIGH, start_y);
716 if (!ret) 754 if (!ret) {
717 ret = reg_write(client, REG_WINDOW_WIDTH_LOW , width_low); 755 priv->crop_rect.left = start_x;
718 if (!ret) 756 priv->crop_rect.top = start_y;
719 ret = reg_write(client, REG_WINDOW_HEIGHT_HIGH, height_high); 757 }
720 if (!ret)
721 ret = reg_write(client, REG_WINDOW_HEIGHT_LOW, height_low);
722 758
723 if (!ret) 759 if (!ret)
724 ret = reg_write(client, REG_OUT_WIDTH_HIGH, width_high); 760 ret = reg_write16(client, REG_WINDOW_WIDTH_HIGH, width);
725 if (!ret) 761 if (!ret)
726 ret = reg_write(client, REG_OUT_WIDTH_LOW , width_low); 762 ret = reg_write16(client, REG_WINDOW_HEIGHT_HIGH, height);
727 if (!ret) 763 if (ret)
728 ret = reg_write(client, REG_OUT_HEIGHT_HIGH, height_high); 764 return ret;
765 priv->crop_rect.width = width;
766 priv->crop_rect.height = height;
767
768 /* Set the output window size. Only 1:1 scale is supported so far. */
769 ret = reg_write16(client, REG_OUT_WIDTH_HIGH, width);
729 if (!ret) 770 if (!ret)
730 ret = reg_write(client, REG_OUT_HEIGHT_LOW, height_low); 771 ret = reg_write16(client, REG_OUT_HEIGHT_HIGH, height);
731 772
773 /* Total width = output size + blanking */
732 if (!ret) 774 if (!ret)
733 ret = reg_write(client, REG_OUT_TOTAL_WIDTH_HIGH, total_width_high); 775 ret = reg_write16(client, REG_OUT_TOTAL_WIDTH_HIGH, total_width);
734 if (!ret) 776 if (!ret)
735 ret = reg_write(client, REG_OUT_TOTAL_WIDTH_LOW, total_width_low); 777 ret = reg_write16(client, REG_OUT_TOTAL_HEIGHT_HIGH, total_height);
778
779 /* Sets the window for AWB calculations */
736 if (!ret) 780 if (!ret)
737 ret = reg_write(client, REG_OUT_TOTAL_HEIGHT_HIGH, total_height_high); 781 ret = reg_write16(client, REG_AVG_WINDOW_END_X_HIGH, width);
738 if (!ret) 782 if (!ret)
739 ret = reg_write(client, REG_OUT_TOTAL_HEIGHT_LOW, total_height_low); 783 ret = reg_write16(client, REG_AVG_WINDOW_END_Y_HIGH, height);
740 784
741 return ret; 785 return ret;
742} 786}
@@ -744,18 +788,18 @@ static int ov5642_set_resolution(struct i2c_client *client)
744static int ov5642_try_fmt(struct v4l2_subdev *sd, 788static int ov5642_try_fmt(struct v4l2_subdev *sd,
745 struct v4l2_mbus_framefmt *mf) 789 struct v4l2_mbus_framefmt *mf)
746{ 790{
791 struct i2c_client *client = v4l2_get_subdevdata(sd);
792 struct ov5642 *priv = to_ov5642(client);
747 const struct ov5642_datafmt *fmt = ov5642_find_datafmt(mf->code); 793 const struct ov5642_datafmt *fmt = ov5642_find_datafmt(mf->code);
748 794
749 dev_dbg(sd->v4l2_dev->dev, "%s(%u) width: %u heigth: %u\n", 795 mf->width = priv->crop_rect.width;
750 __func__, mf->code, mf->width, mf->height); 796 mf->height = priv->crop_rect.height;
751 797
752 if (!fmt) { 798 if (!fmt) {
753 mf->code = ov5642_colour_fmts[0].code; 799 mf->code = ov5642_colour_fmts[0].code;
754 mf->colorspace = ov5642_colour_fmts[0].colorspace; 800 mf->colorspace = ov5642_colour_fmts[0].colorspace;
755 } 801 }
756 802
757 mf->width = OV5642_WIDTH;
758 mf->height = OV5642_HEIGHT;
759 mf->field = V4L2_FIELD_NONE; 803 mf->field = V4L2_FIELD_NONE;
760 804
761 return 0; 805 return 0;
@@ -767,20 +811,13 @@ static int ov5642_s_fmt(struct v4l2_subdev *sd,
767 struct i2c_client *client = v4l2_get_subdevdata(sd); 811 struct i2c_client *client = v4l2_get_subdevdata(sd);
768 struct ov5642 *priv = to_ov5642(client); 812 struct ov5642 *priv = to_ov5642(client);
769 813
770 dev_dbg(sd->v4l2_dev->dev, "%s(%u)\n", __func__, mf->code);
771
772 /* MIPI CSI could have changed the format, double-check */ 814 /* MIPI CSI could have changed the format, double-check */
773 if (!ov5642_find_datafmt(mf->code)) 815 if (!ov5642_find_datafmt(mf->code))
774 return -EINVAL; 816 return -EINVAL;
775 817
776 ov5642_try_fmt(sd, mf); 818 ov5642_try_fmt(sd, mf);
777
778 priv->fmt = ov5642_find_datafmt(mf->code); 819 priv->fmt = ov5642_find_datafmt(mf->code);
779 820
780 ov5642_write_array(client, ov5642_default_regs_init);
781 ov5642_set_resolution(client);
782 ov5642_write_array(client, ov5642_default_regs_finalise);
783
784 return 0; 821 return 0;
785} 822}
786 823
@@ -794,8 +831,8 @@ static int ov5642_g_fmt(struct v4l2_subdev *sd,
794 831
795 mf->code = fmt->code; 832 mf->code = fmt->code;
796 mf->colorspace = fmt->colorspace; 833 mf->colorspace = fmt->colorspace;
797 mf->width = OV5642_WIDTH; 834 mf->width = priv->crop_rect.width;
798 mf->height = OV5642_HEIGHT; 835 mf->height = priv->crop_rect.height;
799 mf->field = V4L2_FIELD_NONE; 836 mf->field = V4L2_FIELD_NONE;
800 837
801 return 0; 838 return 0;
@@ -828,15 +865,44 @@ static int ov5642_g_chip_ident(struct v4l2_subdev *sd,
828 return 0; 865 return 0;
829} 866}
830 867
868static int ov5642_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
869{
870 struct i2c_client *client = v4l2_get_subdevdata(sd);
871 struct ov5642 *priv = to_ov5642(client);
872 struct v4l2_rect *rect = &a->c;
873 int ret;
874
875 v4l_bound_align_image(&rect->width, 48, OV5642_MAX_WIDTH, 1,
876 &rect->height, 32, OV5642_MAX_HEIGHT, 1, 0);
877
878 priv->crop_rect.width = rect->width;
879 priv->crop_rect.height = rect->height;
880 priv->total_width = rect->width + BLANKING_EXTRA_WIDTH;
881 priv->total_height = max_t(int, rect->height +
882 BLANKING_EXTRA_HEIGHT,
883 BLANKING_MIN_HEIGHT);
884 priv->crop_rect.width = rect->width;
885 priv->crop_rect.height = rect->height;
886
887 ret = ov5642_write_array(client, ov5642_default_regs_init);
888 if (!ret)
889 ret = ov5642_set_resolution(sd);
890 if (!ret)
891 ret = ov5642_write_array(client, ov5642_default_regs_finalise);
892
893 return ret;
894}
895
831static int ov5642_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) 896static int ov5642_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
832{ 897{
898 struct i2c_client *client = v4l2_get_subdevdata(sd);
899 struct ov5642 *priv = to_ov5642(client);
833 struct v4l2_rect *rect = &a->c; 900 struct v4l2_rect *rect = &a->c;
834 901
835 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 902 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
836 rect->top = 0; 903 return -EINVAL;
837 rect->left = 0; 904
838 rect->width = OV5642_WIDTH; 905 *rect = priv->crop_rect;
839 rect->height = OV5642_HEIGHT;
840 906
841 return 0; 907 return 0;
842} 908}
@@ -845,8 +911,8 @@ static int ov5642_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a)
845{ 911{
846 a->bounds.left = 0; 912 a->bounds.left = 0;
847 a->bounds.top = 0; 913 a->bounds.top = 0;
848 a->bounds.width = OV5642_WIDTH; 914 a->bounds.width = OV5642_MAX_WIDTH;
849 a->bounds.height = OV5642_HEIGHT; 915 a->bounds.height = OV5642_MAX_HEIGHT;
850 a->defrect = a->bounds; 916 a->defrect = a->bounds;
851 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 917 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
852 a->pixelaspect.numerator = 1; 918 a->pixelaspect.numerator = 1;
@@ -855,16 +921,47 @@ static int ov5642_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a)
855 return 0; 921 return 0;
856} 922}
857 923
924static int ov5642_g_mbus_config(struct v4l2_subdev *sd,
925 struct v4l2_mbus_config *cfg)
926{
927 cfg->type = V4L2_MBUS_CSI2;
928 cfg->flags = V4L2_MBUS_CSI2_2_LANE | V4L2_MBUS_CSI2_CHANNEL_0 |
929 V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
930
931 return 0;
932}
933
934static int ov5642_s_power(struct v4l2_subdev *sd, int on)
935{
936 struct i2c_client *client;
937 int ret;
938
939 if (!on)
940 return 0;
941
942 client = v4l2_get_subdevdata(sd);
943 ret = ov5642_write_array(client, ov5642_default_regs_init);
944 if (!ret)
945 ret = ov5642_set_resolution(sd);
946 if (!ret)
947 ret = ov5642_write_array(client, ov5642_default_regs_finalise);
948
949 return ret;
950}
951
858static struct v4l2_subdev_video_ops ov5642_subdev_video_ops = { 952static struct v4l2_subdev_video_ops ov5642_subdev_video_ops = {
859 .s_mbus_fmt = ov5642_s_fmt, 953 .s_mbus_fmt = ov5642_s_fmt,
860 .g_mbus_fmt = ov5642_g_fmt, 954 .g_mbus_fmt = ov5642_g_fmt,
861 .try_mbus_fmt = ov5642_try_fmt, 955 .try_mbus_fmt = ov5642_try_fmt,
862 .enum_mbus_fmt = ov5642_enum_fmt, 956 .enum_mbus_fmt = ov5642_enum_fmt,
957 .s_crop = ov5642_s_crop,
863 .g_crop = ov5642_g_crop, 958 .g_crop = ov5642_g_crop,
864 .cropcap = ov5642_cropcap, 959 .cropcap = ov5642_cropcap,
960 .g_mbus_config = ov5642_g_mbus_config,
865}; 961};
866 962
867static struct v4l2_subdev_core_ops ov5642_subdev_core_ops = { 963static struct v4l2_subdev_core_ops ov5642_subdev_core_ops = {
964 .s_power = ov5642_s_power,
868 .g_chip_ident = ov5642_g_chip_ident, 965 .g_chip_ident = ov5642_g_chip_ident,
869#ifdef CONFIG_VIDEO_ADV_DEBUG 966#ifdef CONFIG_VIDEO_ADV_DEBUG
870 .g_register = ov5642_get_register, 967 .g_register = ov5642_get_register,
@@ -877,28 +974,7 @@ static struct v4l2_subdev_ops ov5642_subdev_ops = {
877 .video = &ov5642_subdev_video_ops, 974 .video = &ov5642_subdev_video_ops,
878}; 975};
879 976
880/* 977static int ov5642_video_probe(struct i2c_client *client)
881 * We have to provide soc-camera operations, but we don't have anything to say
882 * there. The MIPI CSI2 driver will provide .query_bus_param and .set_bus_param
883 */
884static unsigned long soc_ov5642_query_bus_param(struct soc_camera_device *icd)
885{
886 return 0;
887}
888
889static int soc_ov5642_set_bus_param(struct soc_camera_device *icd,
890 unsigned long flags)
891{
892 return -EINVAL;
893}
894
895static struct soc_camera_ops soc_ov5642_ops = {
896 .query_bus_param = soc_ov5642_query_bus_param,
897 .set_bus_param = soc_ov5642_set_bus_param,
898};
899
900static int ov5642_video_probe(struct soc_camera_device *icd,
901 struct i2c_client *client)
902{ 978{
903 int ret; 979 int ret;
904 u8 id_high, id_low; 980 u8 id_high, id_low;
@@ -929,16 +1005,9 @@ static int ov5642_probe(struct i2c_client *client,
929 const struct i2c_device_id *did) 1005 const struct i2c_device_id *did)
930{ 1006{
931 struct ov5642 *priv; 1007 struct ov5642 *priv;
932 struct soc_camera_device *icd = client->dev.platform_data; 1008 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
933 struct soc_camera_link *icl;
934 int ret; 1009 int ret;
935 1010
936 if (!icd) {
937 dev_err(&client->dev, "OV5642: missing soc-camera data!\n");
938 return -EINVAL;
939 }
940
941 icl = to_soc_camera_link(icd);
942 if (!icl) { 1011 if (!icl) {
943 dev_err(&client->dev, "OV5642: missing platform data!\n"); 1012 dev_err(&client->dev, "OV5642: missing platform data!\n");
944 return -EINVAL; 1013 return -EINVAL;
@@ -950,17 +1019,24 @@ static int ov5642_probe(struct i2c_client *client,
950 1019
951 v4l2_i2c_subdev_init(&priv->subdev, client, &ov5642_subdev_ops); 1020 v4l2_i2c_subdev_init(&priv->subdev, client, &ov5642_subdev_ops);
952 1021
953 icd->ops = &soc_ov5642_ops; 1022 priv->fmt = &ov5642_colour_fmts[0];
954 priv->fmt = &ov5642_colour_fmts[0]; 1023
1024 priv->crop_rect.width = OV5642_DEFAULT_WIDTH;
1025 priv->crop_rect.height = OV5642_DEFAULT_HEIGHT;
1026 priv->crop_rect.left = (OV5642_MAX_WIDTH - OV5642_DEFAULT_WIDTH) / 2;
1027 priv->crop_rect.top = (OV5642_MAX_HEIGHT - OV5642_DEFAULT_HEIGHT) / 2;
1028 priv->crop_rect.width = OV5642_DEFAULT_WIDTH;
1029 priv->crop_rect.height = OV5642_DEFAULT_HEIGHT;
1030 priv->total_width = OV5642_DEFAULT_WIDTH + BLANKING_EXTRA_WIDTH;
1031 priv->total_height = BLANKING_MIN_HEIGHT;
955 1032
956 ret = ov5642_video_probe(icd, client); 1033 ret = ov5642_video_probe(client);
957 if (ret < 0) 1034 if (ret < 0)
958 goto error; 1035 goto error;
959 1036
960 return 0; 1037 return 0;
961 1038
962error: 1039error:
963 icd->ops = NULL;
964 kfree(priv); 1040 kfree(priv);
965 return ret; 1041 return ret;
966} 1042}
@@ -968,10 +1044,8 @@ error:
968static int ov5642_remove(struct i2c_client *client) 1044static int ov5642_remove(struct i2c_client *client)
969{ 1045{
970 struct ov5642 *priv = to_ov5642(client); 1046 struct ov5642 *priv = to_ov5642(client);
971 struct soc_camera_device *icd = client->dev.platform_data; 1047 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
972 struct soc_camera_link *icl = to_soc_camera_link(icd);
973 1048
974 icd->ops = NULL;
975 if (icl->free_bus) 1049 if (icl->free_bus)
976 icl->free_bus(icl); 1050 icl->free_bus(icl);
977 kfree(priv); 1051 kfree(priv);
diff --git a/drivers/media/video/ov6650.c b/drivers/media/video/ov6650.c
index 456d9ad9ae5a..9f2d26b1d4cb 100644
--- a/drivers/media/video/ov6650.c
+++ b/drivers/media/video/ov6650.c
@@ -28,10 +28,12 @@
28#include <linux/delay.h> 28#include <linux/delay.h>
29#include <linux/i2c.h> 29#include <linux/i2c.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/v4l2-mediabus.h>
32#include <linux/module.h>
31 33
32#include <media/soc_camera.h> 34#include <media/soc_camera.h>
33#include <media/v4l2-chip-ident.h> 35#include <media/v4l2-chip-ident.h>
34 36#include <media/v4l2-ctrls.h>
35 37
36/* Register definitions */ 38/* Register definitions */
37#define REG_GAIN 0x00 /* range 00 - 3F */ 39#define REG_GAIN 0x00 /* range 00 - 3F */
@@ -177,20 +179,23 @@ struct ov6650_reg {
177 179
178struct ov6650 { 180struct ov6650 {
179 struct v4l2_subdev subdev; 181 struct v4l2_subdev subdev;
180 182 struct v4l2_ctrl_handler hdl;
181 int gain; 183 struct {
182 int blue; 184 /* exposure/autoexposure cluster */
183 int red; 185 struct v4l2_ctrl *autoexposure;
184 int saturation; 186 struct v4l2_ctrl *exposure;
185 int hue; 187 };
186 int brightness; 188 struct {
187 int exposure; 189 /* gain/autogain cluster */
188 int gamma; 190 struct v4l2_ctrl *autogain;
189 int aec; 191 struct v4l2_ctrl *gain;
190 bool vflip; 192 };
191 bool hflip; 193 struct {
192 bool awb; 194 /* blue/red/autowhitebalance cluster */
193 bool agc; 195 struct v4l2_ctrl *autowb;
196 struct v4l2_ctrl *blue;
197 struct v4l2_ctrl *red;
198 };
194 bool half_scale; /* scale down output by 2 */ 199 bool half_scale; /* scale down output by 2 */
195 struct v4l2_rect rect; /* sensor cropping window */ 200 struct v4l2_rect rect; /* sensor cropping window */
196 unsigned long pclk_limit; /* from host */ 201 unsigned long pclk_limit; /* from host */
@@ -210,126 +215,6 @@ static enum v4l2_mbus_pixelcode ov6650_codes[] = {
210 V4L2_MBUS_FMT_Y8_1X8, 215 V4L2_MBUS_FMT_Y8_1X8,
211}; 216};
212 217
213static const struct v4l2_queryctrl ov6650_controls[] = {
214 {
215 .id = V4L2_CID_AUTOGAIN,
216 .type = V4L2_CTRL_TYPE_BOOLEAN,
217 .name = "AGC",
218 .minimum = 0,
219 .maximum = 1,
220 .step = 1,
221 .default_value = 1,
222 },
223 {
224 .id = V4L2_CID_GAIN,
225 .type = V4L2_CTRL_TYPE_INTEGER,
226 .name = "Gain",
227 .minimum = 0,
228 .maximum = 0x3f,
229 .step = 1,
230 .default_value = DEF_GAIN,
231 },
232 {
233 .id = V4L2_CID_AUTO_WHITE_BALANCE,
234 .type = V4L2_CTRL_TYPE_BOOLEAN,
235 .name = "AWB",
236 .minimum = 0,
237 .maximum = 1,
238 .step = 1,
239 .default_value = 1,
240 },
241 {
242 .id = V4L2_CID_BLUE_BALANCE,
243 .type = V4L2_CTRL_TYPE_INTEGER,
244 .name = "Blue",
245 .minimum = 0,
246 .maximum = 0xff,
247 .step = 1,
248 .default_value = DEF_BLUE,
249 },
250 {
251 .id = V4L2_CID_RED_BALANCE,
252 .type = V4L2_CTRL_TYPE_INTEGER,
253 .name = "Red",
254 .minimum = 0,
255 .maximum = 0xff,
256 .step = 1,
257 .default_value = DEF_RED,
258 },
259 {
260 .id = V4L2_CID_SATURATION,
261 .type = V4L2_CTRL_TYPE_INTEGER,
262 .name = "Saturation",
263 .minimum = 0,
264 .maximum = 0xf,
265 .step = 1,
266 .default_value = 0x8,
267 },
268 {
269 .id = V4L2_CID_HUE,
270 .type = V4L2_CTRL_TYPE_INTEGER,
271 .name = "Hue",
272 .minimum = 0,
273 .maximum = HUE_MASK,
274 .step = 1,
275 .default_value = DEF_HUE,
276 },
277 {
278 .id = V4L2_CID_BRIGHTNESS,
279 .type = V4L2_CTRL_TYPE_INTEGER,
280 .name = "Brightness",
281 .minimum = 0,
282 .maximum = 0xff,
283 .step = 1,
284 .default_value = 0x80,
285 },
286 {
287 .id = V4L2_CID_EXPOSURE_AUTO,
288 .type = V4L2_CTRL_TYPE_INTEGER,
289 .name = "AEC",
290 .minimum = 0,
291 .maximum = 3,
292 .step = 1,
293 .default_value = 0,
294 },
295 {
296 .id = V4L2_CID_EXPOSURE,
297 .type = V4L2_CTRL_TYPE_INTEGER,
298 .name = "Exposure",
299 .minimum = 0,
300 .maximum = 0xff,
301 .step = 1,
302 .default_value = DEF_AECH,
303 },
304 {
305 .id = V4L2_CID_GAMMA,
306 .type = V4L2_CTRL_TYPE_INTEGER,
307 .name = "Gamma",
308 .minimum = 0,
309 .maximum = 0xff,
310 .step = 1,
311 .default_value = 0x12,
312 },
313 {
314 .id = V4L2_CID_VFLIP,
315 .type = V4L2_CTRL_TYPE_BOOLEAN,
316 .name = "Flip Vertically",
317 .minimum = 0,
318 .maximum = 1,
319 .step = 1,
320 .default_value = 0,
321 },
322 {
323 .id = V4L2_CID_HFLIP,
324 .type = V4L2_CTRL_TYPE_BOOLEAN,
325 .name = "Flip Horizontally",
326 .minimum = 0,
327 .maximum = 1,
328 .step = 1,
329 .default_value = 0,
330 },
331};
332
333/* read a register */ 218/* read a register */
334static int ov6650_reg_read(struct i2c_client *client, u8 reg, u8 *val) 219static int ov6650_reg_read(struct i2c_client *client, u8 reg, u8 *val)
335{ 220{
@@ -419,213 +304,90 @@ static int ov6650_s_stream(struct v4l2_subdev *sd, int enable)
419 return 0; 304 return 0;
420} 305}
421 306
422/* Alter bus settings on camera side */
423static int ov6650_set_bus_param(struct soc_camera_device *icd,
424 unsigned long flags)
425{
426 struct soc_camera_link *icl = to_soc_camera_link(icd);
427 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
428 int ret;
429
430 flags = soc_camera_apply_sensor_flags(icl, flags);
431
432 if (flags & SOCAM_PCLK_SAMPLE_RISING)
433 ret = ov6650_reg_rmw(client, REG_COMJ, COMJ_PCLK_RISING, 0);
434 else
435 ret = ov6650_reg_rmw(client, REG_COMJ, 0, COMJ_PCLK_RISING);
436 if (ret)
437 return ret;
438
439 if (flags & SOCAM_HSYNC_ACTIVE_LOW)
440 ret = ov6650_reg_rmw(client, REG_COMF, COMF_HREF_LOW, 0);
441 else
442 ret = ov6650_reg_rmw(client, REG_COMF, 0, COMF_HREF_LOW);
443 if (ret)
444 return ret;
445
446 if (flags & SOCAM_VSYNC_ACTIVE_HIGH)
447 ret = ov6650_reg_rmw(client, REG_COMJ, COMJ_VSYNC_HIGH, 0);
448 else
449 ret = ov6650_reg_rmw(client, REG_COMJ, 0, COMJ_VSYNC_HIGH);
450
451 return ret;
452}
453
454/* Request bus settings on camera side */
455static unsigned long ov6650_query_bus_param(struct soc_camera_device *icd)
456{
457 struct soc_camera_link *icl = to_soc_camera_link(icd);
458
459 unsigned long flags = SOCAM_MASTER |
460 SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING |
461 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW |
462 SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |
463 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8;
464
465 return soc_camera_apply_sensor_flags(icl, flags);
466}
467
468/* Get status of additional camera capabilities */ 307/* Get status of additional camera capabilities */
469static int ov6650_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 308static int ov6550_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
470{ 309{
310 struct ov6650 *priv = container_of(ctrl->handler, struct ov6650, hdl);
311 struct v4l2_subdev *sd = &priv->subdev;
471 struct i2c_client *client = v4l2_get_subdevdata(sd); 312 struct i2c_client *client = v4l2_get_subdevdata(sd);
472 struct ov6650 *priv = to_ov6650(client); 313 uint8_t reg, reg2;
473 uint8_t reg; 314 int ret;
474 int ret = 0;
475 315
476 switch (ctrl->id) { 316 switch (ctrl->id) {
477 case V4L2_CID_AUTOGAIN: 317 case V4L2_CID_AUTOGAIN:
478 ctrl->value = priv->agc; 318 ret = ov6650_reg_read(client, REG_GAIN, &reg);
479 break; 319 if (!ret)
480 case V4L2_CID_GAIN: 320 priv->gain->val = reg;
481 if (priv->agc) { 321 return ret;
482 ret = ov6650_reg_read(client, REG_GAIN, &reg);
483 ctrl->value = reg;
484 } else {
485 ctrl->value = priv->gain;
486 }
487 break;
488 case V4L2_CID_AUTO_WHITE_BALANCE: 322 case V4L2_CID_AUTO_WHITE_BALANCE:
489 ctrl->value = priv->awb; 323 ret = ov6650_reg_read(client, REG_BLUE, &reg);
490 break; 324 if (!ret)
491 case V4L2_CID_BLUE_BALANCE: 325 ret = ov6650_reg_read(client, REG_RED, &reg2);
492 if (priv->awb) { 326 if (!ret) {
493 ret = ov6650_reg_read(client, REG_BLUE, &reg); 327 priv->blue->val = reg;
494 ctrl->value = reg; 328 priv->red->val = reg2;
495 } else {
496 ctrl->value = priv->blue;
497 }
498 break;
499 case V4L2_CID_RED_BALANCE:
500 if (priv->awb) {
501 ret = ov6650_reg_read(client, REG_RED, &reg);
502 ctrl->value = reg;
503 } else {
504 ctrl->value = priv->red;
505 } 329 }
506 break; 330 return ret;
507 case V4L2_CID_SATURATION:
508 ctrl->value = priv->saturation;
509 break;
510 case V4L2_CID_HUE:
511 ctrl->value = priv->hue;
512 break;
513 case V4L2_CID_BRIGHTNESS:
514 ctrl->value = priv->brightness;
515 break;
516 case V4L2_CID_EXPOSURE_AUTO: 331 case V4L2_CID_EXPOSURE_AUTO:
517 ctrl->value = priv->aec; 332 ret = ov6650_reg_read(client, REG_AECH, &reg);
518 break; 333 if (!ret)
519 case V4L2_CID_EXPOSURE: 334 priv->exposure->val = reg;
520 if (priv->aec) { 335 return ret;
521 ret = ov6650_reg_read(client, REG_AECH, &reg);
522 ctrl->value = reg;
523 } else {
524 ctrl->value = priv->exposure;
525 }
526 break;
527 case V4L2_CID_GAMMA:
528 ctrl->value = priv->gamma;
529 break;
530 case V4L2_CID_VFLIP:
531 ctrl->value = priv->vflip;
532 break;
533 case V4L2_CID_HFLIP:
534 ctrl->value = priv->hflip;
535 break;
536 } 336 }
537 return ret; 337 return -EINVAL;
538} 338}
539 339
540/* Set status of additional camera capabilities */ 340/* Set status of additional camera capabilities */
541static int ov6650_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 341static int ov6550_s_ctrl(struct v4l2_ctrl *ctrl)
542{ 342{
343 struct ov6650 *priv = container_of(ctrl->handler, struct ov6650, hdl);
344 struct v4l2_subdev *sd = &priv->subdev;
543 struct i2c_client *client = v4l2_get_subdevdata(sd); 345 struct i2c_client *client = v4l2_get_subdevdata(sd);
544 struct ov6650 *priv = to_ov6650(client); 346 int ret;
545 int ret = 0;
546 347
547 switch (ctrl->id) { 348 switch (ctrl->id) {
548 case V4L2_CID_AUTOGAIN: 349 case V4L2_CID_AUTOGAIN:
549 ret = ov6650_reg_rmw(client, REG_COMB, 350 ret = ov6650_reg_rmw(client, REG_COMB,
550 ctrl->value ? COMB_AGC : 0, COMB_AGC); 351 ctrl->val ? COMB_AGC : 0, COMB_AGC);
551 if (!ret) 352 if (!ret && !ctrl->val)
552 priv->agc = ctrl->value; 353 ret = ov6650_reg_write(client, REG_GAIN, priv->gain->val);
553 break; 354 return ret;
554 case V4L2_CID_GAIN:
555 ret = ov6650_reg_write(client, REG_GAIN, ctrl->value);
556 if (!ret)
557 priv->gain = ctrl->value;
558 break;
559 case V4L2_CID_AUTO_WHITE_BALANCE: 355 case V4L2_CID_AUTO_WHITE_BALANCE:
560 ret = ov6650_reg_rmw(client, REG_COMB, 356 ret = ov6650_reg_rmw(client, REG_COMB,
561 ctrl->value ? COMB_AWB : 0, COMB_AWB); 357 ctrl->val ? COMB_AWB : 0, COMB_AWB);
562 if (!ret) 358 if (!ret && !ctrl->val) {
563 priv->awb = ctrl->value; 359 ret = ov6650_reg_write(client, REG_BLUE, priv->blue->val);
564 break; 360 if (!ret)
565 case V4L2_CID_BLUE_BALANCE: 361 ret = ov6650_reg_write(client, REG_RED,
566 ret = ov6650_reg_write(client, REG_BLUE, ctrl->value); 362 priv->red->val);
567 if (!ret) 363 }
568 priv->blue = ctrl->value; 364 return ret;
569 break;
570 case V4L2_CID_RED_BALANCE:
571 ret = ov6650_reg_write(client, REG_RED, ctrl->value);
572 if (!ret)
573 priv->red = ctrl->value;
574 break;
575 case V4L2_CID_SATURATION: 365 case V4L2_CID_SATURATION:
576 ret = ov6650_reg_rmw(client, REG_SAT, SET_SAT(ctrl->value), 366 return ov6650_reg_rmw(client, REG_SAT, SET_SAT(ctrl->val),
577 SAT_MASK); 367 SAT_MASK);
578 if (!ret)
579 priv->saturation = ctrl->value;
580 break;
581 case V4L2_CID_HUE: 368 case V4L2_CID_HUE:
582 ret = ov6650_reg_rmw(client, REG_HUE, SET_HUE(ctrl->value), 369 return ov6650_reg_rmw(client, REG_HUE, SET_HUE(ctrl->val),
583 HUE_MASK); 370 HUE_MASK);
584 if (!ret)
585 priv->hue = ctrl->value;
586 break;
587 case V4L2_CID_BRIGHTNESS: 371 case V4L2_CID_BRIGHTNESS:
588 ret = ov6650_reg_write(client, REG_BRT, ctrl->value); 372 return ov6650_reg_write(client, REG_BRT, ctrl->val);
589 if (!ret)
590 priv->brightness = ctrl->value;
591 break;
592 case V4L2_CID_EXPOSURE_AUTO: 373 case V4L2_CID_EXPOSURE_AUTO:
593 switch (ctrl->value) { 374 ret = ov6650_reg_rmw(client, REG_COMB, ctrl->val ==
594 case V4L2_EXPOSURE_AUTO: 375 V4L2_EXPOSURE_AUTO ? COMB_AEC : 0, COMB_AEC);
595 ret = ov6650_reg_rmw(client, REG_COMB, COMB_AEC, 0); 376 if (!ret && ctrl->val == V4L2_EXPOSURE_MANUAL)
596 break; 377 ret = ov6650_reg_write(client, REG_AECH,
597 default: 378 priv->exposure->val);
598 ret = ov6650_reg_rmw(client, REG_COMB, 0, COMB_AEC); 379 return ret;
599 break;
600 }
601 if (!ret)
602 priv->aec = ctrl->value;
603 break;
604 case V4L2_CID_EXPOSURE:
605 ret = ov6650_reg_write(client, REG_AECH, ctrl->value);
606 if (!ret)
607 priv->exposure = ctrl->value;
608 break;
609 case V4L2_CID_GAMMA: 380 case V4L2_CID_GAMMA:
610 ret = ov6650_reg_write(client, REG_GAM1, ctrl->value); 381 return ov6650_reg_write(client, REG_GAM1, ctrl->val);
611 if (!ret)
612 priv->gamma = ctrl->value;
613 break;
614 case V4L2_CID_VFLIP: 382 case V4L2_CID_VFLIP:
615 ret = ov6650_reg_rmw(client, REG_COMB, 383 return ov6650_reg_rmw(client, REG_COMB,
616 ctrl->value ? COMB_FLIP_V : 0, COMB_FLIP_V); 384 ctrl->val ? COMB_FLIP_V : 0, COMB_FLIP_V);
617 if (!ret)
618 priv->vflip = ctrl->value;
619 break;
620 case V4L2_CID_HFLIP: 385 case V4L2_CID_HFLIP:
621 ret = ov6650_reg_rmw(client, REG_COMB, 386 return ov6650_reg_rmw(client, REG_COMB,
622 ctrl->value ? COMB_FLIP_H : 0, COMB_FLIP_H); 387 ctrl->val ? COMB_FLIP_H : 0, COMB_FLIP_H);
623 if (!ret)
624 priv->hflip = ctrl->value;
625 break;
626 } 388 }
627 389
628 return ret; 390 return -EINVAL;
629} 391}
630 392
631/* Get chip identification */ 393/* Get chip identification */
@@ -778,7 +540,7 @@ static u8 to_clkrc(struct v4l2_fract *timeperframe,
778static int ov6650_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf) 540static int ov6650_s_fmt(struct v4l2_subdev *sd, struct v4l2_mbus_framefmt *mf)
779{ 541{
780 struct i2c_client *client = v4l2_get_subdevdata(sd); 542 struct i2c_client *client = v4l2_get_subdevdata(sd);
781 struct soc_camera_device *icd = client->dev.platform_data; 543 struct soc_camera_device *icd = (struct soc_camera_device *)sd->grp_id;
782 struct soc_camera_sense *sense = icd->sense; 544 struct soc_camera_sense *sense = icd->sense;
783 struct ov6650 *priv = to_ov6650(client); 545 struct ov6650 *priv = to_ov6650(client);
784 bool half_scale = !is_unscaled_ok(mf->width, mf->height, &priv->rect); 546 bool half_scale = !is_unscaled_ok(mf->width, mf->height, &priv->rect);
@@ -1057,8 +819,7 @@ static int ov6650_prog_dflt(struct i2c_client *client)
1057 return ret; 819 return ret;
1058} 820}
1059 821
1060static int ov6650_video_probe(struct soc_camera_device *icd, 822static int ov6650_video_probe(struct i2c_client *client)
1061 struct i2c_client *client)
1062{ 823{
1063 u8 pidh, pidl, midh, midl; 824 u8 pidh, pidl, midh, midl;
1064 int ret = 0; 825 int ret = 0;
@@ -1094,16 +855,12 @@ static int ov6650_video_probe(struct soc_camera_device *icd,
1094 return ret; 855 return ret;
1095} 856}
1096 857
1097static struct soc_camera_ops ov6650_ops = { 858static const struct v4l2_ctrl_ops ov6550_ctrl_ops = {
1098 .set_bus_param = ov6650_set_bus_param, 859 .g_volatile_ctrl = ov6550_g_volatile_ctrl,
1099 .query_bus_param = ov6650_query_bus_param, 860 .s_ctrl = ov6550_s_ctrl,
1100 .controls = ov6650_controls,
1101 .num_controls = ARRAY_SIZE(ov6650_controls),
1102}; 861};
1103 862
1104static struct v4l2_subdev_core_ops ov6650_core_ops = { 863static struct v4l2_subdev_core_ops ov6650_core_ops = {
1105 .g_ctrl = ov6650_g_ctrl,
1106 .s_ctrl = ov6650_s_ctrl,
1107 .g_chip_ident = ov6650_g_chip_ident, 864 .g_chip_ident = ov6650_g_chip_ident,
1108#ifdef CONFIG_VIDEO_ADV_DEBUG 865#ifdef CONFIG_VIDEO_ADV_DEBUG
1109 .g_register = ov6650_get_register, 866 .g_register = ov6650_get_register,
@@ -1111,6 +868,55 @@ static struct v4l2_subdev_core_ops ov6650_core_ops = {
1111#endif 868#endif
1112}; 869};
1113 870
871/* Request bus settings on camera side */
872static int ov6650_g_mbus_config(struct v4l2_subdev *sd,
873 struct v4l2_mbus_config *cfg)
874{
875 struct i2c_client *client = v4l2_get_subdevdata(sd);
876 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
877
878 cfg->flags = V4L2_MBUS_MASTER |
879 V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING |
880 V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_LOW |
881 V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW |
882 V4L2_MBUS_DATA_ACTIVE_HIGH;
883 cfg->type = V4L2_MBUS_PARALLEL;
884 cfg->flags = soc_camera_apply_board_flags(icl, cfg);
885
886 return 0;
887}
888
889/* Alter bus settings on camera side */
890static int ov6650_s_mbus_config(struct v4l2_subdev *sd,
891 const struct v4l2_mbus_config *cfg)
892{
893 struct i2c_client *client = v4l2_get_subdevdata(sd);
894 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
895 unsigned long flags = soc_camera_apply_board_flags(icl, cfg);
896 int ret;
897
898 if (flags & V4L2_MBUS_PCLK_SAMPLE_RISING)
899 ret = ov6650_reg_rmw(client, REG_COMJ, COMJ_PCLK_RISING, 0);
900 else
901 ret = ov6650_reg_rmw(client, REG_COMJ, 0, COMJ_PCLK_RISING);
902 if (ret)
903 return ret;
904
905 if (flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)
906 ret = ov6650_reg_rmw(client, REG_COMF, COMF_HREF_LOW, 0);
907 else
908 ret = ov6650_reg_rmw(client, REG_COMF, 0, COMF_HREF_LOW);
909 if (ret)
910 return ret;
911
912 if (flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH)
913 ret = ov6650_reg_rmw(client, REG_COMJ, COMJ_VSYNC_HIGH, 0);
914 else
915 ret = ov6650_reg_rmw(client, REG_COMJ, 0, COMJ_VSYNC_HIGH);
916
917 return ret;
918}
919
1114static struct v4l2_subdev_video_ops ov6650_video_ops = { 920static struct v4l2_subdev_video_ops ov6650_video_ops = {
1115 .s_stream = ov6650_s_stream, 921 .s_stream = ov6650_s_stream,
1116 .g_mbus_fmt = ov6650_g_fmt, 922 .g_mbus_fmt = ov6650_g_fmt,
@@ -1122,6 +928,8 @@ static struct v4l2_subdev_video_ops ov6650_video_ops = {
1122 .s_crop = ov6650_s_crop, 928 .s_crop = ov6650_s_crop,
1123 .g_parm = ov6650_g_parm, 929 .g_parm = ov6650_g_parm,
1124 .s_parm = ov6650_s_parm, 930 .s_parm = ov6650_s_parm,
931 .g_mbus_config = ov6650_g_mbus_config,
932 .s_mbus_config = ov6650_s_mbus_config,
1125}; 933};
1126 934
1127static struct v4l2_subdev_ops ov6650_subdev_ops = { 935static struct v4l2_subdev_ops ov6650_subdev_ops = {
@@ -1136,16 +944,9 @@ static int ov6650_probe(struct i2c_client *client,
1136 const struct i2c_device_id *did) 944 const struct i2c_device_id *did)
1137{ 945{
1138 struct ov6650 *priv; 946 struct ov6650 *priv;
1139 struct soc_camera_device *icd = client->dev.platform_data; 947 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
1140 struct soc_camera_link *icl;
1141 int ret; 948 int ret;
1142 949
1143 if (!icd) {
1144 dev_err(&client->dev, "Missing soc-camera data!\n");
1145 return -EINVAL;
1146 }
1147
1148 icl = to_soc_camera_link(icd);
1149 if (!icl) { 950 if (!icl) {
1150 dev_err(&client->dev, "Missing platform_data for driver\n"); 951 dev_err(&client->dev, "Missing platform_data for driver\n");
1151 return -EINVAL; 952 return -EINVAL;
@@ -1159,8 +960,46 @@ static int ov6650_probe(struct i2c_client *client,
1159 } 960 }
1160 961
1161 v4l2_i2c_subdev_init(&priv->subdev, client, &ov6650_subdev_ops); 962 v4l2_i2c_subdev_init(&priv->subdev, client, &ov6650_subdev_ops);
963 v4l2_ctrl_handler_init(&priv->hdl, 13);
964 v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
965 V4L2_CID_VFLIP, 0, 1, 1, 0);
966 v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
967 V4L2_CID_HFLIP, 0, 1, 1, 0);
968 priv->autogain = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
969 V4L2_CID_AUTOGAIN, 0, 1, 1, 1);
970 priv->gain = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
971 V4L2_CID_GAIN, 0, 0x3f, 1, DEF_GAIN);
972 priv->autowb = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
973 V4L2_CID_AUTO_WHITE_BALANCE, 0, 1, 1, 1);
974 priv->blue = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
975 V4L2_CID_BLUE_BALANCE, 0, 0xff, 1, DEF_BLUE);
976 priv->red = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
977 V4L2_CID_RED_BALANCE, 0, 0xff, 1, DEF_RED);
978 v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
979 V4L2_CID_SATURATION, 0, 0xf, 1, 0x8);
980 v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
981 V4L2_CID_HUE, 0, HUE_MASK, 1, DEF_HUE);
982 v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
983 V4L2_CID_BRIGHTNESS, 0, 0xff, 1, 0x80);
984 priv->autoexposure = v4l2_ctrl_new_std_menu(&priv->hdl,
985 &ov6550_ctrl_ops, V4L2_CID_EXPOSURE_AUTO,
986 V4L2_EXPOSURE_MANUAL, 0, V4L2_EXPOSURE_AUTO);
987 priv->exposure = v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
988 V4L2_CID_EXPOSURE, 0, 0xff, 1, DEF_AECH);
989 v4l2_ctrl_new_std(&priv->hdl, &ov6550_ctrl_ops,
990 V4L2_CID_GAMMA, 0, 0xff, 1, 0x12);
991
992 priv->subdev.ctrl_handler = &priv->hdl;
993 if (priv->hdl.error) {
994 int err = priv->hdl.error;
1162 995
1163 icd->ops = &ov6650_ops; 996 kfree(priv);
997 return err;
998 }
999 v4l2_ctrl_auto_cluster(2, &priv->autogain, 0, true);
1000 v4l2_ctrl_auto_cluster(3, &priv->autowb, 0, true);
1001 v4l2_ctrl_auto_cluster(2, &priv->autoexposure,
1002 V4L2_EXPOSURE_MANUAL, true);
1164 1003
1165 priv->rect.left = DEF_HSTRT << 1; 1004 priv->rect.left = DEF_HSTRT << 1;
1166 priv->rect.top = DEF_VSTRT << 1; 1005 priv->rect.top = DEF_VSTRT << 1;
@@ -1170,10 +1009,12 @@ static int ov6650_probe(struct i2c_client *client,
1170 priv->code = V4L2_MBUS_FMT_YUYV8_2X8; 1009 priv->code = V4L2_MBUS_FMT_YUYV8_2X8;
1171 priv->colorspace = V4L2_COLORSPACE_JPEG; 1010 priv->colorspace = V4L2_COLORSPACE_JPEG;
1172 1011
1173 ret = ov6650_video_probe(icd, client); 1012 ret = ov6650_video_probe(client);
1013 if (!ret)
1014 ret = v4l2_ctrl_handler_setup(&priv->hdl);
1174 1015
1175 if (ret) { 1016 if (ret) {
1176 icd->ops = NULL; 1017 v4l2_ctrl_handler_free(&priv->hdl);
1177 kfree(priv); 1018 kfree(priv);
1178 } 1019 }
1179 1020
@@ -1184,6 +1025,8 @@ static int ov6650_remove(struct i2c_client *client)
1184{ 1025{
1185 struct ov6650 *priv = to_ov6650(client); 1026 struct ov6650 *priv = to_ov6650(client);
1186 1027
1028 v4l2_device_unregister_subdev(&priv->subdev);
1029 v4l2_ctrl_handler_free(&priv->hdl);
1187 kfree(priv); 1030 kfree(priv);
1188 return 0; 1031 return 0;
1189} 1032}
diff --git a/drivers/media/video/ov772x.c b/drivers/media/video/ov772x.c
index 397870f076c1..9f6ce3d8a29e 100644
--- a/drivers/media/video/ov772x.c
+++ b/drivers/media/video/ov772x.c
@@ -20,12 +20,14 @@
20#include <linux/i2c.h> 20#include <linux/i2c.h>
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/delay.h> 22#include <linux/delay.h>
23#include <linux/v4l2-mediabus.h>
23#include <linux/videodev2.h> 24#include <linux/videodev2.h>
25
26#include <media/ov772x.h>
27#include <media/soc_camera.h>
28#include <media/v4l2-ctrls.h>
24#include <media/v4l2-chip-ident.h> 29#include <media/v4l2-chip-ident.h>
25#include <media/v4l2-subdev.h> 30#include <media/v4l2-subdev.h>
26#include <media/soc_camera.h>
27#include <media/soc_mediabus.h>
28#include <media/ov772x.h>
29 31
30/* 32/*
31 * register offset 33 * register offset
@@ -400,6 +402,7 @@ struct ov772x_win_size {
400 402
401struct ov772x_priv { 403struct ov772x_priv {
402 struct v4l2_subdev subdev; 404 struct v4l2_subdev subdev;
405 struct v4l2_ctrl_handler hdl;
403 struct ov772x_camera_info *info; 406 struct ov772x_camera_info *info;
404 const struct ov772x_color_format *cfmt; 407 const struct ov772x_color_format *cfmt;
405 const struct ov772x_win_size *win; 408 const struct ov772x_win_size *win;
@@ -517,36 +520,6 @@ static const struct ov772x_win_size ov772x_win_qvga = {
517 .regs = ov772x_qvga_regs, 520 .regs = ov772x_qvga_regs,
518}; 521};
519 522
520static const struct v4l2_queryctrl ov772x_controls[] = {
521 {
522 .id = V4L2_CID_VFLIP,
523 .type = V4L2_CTRL_TYPE_BOOLEAN,
524 .name = "Flip Vertically",
525 .minimum = 0,
526 .maximum = 1,
527 .step = 1,
528 .default_value = 0,
529 },
530 {
531 .id = V4L2_CID_HFLIP,
532 .type = V4L2_CTRL_TYPE_BOOLEAN,
533 .name = "Flip Horizontally",
534 .minimum = 0,
535 .maximum = 1,
536 .step = 1,
537 .default_value = 0,
538 },
539 {
540 .id = V4L2_CID_BAND_STOP_FILTER,
541 .type = V4L2_CTRL_TYPE_INTEGER,
542 .name = "Band-stop filter",
543 .minimum = 0,
544 .maximum = 256,
545 .step = 1,
546 .default_value = 0,
547 },
548};
549
550/* 523/*
551 * general function 524 * general function
552 */ 525 */
@@ -620,75 +593,30 @@ static int ov772x_s_stream(struct v4l2_subdev *sd, int enable)
620 return 0; 593 return 0;
621} 594}
622 595
623static int ov772x_set_bus_param(struct soc_camera_device *icd, 596static int ov772x_s_ctrl(struct v4l2_ctrl *ctrl)
624 unsigned long flags)
625{
626 return 0;
627}
628
629static unsigned long ov772x_query_bus_param(struct soc_camera_device *icd)
630{
631 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd));
632 struct ov772x_priv *priv = i2c_get_clientdata(client);
633 struct soc_camera_link *icl = to_soc_camera_link(icd);
634 unsigned long flags = SOCAM_PCLK_SAMPLE_RISING | SOCAM_MASTER |
635 SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_HIGH |
636 SOCAM_DATA_ACTIVE_HIGH;
637
638 if (priv->info->flags & OV772X_FLAG_8BIT)
639 flags |= SOCAM_DATAWIDTH_8;
640 else
641 flags |= SOCAM_DATAWIDTH_10;
642
643 return soc_camera_apply_sensor_flags(icl, flags);
644}
645
646static int ov772x_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
647{
648 struct ov772x_priv *priv = container_of(sd, struct ov772x_priv, subdev);
649
650 switch (ctrl->id) {
651 case V4L2_CID_VFLIP:
652 ctrl->value = priv->flag_vflip;
653 break;
654 case V4L2_CID_HFLIP:
655 ctrl->value = priv->flag_hflip;
656 break;
657 case V4L2_CID_BAND_STOP_FILTER:
658 ctrl->value = priv->band_filter;
659 break;
660 }
661 return 0;
662}
663
664static int ov772x_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
665{ 597{
598 struct ov772x_priv *priv = container_of(ctrl->handler,
599 struct ov772x_priv, hdl);
600 struct v4l2_subdev *sd = &priv->subdev;
666 struct i2c_client *client = v4l2_get_subdevdata(sd); 601 struct i2c_client *client = v4l2_get_subdevdata(sd);
667 struct ov772x_priv *priv = container_of(sd, struct ov772x_priv, subdev);
668 int ret = 0; 602 int ret = 0;
669 u8 val; 603 u8 val;
670 604
671 switch (ctrl->id) { 605 switch (ctrl->id) {
672 case V4L2_CID_VFLIP: 606 case V4L2_CID_VFLIP:
673 val = ctrl->value ? VFLIP_IMG : 0x00; 607 val = ctrl->val ? VFLIP_IMG : 0x00;
674 priv->flag_vflip = ctrl->value; 608 priv->flag_vflip = ctrl->val;
675 if (priv->info->flags & OV772X_FLAG_VFLIP) 609 if (priv->info->flags & OV772X_FLAG_VFLIP)
676 val ^= VFLIP_IMG; 610 val ^= VFLIP_IMG;
677 ret = ov772x_mask_set(client, COM3, VFLIP_IMG, val); 611 return ov772x_mask_set(client, COM3, VFLIP_IMG, val);
678 break;
679 case V4L2_CID_HFLIP: 612 case V4L2_CID_HFLIP:
680 val = ctrl->value ? HFLIP_IMG : 0x00; 613 val = ctrl->val ? HFLIP_IMG : 0x00;
681 priv->flag_hflip = ctrl->value; 614 priv->flag_hflip = ctrl->val;
682 if (priv->info->flags & OV772X_FLAG_HFLIP) 615 if (priv->info->flags & OV772X_FLAG_HFLIP)
683 val ^= HFLIP_IMG; 616 val ^= HFLIP_IMG;
684 ret = ov772x_mask_set(client, COM3, HFLIP_IMG, val); 617 return ov772x_mask_set(client, COM3, HFLIP_IMG, val);
685 break;
686 case V4L2_CID_BAND_STOP_FILTER: 618 case V4L2_CID_BAND_STOP_FILTER:
687 if ((unsigned)ctrl->value > 256) 619 if (!ctrl->val) {
688 ctrl->value = 256;
689 if (ctrl->value == priv->band_filter)
690 break;
691 if (!ctrl->value) {
692 /* Switch the filter off, it is on now */ 620 /* Switch the filter off, it is on now */
693 ret = ov772x_mask_set(client, BDBASE, 0xff, 0xff); 621 ret = ov772x_mask_set(client, BDBASE, 0xff, 0xff);
694 if (!ret) 622 if (!ret)
@@ -696,7 +624,7 @@ static int ov772x_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
696 BNDF_ON_OFF, 0); 624 BNDF_ON_OFF, 0);
697 } else { 625 } else {
698 /* Switch the filter on, set AEC low limit */ 626 /* Switch the filter on, set AEC low limit */
699 val = 256 - ctrl->value; 627 val = 256 - ctrl->val;
700 ret = ov772x_mask_set(client, COM8, 628 ret = ov772x_mask_set(client, COM8,
701 BNDF_ON_OFF, BNDF_ON_OFF); 629 BNDF_ON_OFF, BNDF_ON_OFF);
702 if (!ret) 630 if (!ret)
@@ -704,11 +632,11 @@ static int ov772x_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
704 0xff, val); 632 0xff, val);
705 } 633 }
706 if (!ret) 634 if (!ret)
707 priv->band_filter = ctrl->value; 635 priv->band_filter = ctrl->val;
708 break; 636 return ret;
709 } 637 }
710 638
711 return ret; 639 return -EINVAL;
712} 640}
713 641
714static int ov772x_g_chip_ident(struct v4l2_subdev *sd, 642static int ov772x_g_chip_ident(struct v4l2_subdev *sd,
@@ -822,13 +750,13 @@ static int ov772x_set_params(struct i2c_client *client, u32 *width, u32 *height,
822 goto ov772x_set_fmt_error; 750 goto ov772x_set_fmt_error;
823 751
824 ret = ov772x_mask_set(client, 752 ret = ov772x_mask_set(client,
825 EDGE_TRSHLD, EDGE_THRESHOLD_MASK, 753 EDGE_TRSHLD, OV772X_EDGE_THRESHOLD_MASK,
826 priv->info->edgectrl.threshold); 754 priv->info->edgectrl.threshold);
827 if (ret < 0) 755 if (ret < 0)
828 goto ov772x_set_fmt_error; 756 goto ov772x_set_fmt_error;
829 757
830 ret = ov772x_mask_set(client, 758 ret = ov772x_mask_set(client,
831 EDGE_STRNGT, EDGE_STRENGTH_MASK, 759 EDGE_STRNGT, OV772X_EDGE_STRENGTH_MASK,
832 priv->info->edgectrl.strength); 760 priv->info->edgectrl.strength);
833 if (ret < 0) 761 if (ret < 0)
834 goto ov772x_set_fmt_error; 762 goto ov772x_set_fmt_error;
@@ -840,13 +768,13 @@ static int ov772x_set_params(struct i2c_client *client, u32 *width, u32 *height,
840 * set upper and lower limit 768 * set upper and lower limit
841 */ 769 */
842 ret = ov772x_mask_set(client, 770 ret = ov772x_mask_set(client,
843 EDGE_UPPER, EDGE_UPPER_MASK, 771 EDGE_UPPER, OV772X_EDGE_UPPER_MASK,
844 priv->info->edgectrl.upper); 772 priv->info->edgectrl.upper);
845 if (ret < 0) 773 if (ret < 0)
846 goto ov772x_set_fmt_error; 774 goto ov772x_set_fmt_error;
847 775
848 ret = ov772x_mask_set(client, 776 ret = ov772x_mask_set(client,
849 EDGE_LOWER, EDGE_LOWER_MASK, 777 EDGE_LOWER, OV772X_EDGE_LOWER_MASK,
850 priv->info->edgectrl.lower); 778 priv->info->edgectrl.lower);
851 if (ret < 0) 779 if (ret < 0)
852 goto ov772x_set_fmt_error; 780 goto ov772x_set_fmt_error;
@@ -1025,17 +953,12 @@ static int ov772x_try_fmt(struct v4l2_subdev *sd,
1025 return 0; 953 return 0;
1026} 954}
1027 955
1028static int ov772x_video_probe(struct soc_camera_device *icd, 956static int ov772x_video_probe(struct i2c_client *client)
1029 struct i2c_client *client)
1030{ 957{
1031 struct ov772x_priv *priv = to_ov772x(client); 958 struct ov772x_priv *priv = to_ov772x(client);
1032 u8 pid, ver; 959 u8 pid, ver;
1033 const char *devname; 960 const char *devname;
1034 961
1035 /* We must have a parent by now. And it cannot be a wrong one. */
1036 BUG_ON(!icd->parent ||
1037 to_soc_camera_host(icd->parent)->nr != icd->iface);
1038
1039 /* 962 /*
1040 * check and show product ID and manufacturer ID 963 * check and show product ID and manufacturer ID
1041 */ 964 */
@@ -1064,20 +987,14 @@ static int ov772x_video_probe(struct soc_camera_device *icd,
1064 ver, 987 ver,
1065 i2c_smbus_read_byte_data(client, MIDH), 988 i2c_smbus_read_byte_data(client, MIDH),
1066 i2c_smbus_read_byte_data(client, MIDL)); 989 i2c_smbus_read_byte_data(client, MIDL));
1067 990 return v4l2_ctrl_handler_setup(&priv->hdl);
1068 return 0;
1069} 991}
1070 992
1071static struct soc_camera_ops ov772x_ops = { 993static const struct v4l2_ctrl_ops ov772x_ctrl_ops = {
1072 .set_bus_param = ov772x_set_bus_param, 994 .s_ctrl = ov772x_s_ctrl,
1073 .query_bus_param = ov772x_query_bus_param,
1074 .controls = ov772x_controls,
1075 .num_controls = ARRAY_SIZE(ov772x_controls),
1076}; 995};
1077 996
1078static struct v4l2_subdev_core_ops ov772x_subdev_core_ops = { 997static struct v4l2_subdev_core_ops ov772x_subdev_core_ops = {
1079 .g_ctrl = ov772x_g_ctrl,
1080 .s_ctrl = ov772x_s_ctrl,
1081 .g_chip_ident = ov772x_g_chip_ident, 998 .g_chip_ident = ov772x_g_chip_ident,
1082#ifdef CONFIG_VIDEO_ADV_DEBUG 999#ifdef CONFIG_VIDEO_ADV_DEBUG
1083 .g_register = ov772x_g_register, 1000 .g_register = ov772x_g_register,
@@ -1095,6 +1012,21 @@ static int ov772x_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
1095 return 0; 1012 return 0;
1096} 1013}
1097 1014
1015static int ov772x_g_mbus_config(struct v4l2_subdev *sd,
1016 struct v4l2_mbus_config *cfg)
1017{
1018 struct i2c_client *client = v4l2_get_subdevdata(sd);
1019 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
1020
1021 cfg->flags = V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_MASTER |
1022 V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_HIGH |
1023 V4L2_MBUS_DATA_ACTIVE_HIGH;
1024 cfg->type = V4L2_MBUS_PARALLEL;
1025 cfg->flags = soc_camera_apply_board_flags(icl, cfg);
1026
1027 return 0;
1028}
1029
1098static struct v4l2_subdev_video_ops ov772x_subdev_video_ops = { 1030static struct v4l2_subdev_video_ops ov772x_subdev_video_ops = {
1099 .s_stream = ov772x_s_stream, 1031 .s_stream = ov772x_s_stream,
1100 .g_mbus_fmt = ov772x_g_fmt, 1032 .g_mbus_fmt = ov772x_g_fmt,
@@ -1103,6 +1035,7 @@ static struct v4l2_subdev_video_ops ov772x_subdev_video_ops = {
1103 .cropcap = ov772x_cropcap, 1035 .cropcap = ov772x_cropcap,
1104 .g_crop = ov772x_g_crop, 1036 .g_crop = ov772x_g_crop,
1105 .enum_mbus_fmt = ov772x_enum_fmt, 1037 .enum_mbus_fmt = ov772x_enum_fmt,
1038 .g_mbus_config = ov772x_g_mbus_config,
1106}; 1039};
1107 1040
1108static struct v4l2_subdev_ops ov772x_subdev_ops = { 1041static struct v4l2_subdev_ops ov772x_subdev_ops = {
@@ -1117,20 +1050,15 @@ static struct v4l2_subdev_ops ov772x_subdev_ops = {
1117static int ov772x_probe(struct i2c_client *client, 1050static int ov772x_probe(struct i2c_client *client,
1118 const struct i2c_device_id *did) 1051 const struct i2c_device_id *did)
1119{ 1052{
1120 struct ov772x_priv *priv; 1053 struct ov772x_priv *priv;
1121 struct soc_camera_device *icd = client->dev.platform_data; 1054 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
1122 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 1055 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
1123 struct soc_camera_link *icl; 1056 int ret;
1124 int ret;
1125
1126 if (!icd) {
1127 dev_err(&client->dev, "OV772X: missing soc-camera data!\n");
1128 return -EINVAL;
1129 }
1130 1057
1131 icl = to_soc_camera_link(icd); 1058 if (!icl || !icl->priv) {
1132 if (!icl || !icl->priv) 1059 dev_err(&client->dev, "OV772X: missing platform data!\n");
1133 return -EINVAL; 1060 return -EINVAL;
1061 }
1134 1062
1135 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 1063 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
1136 dev_err(&adapter->dev, 1064 dev_err(&adapter->dev,
@@ -1146,12 +1074,24 @@ static int ov772x_probe(struct i2c_client *client,
1146 priv->info = icl->priv; 1074 priv->info = icl->priv;
1147 1075
1148 v4l2_i2c_subdev_init(&priv->subdev, client, &ov772x_subdev_ops); 1076 v4l2_i2c_subdev_init(&priv->subdev, client, &ov772x_subdev_ops);
1077 v4l2_ctrl_handler_init(&priv->hdl, 3);
1078 v4l2_ctrl_new_std(&priv->hdl, &ov772x_ctrl_ops,
1079 V4L2_CID_VFLIP, 0, 1, 1, 0);
1080 v4l2_ctrl_new_std(&priv->hdl, &ov772x_ctrl_ops,
1081 V4L2_CID_HFLIP, 0, 1, 1, 0);
1082 v4l2_ctrl_new_std(&priv->hdl, &ov772x_ctrl_ops,
1083 V4L2_CID_BAND_STOP_FILTER, 0, 256, 1, 0);
1084 priv->subdev.ctrl_handler = &priv->hdl;
1085 if (priv->hdl.error) {
1086 int err = priv->hdl.error;
1149 1087
1150 icd->ops = &ov772x_ops; 1088 kfree(priv);
1089 return err;
1090 }
1151 1091
1152 ret = ov772x_video_probe(icd, client); 1092 ret = ov772x_video_probe(client);
1153 if (ret) { 1093 if (ret) {
1154 icd->ops = NULL; 1094 v4l2_ctrl_handler_free(&priv->hdl);
1155 kfree(priv); 1095 kfree(priv);
1156 } 1096 }
1157 1097
@@ -1161,9 +1101,9 @@ static int ov772x_probe(struct i2c_client *client,
1161static int ov772x_remove(struct i2c_client *client) 1101static int ov772x_remove(struct i2c_client *client)
1162{ 1102{
1163 struct ov772x_priv *priv = to_ov772x(client); 1103 struct ov772x_priv *priv = to_ov772x(client);
1164 struct soc_camera_device *icd = client->dev.platform_data;
1165 1104
1166 icd->ops = NULL; 1105 v4l2_device_unregister_subdev(&priv->subdev);
1106 v4l2_ctrl_handler_free(&priv->hdl);
1167 kfree(priv); 1107 kfree(priv);
1168 return 0; 1108 return 0;
1169} 1109}
diff --git a/drivers/media/video/ov9640.c b/drivers/media/video/ov9640.c
index 3681a6ff0815..a4f99797eb56 100644
--- a/drivers/media/video/ov9640.c
+++ b/drivers/media/video/ov9640.c
@@ -24,10 +24,13 @@
24#include <linux/i2c.h> 24#include <linux/i2c.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/delay.h> 26#include <linux/delay.h>
27#include <linux/v4l2-mediabus.h>
27#include <linux/videodev2.h> 28#include <linux/videodev2.h>
29
30#include <media/soc_camera.h>
28#include <media/v4l2-chip-ident.h> 31#include <media/v4l2-chip-ident.h>
29#include <media/v4l2-common.h> 32#include <media/v4l2-common.h>
30#include <media/soc_camera.h> 33#include <media/v4l2-ctrls.h>
31 34
32#include "ov9640.h" 35#include "ov9640.h"
33 36
@@ -162,27 +165,6 @@ static enum v4l2_mbus_pixelcode ov9640_codes[] = {
162 V4L2_MBUS_FMT_RGB565_2X8_LE, 165 V4L2_MBUS_FMT_RGB565_2X8_LE,
163}; 166};
164 167
165static const struct v4l2_queryctrl ov9640_controls[] = {
166 {
167 .id = V4L2_CID_VFLIP,
168 .type = V4L2_CTRL_TYPE_BOOLEAN,
169 .name = "Flip Vertically",
170 .minimum = 0,
171 .maximum = 1,
172 .step = 1,
173 .default_value = 0,
174 },
175 {
176 .id = V4L2_CID_HFLIP,
177 .type = V4L2_CTRL_TYPE_BOOLEAN,
178 .name = "Flip Horizontally",
179 .minimum = 0,
180 .maximum = 1,
181 .step = 1,
182 .default_value = 0,
183 },
184};
185
186/* read a register */ 168/* read a register */
187static int ov9640_reg_read(struct i2c_client *client, u8 reg, u8 *val) 169static int ov9640_reg_read(struct i2c_client *client, u8 reg, u8 *val)
188{ 170{
@@ -284,75 +266,25 @@ static int ov9640_s_stream(struct v4l2_subdev *sd, int enable)
284 return 0; 266 return 0;
285} 267}
286 268
287/* Alter bus settings on camera side */
288static int ov9640_set_bus_param(struct soc_camera_device *icd,
289 unsigned long flags)
290{
291 return 0;
292}
293
294/* Request bus settings on camera side */
295static unsigned long ov9640_query_bus_param(struct soc_camera_device *icd)
296{
297 struct soc_camera_link *icl = to_soc_camera_link(icd);
298
299 /*
300 * REVISIT: the camera probably can do 10 bit transfers, but I don't
301 * have those pins connected on my hardware.
302 */
303 unsigned long flags = SOCAM_PCLK_SAMPLE_RISING | SOCAM_MASTER |
304 SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_HIGH |
305 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8;
306
307 return soc_camera_apply_sensor_flags(icl, flags);
308}
309
310/* Get status of additional camera capabilities */
311static int ov9640_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
312{
313 struct ov9640_priv *priv = to_ov9640_sensor(sd);
314
315 switch (ctrl->id) {
316 case V4L2_CID_VFLIP:
317 ctrl->value = priv->flag_vflip;
318 break;
319 case V4L2_CID_HFLIP:
320 ctrl->value = priv->flag_hflip;
321 break;
322 }
323 return 0;
324}
325
326/* Set status of additional camera capabilities */ 269/* Set status of additional camera capabilities */
327static int ov9640_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 270static int ov9640_s_ctrl(struct v4l2_ctrl *ctrl)
328{ 271{
329 struct i2c_client *client = v4l2_get_subdevdata(sd); 272 struct ov9640_priv *priv = container_of(ctrl->handler, struct ov9640_priv, hdl);
330 struct ov9640_priv *priv = to_ov9640_sensor(sd); 273 struct i2c_client *client = v4l2_get_subdevdata(&priv->subdev);
331
332 int ret = 0;
333 274
334 switch (ctrl->id) { 275 switch (ctrl->id) {
335 case V4L2_CID_VFLIP: 276 case V4L2_CID_VFLIP:
336 priv->flag_vflip = ctrl->value; 277 if (ctrl->val)
337 if (ctrl->value) 278 return ov9640_reg_rmw(client, OV9640_MVFP,
338 ret = ov9640_reg_rmw(client, OV9640_MVFP,
339 OV9640_MVFP_V, 0); 279 OV9640_MVFP_V, 0);
340 else 280 return ov9640_reg_rmw(client, OV9640_MVFP, 0, OV9640_MVFP_V);
341 ret = ov9640_reg_rmw(client, OV9640_MVFP,
342 0, OV9640_MVFP_V);
343 break;
344 case V4L2_CID_HFLIP: 281 case V4L2_CID_HFLIP:
345 priv->flag_hflip = ctrl->value; 282 if (ctrl->val)
346 if (ctrl->value) 283 return ov9640_reg_rmw(client, OV9640_MVFP,
347 ret = ov9640_reg_rmw(client, OV9640_MVFP,
348 OV9640_MVFP_H, 0); 284 OV9640_MVFP_H, 0);
349 else 285 return ov9640_reg_rmw(client, OV9640_MVFP, 0, OV9640_MVFP_H);
350 ret = ov9640_reg_rmw(client, OV9640_MVFP,
351 0, OV9640_MVFP_H);
352 break;
353 } 286 }
354 287 return -EINVAL;
355 return ret;
356} 288}
357 289
358/* Get chip identification */ 290/* Get chip identification */
@@ -646,10 +578,7 @@ static int ov9640_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a)
646 return 0; 578 return 0;
647} 579}
648 580
649 581static int ov9640_video_probe(struct i2c_client *client)
650
651static int ov9640_video_probe(struct soc_camera_device *icd,
652 struct i2c_client *client)
653{ 582{
654 struct v4l2_subdev *sd = i2c_get_clientdata(client); 583 struct v4l2_subdev *sd = i2c_get_clientdata(client);
655 struct ov9640_priv *priv = to_ov9640_sensor(sd); 584 struct ov9640_priv *priv = to_ov9640_sensor(sd);
@@ -657,29 +586,19 @@ static int ov9640_video_probe(struct soc_camera_device *icd,
657 const char *devname; 586 const char *devname;
658 int ret = 0; 587 int ret = 0;
659 588
660 /* We must have a parent by now. And it cannot be a wrong one. */
661 BUG_ON(!icd->parent ||
662 to_soc_camera_host(icd->parent)->nr != icd->iface);
663
664 /* 589 /*
665 * check and show product ID and manufacturer ID 590 * check and show product ID and manufacturer ID
666 */ 591 */
667 592
668 ret = ov9640_reg_read(client, OV9640_PID, &pid); 593 ret = ov9640_reg_read(client, OV9640_PID, &pid);
594 if (!ret)
595 ret = ov9640_reg_read(client, OV9640_VER, &ver);
596 if (!ret)
597 ret = ov9640_reg_read(client, OV9640_MIDH, &midh);
598 if (!ret)
599 ret = ov9640_reg_read(client, OV9640_MIDL, &midl);
669 if (ret) 600 if (ret)
670 goto err; 601 return ret;
671
672 ret = ov9640_reg_read(client, OV9640_VER, &ver);
673 if (ret)
674 goto err;
675
676 ret = ov9640_reg_read(client, OV9640_MIDH, &midh);
677 if (ret)
678 goto err;
679
680 ret = ov9640_reg_read(client, OV9640_MIDL, &midl);
681 if (ret)
682 goto err;
683 602
684 switch (VERSION(pid, ver)) { 603 switch (VERSION(pid, ver)) {
685 case OV9640_V2: 604 case OV9640_V2:
@@ -693,27 +612,20 @@ static int ov9640_video_probe(struct soc_camera_device *icd,
693 break; 612 break;
694 default: 613 default:
695 dev_err(&client->dev, "Product ID error %x:%x\n", pid, ver); 614 dev_err(&client->dev, "Product ID error %x:%x\n", pid, ver);
696 ret = -ENODEV; 615 return -ENODEV;
697 goto err;
698 } 616 }
699 617
700 dev_info(&client->dev, "%s Product ID %0x:%0x Manufacturer ID %x:%x\n", 618 dev_info(&client->dev, "%s Product ID %0x:%0x Manufacturer ID %x:%x\n",
701 devname, pid, ver, midh, midl); 619 devname, pid, ver, midh, midl);
702 620
703err: 621 return v4l2_ctrl_handler_setup(&priv->hdl);
704 return ret;
705} 622}
706 623
707static struct soc_camera_ops ov9640_ops = { 624static const struct v4l2_ctrl_ops ov9640_ctrl_ops = {
708 .set_bus_param = ov9640_set_bus_param, 625 .s_ctrl = ov9640_s_ctrl,
709 .query_bus_param = ov9640_query_bus_param,
710 .controls = ov9640_controls,
711 .num_controls = ARRAY_SIZE(ov9640_controls),
712}; 626};
713 627
714static struct v4l2_subdev_core_ops ov9640_core_ops = { 628static struct v4l2_subdev_core_ops ov9640_core_ops = {
715 .g_ctrl = ov9640_g_ctrl,
716 .s_ctrl = ov9640_s_ctrl,
717 .g_chip_ident = ov9640_g_chip_ident, 629 .g_chip_ident = ov9640_g_chip_ident,
718#ifdef CONFIG_VIDEO_ADV_DEBUG 630#ifdef CONFIG_VIDEO_ADV_DEBUG
719 .g_register = ov9640_get_register, 631 .g_register = ov9640_get_register,
@@ -722,6 +634,22 @@ static struct v4l2_subdev_core_ops ov9640_core_ops = {
722 634
723}; 635};
724 636
637/* Request bus settings on camera side */
638static int ov9640_g_mbus_config(struct v4l2_subdev *sd,
639 struct v4l2_mbus_config *cfg)
640{
641 struct i2c_client *client = v4l2_get_subdevdata(sd);
642 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
643
644 cfg->flags = V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_MASTER |
645 V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_HIGH |
646 V4L2_MBUS_DATA_ACTIVE_HIGH;
647 cfg->type = V4L2_MBUS_PARALLEL;
648 cfg->flags = soc_camera_apply_board_flags(icl, cfg);
649
650 return 0;
651}
652
725static struct v4l2_subdev_video_ops ov9640_video_ops = { 653static struct v4l2_subdev_video_ops ov9640_video_ops = {
726 .s_stream = ov9640_s_stream, 654 .s_stream = ov9640_s_stream,
727 .s_mbus_fmt = ov9640_s_fmt, 655 .s_mbus_fmt = ov9640_s_fmt,
@@ -729,7 +657,7 @@ static struct v4l2_subdev_video_ops ov9640_video_ops = {
729 .enum_mbus_fmt = ov9640_enum_fmt, 657 .enum_mbus_fmt = ov9640_enum_fmt,
730 .cropcap = ov9640_cropcap, 658 .cropcap = ov9640_cropcap,
731 .g_crop = ov9640_g_crop, 659 .g_crop = ov9640_g_crop,
732 660 .g_mbus_config = ov9640_g_mbus_config,
733}; 661};
734 662
735static struct v4l2_subdev_ops ov9640_subdev_ops = { 663static struct v4l2_subdev_ops ov9640_subdev_ops = {
@@ -744,16 +672,9 @@ static int ov9640_probe(struct i2c_client *client,
744 const struct i2c_device_id *did) 672 const struct i2c_device_id *did)
745{ 673{
746 struct ov9640_priv *priv; 674 struct ov9640_priv *priv;
747 struct soc_camera_device *icd = client->dev.platform_data; 675 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
748 struct soc_camera_link *icl;
749 int ret; 676 int ret;
750 677
751 if (!icd) {
752 dev_err(&client->dev, "Missing soc-camera data!\n");
753 return -EINVAL;
754 }
755
756 icl = to_soc_camera_link(icd);
757 if (!icl) { 678 if (!icl) {
758 dev_err(&client->dev, "Missing platform_data for driver\n"); 679 dev_err(&client->dev, "Missing platform_data for driver\n");
759 return -EINVAL; 680 return -EINVAL;
@@ -768,12 +689,23 @@ static int ov9640_probe(struct i2c_client *client,
768 689
769 v4l2_i2c_subdev_init(&priv->subdev, client, &ov9640_subdev_ops); 690 v4l2_i2c_subdev_init(&priv->subdev, client, &ov9640_subdev_ops);
770 691
771 icd->ops = &ov9640_ops; 692 v4l2_ctrl_handler_init(&priv->hdl, 2);
693 v4l2_ctrl_new_std(&priv->hdl, &ov9640_ctrl_ops,
694 V4L2_CID_VFLIP, 0, 1, 1, 0);
695 v4l2_ctrl_new_std(&priv->hdl, &ov9640_ctrl_ops,
696 V4L2_CID_HFLIP, 0, 1, 1, 0);
697 priv->subdev.ctrl_handler = &priv->hdl;
698 if (priv->hdl.error) {
699 int err = priv->hdl.error;
700
701 kfree(priv);
702 return err;
703 }
772 704
773 ret = ov9640_video_probe(icd, client); 705 ret = ov9640_video_probe(client);
774 706
775 if (ret) { 707 if (ret) {
776 icd->ops = NULL; 708 v4l2_ctrl_handler_free(&priv->hdl);
777 kfree(priv); 709 kfree(priv);
778 } 710 }
779 711
@@ -785,6 +717,8 @@ static int ov9640_remove(struct i2c_client *client)
785 struct v4l2_subdev *sd = i2c_get_clientdata(client); 717 struct v4l2_subdev *sd = i2c_get_clientdata(client);
786 struct ov9640_priv *priv = to_ov9640_sensor(sd); 718 struct ov9640_priv *priv = to_ov9640_sensor(sd);
787 719
720 v4l2_device_unregister_subdev(&priv->subdev);
721 v4l2_ctrl_handler_free(&priv->hdl);
788 kfree(priv); 722 kfree(priv);
789 return 0; 723 return 0;
790} 724}
diff --git a/drivers/media/video/ov9640.h b/drivers/media/video/ov9640.h
index f8a51b70792e..6b33a972c83c 100644
--- a/drivers/media/video/ov9640.h
+++ b/drivers/media/video/ov9640.h
@@ -198,12 +198,10 @@ struct ov9640_reg {
198 198
199struct ov9640_priv { 199struct ov9640_priv {
200 struct v4l2_subdev subdev; 200 struct v4l2_subdev subdev;
201 struct v4l2_ctrl_handler hdl;
201 202
202 int model; 203 int model;
203 int revision; 204 int revision;
204
205 bool flag_vflip;
206 bool flag_hflip;
207}; 205};
208 206
209#endif /* __DRIVERS_MEDIA_VIDEO_OV9640_H__ */ 207#endif /* __DRIVERS_MEDIA_VIDEO_OV9640_H__ */
diff --git a/drivers/media/video/ov9740.c b/drivers/media/video/ov9740.c
index edd1ffcca30b..d9a9f7174f7a 100644
--- a/drivers/media/video/ov9740.c
+++ b/drivers/media/video/ov9740.c
@@ -14,8 +14,11 @@
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/i2c.h> 15#include <linux/i2c.h>
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <media/v4l2-chip-ident.h> 17#include <linux/v4l2-mediabus.h>
18
18#include <media/soc_camera.h> 19#include <media/soc_camera.h>
20#include <media/v4l2-chip-ident.h>
21#include <media/v4l2-ctrls.h>
19 22
20#define to_ov9740(sd) container_of(sd, struct ov9740_priv, subdev) 23#define to_ov9740(sd) container_of(sd, struct ov9740_priv, subdev)
21 24
@@ -192,6 +195,7 @@ struct ov9740_reg {
192 195
193struct ov9740_priv { 196struct ov9740_priv {
194 struct v4l2_subdev subdev; 197 struct v4l2_subdev subdev;
198 struct v4l2_ctrl_handler hdl;
195 199
196 int ident; 200 int ident;
197 u16 model; 201 u16 model;
@@ -392,27 +396,6 @@ static enum v4l2_mbus_pixelcode ov9740_codes[] = {
392 V4L2_MBUS_FMT_YUYV8_2X8, 396 V4L2_MBUS_FMT_YUYV8_2X8,
393}; 397};
394 398
395static const struct v4l2_queryctrl ov9740_controls[] = {
396 {
397 .id = V4L2_CID_VFLIP,
398 .type = V4L2_CTRL_TYPE_BOOLEAN,
399 .name = "Flip Vertically",
400 .minimum = 0,
401 .maximum = 1,
402 .step = 1,
403 .default_value = 0,
404 },
405 {
406 .id = V4L2_CID_HFLIP,
407 .type = V4L2_CTRL_TYPE_BOOLEAN,
408 .name = "Flip Horizontally",
409 .minimum = 0,
410 .maximum = 1,
411 .step = 1,
412 .default_value = 0,
413 },
414};
415
416/* read a register */ 399/* read a register */
417static int ov9740_reg_read(struct i2c_client *client, u16 reg, u8 *val) 400static int ov9740_reg_read(struct i2c_client *client, u16 reg, u8 *val)
418{ 401{
@@ -560,25 +543,6 @@ static int ov9740_s_stream(struct v4l2_subdev *sd, int enable)
560 return ret; 543 return ret;
561} 544}
562 545
563/* Alter bus settings on camera side */
564static int ov9740_set_bus_param(struct soc_camera_device *icd,
565 unsigned long flags)
566{
567 return 0;
568}
569
570/* Request bus settings on camera side */
571static unsigned long ov9740_query_bus_param(struct soc_camera_device *icd)
572{
573 struct soc_camera_link *icl = to_soc_camera_link(icd);
574
575 unsigned long flags = SOCAM_PCLK_SAMPLE_RISING | SOCAM_MASTER |
576 SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_HIGH |
577 SOCAM_DATA_ACTIVE_HIGH | SOCAM_DATAWIDTH_8;
578
579 return soc_camera_apply_sensor_flags(icl, flags);
580}
581
582/* select nearest higher resolution for capture */ 546/* select nearest higher resolution for capture */
583static void ov9740_res_roundup(u32 *width, u32 *height) 547static void ov9740_res_roundup(u32 *width, u32 *height)
584{ 548{
@@ -788,36 +752,18 @@ static int ov9740_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
788 return 0; 752 return 0;
789} 753}
790 754
791/* Get status of additional camera capabilities */
792static int ov9740_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
793{
794 struct ov9740_priv *priv = to_ov9740(sd);
795
796 switch (ctrl->id) {
797 case V4L2_CID_VFLIP:
798 ctrl->value = priv->flag_vflip;
799 break;
800 case V4L2_CID_HFLIP:
801 ctrl->value = priv->flag_hflip;
802 break;
803 default:
804 return -EINVAL;
805 }
806
807 return 0;
808}
809
810/* Set status of additional camera capabilities */ 755/* Set status of additional camera capabilities */
811static int ov9740_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) 756static int ov9740_s_ctrl(struct v4l2_ctrl *ctrl)
812{ 757{
813 struct ov9740_priv *priv = to_ov9740(sd); 758 struct ov9740_priv *priv =
759 container_of(ctrl->handler, struct ov9740_priv, hdl);
814 760
815 switch (ctrl->id) { 761 switch (ctrl->id) {
816 case V4L2_CID_VFLIP: 762 case V4L2_CID_VFLIP:
817 priv->flag_vflip = ctrl->value; 763 priv->flag_vflip = ctrl->val;
818 break; 764 break;
819 case V4L2_CID_HFLIP: 765 case V4L2_CID_HFLIP:
820 priv->flag_hflip = ctrl->value; 766 priv->flag_hflip = ctrl->val;
821 break; 767 break;
822 default: 768 default:
823 return -EINVAL; 769 return -EINVAL;
@@ -890,18 +836,13 @@ static int ov9740_set_register(struct v4l2_subdev *sd,
890} 836}
891#endif 837#endif
892 838
893static int ov9740_video_probe(struct soc_camera_device *icd, 839static int ov9740_video_probe(struct i2c_client *client)
894 struct i2c_client *client)
895{ 840{
896 struct v4l2_subdev *sd = i2c_get_clientdata(client); 841 struct v4l2_subdev *sd = i2c_get_clientdata(client);
897 struct ov9740_priv *priv = to_ov9740(sd); 842 struct ov9740_priv *priv = to_ov9740(sd);
898 u8 modelhi, modello; 843 u8 modelhi, modello;
899 int ret; 844 int ret;
900 845
901 /* We must have a parent by now. And it cannot be a wrong one. */
902 BUG_ON(!icd->parent ||
903 to_soc_camera_host(icd->parent)->nr != icd->iface);
904
905 /* 846 /*
906 * check and show product ID and manufacturer ID 847 * check and show product ID and manufacturer ID
907 */ 848 */
@@ -942,25 +883,33 @@ err:
942 return ret; 883 return ret;
943} 884}
944 885
945static struct soc_camera_ops ov9740_ops = { 886/* Request bus settings on camera side */
946 .set_bus_param = ov9740_set_bus_param, 887static int ov9740_g_mbus_config(struct v4l2_subdev *sd,
947 .query_bus_param = ov9740_query_bus_param, 888 struct v4l2_mbus_config *cfg)
948 .controls = ov9740_controls, 889{
949 .num_controls = ARRAY_SIZE(ov9740_controls), 890 struct i2c_client *client = v4l2_get_subdevdata(sd);
950}; 891 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
892
893 cfg->flags = V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_MASTER |
894 V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_HIGH |
895 V4L2_MBUS_DATA_ACTIVE_HIGH;
896 cfg->type = V4L2_MBUS_PARALLEL;
897 cfg->flags = soc_camera_apply_board_flags(icl, cfg);
898
899 return 0;
900}
951 901
952static struct v4l2_subdev_video_ops ov9740_video_ops = { 902static struct v4l2_subdev_video_ops ov9740_video_ops = {
953 .s_stream = ov9740_s_stream, 903 .s_stream = ov9740_s_stream,
954 .s_mbus_fmt = ov9740_s_fmt, 904 .s_mbus_fmt = ov9740_s_fmt,
955 .try_mbus_fmt = ov9740_try_fmt, 905 .try_mbus_fmt = ov9740_try_fmt,
956 .enum_mbus_fmt = ov9740_enum_fmt, 906 .enum_mbus_fmt = ov9740_enum_fmt,
957 .cropcap = ov9740_cropcap, 907 .cropcap = ov9740_cropcap,
958 .g_crop = ov9740_g_crop, 908 .g_crop = ov9740_g_crop,
909 .g_mbus_config = ov9740_g_mbus_config,
959}; 910};
960 911
961static struct v4l2_subdev_core_ops ov9740_core_ops = { 912static struct v4l2_subdev_core_ops ov9740_core_ops = {
962 .g_ctrl = ov9740_g_ctrl,
963 .s_ctrl = ov9740_s_ctrl,
964 .g_chip_ident = ov9740_g_chip_ident, 913 .g_chip_ident = ov9740_g_chip_ident,
965 .s_power = ov9740_s_power, 914 .s_power = ov9740_s_power,
966#ifdef CONFIG_VIDEO_ADV_DEBUG 915#ifdef CONFIG_VIDEO_ADV_DEBUG
@@ -974,6 +923,10 @@ static struct v4l2_subdev_ops ov9740_subdev_ops = {
974 .video = &ov9740_video_ops, 923 .video = &ov9740_video_ops,
975}; 924};
976 925
926static const struct v4l2_ctrl_ops ov9740_ctrl_ops = {
927 .s_ctrl = ov9740_s_ctrl,
928};
929
977/* 930/*
978 * i2c_driver function 931 * i2c_driver function
979 */ 932 */
@@ -981,16 +934,9 @@ static int ov9740_probe(struct i2c_client *client,
981 const struct i2c_device_id *did) 934 const struct i2c_device_id *did)
982{ 935{
983 struct ov9740_priv *priv; 936 struct ov9740_priv *priv;
984 struct soc_camera_device *icd = client->dev.platform_data; 937 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
985 struct soc_camera_link *icl;
986 int ret; 938 int ret;
987 939
988 if (!icd) {
989 dev_err(&client->dev, "Missing soc-camera data!\n");
990 return -EINVAL;
991 }
992
993 icl = to_soc_camera_link(icd);
994 if (!icl) { 940 if (!icl) {
995 dev_err(&client->dev, "Missing platform_data for driver\n"); 941 dev_err(&client->dev, "Missing platform_data for driver\n");
996 return -EINVAL; 942 return -EINVAL;
@@ -1003,12 +949,24 @@ static int ov9740_probe(struct i2c_client *client,
1003 } 949 }
1004 950
1005 v4l2_i2c_subdev_init(&priv->subdev, client, &ov9740_subdev_ops); 951 v4l2_i2c_subdev_init(&priv->subdev, client, &ov9740_subdev_ops);
952 v4l2_ctrl_handler_init(&priv->hdl, 13);
953 v4l2_ctrl_new_std(&priv->hdl, &ov9740_ctrl_ops,
954 V4L2_CID_VFLIP, 0, 1, 1, 0);
955 v4l2_ctrl_new_std(&priv->hdl, &ov9740_ctrl_ops,
956 V4L2_CID_HFLIP, 0, 1, 1, 0);
957 priv->subdev.ctrl_handler = &priv->hdl;
958 if (priv->hdl.error) {
959 int err = priv->hdl.error;
1006 960
1007 icd->ops = &ov9740_ops; 961 kfree(priv);
962 return err;
963 }
1008 964
1009 ret = ov9740_video_probe(icd, client); 965 ret = ov9740_video_probe(client);
966 if (!ret)
967 ret = v4l2_ctrl_handler_setup(&priv->hdl);
1010 if (ret < 0) { 968 if (ret < 0) {
1011 icd->ops = NULL; 969 v4l2_ctrl_handler_free(&priv->hdl);
1012 kfree(priv); 970 kfree(priv);
1013 } 971 }
1014 972
@@ -1019,8 +977,9 @@ static int ov9740_remove(struct i2c_client *client)
1019{ 977{
1020 struct ov9740_priv *priv = i2c_get_clientdata(client); 978 struct ov9740_priv *priv = i2c_get_clientdata(client);
1021 979
980 v4l2_device_unregister_subdev(&priv->subdev);
981 v4l2_ctrl_handler_free(&priv->hdl);
1022 kfree(priv); 982 kfree(priv);
1023
1024 return 0; 983 return 0;
1025} 984}
1026 985
diff --git a/drivers/media/video/pvrusb2/pvrusb2-devattr.c b/drivers/media/video/pvrusb2/pvrusb2-devattr.c
index e799331389b1..c6da8f77e1a2 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-devattr.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-devattr.c
@@ -28,6 +28,7 @@ pvr2_device_desc structures.
28 28
29#include "pvrusb2-devattr.h" 29#include "pvrusb2-devattr.h"
30#include <linux/usb.h> 30#include <linux/usb.h>
31#include <linux/module.h>
31/* This is needed in order to pull in tuner type ids... */ 32/* This is needed in order to pull in tuner type ids... */
32#include <linux/i2c.h> 33#include <linux/i2c.h>
33#include <media/tuner.h> 34#include <media/tuner.h>
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw.c b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
index 5a6f24d1246d..122b45760f0d 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
@@ -21,6 +21,7 @@
21#include <linux/errno.h> 21#include <linux/errno.h>
22#include <linux/string.h> 22#include <linux/string.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/module.h>
24#include <linux/firmware.h> 25#include <linux/firmware.h>
25#include <linux/videodev2.h> 26#include <linux/videodev2.h>
26#include <media/v4l2-common.h> 27#include <media/v4l2-common.h>
diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
index e72d5103e778..885ce11f222d 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
@@ -19,6 +19,7 @@
19 */ 19 */
20 20
21#include <linux/i2c.h> 21#include <linux/i2c.h>
22#include <linux/module.h>
22#include <media/ir-kbd-i2c.h> 23#include <media/ir-kbd-i2c.h>
23#include "pvrusb2-i2c-core.h" 24#include "pvrusb2-i2c-core.h"
24#include "pvrusb2-hdw-internal.h" 25#include "pvrusb2-hdw-internal.h"
diff --git a/drivers/media/video/pvrusb2/pvrusb2-v4l2.c b/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
index ce7ac4595276..6d666174dbb4 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
@@ -29,6 +29,7 @@
29#include "pvrusb2-v4l2.h" 29#include "pvrusb2-v4l2.h"
30#include "pvrusb2-ioread.h" 30#include "pvrusb2-ioread.h"
31#include <linux/videodev2.h> 31#include <linux/videodev2.h>
32#include <linux/module.h>
32#include <media/v4l2-dev.h> 33#include <media/v4l2-dev.h>
33#include <media/v4l2-common.h> 34#include <media/v4l2-common.h>
34#include <media/v4l2-ioctl.h> 35#include <media/v4l2-ioctl.h>
diff --git a/drivers/media/video/pwc/pwc-if.c b/drivers/media/video/pwc/pwc-if.c
index 360be226718d..01ff643e682d 100644
--- a/drivers/media/video/pwc/pwc-if.c
+++ b/drivers/media/video/pwc/pwc-if.c
@@ -744,9 +744,9 @@ static int pwc_video_mmap(struct file *file, struct vm_area_struct *vma)
744/***************************************************************************/ 744/***************************************************************************/
745/* Videobuf2 operations */ 745/* Videobuf2 operations */
746 746
747static int queue_setup(struct vb2_queue *vq, unsigned int *nbuffers, 747static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
748 unsigned int *nplanes, unsigned int sizes[], 748 unsigned int *nbuffers, unsigned int *nplanes,
749 void *alloc_ctxs[]) 749 unsigned int sizes[], void *alloc_ctxs[])
750{ 750{
751 struct pwc_device *pdev = vb2_get_drv_priv(vq); 751 struct pwc_device *pdev = vb2_get_drv_priv(vq);
752 752
diff --git a/drivers/media/video/pxa_camera.c b/drivers/media/video/pxa_camera.c
index d07df22a5ec6..79fb22c89ae9 100644
--- a/drivers/media/video/pxa_camera.c
+++ b/drivers/media/video/pxa_camera.c
@@ -214,6 +214,7 @@ struct pxa_camera_dev {
214 unsigned long ciclk; 214 unsigned long ciclk;
215 unsigned long mclk; 215 unsigned long mclk;
216 u32 mclk_divisor; 216 u32 mclk_divisor;
217 u16 width_flags; /* max 10 bits */
217 218
218 struct list_head capture; 219 struct list_head capture;
219 220
@@ -1020,37 +1021,20 @@ static int test_platform_param(struct pxa_camera_dev *pcdev,
1020 * quick capture interface supports both. 1021 * quick capture interface supports both.
1021 */ 1022 */
1022 *flags = (pcdev->platform_flags & PXA_CAMERA_MASTER ? 1023 *flags = (pcdev->platform_flags & PXA_CAMERA_MASTER ?
1023 SOCAM_MASTER : SOCAM_SLAVE) | 1024 V4L2_MBUS_MASTER : V4L2_MBUS_SLAVE) |
1024 SOCAM_HSYNC_ACTIVE_HIGH | 1025 V4L2_MBUS_HSYNC_ACTIVE_HIGH |
1025 SOCAM_HSYNC_ACTIVE_LOW | 1026 V4L2_MBUS_HSYNC_ACTIVE_LOW |
1026 SOCAM_VSYNC_ACTIVE_HIGH | 1027 V4L2_MBUS_VSYNC_ACTIVE_HIGH |
1027 SOCAM_VSYNC_ACTIVE_LOW | 1028 V4L2_MBUS_VSYNC_ACTIVE_LOW |
1028 SOCAM_DATA_ACTIVE_HIGH | 1029 V4L2_MBUS_DATA_ACTIVE_HIGH |
1029 SOCAM_PCLK_SAMPLE_RISING | 1030 V4L2_MBUS_PCLK_SAMPLE_RISING |
1030 SOCAM_PCLK_SAMPLE_FALLING; 1031 V4L2_MBUS_PCLK_SAMPLE_FALLING;
1031 1032
1032 /* If requested data width is supported by the platform, use it */ 1033 /* If requested data width is supported by the platform, use it */
1033 switch (buswidth) { 1034 if ((1 << (buswidth - 1)) & pcdev->width_flags)
1034 case 10: 1035 return 0;
1035 if (!(pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_10))
1036 return -EINVAL;
1037 *flags |= SOCAM_DATAWIDTH_10;
1038 break;
1039 case 9:
1040 if (!(pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_9))
1041 return -EINVAL;
1042 *flags |= SOCAM_DATAWIDTH_9;
1043 break;
1044 case 8:
1045 if (!(pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_8))
1046 return -EINVAL;
1047 *flags |= SOCAM_DATAWIDTH_8;
1048 break;
1049 default:
1050 return -EINVAL;
1051 }
1052 1036
1053 return 0; 1037 return -EINVAL;
1054} 1038}
1055 1039
1056static void pxa_camera_setup_cicr(struct soc_camera_device *icd, 1040static void pxa_camera_setup_cicr(struct soc_camera_device *icd,
@@ -1070,12 +1054,12 @@ static void pxa_camera_setup_cicr(struct soc_camera_device *icd,
1070 * Datawidth is now guaranteed to be equal to one of the three values. 1054 * Datawidth is now guaranteed to be equal to one of the three values.
1071 * We fix bit-per-pixel equal to data-width... 1055 * We fix bit-per-pixel equal to data-width...
1072 */ 1056 */
1073 switch (flags & SOCAM_DATAWIDTH_MASK) { 1057 switch (icd->current_fmt->host_fmt->bits_per_sample) {
1074 case SOCAM_DATAWIDTH_10: 1058 case 10:
1075 dw = 4; 1059 dw = 4;
1076 bpp = 0x40; 1060 bpp = 0x40;
1077 break; 1061 break;
1078 case SOCAM_DATAWIDTH_9: 1062 case 9:
1079 dw = 3; 1063 dw = 3;
1080 bpp = 0x20; 1064 bpp = 0x20;
1081 break; 1065 break;
@@ -1084,7 +1068,7 @@ static void pxa_camera_setup_cicr(struct soc_camera_device *icd,
1084 * Actually it can only be 8 now, 1068 * Actually it can only be 8 now,
1085 * default is just to silence compiler warnings 1069 * default is just to silence compiler warnings
1086 */ 1070 */
1087 case SOCAM_DATAWIDTH_8: 1071 case 8:
1088 dw = 2; 1072 dw = 2;
1089 bpp = 0; 1073 bpp = 0;
1090 } 1074 }
@@ -1093,11 +1077,11 @@ static void pxa_camera_setup_cicr(struct soc_camera_device *icd,
1093 cicr4 |= CICR4_PCLK_EN; 1077 cicr4 |= CICR4_PCLK_EN;
1094 if (pcdev->platform_flags & PXA_CAMERA_MCLK_EN) 1078 if (pcdev->platform_flags & PXA_CAMERA_MCLK_EN)
1095 cicr4 |= CICR4_MCLK_EN; 1079 cicr4 |= CICR4_MCLK_EN;
1096 if (flags & SOCAM_PCLK_SAMPLE_FALLING) 1080 if (flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)
1097 cicr4 |= CICR4_PCP; 1081 cicr4 |= CICR4_PCP;
1098 if (flags & SOCAM_HSYNC_ACTIVE_LOW) 1082 if (flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)
1099 cicr4 |= CICR4_HSP; 1083 cicr4 |= CICR4_HSP;
1100 if (flags & SOCAM_VSYNC_ACTIVE_LOW) 1084 if (flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)
1101 cicr4 |= CICR4_VSP; 1085 cicr4 |= CICR4_VSP;
1102 1086
1103 cicr0 = __raw_readl(pcdev->base + CICR0); 1087 cicr0 = __raw_readl(pcdev->base + CICR0);
@@ -1151,9 +1135,11 @@ static void pxa_camera_setup_cicr(struct soc_camera_device *icd,
1151 1135
1152static int pxa_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt) 1136static int pxa_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt)
1153{ 1137{
1138 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
1154 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 1139 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
1155 struct pxa_camera_dev *pcdev = ici->priv; 1140 struct pxa_camera_dev *pcdev = ici->priv;
1156 unsigned long bus_flags, camera_flags, common_flags; 1141 struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,};
1142 unsigned long bus_flags, common_flags;
1157 int ret; 1143 int ret;
1158 struct pxa_cam *cam = icd->host_priv; 1144 struct pxa_cam *cam = icd->host_priv;
1159 1145
@@ -1162,44 +1148,58 @@ static int pxa_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt)
1162 if (ret < 0) 1148 if (ret < 0)
1163 return ret; 1149 return ret;
1164 1150
1165 camera_flags = icd->ops->query_bus_param(icd); 1151 ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg);
1166 1152 if (!ret) {
1167 common_flags = soc_camera_bus_param_compatible(camera_flags, bus_flags); 1153 common_flags = soc_mbus_config_compatible(&cfg,
1168 if (!common_flags) 1154 bus_flags);
1169 return -EINVAL; 1155 if (!common_flags) {
1156 dev_warn(icd->parent,
1157 "Flags incompatible: camera 0x%x, host 0x%lx\n",
1158 cfg.flags, bus_flags);
1159 return -EINVAL;
1160 }
1161 } else if (ret != -ENOIOCTLCMD) {
1162 return ret;
1163 } else {
1164 common_flags = bus_flags;
1165 }
1170 1166
1171 pcdev->channels = 1; 1167 pcdev->channels = 1;
1172 1168
1173 /* Make choises, based on platform preferences */ 1169 /* Make choises, based on platform preferences */
1174 if ((common_flags & SOCAM_HSYNC_ACTIVE_HIGH) && 1170 if ((common_flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) &&
1175 (common_flags & SOCAM_HSYNC_ACTIVE_LOW)) { 1171 (common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)) {
1176 if (pcdev->platform_flags & PXA_CAMERA_HSP) 1172 if (pcdev->platform_flags & PXA_CAMERA_HSP)
1177 common_flags &= ~SOCAM_HSYNC_ACTIVE_HIGH; 1173 common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_HIGH;
1178 else 1174 else
1179 common_flags &= ~SOCAM_HSYNC_ACTIVE_LOW; 1175 common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_LOW;
1180 } 1176 }
1181 1177
1182 if ((common_flags & SOCAM_VSYNC_ACTIVE_HIGH) && 1178 if ((common_flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) &&
1183 (common_flags & SOCAM_VSYNC_ACTIVE_LOW)) { 1179 (common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)) {
1184 if (pcdev->platform_flags & PXA_CAMERA_VSP) 1180 if (pcdev->platform_flags & PXA_CAMERA_VSP)
1185 common_flags &= ~SOCAM_VSYNC_ACTIVE_HIGH; 1181 common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_HIGH;
1186 else 1182 else
1187 common_flags &= ~SOCAM_VSYNC_ACTIVE_LOW; 1183 common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_LOW;
1188 } 1184 }
1189 1185
1190 if ((common_flags & SOCAM_PCLK_SAMPLE_RISING) && 1186 if ((common_flags & V4L2_MBUS_PCLK_SAMPLE_RISING) &&
1191 (common_flags & SOCAM_PCLK_SAMPLE_FALLING)) { 1187 (common_flags & V4L2_MBUS_PCLK_SAMPLE_FALLING)) {
1192 if (pcdev->platform_flags & PXA_CAMERA_PCP) 1188 if (pcdev->platform_flags & PXA_CAMERA_PCP)
1193 common_flags &= ~SOCAM_PCLK_SAMPLE_RISING; 1189 common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_RISING;
1194 else 1190 else
1195 common_flags &= ~SOCAM_PCLK_SAMPLE_FALLING; 1191 common_flags &= ~V4L2_MBUS_PCLK_SAMPLE_FALLING;
1196 } 1192 }
1197 1193
1198 cam->flags = common_flags; 1194 cfg.flags = common_flags;
1199 1195 ret = v4l2_subdev_call(sd, video, s_mbus_config, &cfg);
1200 ret = icd->ops->set_bus_param(icd, common_flags); 1196 if (ret < 0 && ret != -ENOIOCTLCMD) {
1201 if (ret < 0) 1197 dev_dbg(icd->parent, "camera s_mbus_config(0x%lx) returned %d\n",
1198 common_flags, ret);
1202 return ret; 1199 return ret;
1200 }
1201
1202 cam->flags = common_flags;
1203 1203
1204 pxa_camera_setup_cicr(icd, common_flags, pixfmt); 1204 pxa_camera_setup_cicr(icd, common_flags, pixfmt);
1205 1205
@@ -1209,17 +1209,31 @@ static int pxa_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt)
1209static int pxa_camera_try_bus_param(struct soc_camera_device *icd, 1209static int pxa_camera_try_bus_param(struct soc_camera_device *icd,
1210 unsigned char buswidth) 1210 unsigned char buswidth)
1211{ 1211{
1212 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
1212 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 1213 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
1213 struct pxa_camera_dev *pcdev = ici->priv; 1214 struct pxa_camera_dev *pcdev = ici->priv;
1214 unsigned long bus_flags, camera_flags; 1215 struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,};
1216 unsigned long bus_flags, common_flags;
1215 int ret = test_platform_param(pcdev, buswidth, &bus_flags); 1217 int ret = test_platform_param(pcdev, buswidth, &bus_flags);
1216 1218
1217 if (ret < 0) 1219 if (ret < 0)
1218 return ret; 1220 return ret;
1219 1221
1220 camera_flags = icd->ops->query_bus_param(icd); 1222 ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg);
1223 if (!ret) {
1224 common_flags = soc_mbus_config_compatible(&cfg,
1225 bus_flags);
1226 if (!common_flags) {
1227 dev_warn(icd->parent,
1228 "Flags incompatible: camera 0x%x, host 0x%lx\n",
1229 cfg.flags, bus_flags);
1230 return -EINVAL;
1231 }
1232 } else if (ret == -ENOIOCTLCMD) {
1233 ret = 0;
1234 }
1221 1235
1222 return soc_camera_bus_param_compatible(camera_flags, bus_flags) ? 0 : -EINVAL; 1236 return ret;
1223} 1237}
1224 1238
1225static const struct soc_mbus_pixelfmt pxa_camera_formats[] = { 1239static const struct soc_mbus_pixelfmt pxa_camera_formats[] = {
@@ -1687,6 +1701,12 @@ static int __devinit pxa_camera_probe(struct platform_device *pdev)
1687 "data widths, using default 10 bit\n"); 1701 "data widths, using default 10 bit\n");
1688 pcdev->platform_flags |= PXA_CAMERA_DATAWIDTH_10; 1702 pcdev->platform_flags |= PXA_CAMERA_DATAWIDTH_10;
1689 } 1703 }
1704 if (pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_8)
1705 pcdev->width_flags = 1 << 7;
1706 if (pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_9)
1707 pcdev->width_flags |= 1 << 8;
1708 if (pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_10)
1709 pcdev->width_flags |= 1 << 9;
1690 pcdev->mclk = pcdev->pdata->mclk_10khz * 10000; 1710 pcdev->mclk = pcdev->pdata->mclk_10khz * 10000;
1691 if (!pcdev->mclk) { 1711 if (!pcdev->mclk) {
1692 dev_warn(&pdev->dev, 1712 dev_warn(&pdev->dev,
diff --git a/drivers/media/video/rj54n1cb0c.c b/drivers/media/video/rj54n1cb0c.c
index 847ccc067e87..9937386a3bae 100644
--- a/drivers/media/video/rj54n1cb0c.c
+++ b/drivers/media/video/rj54n1cb0c.c
@@ -11,13 +11,15 @@
11#include <linux/delay.h> 11#include <linux/delay.h>
12#include <linux/i2c.h> 12#include <linux/i2c.h>
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/v4l2-mediabus.h>
14#include <linux/videodev2.h> 15#include <linux/videodev2.h>
16#include <linux/module.h>
15 17
16#include <media/rj54n1cb0c.h> 18#include <media/rj54n1cb0c.h>
17#include <media/soc_camera.h> 19#include <media/soc_camera.h>
18#include <media/soc_mediabus.h>
19#include <media/v4l2-subdev.h> 20#include <media/v4l2-subdev.h>
20#include <media/v4l2-chip-ident.h> 21#include <media/v4l2-chip-ident.h>
22#include <media/v4l2-ctrls.h>
21 23
22#define RJ54N1_DEV_CODE 0x0400 24#define RJ54N1_DEV_CODE 0x0400
23#define RJ54N1_DEV_CODE2 0x0401 25#define RJ54N1_DEV_CODE2 0x0401
@@ -148,6 +150,7 @@ struct rj54n1_clock_div {
148 150
149struct rj54n1 { 151struct rj54n1 {
150 struct v4l2_subdev subdev; 152 struct v4l2_subdev subdev;
153 struct v4l2_ctrl_handler hdl;
151 struct rj54n1_clock_div clk_div; 154 struct rj54n1_clock_div clk_div;
152 const struct rj54n1_datafmt *fmt; 155 const struct rj54n1_datafmt *fmt;
153 struct v4l2_rect rect; /* Sensor window */ 156 struct v4l2_rect rect; /* Sensor window */
@@ -499,31 +502,6 @@ static int rj54n1_s_stream(struct v4l2_subdev *sd, int enable)
499 return reg_set(client, RJ54N1_STILL_CONTROL, (!enable) << 7, 0x80); 502 return reg_set(client, RJ54N1_STILL_CONTROL, (!enable) << 7, 0x80);
500} 503}
501 504
502static int rj54n1_set_bus_param(struct soc_camera_device *icd,
503 unsigned long flags)
504{
505 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
506 struct i2c_client *client = v4l2_get_subdevdata(sd);
507 /* Figures 2.5-1 to 2.5-3 - default falling pixclk edge */
508
509 if (flags & SOCAM_PCLK_SAMPLE_RISING)
510 return reg_write(client, RJ54N1_OUT_SIGPO, 1 << 4);
511 else
512 return reg_write(client, RJ54N1_OUT_SIGPO, 0);
513}
514
515static unsigned long rj54n1_query_bus_param(struct soc_camera_device *icd)
516{
517 struct soc_camera_link *icl = to_soc_camera_link(icd);
518 const unsigned long flags =
519 SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING |
520 SOCAM_MASTER | SOCAM_DATAWIDTH_8 |
521 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH |
522 SOCAM_DATA_ACTIVE_HIGH;
523
524 return soc_camera_apply_sensor_flags(icl, flags);
525}
526
527static int rj54n1_set_rect(struct i2c_client *client, 505static int rj54n1_set_rect(struct i2c_client *client,
528 u16 reg_x, u16 reg_y, u16 reg_xy, 506 u16 reg_x, u16 reg_y, u16 reg_xy,
529 u32 width, u32 height) 507 u32 width, u32 height)
@@ -1202,134 +1180,51 @@ static int rj54n1_s_register(struct v4l2_subdev *sd,
1202} 1180}
1203#endif 1181#endif
1204 1182
1205static const struct v4l2_queryctrl rj54n1_controls[] = { 1183static int rj54n1_s_ctrl(struct v4l2_ctrl *ctrl)
1206 {
1207 .id = V4L2_CID_VFLIP,
1208 .type = V4L2_CTRL_TYPE_BOOLEAN,
1209 .name = "Flip Vertically",
1210 .minimum = 0,
1211 .maximum = 1,
1212 .step = 1,
1213 .default_value = 0,
1214 }, {
1215 .id = V4L2_CID_HFLIP,
1216 .type = V4L2_CTRL_TYPE_BOOLEAN,
1217 .name = "Flip Horizontally",
1218 .minimum = 0,
1219 .maximum = 1,
1220 .step = 1,
1221 .default_value = 0,
1222 }, {
1223 .id = V4L2_CID_GAIN,
1224 .type = V4L2_CTRL_TYPE_INTEGER,
1225 .name = "Gain",
1226 .minimum = 0,
1227 .maximum = 127,
1228 .step = 1,
1229 .default_value = 66,
1230 .flags = V4L2_CTRL_FLAG_SLIDER,
1231 }, {
1232 .id = V4L2_CID_AUTO_WHITE_BALANCE,
1233 .type = V4L2_CTRL_TYPE_BOOLEAN,
1234 .name = "Auto white balance",
1235 .minimum = 0,
1236 .maximum = 1,
1237 .step = 1,
1238 .default_value = 1,
1239 },
1240};
1241
1242static struct soc_camera_ops rj54n1_ops = {
1243 .set_bus_param = rj54n1_set_bus_param,
1244 .query_bus_param = rj54n1_query_bus_param,
1245 .controls = rj54n1_controls,
1246 .num_controls = ARRAY_SIZE(rj54n1_controls),
1247};
1248
1249static int rj54n1_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
1250{ 1184{
1185 struct rj54n1 *rj54n1 = container_of(ctrl->handler, struct rj54n1, hdl);
1186 struct v4l2_subdev *sd = &rj54n1->subdev;
1251 struct i2c_client *client = v4l2_get_subdevdata(sd); 1187 struct i2c_client *client = v4l2_get_subdevdata(sd);
1252 struct rj54n1 *rj54n1 = to_rj54n1(client);
1253 int data; 1188 int data;
1254 1189
1255 switch (ctrl->id) { 1190 switch (ctrl->id) {
1256 case V4L2_CID_VFLIP: 1191 case V4L2_CID_VFLIP:
1257 data = reg_read(client, RJ54N1_MIRROR_STILL_MODE); 1192 if (ctrl->val)
1258 if (data < 0)
1259 return -EIO;
1260 ctrl->value = !(data & 1);
1261 break;
1262 case V4L2_CID_HFLIP:
1263 data = reg_read(client, RJ54N1_MIRROR_STILL_MODE);
1264 if (data < 0)
1265 return -EIO;
1266 ctrl->value = !(data & 2);
1267 break;
1268 case V4L2_CID_GAIN:
1269 data = reg_read(client, RJ54N1_Y_GAIN);
1270 if (data < 0)
1271 return -EIO;
1272
1273 ctrl->value = data / 2;
1274 break;
1275 case V4L2_CID_AUTO_WHITE_BALANCE:
1276 ctrl->value = rj54n1->auto_wb;
1277 break;
1278 }
1279
1280 return 0;
1281}
1282
1283static int rj54n1_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
1284{
1285 int data;
1286 struct i2c_client *client = v4l2_get_subdevdata(sd);
1287 struct rj54n1 *rj54n1 = to_rj54n1(client);
1288 const struct v4l2_queryctrl *qctrl;
1289
1290 qctrl = soc_camera_find_qctrl(&rj54n1_ops, ctrl->id);
1291 if (!qctrl)
1292 return -EINVAL;
1293
1294 switch (ctrl->id) {
1295 case V4L2_CID_VFLIP:
1296 if (ctrl->value)
1297 data = reg_set(client, RJ54N1_MIRROR_STILL_MODE, 0, 1); 1193 data = reg_set(client, RJ54N1_MIRROR_STILL_MODE, 0, 1);
1298 else 1194 else
1299 data = reg_set(client, RJ54N1_MIRROR_STILL_MODE, 1, 1); 1195 data = reg_set(client, RJ54N1_MIRROR_STILL_MODE, 1, 1);
1300 if (data < 0) 1196 if (data < 0)
1301 return -EIO; 1197 return -EIO;
1302 break; 1198 return 0;
1303 case V4L2_CID_HFLIP: 1199 case V4L2_CID_HFLIP:
1304 if (ctrl->value) 1200 if (ctrl->val)
1305 data = reg_set(client, RJ54N1_MIRROR_STILL_MODE, 0, 2); 1201 data = reg_set(client, RJ54N1_MIRROR_STILL_MODE, 0, 2);
1306 else 1202 else
1307 data = reg_set(client, RJ54N1_MIRROR_STILL_MODE, 2, 2); 1203 data = reg_set(client, RJ54N1_MIRROR_STILL_MODE, 2, 2);
1308 if (data < 0) 1204 if (data < 0)
1309 return -EIO; 1205 return -EIO;
1310 break; 1206 return 0;
1311 case V4L2_CID_GAIN: 1207 case V4L2_CID_GAIN:
1312 if (ctrl->value > qctrl->maximum || 1208 if (reg_write(client, RJ54N1_Y_GAIN, ctrl->val * 2) < 0)
1313 ctrl->value < qctrl->minimum)
1314 return -EINVAL;
1315 else if (reg_write(client, RJ54N1_Y_GAIN, ctrl->value * 2) < 0)
1316 return -EIO; 1209 return -EIO;
1317 break; 1210 return 0;
1318 case V4L2_CID_AUTO_WHITE_BALANCE: 1211 case V4L2_CID_AUTO_WHITE_BALANCE:
1319 /* Auto WB area - whole image */ 1212 /* Auto WB area - whole image */
1320 if (reg_set(client, RJ54N1_WB_SEL_WEIGHT_I, ctrl->value << 7, 1213 if (reg_set(client, RJ54N1_WB_SEL_WEIGHT_I, ctrl->val << 7,
1321 0x80) < 0) 1214 0x80) < 0)
1322 return -EIO; 1215 return -EIO;
1323 rj54n1->auto_wb = ctrl->value; 1216 rj54n1->auto_wb = ctrl->val;
1324 break; 1217 return 0;
1325 } 1218 }
1326 1219
1327 return 0; 1220 return -EINVAL;
1328} 1221}
1329 1222
1223static const struct v4l2_ctrl_ops rj54n1_ctrl_ops = {
1224 .s_ctrl = rj54n1_s_ctrl,
1225};
1226
1330static struct v4l2_subdev_core_ops rj54n1_subdev_core_ops = { 1227static struct v4l2_subdev_core_ops rj54n1_subdev_core_ops = {
1331 .g_ctrl = rj54n1_g_ctrl,
1332 .s_ctrl = rj54n1_s_ctrl,
1333 .g_chip_ident = rj54n1_g_chip_ident, 1228 .g_chip_ident = rj54n1_g_chip_ident,
1334#ifdef CONFIG_VIDEO_ADV_DEBUG 1229#ifdef CONFIG_VIDEO_ADV_DEBUG
1335 .g_register = rj54n1_g_register, 1230 .g_register = rj54n1_g_register,
@@ -1337,6 +1232,36 @@ static struct v4l2_subdev_core_ops rj54n1_subdev_core_ops = {
1337#endif 1232#endif
1338}; 1233};
1339 1234
1235static int rj54n1_g_mbus_config(struct v4l2_subdev *sd,
1236 struct v4l2_mbus_config *cfg)
1237{
1238 struct i2c_client *client = v4l2_get_subdevdata(sd);
1239 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
1240
1241 cfg->flags =
1242 V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING |
1243 V4L2_MBUS_MASTER | V4L2_MBUS_DATA_ACTIVE_HIGH |
1244 V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_HIGH;
1245 cfg->type = V4L2_MBUS_PARALLEL;
1246 cfg->flags = soc_camera_apply_board_flags(icl, cfg);
1247
1248 return 0;
1249}
1250
1251static int rj54n1_s_mbus_config(struct v4l2_subdev *sd,
1252 const struct v4l2_mbus_config *cfg)
1253{
1254 struct i2c_client *client = v4l2_get_subdevdata(sd);
1255 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
1256
1257 /* Figures 2.5-1 to 2.5-3 - default falling pixclk edge */
1258 if (soc_camera_apply_board_flags(icl, cfg) &
1259 V4L2_MBUS_PCLK_SAMPLE_RISING)
1260 return reg_write(client, RJ54N1_OUT_SIGPO, 1 << 4);
1261 else
1262 return reg_write(client, RJ54N1_OUT_SIGPO, 0);
1263}
1264
1340static struct v4l2_subdev_video_ops rj54n1_subdev_video_ops = { 1265static struct v4l2_subdev_video_ops rj54n1_subdev_video_ops = {
1341 .s_stream = rj54n1_s_stream, 1266 .s_stream = rj54n1_s_stream,
1342 .s_mbus_fmt = rj54n1_s_fmt, 1267 .s_mbus_fmt = rj54n1_s_fmt,
@@ -1346,6 +1271,8 @@ static struct v4l2_subdev_video_ops rj54n1_subdev_video_ops = {
1346 .g_crop = rj54n1_g_crop, 1271 .g_crop = rj54n1_g_crop,
1347 .s_crop = rj54n1_s_crop, 1272 .s_crop = rj54n1_s_crop,
1348 .cropcap = rj54n1_cropcap, 1273 .cropcap = rj54n1_cropcap,
1274 .g_mbus_config = rj54n1_g_mbus_config,
1275 .s_mbus_config = rj54n1_s_mbus_config,
1349}; 1276};
1350 1277
1351static struct v4l2_subdev_ops rj54n1_subdev_ops = { 1278static struct v4l2_subdev_ops rj54n1_subdev_ops = {
@@ -1357,17 +1284,12 @@ static struct v4l2_subdev_ops rj54n1_subdev_ops = {
1357 * Interface active, can use i2c. If it fails, it can indeed mean, that 1284 * Interface active, can use i2c. If it fails, it can indeed mean, that
1358 * this wasn't our capture interface, so, we wait for the right one 1285 * this wasn't our capture interface, so, we wait for the right one
1359 */ 1286 */
1360static int rj54n1_video_probe(struct soc_camera_device *icd, 1287static int rj54n1_video_probe(struct i2c_client *client,
1361 struct i2c_client *client,
1362 struct rj54n1_pdata *priv) 1288 struct rj54n1_pdata *priv)
1363{ 1289{
1364 int data1, data2; 1290 int data1, data2;
1365 int ret; 1291 int ret;
1366 1292
1367 /* We must have a parent by now. And it cannot be a wrong one. */
1368 BUG_ON(!icd->parent ||
1369 to_soc_camera_host(icd->parent)->nr != icd->iface);
1370
1371 /* Read out the chip version register */ 1293 /* Read out the chip version register */
1372 data1 = reg_read(client, RJ54N1_DEV_CODE); 1294 data1 = reg_read(client, RJ54N1_DEV_CODE);
1373 data2 = reg_read(client, RJ54N1_DEV_CODE2); 1295 data2 = reg_read(client, RJ54N1_DEV_CODE2);
@@ -1395,18 +1317,11 @@ static int rj54n1_probe(struct i2c_client *client,
1395 const struct i2c_device_id *did) 1317 const struct i2c_device_id *did)
1396{ 1318{
1397 struct rj54n1 *rj54n1; 1319 struct rj54n1 *rj54n1;
1398 struct soc_camera_device *icd = client->dev.platform_data; 1320 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
1399 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 1321 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
1400 struct soc_camera_link *icl;
1401 struct rj54n1_pdata *rj54n1_priv; 1322 struct rj54n1_pdata *rj54n1_priv;
1402 int ret; 1323 int ret;
1403 1324
1404 if (!icd) {
1405 dev_err(&client->dev, "RJ54N1CB0C: missing soc-camera data!\n");
1406 return -EINVAL;
1407 }
1408
1409 icl = to_soc_camera_link(icd);
1410 if (!icl || !icl->priv) { 1325 if (!icl || !icl->priv) {
1411 dev_err(&client->dev, "RJ54N1CB0C: missing platform data!\n"); 1326 dev_err(&client->dev, "RJ54N1CB0C: missing platform data!\n");
1412 return -EINVAL; 1327 return -EINVAL;
@@ -1425,8 +1340,22 @@ static int rj54n1_probe(struct i2c_client *client,
1425 return -ENOMEM; 1340 return -ENOMEM;
1426 1341
1427 v4l2_i2c_subdev_init(&rj54n1->subdev, client, &rj54n1_subdev_ops); 1342 v4l2_i2c_subdev_init(&rj54n1->subdev, client, &rj54n1_subdev_ops);
1343 v4l2_ctrl_handler_init(&rj54n1->hdl, 4);
1344 v4l2_ctrl_new_std(&rj54n1->hdl, &rj54n1_ctrl_ops,
1345 V4L2_CID_VFLIP, 0, 1, 1, 0);
1346 v4l2_ctrl_new_std(&rj54n1->hdl, &rj54n1_ctrl_ops,
1347 V4L2_CID_HFLIP, 0, 1, 1, 0);
1348 v4l2_ctrl_new_std(&rj54n1->hdl, &rj54n1_ctrl_ops,
1349 V4L2_CID_GAIN, 0, 127, 1, 66);
1350 v4l2_ctrl_new_std(&rj54n1->hdl, &rj54n1_ctrl_ops,
1351 V4L2_CID_AUTO_WHITE_BALANCE, 0, 1, 1, 1);
1352 rj54n1->subdev.ctrl_handler = &rj54n1->hdl;
1353 if (rj54n1->hdl.error) {
1354 int err = rj54n1->hdl.error;
1428 1355
1429 icd->ops = &rj54n1_ops; 1356 kfree(rj54n1);
1357 return err;
1358 }
1430 1359
1431 rj54n1->clk_div = clk_div; 1360 rj54n1->clk_div = clk_div;
1432 rj54n1->rect.left = RJ54N1_COLUMN_SKIP; 1361 rj54n1->rect.left = RJ54N1_COLUMN_SKIP;
@@ -1440,25 +1369,24 @@ static int rj54n1_probe(struct i2c_client *client,
1440 rj54n1->tgclk_mhz = (rj54n1_priv->mclk_freq / PLL_L * PLL_N) / 1369 rj54n1->tgclk_mhz = (rj54n1_priv->mclk_freq / PLL_L * PLL_N) /
1441 (clk_div.ratio_tg + 1) / (clk_div.ratio_t + 1); 1370 (clk_div.ratio_tg + 1) / (clk_div.ratio_t + 1);
1442 1371
1443 ret = rj54n1_video_probe(icd, client, rj54n1_priv); 1372 ret = rj54n1_video_probe(client, rj54n1_priv);
1444 if (ret < 0) { 1373 if (ret < 0) {
1445 icd->ops = NULL; 1374 v4l2_ctrl_handler_free(&rj54n1->hdl);
1446 kfree(rj54n1); 1375 kfree(rj54n1);
1447 return ret; 1376 return ret;
1448 } 1377 }
1449 1378 return v4l2_ctrl_handler_setup(&rj54n1->hdl);
1450 return ret;
1451} 1379}
1452 1380
1453static int rj54n1_remove(struct i2c_client *client) 1381static int rj54n1_remove(struct i2c_client *client)
1454{ 1382{
1455 struct rj54n1 *rj54n1 = to_rj54n1(client); 1383 struct rj54n1 *rj54n1 = to_rj54n1(client);
1456 struct soc_camera_device *icd = client->dev.platform_data; 1384 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
1457 struct soc_camera_link *icl = to_soc_camera_link(icd);
1458 1385
1459 icd->ops = NULL; 1386 v4l2_device_unregister_subdev(&rj54n1->subdev);
1460 if (icl->free_bus) 1387 if (icl->free_bus)
1461 icl->free_bus(icl); 1388 icl->free_bus(icl);
1389 v4l2_ctrl_handler_free(&rj54n1->hdl);
1462 kfree(rj54n1); 1390 kfree(rj54n1);
1463 1391
1464 return 0; 1392 return 0;
diff --git a/drivers/media/video/s5k6aa.c b/drivers/media/video/s5k6aa.c
new file mode 100644
index 000000000000..2446736b7871
--- /dev/null
+++ b/drivers/media/video/s5k6aa.c
@@ -0,0 +1,1680 @@
1/*
2 * Driver for Samsung S5K6AAFX SXGA 1/6" 1.3M CMOS Image Sensor
3 * with embedded SoC ISP.
4 *
5 * Copyright (C) 2011, Samsung Electronics Co., Ltd.
6 * Sylwester Nawrocki <s.nawrocki@samsung.com>
7 *
8 * Based on a driver authored by Dongsoo Nathaniel Kim.
9 * Copyright (C) 2009, Dongsoo Nathaniel Kim <dongsoo45.kim@samsung.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 */
16
17#include <linux/clk.h>
18#include <linux/delay.h>
19#include <linux/gpio.h>
20#include <linux/i2c.h>
21#include <linux/media.h>
22#include <linux/regulator/consumer.h>
23#include <linux/slab.h>
24
25#include <media/media-entity.h>
26#include <media/v4l2-ctrls.h>
27#include <media/v4l2-device.h>
28#include <media/v4l2-subdev.h>
29#include <media/v4l2-mediabus.h>
30#include <media/s5k6aa.h>
31
32static int debug;
33module_param(debug, int, 0644);
34
35#define DRIVER_NAME "S5K6AA"
36
37/* The token to indicate array termination */
38#define S5K6AA_TERM 0xffff
39#define S5K6AA_OUT_WIDTH_DEF 640
40#define S5K6AA_OUT_HEIGHT_DEF 480
41#define S5K6AA_WIN_WIDTH_MAX 1280
42#define S5K6AA_WIN_HEIGHT_MAX 1024
43#define S5K6AA_WIN_WIDTH_MIN 8
44#define S5K6AA_WIN_HEIGHT_MIN 8
45
46/*
47 * H/W register Interface (0xD0000000 - 0xD0000FFF)
48 */
49#define AHB_MSB_ADDR_PTR 0xfcfc
50#define GEN_REG_OFFSH 0xd000
51#define REG_CMDWR_ADDRH 0x0028
52#define REG_CMDWR_ADDRL 0x002a
53#define REG_CMDRD_ADDRH 0x002c
54#define REG_CMDRD_ADDRL 0x002e
55#define REG_CMDBUF0_ADDR 0x0f12
56#define REG_CMDBUF1_ADDR 0x0f10
57
58/*
59 * Host S/W Register interface (0x70000000 - 0x70002000)
60 * The value of the two most significant address bytes is 0x7000,
61 * (HOST_SWIF_OFFS_H). The register addresses below specify 2 LSBs.
62 */
63#define HOST_SWIF_OFFSH 0x7000
64
65/* Initialization parameters */
66/* Master clock frequency in KHz */
67#define REG_I_INCLK_FREQ_L 0x01b8
68#define REG_I_INCLK_FREQ_H 0x01ba
69#define MIN_MCLK_FREQ_KHZ 6000U
70#define MAX_MCLK_FREQ_KHZ 27000U
71#define REG_I_USE_NPVI_CLOCKS 0x01c6
72#define REG_I_USE_NMIPI_CLOCKS 0x01c8
73
74/* Clock configurations, n = 0..2. REG_I_* frequency unit is 4 kHz. */
75#define REG_I_OPCLK_4KHZ(n) ((n) * 6 + 0x01cc)
76#define REG_I_MIN_OUTRATE_4KHZ(n) ((n) * 6 + 0x01ce)
77#define REG_I_MAX_OUTRATE_4KHZ(n) ((n) * 6 + 0x01d0)
78#define SYS_PLL_OUT_FREQ (48000000 / 4000)
79#define PCLK_FREQ_MIN (24000000 / 4000)
80#define PCLK_FREQ_MAX (48000000 / 4000)
81#define REG_I_INIT_PARAMS_UPDATED 0x01e0
82#define REG_I_ERROR_INFO 0x01e2
83
84/* General purpose parameters */
85#define REG_USER_BRIGHTNESS 0x01e4
86#define REG_USER_CONTRAST 0x01e6
87#define REG_USER_SATURATION 0x01e8
88#define REG_USER_SHARPBLUR 0x01ea
89
90#define REG_G_SPEC_EFFECTS 0x01ee
91#define REG_G_ENABLE_PREV 0x01f0
92#define REG_G_ENABLE_PREV_CHG 0x01f2
93#define REG_G_NEW_CFG_SYNC 0x01f8
94#define REG_G_PREVZOOM_IN_WIDTH 0x020a
95#define REG_G_PREVZOOM_IN_HEIGHT 0x020c
96#define REG_G_PREVZOOM_IN_XOFFS 0x020e
97#define REG_G_PREVZOOM_IN_YOFFS 0x0210
98#define REG_G_INPUTS_CHANGE_REQ 0x021a
99#define REG_G_ACTIVE_PREV_CFG 0x021c
100#define REG_G_PREV_CFG_CHG 0x021e
101#define REG_G_PREV_OPEN_AFTER_CH 0x0220
102#define REG_G_PREV_CFG_ERROR 0x0222
103
104/* Preview control section. n = 0...4. */
105#define PREG(n, x) ((n) * 0x26 + x)
106#define REG_P_OUT_WIDTH(n) PREG(n, 0x0242)
107#define REG_P_OUT_HEIGHT(n) PREG(n, 0x0244)
108#define REG_P_FMT(n) PREG(n, 0x0246)
109#define REG_P_MAX_OUT_RATE(n) PREG(n, 0x0248)
110#define REG_P_MIN_OUT_RATE(n) PREG(n, 0x024a)
111#define REG_P_PVI_MASK(n) PREG(n, 0x024c)
112#define REG_P_CLK_INDEX(n) PREG(n, 0x024e)
113#define REG_P_FR_RATE_TYPE(n) PREG(n, 0x0250)
114#define FR_RATE_DYNAMIC 0
115#define FR_RATE_FIXED 1
116#define FR_RATE_FIXED_ACCURATE 2
117#define REG_P_FR_RATE_Q_TYPE(n) PREG(n, 0x0252)
118#define FR_RATE_Q_BEST_FRRATE 1 /* Binning enabled */
119#define FR_RATE_Q_BEST_QUALITY 2 /* Binning disabled */
120/* Frame period in 0.1 ms units */
121#define REG_P_MAX_FR_TIME(n) PREG(n, 0x0254)
122#define REG_P_MIN_FR_TIME(n) PREG(n, 0x0256)
123/* Conversion to REG_P_[MAX/MIN]_FR_TIME value; __t: time in us */
124#define US_TO_FR_TIME(__t) ((__t) / 100)
125#define S5K6AA_MIN_FR_TIME 33300 /* us */
126#define S5K6AA_MAX_FR_TIME 650000 /* us */
127#define S5K6AA_MAX_HIGHRES_FR_TIME 666 /* x100 us */
128/* The below 5 registers are for "device correction" values */
129#define REG_P_COLORTEMP(n) PREG(n, 0x025e)
130#define REG_P_PREV_MIRROR(n) PREG(n, 0x0262)
131
132/* Extended image property controls */
133/* Exposure time in 10 us units */
134#define REG_SF_USR_EXPOSURE_L 0x03c6
135#define REG_SF_USR_EXPOSURE_H 0x03c8
136#define REG_SF_USR_EXPOSURE_CHG 0x03ca
137#define REG_SF_USR_TOT_GAIN 0x03cc
138#define REG_SF_USR_TOT_GAIN_CHG 0x03ce
139#define REG_SF_RGAIN 0x03d0
140#define REG_SF_RGAIN_CHG 0x03d2
141#define REG_SF_GGAIN 0x03d4
142#define REG_SF_GGAIN_CHG 0x03d6
143#define REG_SF_BGAIN 0x03d8
144#define REG_SF_BGAIN_CHG 0x03da
145#define REG_SF_FLICKER_QUANT 0x03dc
146#define REG_SF_FLICKER_QUANT_CHG 0x03de
147
148/* Output interface (parallel/MIPI) setup */
149#define REG_OIF_EN_MIPI_LANES 0x03fa
150#define REG_OIF_EN_PACKETS 0x03fc
151#define REG_OIF_CFG_CHG 0x03fe
152
153/* Auto-algorithms enable mask */
154#define REG_DBG_AUTOALG_EN 0x0400
155#define AALG_ALL_EN_MASK (1 << 0)
156#define AALG_AE_EN_MASK (1 << 1)
157#define AALG_DIVLEI_EN_MASK (1 << 2)
158#define AALG_WB_EN_MASK (1 << 3)
159#define AALG_FLICKER_EN_MASK (1 << 5)
160#define AALG_FIT_EN_MASK (1 << 6)
161#define AALG_WRHW_EN_MASK (1 << 7)
162
163/* Firmware revision information */
164#define REG_FW_APIVER 0x012e
165#define S5K6AAFX_FW_APIVER 0x0001
166#define REG_FW_REVISION 0x0130
167
168/* For now we use only one user configuration register set */
169#define S5K6AA_MAX_PRESETS 1
170
171static const char * const s5k6aa_supply_names[] = {
172 "vdd_core", /* Digital core supply 1.5V (1.4V to 1.6V) */
173 "vdda", /* Analog power supply 2.8V (2.6V to 3.0V) */
174 "vdd_reg", /* Regulator input power 1.8V (1.7V to 1.9V)
175 or 2.8V (2.6V to 3.0) */
176 "vddio", /* I/O supply 1.8V (1.65V to 1.95V)
177 or 2.8V (2.5V to 3.1V) */
178};
179#define S5K6AA_NUM_SUPPLIES ARRAY_SIZE(s5k6aa_supply_names)
180
181enum s5k6aa_gpio_id {
182 STBY,
183 RST,
184 GPIO_NUM,
185};
186
187struct s5k6aa_regval {
188 u16 addr;
189 u16 val;
190};
191
192struct s5k6aa_pixfmt {
193 enum v4l2_mbus_pixelcode code;
194 u32 colorspace;
195 /* REG_P_FMT(x) register value */
196 u16 reg_p_fmt;
197};
198
199struct s5k6aa_preset {
200 /* output pixel format and resolution */
201 struct v4l2_mbus_framefmt mbus_fmt;
202 u8 clk_id;
203 u8 index;
204};
205
206struct s5k6aa_ctrls {
207 struct v4l2_ctrl_handler handler;
208 /* Auto / manual white balance cluster */
209 struct v4l2_ctrl *awb;
210 struct v4l2_ctrl *gain_red;
211 struct v4l2_ctrl *gain_blue;
212 struct v4l2_ctrl *gain_green;
213 /* Mirror cluster */
214 struct v4l2_ctrl *hflip;
215 struct v4l2_ctrl *vflip;
216 /* Auto exposure / manual exposure and gain cluster */
217 struct v4l2_ctrl *auto_exp;
218 struct v4l2_ctrl *exposure;
219 struct v4l2_ctrl *gain;
220};
221
222struct s5k6aa_interval {
223 u16 reg_fr_time;
224 struct v4l2_fract interval;
225 /* Maximum rectangle for the interval */
226 struct v4l2_frmsize_discrete size;
227};
228
229struct s5k6aa {
230 struct v4l2_subdev sd;
231 struct media_pad pad;
232
233 enum v4l2_mbus_type bus_type;
234 u8 mipi_lanes;
235
236 int (*s_power)(int enable);
237 struct regulator_bulk_data supplies[S5K6AA_NUM_SUPPLIES];
238 struct s5k6aa_gpio gpio[GPIO_NUM];
239
240 /* external master clock frequency */
241 unsigned long mclk_frequency;
242 /* ISP internal master clock frequency */
243 u16 clk_fop;
244 /* output pixel clock frequency range */
245 u16 pclk_fmin;
246 u16 pclk_fmax;
247
248 unsigned int inv_hflip:1;
249 unsigned int inv_vflip:1;
250
251 /* protects the struct members below */
252 struct mutex lock;
253
254 /* sensor matrix scan window */
255 struct v4l2_rect ccd_rect;
256
257 struct s5k6aa_ctrls ctrls;
258 struct s5k6aa_preset presets[S5K6AA_MAX_PRESETS];
259 struct s5k6aa_preset *preset;
260 const struct s5k6aa_interval *fiv;
261
262 unsigned int streaming:1;
263 unsigned int apply_cfg:1;
264 unsigned int apply_crop:1;
265 unsigned int power;
266};
267
268static struct s5k6aa_regval s5k6aa_analog_config[] = {
269 /* Analog settings */
270 { 0x112a, 0x0000 }, { 0x1132, 0x0000 },
271 { 0x113e, 0x0000 }, { 0x115c, 0x0000 },
272 { 0x1164, 0x0000 }, { 0x1174, 0x0000 },
273 { 0x1178, 0x0000 }, { 0x077a, 0x0000 },
274 { 0x077c, 0x0000 }, { 0x077e, 0x0000 },
275 { 0x0780, 0x0000 }, { 0x0782, 0x0000 },
276 { 0x0784, 0x0000 }, { 0x0786, 0x0000 },
277 { 0x0788, 0x0000 }, { 0x07a2, 0x0000 },
278 { 0x07a4, 0x0000 }, { 0x07a6, 0x0000 },
279 { 0x07a8, 0x0000 }, { 0x07b6, 0x0000 },
280 { 0x07b8, 0x0002 }, { 0x07ba, 0x0004 },
281 { 0x07bc, 0x0004 }, { 0x07be, 0x0005 },
282 { 0x07c0, 0x0005 }, { S5K6AA_TERM, 0 },
283};
284
285/* TODO: Add RGB888 and Bayer format */
286static const struct s5k6aa_pixfmt s5k6aa_formats[] = {
287 { V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_JPEG, 5 },
288 /* range 16-240 */
289 { V4L2_MBUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_REC709, 6 },
290 { V4L2_MBUS_FMT_RGB565_2X8_BE, V4L2_COLORSPACE_JPEG, 0 },
291};
292
293static const struct s5k6aa_interval s5k6aa_intervals[] = {
294 { 1000, {10000, 1000000}, {1280, 1024} }, /* 10 fps */
295 { 666, {15000, 1000000}, {1280, 1024} }, /* 15 fps */
296 { 500, {20000, 1000000}, {1280, 720} }, /* 20 fps */
297 { 400, {25000, 1000000}, {640, 480} }, /* 25 fps */
298 { 333, {33300, 1000000}, {640, 480} }, /* 30 fps */
299};
300
301#define S5K6AA_INTERVAL_DEF_INDEX 1 /* 15 fps */
302
303static inline struct v4l2_subdev *ctrl_to_sd(struct v4l2_ctrl *ctrl)
304{
305 return &container_of(ctrl->handler, struct s5k6aa, ctrls.handler)->sd;
306}
307
308static inline struct s5k6aa *to_s5k6aa(struct v4l2_subdev *sd)
309{
310 return container_of(sd, struct s5k6aa, sd);
311}
312
313/* Set initial values for all preview presets */
314static void s5k6aa_presets_data_init(struct s5k6aa *s5k6aa)
315{
316 struct s5k6aa_preset *preset = &s5k6aa->presets[0];
317 int i;
318
319 for (i = 0; i < S5K6AA_MAX_PRESETS; i++) {
320 preset->mbus_fmt.width = S5K6AA_OUT_WIDTH_DEF;
321 preset->mbus_fmt.height = S5K6AA_OUT_HEIGHT_DEF;
322 preset->mbus_fmt.code = s5k6aa_formats[0].code;
323 preset->index = i;
324 preset->clk_id = 0;
325 preset++;
326 }
327
328 s5k6aa->fiv = &s5k6aa_intervals[S5K6AA_INTERVAL_DEF_INDEX];
329 s5k6aa->preset = &s5k6aa->presets[0];
330}
331
332static int s5k6aa_i2c_read(struct i2c_client *client, u16 addr, u16 *val)
333{
334 u8 wbuf[2] = {addr >> 8, addr & 0xFF};
335 struct i2c_msg msg[2];
336 u8 rbuf[2];
337 int ret;
338
339 msg[0].addr = client->addr;
340 msg[0].flags = 0;
341 msg[0].len = 2;
342 msg[0].buf = wbuf;
343
344 msg[1].addr = client->addr;
345 msg[1].flags = I2C_M_RD;
346 msg[1].len = 2;
347 msg[1].buf = rbuf;
348
349 ret = i2c_transfer(client->adapter, msg, 2);
350 *val = be16_to_cpu(*((u16 *)rbuf));
351
352 v4l2_dbg(3, debug, client, "i2c_read: 0x%04X : 0x%04x\n", addr, *val);
353
354 return ret == 2 ? 0 : ret;
355}
356
357static int s5k6aa_i2c_write(struct i2c_client *client, u16 addr, u16 val)
358{
359 u8 buf[4] = {addr >> 8, addr & 0xFF, val >> 8, val & 0xFF};
360
361 int ret = i2c_master_send(client, buf, 4);
362 v4l2_dbg(3, debug, client, "i2c_write: 0x%04X : 0x%04x\n", addr, val);
363
364 return ret == 4 ? 0 : ret;
365}
366
367/* The command register write, assumes Command_Wr_addH = 0x7000. */
368static int s5k6aa_write(struct i2c_client *c, u16 addr, u16 val)
369{
370 int ret = s5k6aa_i2c_write(c, REG_CMDWR_ADDRL, addr);
371 if (ret)
372 return ret;
373 return s5k6aa_i2c_write(c, REG_CMDBUF0_ADDR, val);
374}
375
376/* The command register read, assumes Command_Rd_addH = 0x7000. */
377static int s5k6aa_read(struct i2c_client *client, u16 addr, u16 *val)
378{
379 int ret = s5k6aa_i2c_write(client, REG_CMDRD_ADDRL, addr);
380 if (ret)
381 return ret;
382 return s5k6aa_i2c_read(client, REG_CMDBUF0_ADDR, val);
383}
384
385static int s5k6aa_write_array(struct v4l2_subdev *sd,
386 const struct s5k6aa_regval *msg)
387{
388 struct i2c_client *client = v4l2_get_subdevdata(sd);
389 u16 addr_incr = 0;
390 int ret = 0;
391
392 while (msg->addr != S5K6AA_TERM) {
393 if (addr_incr != 2)
394 ret = s5k6aa_i2c_write(client, REG_CMDWR_ADDRL,
395 msg->addr);
396 if (ret)
397 break;
398 ret = s5k6aa_i2c_write(client, REG_CMDBUF0_ADDR, msg->val);
399 if (ret)
400 break;
401 /* Assume that msg->addr is always less than 0xfffc */
402 addr_incr = (msg + 1)->addr - msg->addr;
403 msg++;
404 }
405
406 return ret;
407}
408
409/* Configure the AHB high address bytes for GTG registers access */
410static int s5k6aa_set_ahb_address(struct i2c_client *client)
411{
412 int ret = s5k6aa_i2c_write(client, AHB_MSB_ADDR_PTR, GEN_REG_OFFSH);
413 if (ret)
414 return ret;
415 ret = s5k6aa_i2c_write(client, REG_CMDRD_ADDRH, HOST_SWIF_OFFSH);
416 if (ret)
417 return ret;
418 return s5k6aa_i2c_write(client, REG_CMDWR_ADDRH, HOST_SWIF_OFFSH);
419}
420
421/**
422 * s5k6aa_configure_pixel_clock - apply ISP main clock/PLL configuration
423 *
424 * Configure the internal ISP PLL for the required output frequency.
425 * Locking: called with s5k6aa.lock mutex held.
426 */
427static int s5k6aa_configure_pixel_clocks(struct s5k6aa *s5k6aa)
428{
429 struct i2c_client *c = v4l2_get_subdevdata(&s5k6aa->sd);
430 unsigned long fmclk = s5k6aa->mclk_frequency / 1000;
431 u16 status;
432 int ret;
433
434 if (WARN(fmclk < MIN_MCLK_FREQ_KHZ || fmclk > MAX_MCLK_FREQ_KHZ,
435 "Invalid clock frequency: %ld\n", fmclk))
436 return -EINVAL;
437
438 s5k6aa->pclk_fmin = PCLK_FREQ_MIN;
439 s5k6aa->pclk_fmax = PCLK_FREQ_MAX;
440 s5k6aa->clk_fop = SYS_PLL_OUT_FREQ;
441
442 /* External input clock frequency in kHz */
443 ret = s5k6aa_write(c, REG_I_INCLK_FREQ_H, fmclk >> 16);
444 if (!ret)
445 ret = s5k6aa_write(c, REG_I_INCLK_FREQ_L, fmclk & 0xFFFF);
446 if (!ret)
447 ret = s5k6aa_write(c, REG_I_USE_NPVI_CLOCKS, 1);
448 /* Internal PLL frequency */
449 if (!ret)
450 ret = s5k6aa_write(c, REG_I_OPCLK_4KHZ(0), s5k6aa->clk_fop);
451 if (!ret)
452 ret = s5k6aa_write(c, REG_I_MIN_OUTRATE_4KHZ(0),
453 s5k6aa->pclk_fmin);
454 if (!ret)
455 ret = s5k6aa_write(c, REG_I_MAX_OUTRATE_4KHZ(0),
456 s5k6aa->pclk_fmax);
457 if (!ret)
458 ret = s5k6aa_write(c, REG_I_INIT_PARAMS_UPDATED, 1);
459 if (!ret)
460 ret = s5k6aa_read(c, REG_I_ERROR_INFO, &status);
461
462 return ret ? ret : (status ? -EINVAL : 0);
463}
464
465/* Set horizontal and vertical image flipping */
466static int s5k6aa_set_mirror(struct s5k6aa *s5k6aa, int horiz_flip)
467{
468 struct i2c_client *client = v4l2_get_subdevdata(&s5k6aa->sd);
469 int index = s5k6aa->preset->index;
470
471 unsigned int vflip = s5k6aa->ctrls.vflip->val ^ s5k6aa->inv_vflip;
472 unsigned int flip = (horiz_flip ^ s5k6aa->inv_hflip) | (vflip << 1);
473
474 return s5k6aa_write(client, REG_P_PREV_MIRROR(index), flip);
475}
476
477/* Configure auto/manual white balance and R/G/B gains */
478static int s5k6aa_set_awb(struct s5k6aa *s5k6aa, int awb)
479{
480 struct i2c_client *c = v4l2_get_subdevdata(&s5k6aa->sd);
481 struct s5k6aa_ctrls *ctrls = &s5k6aa->ctrls;
482 u16 reg;
483
484 int ret = s5k6aa_read(c, REG_DBG_AUTOALG_EN, &reg);
485
486 if (!ret && !awb) {
487 ret = s5k6aa_write(c, REG_SF_RGAIN, ctrls->gain_red->val);
488 if (!ret)
489 ret = s5k6aa_write(c, REG_SF_RGAIN_CHG, 1);
490 if (ret)
491 return ret;
492
493 ret = s5k6aa_write(c, REG_SF_GGAIN, ctrls->gain_green->val);
494 if (!ret)
495 ret = s5k6aa_write(c, REG_SF_GGAIN_CHG, 1);
496 if (ret)
497 return ret;
498
499 ret = s5k6aa_write(c, REG_SF_BGAIN, ctrls->gain_blue->val);
500 if (!ret)
501 ret = s5k6aa_write(c, REG_SF_BGAIN_CHG, 1);
502 }
503 if (!ret) {
504 reg = awb ? reg | AALG_WB_EN_MASK : reg & ~AALG_WB_EN_MASK;
505 ret = s5k6aa_write(c, REG_DBG_AUTOALG_EN, reg);
506 }
507
508 return ret;
509}
510
511/* Program FW with exposure time, 'exposure' in us units */
512static int s5k6aa_set_user_exposure(struct i2c_client *client, int exposure)
513{
514 unsigned int time = exposure / 10;
515
516 int ret = s5k6aa_write(client, REG_SF_USR_EXPOSURE_L, time & 0xffff);
517 if (!ret)
518 ret = s5k6aa_write(client, REG_SF_USR_EXPOSURE_H, time >> 16);
519 if (ret)
520 return ret;
521 return s5k6aa_write(client, REG_SF_USR_EXPOSURE_CHG, 1);
522}
523
524static int s5k6aa_set_user_gain(struct i2c_client *client, int gain)
525{
526 int ret = s5k6aa_write(client, REG_SF_USR_TOT_GAIN, gain);
527 if (ret)
528 return ret;
529 return s5k6aa_write(client, REG_SF_USR_TOT_GAIN_CHG, 1);
530}
531
532/* Set auto/manual exposure and total gain */
533static int s5k6aa_set_auto_exposure(struct s5k6aa *s5k6aa, int value)
534{
535 struct i2c_client *c = v4l2_get_subdevdata(&s5k6aa->sd);
536 unsigned int exp_time = s5k6aa->ctrls.exposure->val;
537 u16 auto_alg;
538
539 int ret = s5k6aa_read(c, REG_DBG_AUTOALG_EN, &auto_alg);
540 if (ret)
541 return ret;
542
543 v4l2_dbg(1, debug, c, "man_exp: %d, auto_exp: %d, a_alg: 0x%x\n",
544 exp_time, value, auto_alg);
545
546 if (value == V4L2_EXPOSURE_AUTO) {
547 auto_alg |= AALG_AE_EN_MASK | AALG_DIVLEI_EN_MASK;
548 } else {
549 ret = s5k6aa_set_user_exposure(c, exp_time);
550 if (ret)
551 return ret;
552 ret = s5k6aa_set_user_gain(c, s5k6aa->ctrls.gain->val);
553 if (ret)
554 return ret;
555 auto_alg &= ~(AALG_AE_EN_MASK | AALG_DIVLEI_EN_MASK);
556 }
557
558 return s5k6aa_write(c, REG_DBG_AUTOALG_EN, auto_alg);
559}
560
561static int s5k6aa_set_anti_flicker(struct s5k6aa *s5k6aa, int value)
562{
563 struct i2c_client *client = v4l2_get_subdevdata(&s5k6aa->sd);
564 u16 auto_alg;
565 int ret;
566
567 ret = s5k6aa_read(client, REG_DBG_AUTOALG_EN, &auto_alg);
568 if (ret)
569 return ret;
570
571 if (value == V4L2_CID_POWER_LINE_FREQUENCY_AUTO) {
572 auto_alg |= AALG_FLICKER_EN_MASK;
573 } else {
574 auto_alg &= ~AALG_FLICKER_EN_MASK;
575 /* The V4L2_CID_LINE_FREQUENCY control values match
576 * the register values */
577 ret = s5k6aa_write(client, REG_SF_FLICKER_QUANT, value);
578 if (ret)
579 return ret;
580 ret = s5k6aa_write(client, REG_SF_FLICKER_QUANT_CHG, 1);
581 if (ret)
582 return ret;
583 }
584
585 return s5k6aa_write(client, REG_DBG_AUTOALG_EN, auto_alg);
586}
587
588static int s5k6aa_set_colorfx(struct s5k6aa *s5k6aa, int val)
589{
590 struct i2c_client *client = v4l2_get_subdevdata(&s5k6aa->sd);
591 static const struct v4l2_control colorfx[] = {
592 { V4L2_COLORFX_NONE, 0 },
593 { V4L2_COLORFX_BW, 1 },
594 { V4L2_COLORFX_NEGATIVE, 2 },
595 { V4L2_COLORFX_SEPIA, 3 },
596 { V4L2_COLORFX_SKY_BLUE, 4 },
597 { V4L2_COLORFX_SKETCH, 5 },
598 };
599 int i;
600
601 for (i = 0; i < ARRAY_SIZE(colorfx); i++) {
602 if (colorfx[i].id == val)
603 return s5k6aa_write(client, REG_G_SPEC_EFFECTS,
604 colorfx[i].value);
605 }
606 return -EINVAL;
607}
608
609static int s5k6aa_preview_config_status(struct i2c_client *client)
610{
611 u16 error = 0;
612 int ret = s5k6aa_read(client, REG_G_PREV_CFG_ERROR, &error);
613
614 v4l2_dbg(1, debug, client, "error: 0x%x (%d)\n", error, ret);
615 return ret ? ret : (error ? -EINVAL : 0);
616}
617
618static int s5k6aa_get_pixfmt_index(struct s5k6aa *s5k6aa,
619 struct v4l2_mbus_framefmt *mf)
620{
621 unsigned int i;
622
623 for (i = 0; i < ARRAY_SIZE(s5k6aa_formats); i++)
624 if (mf->colorspace == s5k6aa_formats[i].colorspace &&
625 mf->code == s5k6aa_formats[i].code)
626 return i;
627 return 0;
628}
629
630static int s5k6aa_set_output_framefmt(struct s5k6aa *s5k6aa,
631 struct s5k6aa_preset *preset)
632{
633 struct i2c_client *client = v4l2_get_subdevdata(&s5k6aa->sd);
634 int fmt_index = s5k6aa_get_pixfmt_index(s5k6aa, &preset->mbus_fmt);
635 int ret;
636
637 ret = s5k6aa_write(client, REG_P_OUT_WIDTH(preset->index),
638 preset->mbus_fmt.width);
639 if (!ret)
640 ret = s5k6aa_write(client, REG_P_OUT_HEIGHT(preset->index),
641 preset->mbus_fmt.height);
642 if (!ret)
643 ret = s5k6aa_write(client, REG_P_FMT(preset->index),
644 s5k6aa_formats[fmt_index].reg_p_fmt);
645 return ret;
646}
647
648static int s5k6aa_set_input_params(struct s5k6aa *s5k6aa)
649{
650 struct i2c_client *c = v4l2_get_subdevdata(&s5k6aa->sd);
651 struct v4l2_rect *r = &s5k6aa->ccd_rect;
652 int ret;
653
654 ret = s5k6aa_write(c, REG_G_PREVZOOM_IN_WIDTH, r->width);
655 if (!ret)
656 ret = s5k6aa_write(c, REG_G_PREVZOOM_IN_HEIGHT, r->height);
657 if (!ret)
658 ret = s5k6aa_write(c, REG_G_PREVZOOM_IN_XOFFS, r->left);
659 if (!ret)
660 ret = s5k6aa_write(c, REG_G_PREVZOOM_IN_YOFFS, r->top);
661 if (!ret)
662 ret = s5k6aa_write(c, REG_G_INPUTS_CHANGE_REQ, 1);
663 if (!ret)
664 s5k6aa->apply_crop = 0;
665
666 return ret;
667}
668
669/**
670 * s5k6aa_configure_video_bus - configure the video output interface
671 * @bus_type: video bus type: parallel or MIPI-CSI
672 * @nlanes: number of MIPI lanes to be used (MIPI-CSI only)
673 *
674 * Note: Only parallel bus operation has been tested.
675 */
676static int s5k6aa_configure_video_bus(struct s5k6aa *s5k6aa,
677 enum v4l2_mbus_type bus_type, int nlanes)
678{
679 struct i2c_client *client = v4l2_get_subdevdata(&s5k6aa->sd);
680 u16 cfg = 0;
681 int ret;
682
683 /*
684 * TODO: The sensor is supposed to support BT.601 and BT.656
685 * but there is nothing indicating how to switch between both
686 * in the datasheet. For now default BT.601 interface is assumed.
687 */
688 if (bus_type == V4L2_MBUS_CSI2)
689 cfg = nlanes;
690 else if (bus_type != V4L2_MBUS_PARALLEL)
691 return -EINVAL;
692
693 ret = s5k6aa_write(client, REG_OIF_EN_MIPI_LANES, cfg);
694 if (ret)
695 return ret;
696 return s5k6aa_write(client, REG_OIF_CFG_CHG, 1);
697}
698
699/* This function should be called when switching to new user configuration set*/
700static int s5k6aa_new_config_sync(struct i2c_client *client, int timeout,
701 int cid)
702{
703 unsigned long end = jiffies + msecs_to_jiffies(timeout);
704 u16 reg = 1;
705 int ret;
706
707 ret = s5k6aa_write(client, REG_G_ACTIVE_PREV_CFG, cid);
708 if (!ret)
709 ret = s5k6aa_write(client, REG_G_PREV_CFG_CHG, 1);
710 if (!ret)
711 ret = s5k6aa_write(client, REG_G_NEW_CFG_SYNC, 1);
712 if (timeout == 0)
713 return ret;
714
715 while (ret >= 0 && time_is_after_jiffies(end)) {
716 ret = s5k6aa_read(client, REG_G_NEW_CFG_SYNC, &reg);
717 if (!reg)
718 return 0;
719 usleep_range(1000, 5000);
720 }
721 return ret ? ret : -ETIMEDOUT;
722}
723
724/**
725 * s5k6aa_set_prev_config - write user preview register set
726 *
727 * Configure output resolution and color fromat, pixel clock
728 * frequency range, device frame rate type and frame period range.
729 */
730static int s5k6aa_set_prev_config(struct s5k6aa *s5k6aa,
731 struct s5k6aa_preset *preset)
732{
733 struct i2c_client *client = v4l2_get_subdevdata(&s5k6aa->sd);
734 int idx = preset->index;
735 u16 frame_rate_q;
736 int ret;
737
738 if (s5k6aa->fiv->reg_fr_time >= S5K6AA_MAX_HIGHRES_FR_TIME)
739 frame_rate_q = FR_RATE_Q_BEST_FRRATE;
740 else
741 frame_rate_q = FR_RATE_Q_BEST_QUALITY;
742
743 ret = s5k6aa_set_output_framefmt(s5k6aa, preset);
744 if (!ret)
745 ret = s5k6aa_write(client, REG_P_MAX_OUT_RATE(idx),
746 s5k6aa->pclk_fmax);
747 if (!ret)
748 ret = s5k6aa_write(client, REG_P_MIN_OUT_RATE(idx),
749 s5k6aa->pclk_fmin);
750 if (!ret)
751 ret = s5k6aa_write(client, REG_P_CLK_INDEX(idx),
752 preset->clk_id);
753 if (!ret)
754 ret = s5k6aa_write(client, REG_P_FR_RATE_TYPE(idx),
755 FR_RATE_DYNAMIC);
756 if (!ret)
757 ret = s5k6aa_write(client, REG_P_FR_RATE_Q_TYPE(idx),
758 frame_rate_q);
759 if (!ret)
760 ret = s5k6aa_write(client, REG_P_MAX_FR_TIME(idx),
761 s5k6aa->fiv->reg_fr_time + 33);
762 if (!ret)
763 ret = s5k6aa_write(client, REG_P_MIN_FR_TIME(idx),
764 s5k6aa->fiv->reg_fr_time - 33);
765 if (!ret)
766 ret = s5k6aa_new_config_sync(client, 250, idx);
767 if (!ret)
768 ret = s5k6aa_preview_config_status(client);
769 if (!ret)
770 s5k6aa->apply_cfg = 0;
771
772 v4l2_dbg(1, debug, client, "Frame interval: %d +/- 3.3ms. (%d)\n",
773 s5k6aa->fiv->reg_fr_time, ret);
774 return ret;
775}
776
777/**
778 * s5k6aa_initialize_isp - basic ISP MCU initialization
779 *
780 * Configure AHB addresses for registers read/write; configure PLLs for
781 * required output pixel clock. The ISP power supply needs to be already
782 * enabled, with an optional H/W reset.
783 * Locking: called with s5k6aa.lock mutex held.
784 */
785static int s5k6aa_initialize_isp(struct v4l2_subdev *sd)
786{
787 struct i2c_client *client = v4l2_get_subdevdata(sd);
788 struct s5k6aa *s5k6aa = to_s5k6aa(sd);
789 int ret;
790
791 s5k6aa->apply_crop = 1;
792 s5k6aa->apply_cfg = 1;
793 msleep(100);
794
795 ret = s5k6aa_set_ahb_address(client);
796 if (ret)
797 return ret;
798 ret = s5k6aa_configure_video_bus(s5k6aa, s5k6aa->bus_type,
799 s5k6aa->mipi_lanes);
800 if (ret)
801 return ret;
802 ret = s5k6aa_write_array(sd, s5k6aa_analog_config);
803 if (ret)
804 return ret;
805 msleep(20);
806
807 return s5k6aa_configure_pixel_clocks(s5k6aa);
808}
809
810static int s5k6aa_gpio_set_value(struct s5k6aa *priv, int id, u32 val)
811{
812 if (!gpio_is_valid(priv->gpio[id].gpio))
813 return 0;
814 gpio_set_value(priv->gpio[id].gpio, !!val);
815 return 1;
816}
817
818static int s5k6aa_gpio_assert(struct s5k6aa *priv, int id)
819{
820 return s5k6aa_gpio_set_value(priv, id, priv->gpio[id].level);
821}
822
823static int s5k6aa_gpio_deassert(struct s5k6aa *priv, int id)
824{
825 return s5k6aa_gpio_set_value(priv, id, !priv->gpio[id].level);
826}
827
828static int __s5k6aa_power_on(struct s5k6aa *s5k6aa)
829{
830 int ret;
831
832 ret = regulator_bulk_enable(S5K6AA_NUM_SUPPLIES, s5k6aa->supplies);
833 if (ret)
834 return ret;
835 if (s5k6aa_gpio_deassert(s5k6aa, STBY))
836 usleep_range(150, 200);
837
838 if (s5k6aa->s_power)
839 ret = s5k6aa->s_power(1);
840 usleep_range(4000, 4000);
841
842 if (s5k6aa_gpio_deassert(s5k6aa, RST))
843 msleep(20);
844
845 return ret;
846}
847
848static int __s5k6aa_power_off(struct s5k6aa *s5k6aa)
849{
850 int ret;
851
852 if (s5k6aa_gpio_assert(s5k6aa, RST))
853 usleep_range(100, 150);
854
855 if (s5k6aa->s_power) {
856 ret = s5k6aa->s_power(0);
857 if (ret)
858 return ret;
859 }
860 if (s5k6aa_gpio_assert(s5k6aa, STBY))
861 usleep_range(50, 100);
862 s5k6aa->streaming = 0;
863
864 return regulator_bulk_disable(S5K6AA_NUM_SUPPLIES, s5k6aa->supplies);
865}
866
867/*
868 * V4L2 subdev core and video operations
869 */
870static int s5k6aa_set_power(struct v4l2_subdev *sd, int on)
871{
872 struct s5k6aa *s5k6aa = to_s5k6aa(sd);
873 int ret = 0;
874
875 mutex_lock(&s5k6aa->lock);
876
877 if (!on == s5k6aa->power) {
878 if (on) {
879 ret = __s5k6aa_power_on(s5k6aa);
880 if (!ret)
881 ret = s5k6aa_initialize_isp(sd);
882 } else {
883 ret = __s5k6aa_power_off(s5k6aa);
884 }
885
886 if (!ret)
887 s5k6aa->power += on ? 1 : -1;
888 }
889
890 mutex_unlock(&s5k6aa->lock);
891
892 if (!on || ret || s5k6aa->power != 1)
893 return ret;
894
895 return v4l2_ctrl_handler_setup(sd->ctrl_handler);
896}
897
898static int __s5k6aa_stream(struct s5k6aa *s5k6aa, int enable)
899{
900 struct i2c_client *client = v4l2_get_subdevdata(&s5k6aa->sd);
901 int ret = 0;
902
903 ret = s5k6aa_write(client, REG_G_ENABLE_PREV, enable);
904 if (!ret)
905 ret = s5k6aa_write(client, REG_G_ENABLE_PREV_CHG, 1);
906 if (!ret)
907 s5k6aa->streaming = enable;
908
909 return ret;
910}
911
912static int s5k6aa_s_stream(struct v4l2_subdev *sd, int on)
913{
914 struct s5k6aa *s5k6aa = to_s5k6aa(sd);
915 int ret = 0;
916
917 mutex_lock(&s5k6aa->lock);
918
919 if (s5k6aa->streaming == !on) {
920 if (!ret && s5k6aa->apply_cfg)
921 ret = s5k6aa_set_prev_config(s5k6aa, s5k6aa->preset);
922 if (s5k6aa->apply_crop)
923 ret = s5k6aa_set_input_params(s5k6aa);
924 if (!ret)
925 ret = __s5k6aa_stream(s5k6aa, !!on);
926 }
927 mutex_unlock(&s5k6aa->lock);
928
929 return ret;
930}
931
932static int s5k6aa_g_frame_interval(struct v4l2_subdev *sd,
933 struct v4l2_subdev_frame_interval *fi)
934{
935 struct s5k6aa *s5k6aa = to_s5k6aa(sd);
936
937 mutex_lock(&s5k6aa->lock);
938 fi->interval = s5k6aa->fiv->interval;
939 mutex_unlock(&s5k6aa->lock);
940
941 return 0;
942}
943
944static int __s5k6aa_set_frame_interval(struct s5k6aa *s5k6aa,
945 struct v4l2_subdev_frame_interval *fi)
946{
947 struct v4l2_mbus_framefmt *mbus_fmt = &s5k6aa->preset->mbus_fmt;
948 const struct s5k6aa_interval *fiv = &s5k6aa_intervals[0];
949 unsigned int err, min_err = UINT_MAX;
950 unsigned int i, fr_time;
951
952 if (fi->interval.denominator == 0)
953 return -EINVAL;
954
955 fr_time = fi->interval.numerator * 10000 / fi->interval.denominator;
956
957 for (i = 0; i < ARRAY_SIZE(s5k6aa_intervals); i++) {
958 const struct s5k6aa_interval *iv = &s5k6aa_intervals[i];
959
960 if (mbus_fmt->width > iv->size.width ||
961 mbus_fmt->height > iv->size.height)
962 continue;
963
964 err = abs(iv->reg_fr_time - fr_time);
965 if (err < min_err) {
966 fiv = iv;
967 min_err = err;
968 }
969 }
970 s5k6aa->fiv = fiv;
971
972 v4l2_dbg(1, debug, &s5k6aa->sd, "Changed frame interval to %d us\n",
973 fiv->reg_fr_time * 100);
974 return 0;
975}
976
977static int s5k6aa_s_frame_interval(struct v4l2_subdev *sd,
978 struct v4l2_subdev_frame_interval *fi)
979{
980 struct s5k6aa *s5k6aa = to_s5k6aa(sd);
981 int ret;
982
983 v4l2_dbg(1, debug, sd, "Setting %d/%d frame interval\n",
984 fi->interval.numerator, fi->interval.denominator);
985
986 mutex_lock(&s5k6aa->lock);
987 ret = __s5k6aa_set_frame_interval(s5k6aa, fi);
988 s5k6aa->apply_cfg = 1;
989
990 mutex_unlock(&s5k6aa->lock);
991 return ret;
992}
993
994/*
995 * V4L2 subdev pad level and video operations
996 */
997static int s5k6aa_enum_frame_interval(struct v4l2_subdev *sd,
998 struct v4l2_subdev_fh *fh,
999 struct v4l2_subdev_frame_interval_enum *fie)
1000{
1001 struct s5k6aa *s5k6aa = to_s5k6aa(sd);
1002 const struct s5k6aa_interval *fi;
1003 int ret = 0;
1004
1005 if (fie->index > ARRAY_SIZE(s5k6aa_intervals))
1006 return -EINVAL;
1007
1008 v4l_bound_align_image(&fie->width, S5K6AA_WIN_WIDTH_MIN,
1009 S5K6AA_WIN_WIDTH_MAX, 1,
1010 &fie->height, S5K6AA_WIN_HEIGHT_MIN,
1011 S5K6AA_WIN_HEIGHT_MAX, 1, 0);
1012
1013 mutex_lock(&s5k6aa->lock);
1014 fi = &s5k6aa_intervals[fie->index];
1015 if (fie->width > fi->size.width || fie->height > fi->size.height)
1016 ret = -EINVAL;
1017 else
1018 fie->interval = fi->interval;
1019 mutex_unlock(&s5k6aa->lock);
1020
1021 return ret;
1022}
1023
1024static int s5k6aa_enum_mbus_code(struct v4l2_subdev *sd,
1025 struct v4l2_subdev_fh *fh,
1026 struct v4l2_subdev_mbus_code_enum *code)
1027{
1028 if (code->index >= ARRAY_SIZE(s5k6aa_formats))
1029 return -EINVAL;
1030
1031 code->code = s5k6aa_formats[code->index].code;
1032 return 0;
1033}
1034
1035static int s5k6aa_enum_frame_size(struct v4l2_subdev *sd,
1036 struct v4l2_subdev_fh *fh,
1037 struct v4l2_subdev_frame_size_enum *fse)
1038{
1039 int i = ARRAY_SIZE(s5k6aa_formats);
1040
1041 if (fse->index > 0)
1042 return -EINVAL;
1043
1044 while (--i)
1045 if (fse->code == s5k6aa_formats[i].code)
1046 break;
1047
1048 fse->code = s5k6aa_formats[i].code;
1049 fse->min_width = S5K6AA_WIN_WIDTH_MIN;
1050 fse->max_width = S5K6AA_WIN_WIDTH_MAX;
1051 fse->max_height = S5K6AA_WIN_HEIGHT_MIN;
1052 fse->min_height = S5K6AA_WIN_HEIGHT_MAX;
1053
1054 return 0;
1055}
1056
1057static struct v4l2_rect *
1058__s5k6aa_get_crop_rect(struct s5k6aa *s5k6aa, struct v4l2_subdev_fh *fh,
1059 enum v4l2_subdev_format_whence which)
1060{
1061 if (which == V4L2_SUBDEV_FORMAT_ACTIVE)
1062 return &s5k6aa->ccd_rect;
1063 if (which == V4L2_SUBDEV_FORMAT_TRY)
1064 return v4l2_subdev_get_try_crop(fh, 0);
1065
1066 return NULL;
1067}
1068
1069static void s5k6aa_try_format(struct s5k6aa *s5k6aa,
1070 struct v4l2_mbus_framefmt *mf)
1071{
1072 unsigned int index;
1073
1074 v4l_bound_align_image(&mf->width, S5K6AA_WIN_WIDTH_MIN,
1075 S5K6AA_WIN_WIDTH_MAX, 1,
1076 &mf->height, S5K6AA_WIN_HEIGHT_MIN,
1077 S5K6AA_WIN_HEIGHT_MAX, 1, 0);
1078
1079 if (mf->colorspace != V4L2_COLORSPACE_JPEG &&
1080 mf->colorspace != V4L2_COLORSPACE_REC709)
1081 mf->colorspace = V4L2_COLORSPACE_JPEG;
1082
1083 index = s5k6aa_get_pixfmt_index(s5k6aa, mf);
1084
1085 mf->colorspace = s5k6aa_formats[index].colorspace;
1086 mf->code = s5k6aa_formats[index].code;
1087 mf->field = V4L2_FIELD_NONE;
1088}
1089
1090static int s5k6aa_get_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1091 struct v4l2_subdev_format *fmt)
1092{
1093 struct s5k6aa *s5k6aa = to_s5k6aa(sd);
1094 struct v4l2_mbus_framefmt *mf;
1095
1096 memset(fmt->reserved, 0, sizeof(fmt->reserved));
1097
1098 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
1099 mf = v4l2_subdev_get_try_format(fh, 0);
1100 fmt->format = *mf;
1101 return 0;
1102 }
1103
1104 mutex_lock(&s5k6aa->lock);
1105 fmt->format = s5k6aa->preset->mbus_fmt;
1106 mutex_unlock(&s5k6aa->lock);
1107
1108 return 0;
1109}
1110
1111static int s5k6aa_set_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1112 struct v4l2_subdev_format *fmt)
1113{
1114 struct s5k6aa *s5k6aa = to_s5k6aa(sd);
1115 struct s5k6aa_preset *preset = s5k6aa->preset;
1116 struct v4l2_mbus_framefmt *mf;
1117 struct v4l2_rect *crop;
1118 int ret = 0;
1119
1120 mutex_lock(&s5k6aa->lock);
1121 s5k6aa_try_format(s5k6aa, &fmt->format);
1122
1123 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
1124 mf = v4l2_subdev_get_try_format(fh, fmt->pad);
1125 crop = v4l2_subdev_get_try_crop(fh, 0);
1126 } else {
1127 if (s5k6aa->streaming) {
1128 ret = -EBUSY;
1129 } else {
1130 mf = &preset->mbus_fmt;
1131 crop = &s5k6aa->ccd_rect;
1132 s5k6aa->apply_cfg = 1;
1133 }
1134 }
1135
1136 if (ret == 0) {
1137 struct v4l2_subdev_frame_interval fiv = {
1138 .interval = {0, 1}
1139 };
1140
1141 *mf = fmt->format;
1142 /*
1143 * Make sure the crop window is valid, i.e. its size is
1144 * greater than the output window, as the ISP supports
1145 * only down-scaling.
1146 */
1147 crop->width = clamp_t(unsigned int, crop->width, mf->width,
1148 S5K6AA_WIN_WIDTH_MAX);
1149 crop->height = clamp_t(unsigned int, crop->height, mf->height,
1150 S5K6AA_WIN_HEIGHT_MAX);
1151 crop->left = clamp_t(unsigned int, crop->left, 0,
1152 S5K6AA_WIN_WIDTH_MAX - crop->width);
1153 crop->top = clamp_t(unsigned int, crop->top, 0,
1154 S5K6AA_WIN_HEIGHT_MAX - crop->height);
1155
1156 /* Reset to minimum possible frame interval */
1157 ret = __s5k6aa_set_frame_interval(s5k6aa, &fiv);
1158 }
1159 mutex_unlock(&s5k6aa->lock);
1160
1161 return ret;
1162}
1163
1164static int s5k6aa_get_crop(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1165 struct v4l2_subdev_crop *crop)
1166{
1167 struct s5k6aa *s5k6aa = to_s5k6aa(sd);
1168 struct v4l2_rect *rect;
1169
1170 memset(crop->reserved, 0, sizeof(crop->reserved));
1171 mutex_lock(&s5k6aa->lock);
1172
1173 rect = __s5k6aa_get_crop_rect(s5k6aa, fh, crop->which);
1174 if (rect)
1175 crop->rect = *rect;
1176
1177 mutex_unlock(&s5k6aa->lock);
1178
1179 v4l2_dbg(1, debug, sd, "Current crop rectangle: (%d,%d)/%dx%d\n",
1180 rect->left, rect->top, rect->width, rect->height);
1181
1182 return 0;
1183}
1184
1185static int s5k6aa_set_crop(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1186 struct v4l2_subdev_crop *crop)
1187{
1188 struct s5k6aa *s5k6aa = to_s5k6aa(sd);
1189 struct v4l2_mbus_framefmt *mf;
1190 unsigned int max_x, max_y;
1191 struct v4l2_rect *crop_r;
1192
1193 mutex_lock(&s5k6aa->lock);
1194 crop_r = __s5k6aa_get_crop_rect(s5k6aa, fh, crop->which);
1195
1196 if (crop->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
1197 mf = &s5k6aa->preset->mbus_fmt;
1198 s5k6aa->apply_crop = 1;
1199 } else {
1200 mf = v4l2_subdev_get_try_format(fh, 0);
1201 }
1202 v4l_bound_align_image(&crop->rect.width, mf->width,
1203 S5K6AA_WIN_WIDTH_MAX, 1,
1204 &crop->rect.height, mf->height,
1205 S5K6AA_WIN_HEIGHT_MAX, 1, 0);
1206
1207 max_x = (S5K6AA_WIN_WIDTH_MAX - crop->rect.width) & ~1;
1208 max_y = (S5K6AA_WIN_HEIGHT_MAX - crop->rect.height) & ~1;
1209
1210 crop->rect.left = clamp_t(unsigned int, crop->rect.left, 0, max_x);
1211 crop->rect.top = clamp_t(unsigned int, crop->rect.top, 0, max_y);
1212
1213 *crop_r = crop->rect;
1214
1215 mutex_unlock(&s5k6aa->lock);
1216
1217 v4l2_dbg(1, debug, sd, "Set crop rectangle: (%d,%d)/%dx%d\n",
1218 crop_r->left, crop_r->top, crop_r->width, crop_r->height);
1219
1220 return 0;
1221}
1222
1223static const struct v4l2_subdev_pad_ops s5k6aa_pad_ops = {
1224 .enum_mbus_code = s5k6aa_enum_mbus_code,
1225 .enum_frame_size = s5k6aa_enum_frame_size,
1226 .enum_frame_interval = s5k6aa_enum_frame_interval,
1227 .get_fmt = s5k6aa_get_fmt,
1228 .set_fmt = s5k6aa_set_fmt,
1229 .get_crop = s5k6aa_get_crop,
1230 .set_crop = s5k6aa_set_crop,
1231};
1232
1233static const struct v4l2_subdev_video_ops s5k6aa_video_ops = {
1234 .g_frame_interval = s5k6aa_g_frame_interval,
1235 .s_frame_interval = s5k6aa_s_frame_interval,
1236 .s_stream = s5k6aa_s_stream,
1237};
1238
1239/*
1240 * V4L2 subdev controls
1241 */
1242
1243static int s5k6aa_s_ctrl(struct v4l2_ctrl *ctrl)
1244{
1245 struct v4l2_subdev *sd = ctrl_to_sd(ctrl);
1246 struct i2c_client *client = v4l2_get_subdevdata(sd);
1247 struct s5k6aa *s5k6aa = to_s5k6aa(sd);
1248 int idx, err = 0;
1249
1250 v4l2_dbg(1, debug, sd, "ctrl: 0x%x, value: %d\n", ctrl->id, ctrl->val);
1251
1252 mutex_lock(&s5k6aa->lock);
1253 /*
1254 * If the device is not powered up by the host driver do
1255 * not apply any controls to H/W at this time. Instead
1256 * the controls will be restored right after power-up.
1257 */
1258 if (s5k6aa->power == 0)
1259 goto unlock;
1260 idx = s5k6aa->preset->index;
1261
1262 switch (ctrl->id) {
1263 case V4L2_CID_AUTO_WHITE_BALANCE:
1264 err = s5k6aa_set_awb(s5k6aa, ctrl->val);
1265 break;
1266
1267 case V4L2_CID_BRIGHTNESS:
1268 err = s5k6aa_write(client, REG_USER_BRIGHTNESS, ctrl->val);
1269 break;
1270
1271 case V4L2_CID_COLORFX:
1272 err = s5k6aa_set_colorfx(s5k6aa, ctrl->val);
1273 break;
1274
1275 case V4L2_CID_CONTRAST:
1276 err = s5k6aa_write(client, REG_USER_CONTRAST, ctrl->val);
1277 break;
1278
1279 case V4L2_CID_EXPOSURE_AUTO:
1280 err = s5k6aa_set_auto_exposure(s5k6aa, ctrl->val);
1281 break;
1282
1283 case V4L2_CID_HFLIP:
1284 err = s5k6aa_set_mirror(s5k6aa, ctrl->val);
1285 if (err)
1286 break;
1287 err = s5k6aa_write(client, REG_G_PREV_CFG_CHG, 1);
1288 break;
1289
1290 case V4L2_CID_POWER_LINE_FREQUENCY:
1291 err = s5k6aa_set_anti_flicker(s5k6aa, ctrl->val);
1292 break;
1293
1294 case V4L2_CID_SATURATION:
1295 err = s5k6aa_write(client, REG_USER_SATURATION, ctrl->val);
1296 break;
1297
1298 case V4L2_CID_SHARPNESS:
1299 err = s5k6aa_write(client, REG_USER_SHARPBLUR, ctrl->val);
1300 break;
1301
1302 case V4L2_CID_WHITE_BALANCE_TEMPERATURE:
1303 err = s5k6aa_write(client, REG_P_COLORTEMP(idx), ctrl->val);
1304 if (err)
1305 break;
1306 err = s5k6aa_write(client, REG_G_PREV_CFG_CHG, 1);
1307 break;
1308 }
1309unlock:
1310 mutex_unlock(&s5k6aa->lock);
1311 return err;
1312}
1313
1314static const struct v4l2_ctrl_ops s5k6aa_ctrl_ops = {
1315 .s_ctrl = s5k6aa_s_ctrl,
1316};
1317
1318static int s5k6aa_log_status(struct v4l2_subdev *sd)
1319{
1320 v4l2_ctrl_handler_log_status(sd->ctrl_handler, sd->name);
1321 return 0;
1322}
1323
1324#define V4L2_CID_RED_GAIN (V4L2_CTRL_CLASS_CAMERA | 0x1001)
1325#define V4L2_CID_GREEN_GAIN (V4L2_CTRL_CLASS_CAMERA | 0x1002)
1326#define V4L2_CID_BLUE_GAIN (V4L2_CTRL_CLASS_CAMERA | 0x1003)
1327
1328static const struct v4l2_ctrl_config s5k6aa_ctrls[] = {
1329 {
1330 .ops = &s5k6aa_ctrl_ops,
1331 .id = V4L2_CID_RED_GAIN,
1332 .type = V4L2_CTRL_TYPE_INTEGER,
1333 .name = "Gain, Red",
1334 .min = 0,
1335 .max = 256,
1336 .def = 127,
1337 .step = 1,
1338 }, {
1339 .ops = &s5k6aa_ctrl_ops,
1340 .id = V4L2_CID_GREEN_GAIN,
1341 .type = V4L2_CTRL_TYPE_INTEGER,
1342 .name = "Gain, Green",
1343 .min = 0,
1344 .max = 256,
1345 .def = 127,
1346 .step = 1,
1347 }, {
1348 .ops = &s5k6aa_ctrl_ops,
1349 .id = V4L2_CID_BLUE_GAIN,
1350 .type = V4L2_CTRL_TYPE_INTEGER,
1351 .name = "Gain, Blue",
1352 .min = 0,
1353 .max = 256,
1354 .def = 127,
1355 .step = 1,
1356 },
1357};
1358
1359static int s5k6aa_initialize_ctrls(struct s5k6aa *s5k6aa)
1360{
1361 const struct v4l2_ctrl_ops *ops = &s5k6aa_ctrl_ops;
1362 struct s5k6aa_ctrls *ctrls = &s5k6aa->ctrls;
1363 struct v4l2_ctrl_handler *hdl = &ctrls->handler;
1364
1365 int ret = v4l2_ctrl_handler_init(hdl, 16);
1366 if (ret)
1367 return ret;
1368 /* Auto white balance cluster */
1369 ctrls->awb = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_AUTO_WHITE_BALANCE,
1370 0, 1, 1, 1);
1371 ctrls->gain_red = v4l2_ctrl_new_custom(hdl, &s5k6aa_ctrls[0], NULL);
1372 ctrls->gain_green = v4l2_ctrl_new_custom(hdl, &s5k6aa_ctrls[1], NULL);
1373 ctrls->gain_blue = v4l2_ctrl_new_custom(hdl, &s5k6aa_ctrls[2], NULL);
1374 v4l2_ctrl_auto_cluster(4, &ctrls->awb, 0, false);
1375
1376 ctrls->hflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_HFLIP, 0, 1, 1, 0);
1377 ctrls->vflip = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_VFLIP, 0, 1, 1, 0);
1378 v4l2_ctrl_cluster(2, &ctrls->hflip);
1379
1380 ctrls->auto_exp = v4l2_ctrl_new_std_menu(hdl, ops,
1381 V4L2_CID_EXPOSURE_AUTO,
1382 V4L2_EXPOSURE_MANUAL, 0, V4L2_EXPOSURE_AUTO);
1383 /* Exposure time: x 1 us */
1384 ctrls->exposure = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_EXPOSURE,
1385 0, 6000000U, 1, 100000U);
1386 /* Total gain: 256 <=> 1x */
1387 ctrls->gain = v4l2_ctrl_new_std(hdl, ops, V4L2_CID_GAIN,
1388 0, 256, 1, 256);
1389 v4l2_ctrl_auto_cluster(3, &ctrls->auto_exp, 0, false);
1390
1391 v4l2_ctrl_new_std_menu(hdl, ops, V4L2_CID_POWER_LINE_FREQUENCY,
1392 V4L2_CID_POWER_LINE_FREQUENCY_AUTO, 0,
1393 V4L2_CID_POWER_LINE_FREQUENCY_AUTO);
1394
1395 v4l2_ctrl_new_std_menu(hdl, ops, V4L2_CID_COLORFX,
1396 V4L2_COLORFX_SKY_BLUE, ~0x6f, V4L2_COLORFX_NONE);
1397
1398 v4l2_ctrl_new_std(hdl, ops, V4L2_CID_WHITE_BALANCE_TEMPERATURE,
1399 0, 256, 1, 0);
1400
1401 v4l2_ctrl_new_std(hdl, ops, V4L2_CID_SATURATION, -127, 127, 1, 0);
1402 v4l2_ctrl_new_std(hdl, ops, V4L2_CID_BRIGHTNESS, -127, 127, 1, 0);
1403 v4l2_ctrl_new_std(hdl, ops, V4L2_CID_CONTRAST, -127, 127, 1, 0);
1404 v4l2_ctrl_new_std(hdl, ops, V4L2_CID_SHARPNESS, -127, 127, 1, 0);
1405
1406 if (hdl->error) {
1407 ret = hdl->error;
1408 v4l2_ctrl_handler_free(hdl);
1409 return ret;
1410 }
1411
1412 s5k6aa->sd.ctrl_handler = hdl;
1413 return 0;
1414}
1415
1416/*
1417 * V4L2 subdev internal operations
1418 */
1419static int s5k6aa_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
1420{
1421 struct v4l2_mbus_framefmt *format = v4l2_subdev_get_try_format(fh, 0);
1422 struct v4l2_rect *crop = v4l2_subdev_get_try_crop(fh, 0);
1423
1424 format->colorspace = s5k6aa_formats[0].colorspace;
1425 format->code = s5k6aa_formats[0].code;
1426 format->width = S5K6AA_OUT_WIDTH_DEF;
1427 format->height = S5K6AA_OUT_HEIGHT_DEF;
1428 format->field = V4L2_FIELD_NONE;
1429
1430 crop->width = S5K6AA_WIN_WIDTH_MAX;
1431 crop->height = S5K6AA_WIN_HEIGHT_MAX;
1432 crop->left = 0;
1433 crop->top = 0;
1434
1435 return 0;
1436}
1437
1438int s5k6aa_check_fw_revision(struct s5k6aa *s5k6aa)
1439{
1440 struct i2c_client *client = v4l2_get_subdevdata(&s5k6aa->sd);
1441 u16 api_ver = 0, fw_rev = 0;
1442
1443 int ret = s5k6aa_set_ahb_address(client);
1444
1445 if (!ret)
1446 ret = s5k6aa_read(client, REG_FW_APIVER, &api_ver);
1447 if (!ret)
1448 ret = s5k6aa_read(client, REG_FW_REVISION, &fw_rev);
1449 if (ret) {
1450 v4l2_err(&s5k6aa->sd, "FW revision check failed!\n");
1451 return ret;
1452 }
1453
1454 v4l2_info(&s5k6aa->sd, "FW API ver.: 0x%X, FW rev.: 0x%X\n",
1455 api_ver, fw_rev);
1456
1457 return api_ver == S5K6AAFX_FW_APIVER ? 0 : -ENODEV;
1458}
1459
1460static int s5k6aa_registered(struct v4l2_subdev *sd)
1461{
1462 struct s5k6aa *s5k6aa = to_s5k6aa(sd);
1463 int ret;
1464
1465 mutex_lock(&s5k6aa->lock);
1466 ret = __s5k6aa_power_on(s5k6aa);
1467 if (!ret) {
1468 msleep(100);
1469 ret = s5k6aa_check_fw_revision(s5k6aa);
1470 __s5k6aa_power_off(s5k6aa);
1471 }
1472 mutex_unlock(&s5k6aa->lock);
1473
1474 return ret;
1475}
1476
1477static const struct v4l2_subdev_internal_ops s5k6aa_subdev_internal_ops = {
1478 .registered = s5k6aa_registered,
1479 .open = s5k6aa_open,
1480};
1481
1482static const struct v4l2_subdev_core_ops s5k6aa_core_ops = {
1483 .s_power = s5k6aa_set_power,
1484 .log_status = s5k6aa_log_status,
1485};
1486
1487static const struct v4l2_subdev_ops s5k6aa_subdev_ops = {
1488 .core = &s5k6aa_core_ops,
1489 .pad = &s5k6aa_pad_ops,
1490 .video = &s5k6aa_video_ops,
1491};
1492
1493/*
1494 * GPIO setup
1495 */
1496static int s5k6aa_configure_gpio(int nr, int val, const char *name)
1497{
1498 unsigned long flags = val ? GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
1499 int ret;
1500
1501 if (!gpio_is_valid(nr))
1502 return 0;
1503 ret = gpio_request_one(nr, flags, name);
1504 if (!ret)
1505 gpio_export(nr, 0);
1506 return ret;
1507}
1508
1509static void s5k6aa_free_gpios(struct s5k6aa *s5k6aa)
1510{
1511 int i;
1512
1513 for (i = 0; i < ARRAY_SIZE(s5k6aa->gpio); i++) {
1514 if (!gpio_is_valid(s5k6aa->gpio[i].gpio))
1515 continue;
1516 gpio_free(s5k6aa->gpio[i].gpio);
1517 s5k6aa->gpio[i].gpio = -EINVAL;
1518 }
1519}
1520
1521static int s5k6aa_configure_gpios(struct s5k6aa *s5k6aa,
1522 const struct s5k6aa_platform_data *pdata)
1523{
1524 const struct s5k6aa_gpio *gpio = &pdata->gpio_stby;
1525 int ret;
1526
1527 s5k6aa->gpio[STBY].gpio = -EINVAL;
1528 s5k6aa->gpio[RST].gpio = -EINVAL;
1529
1530 ret = s5k6aa_configure_gpio(gpio->gpio, gpio->level, "S5K6AA_STBY");
1531 if (ret) {
1532 s5k6aa_free_gpios(s5k6aa);
1533 return ret;
1534 }
1535 s5k6aa->gpio[STBY] = *gpio;
1536 if (gpio_is_valid(gpio->gpio))
1537 gpio_set_value(gpio->gpio, 0);
1538
1539 gpio = &pdata->gpio_reset;
1540 ret = s5k6aa_configure_gpio(gpio->gpio, gpio->level, "S5K6AA_RST");
1541 if (ret) {
1542 s5k6aa_free_gpios(s5k6aa);
1543 return ret;
1544 }
1545 s5k6aa->gpio[RST] = *gpio;
1546 if (gpio_is_valid(gpio->gpio))
1547 gpio_set_value(gpio->gpio, 0);
1548
1549 return 0;
1550}
1551
1552static int s5k6aa_probe(struct i2c_client *client,
1553 const struct i2c_device_id *id)
1554{
1555 const struct s5k6aa_platform_data *pdata = client->dev.platform_data;
1556 struct v4l2_subdev *sd;
1557 struct s5k6aa *s5k6aa;
1558 int i, ret;
1559
1560 if (pdata == NULL) {
1561 dev_err(&client->dev, "Platform data not specified\n");
1562 return -EINVAL;
1563 }
1564
1565 if (pdata->mclk_frequency == 0) {
1566 dev_err(&client->dev, "MCLK frequency not specified\n");
1567 return -EINVAL;
1568 }
1569
1570 s5k6aa = kzalloc(sizeof(*s5k6aa), GFP_KERNEL);
1571 if (!s5k6aa)
1572 return -ENOMEM;
1573
1574 mutex_init(&s5k6aa->lock);
1575
1576 s5k6aa->mclk_frequency = pdata->mclk_frequency;
1577 s5k6aa->bus_type = pdata->bus_type;
1578 s5k6aa->mipi_lanes = pdata->nlanes;
1579 s5k6aa->s_power = pdata->set_power;
1580 s5k6aa->inv_hflip = pdata->horiz_flip;
1581 s5k6aa->inv_vflip = pdata->vert_flip;
1582
1583 sd = &s5k6aa->sd;
1584 strlcpy(sd->name, DRIVER_NAME, sizeof(sd->name));
1585 v4l2_i2c_subdev_init(sd, client, &s5k6aa_subdev_ops);
1586
1587 sd->internal_ops = &s5k6aa_subdev_internal_ops;
1588 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
1589
1590 s5k6aa->pad.flags = MEDIA_PAD_FL_SOURCE;
1591 sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_SENSOR;
1592 ret = media_entity_init(&sd->entity, 1, &s5k6aa->pad, 0);
1593 if (ret)
1594 goto out_err1;
1595
1596 ret = s5k6aa_configure_gpios(s5k6aa, pdata);
1597 if (ret)
1598 goto out_err2;
1599
1600 for (i = 0; i < S5K6AA_NUM_SUPPLIES; i++)
1601 s5k6aa->supplies[i].supply = s5k6aa_supply_names[i];
1602
1603 ret = regulator_bulk_get(&client->dev, S5K6AA_NUM_SUPPLIES,
1604 s5k6aa->supplies);
1605 if (ret) {
1606 dev_err(&client->dev, "Failed to get regulators\n");
1607 goto out_err3;
1608 }
1609
1610 ret = s5k6aa_initialize_ctrls(s5k6aa);
1611 if (ret)
1612 goto out_err4;
1613
1614 s5k6aa_presets_data_init(s5k6aa);
1615
1616 s5k6aa->ccd_rect.width = S5K6AA_WIN_WIDTH_MAX;
1617 s5k6aa->ccd_rect.height = S5K6AA_WIN_HEIGHT_MAX;
1618 s5k6aa->ccd_rect.left = 0;
1619 s5k6aa->ccd_rect.top = 0;
1620
1621 return 0;
1622
1623out_err4:
1624 regulator_bulk_free(S5K6AA_NUM_SUPPLIES, s5k6aa->supplies);
1625out_err3:
1626 s5k6aa_free_gpios(s5k6aa);
1627out_err2:
1628 media_entity_cleanup(&s5k6aa->sd.entity);
1629out_err1:
1630 kfree(s5k6aa);
1631 return ret;
1632}
1633
1634static int s5k6aa_remove(struct i2c_client *client)
1635{
1636 struct v4l2_subdev *sd = i2c_get_clientdata(client);
1637 struct s5k6aa *s5k6aa = to_s5k6aa(sd);
1638
1639 v4l2_device_unregister_subdev(sd);
1640 v4l2_ctrl_handler_free(sd->ctrl_handler);
1641 media_entity_cleanup(&sd->entity);
1642 regulator_bulk_free(S5K6AA_NUM_SUPPLIES, s5k6aa->supplies);
1643 s5k6aa_free_gpios(s5k6aa);
1644 kfree(s5k6aa);
1645
1646 return 0;
1647}
1648
1649static const struct i2c_device_id s5k6aa_id[] = {
1650 { DRIVER_NAME, 0 },
1651 { },
1652};
1653MODULE_DEVICE_TABLE(i2c, s5k6aa_id);
1654
1655
1656static struct i2c_driver s5k6aa_i2c_driver = {
1657 .driver = {
1658 .name = DRIVER_NAME
1659 },
1660 .probe = s5k6aa_probe,
1661 .remove = s5k6aa_remove,
1662 .id_table = s5k6aa_id,
1663};
1664
1665static int __init s5k6aa_init(void)
1666{
1667 return i2c_add_driver(&s5k6aa_i2c_driver);
1668}
1669
1670static void __exit s5k6aa_exit(void)
1671{
1672 i2c_del_driver(&s5k6aa_i2c_driver);
1673}
1674
1675module_init(s5k6aa_init);
1676module_exit(s5k6aa_exit);
1677
1678MODULE_DESCRIPTION("Samsung S5K6AA(FX) SXGA camera driver");
1679MODULE_AUTHOR("Sylwester Nawrocki <s.nawrocki@samsung.com>");
1680MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/s5p-fimc/fimc-capture.c b/drivers/media/video/s5p-fimc/fimc-capture.c
index 931f469604b0..c8d91b0cd9bd 100644
--- a/drivers/media/video/s5p-fimc/fimc-capture.c
+++ b/drivers/media/video/s5p-fimc/fimc-capture.c
@@ -246,9 +246,9 @@ static unsigned int get_plane_size(struct fimc_frame *fr, unsigned int plane)
246 return fr->f_width * fr->f_height * fr->fmt->depth[plane] / 8; 246 return fr->f_width * fr->f_height * fr->fmt->depth[plane] / 8;
247} 247}
248 248
249static int queue_setup(struct vb2_queue *vq, unsigned int *num_buffers, 249static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *pfmt,
250 unsigned int *num_planes, unsigned int sizes[], 250 unsigned int *num_buffers, unsigned int *num_planes,
251 void *allocators[]) 251 unsigned int sizes[], void *allocators[])
252{ 252{
253 struct fimc_ctx *ctx = vq->drv_priv; 253 struct fimc_ctx *ctx = vq->drv_priv;
254 struct fimc_fmt *fmt = ctx->d_frame.fmt; 254 struct fimc_fmt *fmt = ctx->d_frame.fmt;
diff --git a/drivers/media/video/s5p-fimc/fimc-core.c b/drivers/media/video/s5p-fimc/fimc-core.c
index 6c1c9cb55378..19ca6db38b2f 100644
--- a/drivers/media/video/s5p-fimc/fimc-core.c
+++ b/drivers/media/video/s5p-fimc/fimc-core.c
@@ -670,9 +670,9 @@ static void fimc_job_abort(void *priv)
670 fimc_m2m_shutdown(priv); 670 fimc_m2m_shutdown(priv);
671} 671}
672 672
673static int fimc_queue_setup(struct vb2_queue *vq, unsigned int *num_buffers, 673static int fimc_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
674 unsigned int *num_planes, unsigned int sizes[], 674 unsigned int *num_buffers, unsigned int *num_planes,
675 void *allocators[]) 675 unsigned int sizes[], void *allocators[])
676{ 676{
677 struct fimc_ctx *ctx = vb2_get_drv_priv(vq); 677 struct fimc_ctx *ctx = vb2_get_drv_priv(vq);
678 struct fimc_frame *f; 678 struct fimc_frame *f;
diff --git a/drivers/media/video/s5p-mfc/s5p_mfc_ctrl.c b/drivers/media/video/s5p-mfc/s5p_mfc_ctrl.c
index 5f4da80051bb..f2481a85e0a2 100644
--- a/drivers/media/video/s5p-mfc/s5p_mfc_ctrl.c
+++ b/drivers/media/video/s5p-mfc/s5p_mfc_ctrl.c
@@ -38,7 +38,7 @@ int s5p_mfc_alloc_and_load_firmware(struct s5p_mfc_dev *dev)
38 * into kernel. */ 38 * into kernel. */
39 mfc_debug_enter(); 39 mfc_debug_enter();
40 err = request_firmware((const struct firmware **)&fw_blob, 40 err = request_firmware((const struct firmware **)&fw_blob,
41 "s5pc110-mfc.fw", dev->v4l2_dev.dev); 41 "s5p-mfc.fw", dev->v4l2_dev.dev);
42 if (err != 0) { 42 if (err != 0) {
43 mfc_err("Firmware is not present in the /lib/firmware directory nor compiled in kernel\n"); 43 mfc_err("Firmware is not present in the /lib/firmware directory nor compiled in kernel\n");
44 return -EINVAL; 44 return -EINVAL;
@@ -116,7 +116,7 @@ int s5p_mfc_reload_firmware(struct s5p_mfc_dev *dev)
116 * into kernel. */ 116 * into kernel. */
117 mfc_debug_enter(); 117 mfc_debug_enter();
118 err = request_firmware((const struct firmware **)&fw_blob, 118 err = request_firmware((const struct firmware **)&fw_blob,
119 "s5pc110-mfc.fw", dev->v4l2_dev.dev); 119 "s5p-mfc.fw", dev->v4l2_dev.dev);
120 if (err != 0) { 120 if (err != 0) {
121 mfc_err("Firmware is not present in the /lib/firmware directory nor compiled in kernel\n"); 121 mfc_err("Firmware is not present in the /lib/firmware directory nor compiled in kernel\n");
122 return -EINVAL; 122 return -EINVAL;
diff --git a/drivers/media/video/s5p-mfc/s5p_mfc_dec.c b/drivers/media/video/s5p-mfc/s5p_mfc_dec.c
index bfbe08432050..725634d9736d 100644
--- a/drivers/media/video/s5p-mfc/s5p_mfc_dec.c
+++ b/drivers/media/video/s5p-mfc/s5p_mfc_dec.c
@@ -744,9 +744,10 @@ static const struct v4l2_ioctl_ops s5p_mfc_dec_ioctl_ops = {
744 .vidioc_g_crop = vidioc_g_crop, 744 .vidioc_g_crop = vidioc_g_crop,
745}; 745};
746 746
747static int s5p_mfc_queue_setup(struct vb2_queue *vq, unsigned int *buf_count, 747static int s5p_mfc_queue_setup(struct vb2_queue *vq,
748 unsigned int *plane_count, unsigned int psize[], 748 const struct v4l2_format *fmt, unsigned int *buf_count,
749 void *allocators[]) 749 unsigned int *plane_count, unsigned int psize[],
750 void *allocators[])
750{ 751{
751 struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv); 752 struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv);
752 753
diff --git a/drivers/media/video/s5p-mfc/s5p_mfc_enc.c b/drivers/media/video/s5p-mfc/s5p_mfc_enc.c
index 4c90e53bd964..ecef127dbc66 100644
--- a/drivers/media/video/s5p-mfc/s5p_mfc_enc.c
+++ b/drivers/media/video/s5p-mfc/s5p_mfc_enc.c
@@ -1513,8 +1513,9 @@ static int check_vb_with_fmt(struct s5p_mfc_fmt *fmt, struct vb2_buffer *vb)
1513} 1513}
1514 1514
1515static int s5p_mfc_queue_setup(struct vb2_queue *vq, 1515static int s5p_mfc_queue_setup(struct vb2_queue *vq,
1516 unsigned int *buf_count, unsigned int *plane_count, 1516 const struct v4l2_format *fmt,
1517 unsigned int psize[], void *allocators[]) 1517 unsigned int *buf_count, unsigned int *plane_count,
1518 unsigned int psize[], void *allocators[])
1518{ 1519{
1519 struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv); 1520 struct s5p_mfc_ctx *ctx = fh_to_ctx(vq->drv_priv);
1520 1521
diff --git a/drivers/media/video/s5p-tv/mixer_video.c b/drivers/media/video/s5p-tv/mixer_video.c
index 4917e2c2b321..e16d3a4bc1dc 100644
--- a/drivers/media/video/s5p-tv/mixer_video.c
+++ b/drivers/media/video/s5p-tv/mixer_video.c
@@ -727,8 +727,8 @@ static const struct v4l2_file_operations mxr_fops = {
727 .unlocked_ioctl = video_ioctl2, 727 .unlocked_ioctl = video_ioctl2,
728}; 728};
729 729
730static int queue_setup(struct vb2_queue *vq, unsigned int *nbuffers, 730static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *pfmt,
731 unsigned int *nplanes, unsigned int sizes[], 731 unsigned int *nbuffers, unsigned int *nplanes, unsigned int sizes[],
732 void *alloc_ctxs[]) 732 void *alloc_ctxs[])
733{ 733{
734 struct mxr_layer *layer = vb2_get_drv_priv(vq); 734 struct mxr_layer *layer = vb2_get_drv_priv(vq);
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index bc8d6bba8ee5..9b550687213a 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -843,10 +843,10 @@ void saa7134_probe_i2c_ir(struct saa7134_dev *dev);
843int saa7134_ir_start(struct saa7134_dev *dev); 843int saa7134_ir_start(struct saa7134_dev *dev);
844void saa7134_ir_stop(struct saa7134_dev *dev); 844void saa7134_ir_stop(struct saa7134_dev *dev);
845#else 845#else
846#define saa7134_input_init1(dev) (0) 846#define saa7134_input_init1(dev) ((void)0)
847#define saa7134_input_fini(dev) (0) 847#define saa7134_input_fini(dev) ((void)0)
848#define saa7134_input_irq(dev) (0) 848#define saa7134_input_irq(dev) ((void)0)
849#define saa7134_probe_i2c_ir(dev) (0) 849#define saa7134_probe_i2c_ir(dev) ((void)0)
850#define saa7134_ir_start(dev) (0) 850#define saa7134_ir_start(dev) ((void)0)
851#define saa7134_ir_stop(dev) (0) 851#define saa7134_ir_stop(dev) ((void)0)
852#endif 852#endif
diff --git a/drivers/media/video/sh_mobile_ceu_camera.c b/drivers/media/video/sh_mobile_ceu_camera.c
index 8615fb81775f..f390682629cf 100644
--- a/drivers/media/video/sh_mobile_ceu_camera.c
+++ b/drivers/media/video/sh_mobile_ceu_camera.c
@@ -90,7 +90,6 @@
90struct sh_mobile_ceu_buffer { 90struct sh_mobile_ceu_buffer {
91 struct vb2_buffer vb; /* v4l buffer must be first */ 91 struct vb2_buffer vb; /* v4l buffer must be first */
92 struct list_head queue; 92 struct list_head queue;
93 enum v4l2_mbus_pixelcode code;
94}; 93};
95 94
96struct sh_mobile_ceu_dev { 95struct sh_mobile_ceu_dev {
@@ -100,7 +99,8 @@ struct sh_mobile_ceu_dev {
100 99
101 unsigned int irq; 100 unsigned int irq;
102 void __iomem *base; 101 void __iomem *base;
103 unsigned long video_limit; 102 size_t video_limit;
103 size_t buf_total;
104 104
105 spinlock_t lock; /* Protects video buffer lists */ 105 spinlock_t lock; /* Protects video buffer lists */
106 struct list_head capture; 106 struct list_head capture;
@@ -121,7 +121,7 @@ struct sh_mobile_ceu_dev {
121}; 121};
122 122
123struct sh_mobile_ceu_cam { 123struct sh_mobile_ceu_cam {
124 /* CEU offsets within scaled by the CEU camera output */ 124 /* CEU offsets within the camera output, before the CEU scaler */
125 unsigned int ceu_left; 125 unsigned int ceu_left;
126 unsigned int ceu_top; 126 unsigned int ceu_top;
127 /* Client output, as seen by the CEU */ 127 /* Client output, as seen by the CEU */
@@ -144,30 +144,6 @@ static struct sh_mobile_ceu_buffer *to_ceu_vb(struct vb2_buffer *vb)
144 return container_of(vb, struct sh_mobile_ceu_buffer, vb); 144 return container_of(vb, struct sh_mobile_ceu_buffer, vb);
145} 145}
146 146
147static unsigned long make_bus_param(struct sh_mobile_ceu_dev *pcdev)
148{
149 unsigned long flags;
150
151 flags = SOCAM_MASTER |
152 SOCAM_PCLK_SAMPLE_RISING |
153 SOCAM_HSYNC_ACTIVE_HIGH |
154 SOCAM_HSYNC_ACTIVE_LOW |
155 SOCAM_VSYNC_ACTIVE_HIGH |
156 SOCAM_VSYNC_ACTIVE_LOW |
157 SOCAM_DATA_ACTIVE_HIGH;
158
159 if (pcdev->pdata->flags & SH_CEU_FLAG_USE_8BIT_BUS)
160 flags |= SOCAM_DATAWIDTH_8;
161
162 if (pcdev->pdata->flags & SH_CEU_FLAG_USE_16BIT_BUS)
163 flags |= SOCAM_DATAWIDTH_16;
164
165 if (flags & SOCAM_DATAWIDTH_MASK)
166 return flags;
167
168 return 0;
169}
170
171static void ceu_write(struct sh_mobile_ceu_dev *priv, 147static void ceu_write(struct sh_mobile_ceu_dev *priv,
172 unsigned long reg_offs, u32 data) 148 unsigned long reg_offs, u32 data)
173{ 149{
@@ -216,33 +192,61 @@ static int sh_mobile_ceu_soft_reset(struct sh_mobile_ceu_dev *pcdev)
216/* 192/*
217 * Videobuf operations 193 * Videobuf operations
218 */ 194 */
195
196/*
197 * .queue_setup() is called to check, whether the driver can accept the
198 * requested number of buffers and to fill in plane sizes
199 * for the current frame format if required
200 */
219static int sh_mobile_ceu_videobuf_setup(struct vb2_queue *vq, 201static int sh_mobile_ceu_videobuf_setup(struct vb2_queue *vq,
202 const struct v4l2_format *fmt,
220 unsigned int *count, unsigned int *num_planes, 203 unsigned int *count, unsigned int *num_planes,
221 unsigned int sizes[], void *alloc_ctxs[]) 204 unsigned int sizes[], void *alloc_ctxs[])
222{ 205{
223 struct soc_camera_device *icd = container_of(vq, struct soc_camera_device, vb2_vidq); 206 struct soc_camera_device *icd = container_of(vq, struct soc_camera_device, vb2_vidq);
224 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 207 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
225 struct sh_mobile_ceu_dev *pcdev = ici->priv; 208 struct sh_mobile_ceu_dev *pcdev = ici->priv;
226 int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width, 209 int bytes_per_line;
227 icd->current_fmt->host_fmt); 210 unsigned int height;
228 211
212 if (fmt) {
213 const struct soc_camera_format_xlate *xlate = soc_camera_xlate_by_fourcc(icd,
214 fmt->fmt.pix.pixelformat);
215 if (!xlate)
216 return -EINVAL;
217 bytes_per_line = soc_mbus_bytes_per_line(fmt->fmt.pix.width,
218 xlate->host_fmt);
219 height = fmt->fmt.pix.height;
220 } else {
221 /* Called from VIDIOC_REQBUFS or in compatibility mode */
222 bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
223 icd->current_fmt->host_fmt);
224 height = icd->user_height;
225 }
229 if (bytes_per_line < 0) 226 if (bytes_per_line < 0)
230 return bytes_per_line; 227 return bytes_per_line;
231 228
232 *num_planes = 1; 229 sizes[0] = bytes_per_line * height;
233 230
234 pcdev->sequence = 0;
235 sizes[0] = bytes_per_line * icd->user_height;
236 alloc_ctxs[0] = pcdev->alloc_ctx; 231 alloc_ctxs[0] = pcdev->alloc_ctx;
237 232
233 if (!vq->num_buffers)
234 pcdev->sequence = 0;
235
238 if (!*count) 236 if (!*count)
239 *count = 2; 237 *count = 2;
240 238
241 if (pcdev->video_limit) { 239 /* If *num_planes != 0, we have already verified *count. */
242 if (PAGE_ALIGN(sizes[0]) * *count > pcdev->video_limit) 240 if (pcdev->video_limit && !*num_planes) {
243 *count = pcdev->video_limit / PAGE_ALIGN(sizes[0]); 241 size_t size = PAGE_ALIGN(sizes[0]) * *count;
242
243 if (size + pcdev->buf_total > pcdev->video_limit)
244 *count = (pcdev->video_limit - pcdev->buf_total) /
245 PAGE_ALIGN(sizes[0]);
244 } 246 }
245 247
248 *num_planes = 1;
249
246 dev_dbg(icd->parent, "count=%d, size=%u\n", *count, sizes[0]); 250 dev_dbg(icd->parent, "count=%d, size=%u\n", *count, sizes[0]);
247 251
248 return 0; 252 return 0;
@@ -267,6 +271,7 @@ static int sh_mobile_ceu_capture(struct sh_mobile_ceu_dev *pcdev)
267 unsigned long top1, top2; 271 unsigned long top1, top2;
268 unsigned long bottom1, bottom2; 272 unsigned long bottom1, bottom2;
269 u32 status; 273 u32 status;
274 bool planar;
270 int ret = 0; 275 int ret = 0;
271 276
272 /* 277 /*
@@ -314,17 +319,29 @@ static int sh_mobile_ceu_capture(struct sh_mobile_ceu_dev *pcdev)
314 319
315 phys_addr_top = vb2_dma_contig_plane_dma_addr(pcdev->active, 0); 320 phys_addr_top = vb2_dma_contig_plane_dma_addr(pcdev->active, 0);
316 321
317 ceu_write(pcdev, top1, phys_addr_top);
318 if (V4L2_FIELD_NONE != pcdev->field) {
319 phys_addr_bottom = phys_addr_top + icd->user_width;
320 ceu_write(pcdev, bottom1, phys_addr_bottom);
321 }
322
323 switch (icd->current_fmt->host_fmt->fourcc) { 322 switch (icd->current_fmt->host_fmt->fourcc) {
324 case V4L2_PIX_FMT_NV12: 323 case V4L2_PIX_FMT_NV12:
325 case V4L2_PIX_FMT_NV21: 324 case V4L2_PIX_FMT_NV21:
326 case V4L2_PIX_FMT_NV16: 325 case V4L2_PIX_FMT_NV16:
327 case V4L2_PIX_FMT_NV61: 326 case V4L2_PIX_FMT_NV61:
327 planar = true;
328 break;
329 default:
330 planar = false;
331 }
332
333 ceu_write(pcdev, top1, phys_addr_top);
334 if (V4L2_FIELD_NONE != pcdev->field) {
335 if (planar)
336 phys_addr_bottom = phys_addr_top + icd->user_width;
337 else
338 phys_addr_bottom = phys_addr_top +
339 soc_mbus_bytes_per_line(icd->user_width,
340 icd->current_fmt->host_fmt);
341 ceu_write(pcdev, bottom1, phys_addr_bottom);
342 }
343
344 if (planar) {
328 phys_addr_top += icd->user_width * 345 phys_addr_top += icd->user_width *
329 icd->user_height; 346 icd->user_height;
330 ceu_write(pcdev, top2, phys_addr_top); 347 ceu_write(pcdev, top2, phys_addr_top);
@@ -341,23 +358,40 @@ static int sh_mobile_ceu_capture(struct sh_mobile_ceu_dev *pcdev)
341 358
342static int sh_mobile_ceu_videobuf_prepare(struct vb2_buffer *vb) 359static int sh_mobile_ceu_videobuf_prepare(struct vb2_buffer *vb)
343{ 360{
361 struct sh_mobile_ceu_buffer *buf = to_ceu_vb(vb);
362
363 /* Added list head initialization on alloc */
364 WARN(!list_empty(&buf->queue), "Buffer %p on queue!\n", vb);
365
366 return 0;
367}
368
369static void sh_mobile_ceu_videobuf_queue(struct vb2_buffer *vb)
370{
344 struct soc_camera_device *icd = container_of(vb->vb2_queue, struct soc_camera_device, vb2_vidq); 371 struct soc_camera_device *icd = container_of(vb->vb2_queue, struct soc_camera_device, vb2_vidq);
345 struct sh_mobile_ceu_buffer *buf; 372 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
373 struct sh_mobile_ceu_dev *pcdev = ici->priv;
374 struct sh_mobile_ceu_buffer *buf = to_ceu_vb(vb);
375 unsigned long size;
346 int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width, 376 int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
347 icd->current_fmt->host_fmt); 377 icd->current_fmt->host_fmt);
348 unsigned long size;
349 378
350 if (bytes_per_line < 0) 379 if (bytes_per_line < 0)
351 return bytes_per_line; 380 goto error;
352 381
353 buf = to_ceu_vb(vb); 382 size = icd->user_height * bytes_per_line;
383
384 if (vb2_plane_size(vb, 0) < size) {
385 dev_err(icd->parent, "Buffer #%d too small (%lu < %lu)\n",
386 vb->v4l2_buf.index, vb2_plane_size(vb, 0), size);
387 goto error;
388 }
389
390 vb2_set_plane_payload(vb, 0, size);
354 391
355 dev_dbg(icd->parent, "%s (vb=0x%p) 0x%p %lu\n", __func__, 392 dev_dbg(icd->parent, "%s (vb=0x%p) 0x%p %lu\n", __func__,
356 vb, vb2_plane_vaddr(vb, 0), vb2_get_plane_payload(vb, 0)); 393 vb, vb2_plane_vaddr(vb, 0), vb2_get_plane_payload(vb, 0));
357 394
358 /* Added list head initialization on alloc */
359 WARN(!list_empty(&buf->queue), "Buffer %p on queue!\n", vb);
360
361#ifdef DEBUG 395#ifdef DEBUG
362 /* 396 /*
363 * This can be useful if you want to see if we actually fill 397 * This can be useful if you want to see if we actually fill
@@ -367,31 +401,6 @@ static int sh_mobile_ceu_videobuf_prepare(struct vb2_buffer *vb)
367 memset(vb2_plane_vaddr(vb, 0), 0xaa, vb2_get_plane_payload(vb, 0)); 401 memset(vb2_plane_vaddr(vb, 0), 0xaa, vb2_get_plane_payload(vb, 0));
368#endif 402#endif
369 403
370 BUG_ON(NULL == icd->current_fmt);
371
372 size = icd->user_height * bytes_per_line;
373
374 if (vb2_plane_size(vb, 0) < size) {
375 dev_err(icd->parent, "Buffer too small (%lu < %lu)\n",
376 vb2_plane_size(vb, 0), size);
377 return -ENOBUFS;
378 }
379
380 vb2_set_plane_payload(vb, 0, size);
381
382 return 0;
383}
384
385static void sh_mobile_ceu_videobuf_queue(struct vb2_buffer *vb)
386{
387 struct soc_camera_device *icd = container_of(vb->vb2_queue, struct soc_camera_device, vb2_vidq);
388 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
389 struct sh_mobile_ceu_dev *pcdev = ici->priv;
390 struct sh_mobile_ceu_buffer *buf = to_ceu_vb(vb);
391
392 dev_dbg(icd->parent, "%s (vb=0x%p) 0x%p %lu\n", __func__,
393 vb, vb2_plane_vaddr(vb, 0), vb2_get_plane_payload(vb, 0));
394
395 spin_lock_irq(&pcdev->lock); 404 spin_lock_irq(&pcdev->lock);
396 list_add_tail(&buf->queue, &pcdev->capture); 405 list_add_tail(&buf->queue, &pcdev->capture);
397 406
@@ -405,6 +414,11 @@ static void sh_mobile_ceu_videobuf_queue(struct vb2_buffer *vb)
405 sh_mobile_ceu_capture(pcdev); 414 sh_mobile_ceu_capture(pcdev);
406 } 415 }
407 spin_unlock_irq(&pcdev->lock); 416 spin_unlock_irq(&pcdev->lock);
417
418 return;
419
420error:
421 vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
408} 422}
409 423
410static void sh_mobile_ceu_videobuf_release(struct vb2_buffer *vb) 424static void sh_mobile_ceu_videobuf_release(struct vb2_buffer *vb)
@@ -429,11 +443,23 @@ static void sh_mobile_ceu_videobuf_release(struct vb2_buffer *vb)
429 if (buf->queue.next) 443 if (buf->queue.next)
430 list_del_init(&buf->queue); 444 list_del_init(&buf->queue);
431 445
446 pcdev->buf_total -= PAGE_ALIGN(vb2_plane_size(vb, 0));
447 dev_dbg(icd->parent, "%s() %zu bytes buffers\n", __func__,
448 pcdev->buf_total);
449
432 spin_unlock_irq(&pcdev->lock); 450 spin_unlock_irq(&pcdev->lock);
433} 451}
434 452
435static int sh_mobile_ceu_videobuf_init(struct vb2_buffer *vb) 453static int sh_mobile_ceu_videobuf_init(struct vb2_buffer *vb)
436{ 454{
455 struct soc_camera_device *icd = container_of(vb->vb2_queue, struct soc_camera_device, vb2_vidq);
456 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
457 struct sh_mobile_ceu_dev *pcdev = ici->priv;
458
459 pcdev->buf_total += PAGE_ALIGN(vb2_plane_size(vb, 0));
460 dev_dbg(icd->parent, "%s() %zu bytes buffers\n", __func__,
461 pcdev->buf_total);
462
437 /* This is for locking debugging only */ 463 /* This is for locking debugging only */
438 INIT_LIST_HEAD(&to_ceu_vb(vb)->queue); 464 INIT_LIST_HEAD(&to_ceu_vb(vb)->queue);
439 return 0; 465 return 0;
@@ -535,19 +561,29 @@ static int sh_mobile_ceu_add_device(struct soc_camera_device *icd)
535 561
536 pm_runtime_get_sync(ici->v4l2_dev.dev); 562 pm_runtime_get_sync(ici->v4l2_dev.dev);
537 563
564 pcdev->buf_total = 0;
565
538 ret = sh_mobile_ceu_soft_reset(pcdev); 566 ret = sh_mobile_ceu_soft_reset(pcdev);
539 567
540 csi2_sd = find_csi2(pcdev); 568 csi2_sd = find_csi2(pcdev);
569 if (csi2_sd)
570 csi2_sd->grp_id = (long)icd;
541 571
542 ret = v4l2_subdev_call(csi2_sd, core, s_power, 1); 572 ret = v4l2_subdev_call(csi2_sd, core, s_power, 1);
543 if (ret != -ENODEV && ret != -ENOIOCTLCMD && ret < 0) { 573 if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV) {
544 pm_runtime_put_sync(ici->v4l2_dev.dev); 574 pm_runtime_put_sync(ici->v4l2_dev.dev);
545 } else { 575 return ret;
546 pcdev->icd = icd;
547 ret = 0;
548 } 576 }
549 577
550 return ret; 578 /*
579 * -ENODEV is special: either csi2_sd == NULL or the CSI-2 driver
580 * has not found this soc-camera device among its clients
581 */
582 if (ret == -ENODEV && csi2_sd)
583 csi2_sd->grp_id = 0;
584 pcdev->icd = icd;
585
586 return 0;
551} 587}
552 588
553/* Called with .video_lock held */ 589/* Called with .video_lock held */
@@ -560,6 +596,8 @@ static void sh_mobile_ceu_remove_device(struct soc_camera_device *icd)
560 BUG_ON(icd != pcdev->icd); 596 BUG_ON(icd != pcdev->icd);
561 597
562 v4l2_subdev_call(csi2_sd, core, s_power, 0); 598 v4l2_subdev_call(csi2_sd, core, s_power, 0);
599 if (csi2_sd)
600 csi2_sd->grp_id = 0;
563 /* disable capture, disable interrupts */ 601 /* disable capture, disable interrupts */
564 ceu_write(pcdev, CEIER, 0); 602 ceu_write(pcdev, CEIER, 0);
565 sh_mobile_ceu_soft_reset(pcdev); 603 sh_mobile_ceu_soft_reset(pcdev);
@@ -628,22 +666,22 @@ static void sh_mobile_ceu_set_rect(struct soc_camera_device *icd)
628 left_offset = cam->ceu_left; 666 left_offset = cam->ceu_left;
629 top_offset = cam->ceu_top; 667 top_offset = cam->ceu_top;
630 668
631 /* CEU cropping (CFSZR) is applied _after_ the scaling filter (CFLCR) */ 669 WARN_ON(icd->user_width & 3 || icd->user_height & 3);
670
671 width = icd->user_width;
672
632 if (pcdev->image_mode) { 673 if (pcdev->image_mode) {
633 in_width = cam->width; 674 in_width = cam->width;
634 if (!pcdev->is_16bit) { 675 if (!pcdev->is_16bit) {
635 in_width *= 2; 676 in_width *= 2;
636 left_offset *= 2; 677 left_offset *= 2;
637 } 678 }
638 width = icd->user_width; 679 cdwdr_width = width;
639 cdwdr_width = icd->user_width;
640 } else { 680 } else {
641 int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width, 681 int bytes_per_line = soc_mbus_bytes_per_line(width,
642 icd->current_fmt->host_fmt); 682 icd->current_fmt->host_fmt);
643 unsigned int w_factor; 683 unsigned int w_factor;
644 684
645 width = icd->user_width;
646
647 switch (icd->current_fmt->host_fmt->packing) { 685 switch (icd->current_fmt->host_fmt->packing) {
648 case SOC_MBUS_PACKING_2X8_PADHI: 686 case SOC_MBUS_PACKING_2X8_PADHI:
649 w_factor = 2; 687 w_factor = 2;
@@ -653,10 +691,10 @@ static void sh_mobile_ceu_set_rect(struct soc_camera_device *icd)
653 } 691 }
654 692
655 in_width = cam->width * w_factor; 693 in_width = cam->width * w_factor;
656 left_offset = left_offset * w_factor; 694 left_offset *= w_factor;
657 695
658 if (bytes_per_line < 0) 696 if (bytes_per_line < 0)
659 cdwdr_width = icd->user_width; 697 cdwdr_width = width;
660 else 698 else
661 cdwdr_width = bytes_per_line; 699 cdwdr_width = bytes_per_line;
662 } 700 }
@@ -664,7 +702,7 @@ static void sh_mobile_ceu_set_rect(struct soc_camera_device *icd)
664 height = icd->user_height; 702 height = icd->user_height;
665 in_height = cam->height; 703 in_height = cam->height;
666 if (V4L2_FIELD_NONE != pcdev->field) { 704 if (V4L2_FIELD_NONE != pcdev->field) {
667 height /= 2; 705 height = (height / 2) & ~3;
668 in_height /= 2; 706 in_height /= 2;
669 top_offset /= 2; 707 top_offset /= 2;
670 cdwdr_width *= 2; 708 cdwdr_width *= 2;
@@ -686,6 +724,7 @@ static void sh_mobile_ceu_set_rect(struct soc_camera_device *icd)
686 724
687 ceu_write(pcdev, CAMOR, camor); 725 ceu_write(pcdev, CAMOR, camor);
688 ceu_write(pcdev, CAPWR, (in_height << 16) | in_width); 726 ceu_write(pcdev, CAPWR, (in_height << 16) | in_width);
727 /* CFSZR clipping is applied _after_ the scaling filter (CFLCR) */
689 ceu_write(pcdev, CFSZR, (height << 16) | width); 728 ceu_write(pcdev, CFSZR, (height << 16) | width);
690 ceu_write(pcdev, CDWDR, cdwdr_width); 729 ceu_write(pcdev, CDWDR, cdwdr_width);
691} 730}
@@ -723,66 +762,93 @@ static void capture_restore(struct sh_mobile_ceu_dev *pcdev, u32 capsr)
723 ceu_write(pcdev, CAPSR, capsr); 762 ceu_write(pcdev, CAPSR, capsr);
724} 763}
725 764
765/* Find the bus subdevice driver, e.g., CSI2 */
766static struct v4l2_subdev *find_bus_subdev(struct sh_mobile_ceu_dev *pcdev,
767 struct soc_camera_device *icd)
768{
769 if (pcdev->csi2_pdev) {
770 struct v4l2_subdev *csi2_sd = find_csi2(pcdev);
771 if (csi2_sd && csi2_sd->grp_id == (u32)icd)
772 return csi2_sd;
773 }
774
775 return soc_camera_to_subdev(icd);
776}
777
778#define CEU_BUS_FLAGS (V4L2_MBUS_MASTER | \
779 V4L2_MBUS_PCLK_SAMPLE_RISING | \
780 V4L2_MBUS_HSYNC_ACTIVE_HIGH | \
781 V4L2_MBUS_HSYNC_ACTIVE_LOW | \
782 V4L2_MBUS_VSYNC_ACTIVE_HIGH | \
783 V4L2_MBUS_VSYNC_ACTIVE_LOW | \
784 V4L2_MBUS_DATA_ACTIVE_HIGH)
785
726/* Capture is not running, no interrupts, no locking needed */ 786/* Capture is not running, no interrupts, no locking needed */
727static int sh_mobile_ceu_set_bus_param(struct soc_camera_device *icd, 787static int sh_mobile_ceu_set_bus_param(struct soc_camera_device *icd,
728 __u32 pixfmt) 788 __u32 pixfmt)
729{ 789{
730 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 790 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
731 struct sh_mobile_ceu_dev *pcdev = ici->priv; 791 struct sh_mobile_ceu_dev *pcdev = ici->priv;
732 int ret; 792 struct v4l2_subdev *sd = find_bus_subdev(pcdev, icd);
733 unsigned long camera_flags, common_flags, value;
734 int yuv_lineskip;
735 struct sh_mobile_ceu_cam *cam = icd->host_priv; 793 struct sh_mobile_ceu_cam *cam = icd->host_priv;
794 struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,};
795 unsigned long value, common_flags = CEU_BUS_FLAGS;
736 u32 capsr = capture_save_reset(pcdev); 796 u32 capsr = capture_save_reset(pcdev);
797 unsigned int yuv_lineskip;
798 int ret;
737 799
738 camera_flags = icd->ops->query_bus_param(icd); 800 /*
739 common_flags = soc_camera_bus_param_compatible(camera_flags, 801 * If the client doesn't implement g_mbus_config, we just use our
740 make_bus_param(pcdev)); 802 * platform data
741 if (!common_flags) 803 */
742 return -EINVAL; 804 ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg);
805 if (!ret) {
806 common_flags = soc_mbus_config_compatible(&cfg,
807 common_flags);
808 if (!common_flags)
809 return -EINVAL;
810 } else if (ret != -ENOIOCTLCMD) {
811 return ret;
812 }
743 813
744 /* Make choises, based on platform preferences */ 814 /* Make choises, based on platform preferences */
745 if ((common_flags & SOCAM_HSYNC_ACTIVE_HIGH) && 815 if ((common_flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) &&
746 (common_flags & SOCAM_HSYNC_ACTIVE_LOW)) { 816 (common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)) {
747 if (pcdev->pdata->flags & SH_CEU_FLAG_HSYNC_LOW) 817 if (pcdev->pdata->flags & SH_CEU_FLAG_HSYNC_LOW)
748 common_flags &= ~SOCAM_HSYNC_ACTIVE_HIGH; 818 common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_HIGH;
749 else 819 else
750 common_flags &= ~SOCAM_HSYNC_ACTIVE_LOW; 820 common_flags &= ~V4L2_MBUS_HSYNC_ACTIVE_LOW;
751 } 821 }
752 822
753 if ((common_flags & SOCAM_VSYNC_ACTIVE_HIGH) && 823 if ((common_flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) &&
754 (common_flags & SOCAM_VSYNC_ACTIVE_LOW)) { 824 (common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)) {
755 if (pcdev->pdata->flags & SH_CEU_FLAG_VSYNC_LOW) 825 if (pcdev->pdata->flags & SH_CEU_FLAG_VSYNC_LOW)
756 common_flags &= ~SOCAM_VSYNC_ACTIVE_HIGH; 826 common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_HIGH;
757 else 827 else
758 common_flags &= ~SOCAM_VSYNC_ACTIVE_LOW; 828 common_flags &= ~V4L2_MBUS_VSYNC_ACTIVE_LOW;
759 } 829 }
760 830
761 ret = icd->ops->set_bus_param(icd, common_flags); 831 cfg.flags = common_flags;
762 if (ret < 0) 832 ret = v4l2_subdev_call(sd, video, s_mbus_config, &cfg);
833 if (ret < 0 && ret != -ENOIOCTLCMD)
763 return ret; 834 return ret;
764 835
765 switch (common_flags & SOCAM_DATAWIDTH_MASK) { 836 if (icd->current_fmt->host_fmt->bits_per_sample > 8)
766 case SOCAM_DATAWIDTH_8:
767 pcdev->is_16bit = 0;
768 break;
769 case SOCAM_DATAWIDTH_16:
770 pcdev->is_16bit = 1; 837 pcdev->is_16bit = 1;
771 break; 838 else
772 default: 839 pcdev->is_16bit = 0;
773 return -EINVAL;
774 }
775 840
776 ceu_write(pcdev, CRCNTR, 0); 841 ceu_write(pcdev, CRCNTR, 0);
777 ceu_write(pcdev, CRCMPR, 0); 842 ceu_write(pcdev, CRCMPR, 0);
778 843
779 value = 0x00000010; /* data fetch by default */ 844 value = 0x00000010; /* data fetch by default */
780 yuv_lineskip = 0; 845 yuv_lineskip = 0x10;
781 846
782 switch (icd->current_fmt->host_fmt->fourcc) { 847 switch (icd->current_fmt->host_fmt->fourcc) {
783 case V4L2_PIX_FMT_NV12: 848 case V4L2_PIX_FMT_NV12:
784 case V4L2_PIX_FMT_NV21: 849 case V4L2_PIX_FMT_NV21:
785 yuv_lineskip = 1; /* skip for NV12/21, no skip for NV16/61 */ 850 /* convert 4:2:2 -> 4:2:0 */
851 yuv_lineskip = 0; /* skip for NV12/21, no skip for NV16/61 */
786 /* fall-through */ 852 /* fall-through */
787 case V4L2_PIX_FMT_NV16: 853 case V4L2_PIX_FMT_NV16:
788 case V4L2_PIX_FMT_NV61: 854 case V4L2_PIX_FMT_NV61:
@@ -808,8 +874,8 @@ static int sh_mobile_ceu_set_bus_param(struct soc_camera_device *icd,
808 icd->current_fmt->host_fmt->fourcc == V4L2_PIX_FMT_NV61) 874 icd->current_fmt->host_fmt->fourcc == V4L2_PIX_FMT_NV61)
809 value ^= 0x00000100; /* swap U, V to change from NV1x->NVx1 */ 875 value ^= 0x00000100; /* swap U, V to change from NV1x->NVx1 */
810 876
811 value |= common_flags & SOCAM_VSYNC_ACTIVE_LOW ? 1 << 1 : 0; 877 value |= common_flags & V4L2_MBUS_VSYNC_ACTIVE_LOW ? 1 << 1 : 0;
812 value |= common_flags & SOCAM_HSYNC_ACTIVE_LOW ? 1 << 0 : 0; 878 value |= common_flags & V4L2_MBUS_HSYNC_ACTIVE_LOW ? 1 << 0 : 0;
813 value |= pcdev->is_16bit ? 1 << 12 : 0; 879 value |= pcdev->is_16bit ? 1 << 12 : 0;
814 880
815 /* CSI2 mode */ 881 /* CSI2 mode */
@@ -852,9 +918,7 @@ static int sh_mobile_ceu_set_bus_param(struct soc_camera_device *icd,
852 * using 7 we swap the data bytes to match the incoming order: 918 * using 7 we swap the data bytes to match the incoming order:
853 * D0, D1, D2, D3, D4, D5, D6, D7 919 * D0, D1, D2, D3, D4, D5, D6, D7
854 */ 920 */
855 value = 0x00000017; 921 value = 0x00000007 | yuv_lineskip;
856 if (yuv_lineskip)
857 value &= ~0x00000010; /* convert 4:2:2 -> 4:2:0 */
858 922
859 ceu_write(pcdev, CDOCR, value); 923 ceu_write(pcdev, CDOCR, value);
860 ceu_write(pcdev, CFWCR, 0); /* keep "datafetch firewall" disabled */ 924 ceu_write(pcdev, CFWCR, 0); /* keep "datafetch firewall" disabled */
@@ -875,13 +939,19 @@ static int sh_mobile_ceu_try_bus_param(struct soc_camera_device *icd,
875{ 939{
876 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 940 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
877 struct sh_mobile_ceu_dev *pcdev = ici->priv; 941 struct sh_mobile_ceu_dev *pcdev = ici->priv;
878 unsigned long camera_flags, common_flags; 942 struct v4l2_subdev *sd = find_bus_subdev(pcdev, icd);
943 unsigned long common_flags = CEU_BUS_FLAGS;
944 struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,};
945 int ret;
879 946
880 camera_flags = icd->ops->query_bus_param(icd); 947 ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg);
881 common_flags = soc_camera_bus_param_compatible(camera_flags, 948 if (!ret)
882 make_bus_param(pcdev)); 949 common_flags = soc_mbus_config_compatible(&cfg,
883 if (!common_flags || buswidth > 16 || 950 common_flags);
884 (buswidth > 8 && !(common_flags & SOCAM_DATAWIDTH_16))) 951 else if (ret != -ENOIOCTLCMD)
952 return ret;
953
954 if (!common_flags || buswidth > 16)
885 return -EINVAL; 955 return -EINVAL;
886 956
887 return 0; 957 return 0;
@@ -891,26 +961,26 @@ static const struct soc_mbus_pixelfmt sh_mobile_ceu_formats[] = {
891 { 961 {
892 .fourcc = V4L2_PIX_FMT_NV12, 962 .fourcc = V4L2_PIX_FMT_NV12,
893 .name = "NV12", 963 .name = "NV12",
894 .bits_per_sample = 12, 964 .bits_per_sample = 8,
895 .packing = SOC_MBUS_PACKING_NONE, 965 .packing = SOC_MBUS_PACKING_1_5X8,
896 .order = SOC_MBUS_ORDER_LE, 966 .order = SOC_MBUS_ORDER_LE,
897 }, { 967 }, {
898 .fourcc = V4L2_PIX_FMT_NV21, 968 .fourcc = V4L2_PIX_FMT_NV21,
899 .name = "NV21", 969 .name = "NV21",
900 .bits_per_sample = 12, 970 .bits_per_sample = 8,
901 .packing = SOC_MBUS_PACKING_NONE, 971 .packing = SOC_MBUS_PACKING_1_5X8,
902 .order = SOC_MBUS_ORDER_LE, 972 .order = SOC_MBUS_ORDER_LE,
903 }, { 973 }, {
904 .fourcc = V4L2_PIX_FMT_NV16, 974 .fourcc = V4L2_PIX_FMT_NV16,
905 .name = "NV16", 975 .name = "NV16",
906 .bits_per_sample = 16, 976 .bits_per_sample = 8,
907 .packing = SOC_MBUS_PACKING_NONE, 977 .packing = SOC_MBUS_PACKING_2X8_PADHI,
908 .order = SOC_MBUS_ORDER_LE, 978 .order = SOC_MBUS_ORDER_LE,
909 }, { 979 }, {
910 .fourcc = V4L2_PIX_FMT_NV61, 980 .fourcc = V4L2_PIX_FMT_NV61,
911 .name = "NV61", 981 .name = "NV61",
912 .bits_per_sample = 16, 982 .bits_per_sample = 8,
913 .packing = SOC_MBUS_PACKING_NONE, 983 .packing = SOC_MBUS_PACKING_2X8_PADHI,
914 .order = SOC_MBUS_ORDER_LE, 984 .order = SOC_MBUS_ORDER_LE,
915 }, 985 },
916}; 986};
@@ -920,6 +990,8 @@ static bool sh_mobile_ceu_packing_supported(const struct soc_mbus_pixelfmt *fmt)
920{ 990{
921 return fmt->packing == SOC_MBUS_PACKING_NONE || 991 return fmt->packing == SOC_MBUS_PACKING_NONE ||
922 (fmt->bits_per_sample == 8 && 992 (fmt->bits_per_sample == 8 &&
993 fmt->packing == SOC_MBUS_PACKING_1_5X8) ||
994 (fmt->bits_per_sample == 8 &&
923 fmt->packing == SOC_MBUS_PACKING_2X8_PADHI) || 995 fmt->packing == SOC_MBUS_PACKING_2X8_PADHI) ||
924 (fmt->bits_per_sample > 8 && 996 (fmt->bits_per_sample > 8 &&
925 fmt->packing == SOC_MBUS_PACKING_EXTEND16); 997 fmt->packing == SOC_MBUS_PACKING_EXTEND16);
@@ -927,6 +999,38 @@ static bool sh_mobile_ceu_packing_supported(const struct soc_mbus_pixelfmt *fmt)
927 999
928static int client_g_rect(struct v4l2_subdev *sd, struct v4l2_rect *rect); 1000static int client_g_rect(struct v4l2_subdev *sd, struct v4l2_rect *rect);
929 1001
1002static struct soc_camera_device *ctrl_to_icd(struct v4l2_ctrl *ctrl)
1003{
1004 return container_of(ctrl->handler, struct soc_camera_device,
1005 ctrl_handler);
1006}
1007
1008static int sh_mobile_ceu_s_ctrl(struct v4l2_ctrl *ctrl)
1009{
1010 struct soc_camera_device *icd = ctrl_to_icd(ctrl);
1011 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
1012 struct sh_mobile_ceu_dev *pcdev = ici->priv;
1013
1014 switch (ctrl->id) {
1015 case V4L2_CID_SHARPNESS:
1016 switch (icd->current_fmt->host_fmt->fourcc) {
1017 case V4L2_PIX_FMT_NV12:
1018 case V4L2_PIX_FMT_NV21:
1019 case V4L2_PIX_FMT_NV16:
1020 case V4L2_PIX_FMT_NV61:
1021 ceu_write(pcdev, CLFCR, !ctrl->val);
1022 return 0;
1023 }
1024 break;
1025 }
1026
1027 return -EINVAL;
1028}
1029
1030static const struct v4l2_ctrl_ops sh_mobile_ceu_ctrl_ops = {
1031 .s_ctrl = sh_mobile_ceu_s_ctrl,
1032};
1033
930static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, unsigned int idx, 1034static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, unsigned int idx,
931 struct soc_camera_format_xlate *xlate) 1035 struct soc_camera_format_xlate *xlate)
932{ 1036{
@@ -952,6 +1056,7 @@ static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, unsigned int
952 } 1056 }
953 1057
954 if (!pcdev->pdata->csi2) { 1058 if (!pcdev->pdata->csi2) {
1059 /* Are there any restrictions in the CSI-2 case? */
955 ret = sh_mobile_ceu_try_bus_param(icd, fmt->bits_per_sample); 1060 ret = sh_mobile_ceu_try_bus_param(icd, fmt->bits_per_sample);
956 if (ret < 0) 1061 if (ret < 0)
957 return 0; 1062 return 0;
@@ -962,6 +1067,12 @@ static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, unsigned int
962 struct v4l2_rect rect; 1067 struct v4l2_rect rect;
963 int shift = 0; 1068 int shift = 0;
964 1069
1070 /* Add our control */
1071 v4l2_ctrl_new_std(&icd->ctrl_handler, &sh_mobile_ceu_ctrl_ops,
1072 V4L2_CID_SHARPNESS, 0, 1, 1, 0);
1073 if (icd->ctrl_handler.error)
1074 return icd->ctrl_handler.error;
1075
965 /* FIXME: subwindow is lost between close / open */ 1076 /* FIXME: subwindow is lost between close / open */
966 1077
967 /* Cache current client geometry */ 1078 /* Cache current client geometry */
@@ -1004,9 +1115,6 @@ static int sh_mobile_ceu_get_formats(struct soc_camera_device *icd, unsigned int
1004 cam->width = mf.width; 1115 cam->width = mf.width;
1005 cam->height = mf.height; 1116 cam->height = mf.height;
1006 1117
1007 cam->width = mf.width;
1008 cam->height = mf.height;
1009
1010 icd->host_priv = cam; 1118 icd->host_priv = cam;
1011 } else { 1119 } else {
1012 cam = icd->host_priv; 1120 cam = icd->host_priv;
@@ -1278,6 +1386,7 @@ static int client_s_fmt(struct soc_camera_device *icd,
1278 unsigned int width = mf->width, height = mf->height, tmp_w, tmp_h; 1386 unsigned int width = mf->width, height = mf->height, tmp_w, tmp_h;
1279 unsigned int max_width, max_height; 1387 unsigned int max_width, max_height;
1280 struct v4l2_cropcap cap; 1388 struct v4l2_cropcap cap;
1389 bool ceu_1to1;
1281 int ret; 1390 int ret;
1282 1391
1283 ret = v4l2_device_call_until_err(sd->v4l2_dev, (long)icd, video, 1392 ret = v4l2_device_call_until_err(sd->v4l2_dev, (long)icd, video,
@@ -1287,7 +1396,14 @@ static int client_s_fmt(struct soc_camera_device *icd,
1287 1396
1288 dev_geo(dev, "camera scaled to %ux%u\n", mf->width, mf->height); 1397 dev_geo(dev, "camera scaled to %ux%u\n", mf->width, mf->height);
1289 1398
1290 if ((width == mf->width && height == mf->height) || !ceu_can_scale) 1399 if (width == mf->width && height == mf->height) {
1400 /* Perfect! The client has done it all. */
1401 ceu_1to1 = true;
1402 goto update_cache;
1403 }
1404
1405 ceu_1to1 = false;
1406 if (!ceu_can_scale)
1291 goto update_cache; 1407 goto update_cache;
1292 1408
1293 cap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1409 cap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
@@ -1327,7 +1443,10 @@ update_cache:
1327 if (ret < 0) 1443 if (ret < 0)
1328 return ret; 1444 return ret;
1329 1445
1330 update_subrect(cam); 1446 if (ceu_1to1)
1447 cam->subrect = cam->rect;
1448 else
1449 update_subrect(cam);
1331 1450
1332 return 0; 1451 return 0;
1333} 1452}
@@ -1414,7 +1533,10 @@ static int sh_mobile_ceu_set_crop(struct soc_camera_device *icd,
1414 capsr = capture_save_reset(pcdev); 1533 capsr = capture_save_reset(pcdev);
1415 dev_dbg(dev, "CAPSR 0x%x, CFLCR 0x%x\n", capsr, pcdev->cflcr); 1534 dev_dbg(dev, "CAPSR 0x%x, CFLCR 0x%x\n", capsr, pcdev->cflcr);
1416 1535
1417 /* 1. - 2. Apply iterative camera S_CROP for new input window. */ 1536 /*
1537 * 1. - 2. Apply iterative camera S_CROP for new input window, read back
1538 * actual camera rectangle.
1539 */
1418 ret = client_s_crop(icd, a, &cam_crop); 1540 ret = client_s_crop(icd, a, &cam_crop);
1419 if (ret < 0) 1541 if (ret < 0)
1420 return ret; 1542 return ret;
@@ -1498,8 +1620,9 @@ static int sh_mobile_ceu_set_crop(struct soc_camera_device *icd,
1498 ceu_write(pcdev, CFLCR, cflcr); 1620 ceu_write(pcdev, CFLCR, cflcr);
1499 } 1621 }
1500 1622
1501 icd->user_width = out_width; 1623 icd->user_width = out_width & ~3;
1502 icd->user_height = out_height; 1624 icd->user_height = out_height & ~3;
1625 /* Offsets are applied at the CEU scaling filter input */
1503 cam->ceu_left = scale_down(rect->left - cam_rect->left, scale_cam_h) & ~1; 1626 cam->ceu_left = scale_down(rect->left - cam_rect->left, scale_cam_h) & ~1;
1504 cam->ceu_top = scale_down(rect->top - cam_rect->top, scale_cam_v) & ~1; 1627 cam->ceu_top = scale_down(rect->top - cam_rect->top, scale_cam_v) & ~1;
1505 1628
@@ -1538,7 +1661,7 @@ static int sh_mobile_ceu_get_crop(struct soc_camera_device *icd,
1538 * CEU crop, mapped backed onto the client input (subrect). 1661 * CEU crop, mapped backed onto the client input (subrect).
1539 */ 1662 */
1540static void calculate_client_output(struct soc_camera_device *icd, 1663static void calculate_client_output(struct soc_camera_device *icd,
1541 struct v4l2_pix_format *pix, struct v4l2_mbus_framefmt *mf) 1664 const struct v4l2_pix_format *pix, struct v4l2_mbus_framefmt *mf)
1542{ 1665{
1543 struct sh_mobile_ceu_cam *cam = icd->host_priv; 1666 struct sh_mobile_ceu_cam *cam = icd->host_priv;
1544 struct device *dev = icd->parent; 1667 struct device *dev = icd->parent;
@@ -1574,8 +1697,8 @@ static void calculate_client_output(struct soc_camera_device *icd,
1574 dev_geo(dev, "3: scales %u:%u\n", scale_h, scale_v); 1697 dev_geo(dev, "3: scales %u:%u\n", scale_h, scale_v);
1575 1698
1576 /* 1699 /*
1577 * 4. Calculate client output window by applying combined scales to real 1700 * 4. Calculate desired client output window by applying combined scales
1578 * input window. 1701 * to client (real) input window.
1579 */ 1702 */
1580 mf->width = scale_down(cam->rect.width, scale_h); 1703 mf->width = scale_down(cam->rect.width, scale_h);
1581 mf->height = scale_down(cam->rect.height, scale_v); 1704 mf->height = scale_down(cam->rect.height, scale_v);
@@ -1600,8 +1723,6 @@ static int sh_mobile_ceu_set_fmt(struct soc_camera_device *icd,
1600 bool image_mode; 1723 bool image_mode;
1601 enum v4l2_field field; 1724 enum v4l2_field field;
1602 1725
1603 dev_geo(dev, "S_FMT(pix=0x%x, %ux%u)\n", pixfmt, pix->width, pix->height);
1604
1605 switch (pix->field) { 1726 switch (pix->field) {
1606 default: 1727 default:
1607 pix->field = V4L2_FIELD_NONE; 1728 pix->field = V4L2_FIELD_NONE;
@@ -1622,8 +1743,8 @@ static int sh_mobile_ceu_set_fmt(struct soc_camera_device *icd,
1622 return -EINVAL; 1743 return -EINVAL;
1623 } 1744 }
1624 1745
1625 /* 1.-4. Calculate client output geometry */ 1746 /* 1.-4. Calculate desired client output geometry */
1626 calculate_client_output(icd, &f->fmt.pix, &mf); 1747 calculate_client_output(icd, pix, &mf);
1627 mf.field = pix->field; 1748 mf.field = pix->field;
1628 mf.colorspace = pix->colorspace; 1749 mf.colorspace = pix->colorspace;
1629 mf.code = xlate->code; 1750 mf.code = xlate->code;
@@ -1639,6 +1760,9 @@ static int sh_mobile_ceu_set_fmt(struct soc_camera_device *icd,
1639 image_mode = false; 1760 image_mode = false;
1640 } 1761 }
1641 1762
1763 dev_geo(dev, "S_FMT(pix=0x%x, fld 0x%x, code 0x%x, %ux%u)\n", pixfmt, mf.field, mf.code,
1764 pix->width, pix->height);
1765
1642 dev_geo(dev, "4: request camera output %ux%u\n", mf.width, mf.height); 1766 dev_geo(dev, "4: request camera output %ux%u\n", mf.width, mf.height);
1643 1767
1644 /* 5. - 9. */ 1768 /* 5. - 9. */
@@ -1700,6 +1824,10 @@ static int sh_mobile_ceu_set_fmt(struct soc_camera_device *icd,
1700 pcdev->field = field; 1824 pcdev->field = field;
1701 pcdev->image_mode = image_mode; 1825 pcdev->image_mode = image_mode;
1702 1826
1827 /* CFSZR requirement */
1828 pix->width &= ~3;
1829 pix->height &= ~3;
1830
1703 return 0; 1831 return 0;
1704} 1832}
1705 1833
@@ -1725,7 +1853,8 @@ static int sh_mobile_ceu_try_fmt(struct soc_camera_device *icd,
1725 1853
1726 /* FIXME: calculate using depth and bus width */ 1854 /* FIXME: calculate using depth and bus width */
1727 1855
1728 v4l_bound_align_image(&pix->width, 2, 2560, 1, 1856 /* CFSZR requires height and width to be 4-pixel aligned */
1857 v4l_bound_align_image(&pix->width, 2, 2560, 2,
1729 &pix->height, 4, 1920, 2, 0); 1858 &pix->height, 4, 1920, 2, 0);
1730 1859
1731 width = pix->width; 1860 width = pix->width;
@@ -1778,6 +1907,9 @@ static int sh_mobile_ceu_try_fmt(struct soc_camera_device *icd,
1778 pix->height = height; 1907 pix->height = height;
1779 } 1908 }
1780 1909
1910 pix->width &= ~3;
1911 pix->height &= ~3;
1912
1781 dev_geo(icd->parent, "%s(): return %d, fmt 0x%x, %ux%u\n", 1913 dev_geo(icd->parent, "%s(): return %d, fmt 0x%x, %ux%u\n",
1782 __func__, ret, pix->pixelformat, pix->width, pix->height); 1914 __func__, ret, pix->pixelformat, pix->width, pix->height);
1783 1915
@@ -1824,8 +1956,8 @@ static int sh_mobile_ceu_set_livecrop(struct soc_camera_device *icd,
1824 out_height != f.fmt.pix.height)) 1956 out_height != f.fmt.pix.height))
1825 ret = -EINVAL; 1957 ret = -EINVAL;
1826 if (!ret) { 1958 if (!ret) {
1827 icd->user_width = out_width; 1959 icd->user_width = out_width & ~3;
1828 icd->user_height = out_height; 1960 icd->user_height = out_height & ~3;
1829 ret = sh_mobile_ceu_set_bus_param(icd, 1961 ret = sh_mobile_ceu_set_bus_param(icd,
1830 icd->current_fmt->host_fmt->fourcc); 1962 icd->current_fmt->host_fmt->fourcc);
1831 } 1963 }
@@ -1869,55 +2001,6 @@ static int sh_mobile_ceu_init_videobuf(struct vb2_queue *q,
1869 return vb2_queue_init(q); 2001 return vb2_queue_init(q);
1870} 2002}
1871 2003
1872static int sh_mobile_ceu_get_ctrl(struct soc_camera_device *icd,
1873 struct v4l2_control *ctrl)
1874{
1875 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
1876 struct sh_mobile_ceu_dev *pcdev = ici->priv;
1877 u32 val;
1878
1879 switch (ctrl->id) {
1880 case V4L2_CID_SHARPNESS:
1881 val = ceu_read(pcdev, CLFCR);
1882 ctrl->value = val ^ 1;
1883 return 0;
1884 }
1885 return -ENOIOCTLCMD;
1886}
1887
1888static int sh_mobile_ceu_set_ctrl(struct soc_camera_device *icd,
1889 struct v4l2_control *ctrl)
1890{
1891 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
1892 struct sh_mobile_ceu_dev *pcdev = ici->priv;
1893
1894 switch (ctrl->id) {
1895 case V4L2_CID_SHARPNESS:
1896 switch (icd->current_fmt->host_fmt->fourcc) {
1897 case V4L2_PIX_FMT_NV12:
1898 case V4L2_PIX_FMT_NV21:
1899 case V4L2_PIX_FMT_NV16:
1900 case V4L2_PIX_FMT_NV61:
1901 ceu_write(pcdev, CLFCR, !ctrl->value);
1902 return 0;
1903 }
1904 return -EINVAL;
1905 }
1906 return -ENOIOCTLCMD;
1907}
1908
1909static const struct v4l2_queryctrl sh_mobile_ceu_controls[] = {
1910 {
1911 .id = V4L2_CID_SHARPNESS,
1912 .type = V4L2_CTRL_TYPE_BOOLEAN,
1913 .name = "Low-pass filter",
1914 .minimum = 0,
1915 .maximum = 1,
1916 .step = 1,
1917 .default_value = 0,
1918 },
1919};
1920
1921static struct soc_camera_host_ops sh_mobile_ceu_host_ops = { 2004static struct soc_camera_host_ops sh_mobile_ceu_host_ops = {
1922 .owner = THIS_MODULE, 2005 .owner = THIS_MODULE,
1923 .add = sh_mobile_ceu_add_device, 2006 .add = sh_mobile_ceu_add_device,
@@ -1929,14 +2012,10 @@ static struct soc_camera_host_ops sh_mobile_ceu_host_ops = {
1929 .set_livecrop = sh_mobile_ceu_set_livecrop, 2012 .set_livecrop = sh_mobile_ceu_set_livecrop,
1930 .set_fmt = sh_mobile_ceu_set_fmt, 2013 .set_fmt = sh_mobile_ceu_set_fmt,
1931 .try_fmt = sh_mobile_ceu_try_fmt, 2014 .try_fmt = sh_mobile_ceu_try_fmt,
1932 .set_ctrl = sh_mobile_ceu_set_ctrl,
1933 .get_ctrl = sh_mobile_ceu_get_ctrl,
1934 .poll = sh_mobile_ceu_poll, 2015 .poll = sh_mobile_ceu_poll,
1935 .querycap = sh_mobile_ceu_querycap, 2016 .querycap = sh_mobile_ceu_querycap,
1936 .set_bus_param = sh_mobile_ceu_set_bus_param, 2017 .set_bus_param = sh_mobile_ceu_set_bus_param,
1937 .init_videobuf2 = sh_mobile_ceu_init_videobuf, 2018 .init_videobuf2 = sh_mobile_ceu_init_videobuf,
1938 .controls = sh_mobile_ceu_controls,
1939 .num_controls = ARRAY_SIZE(sh_mobile_ceu_controls),
1940}; 2019};
1941 2020
1942struct bus_wait { 2021struct bus_wait {
diff --git a/drivers/media/video/sh_mobile_csi2.c b/drivers/media/video/sh_mobile_csi2.c
index 2893a0134c7e..ea4f0473ed3b 100644
--- a/drivers/media/video/sh_mobile_csi2.c
+++ b/drivers/media/video/sh_mobile_csi2.c
@@ -15,10 +15,12 @@
15#include <linux/pm_runtime.h> 15#include <linux/pm_runtime.h>
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <linux/videodev2.h> 17#include <linux/videodev2.h>
18#include <linux/module.h>
18 19
19#include <media/sh_mobile_ceu.h> 20#include <media/sh_mobile_ceu.h>
20#include <media/sh_mobile_csi2.h> 21#include <media/sh_mobile_csi2.h>
21#include <media/soc_camera.h> 22#include <media/soc_camera.h>
23#include <media/soc_mediabus.h>
22#include <media/v4l2-common.h> 24#include <media/v4l2-common.h>
23#include <media/v4l2-dev.h> 25#include <media/v4l2-dev.h>
24#include <media/v4l2-device.h> 26#include <media/v4l2-device.h>
@@ -35,11 +37,10 @@ struct sh_csi2 {
35 struct v4l2_subdev subdev; 37 struct v4l2_subdev subdev;
36 struct list_head list; 38 struct list_head list;
37 unsigned int irq; 39 unsigned int irq;
40 unsigned long mipi_flags;
38 void __iomem *base; 41 void __iomem *base;
39 struct platform_device *pdev; 42 struct platform_device *pdev;
40 struct sh_csi2_client_config *client; 43 struct sh_csi2_client_config *client;
41 unsigned long (*query_bus_param)(struct soc_camera_device *);
42 int (*set_bus_param)(struct soc_camera_device *, unsigned long);
43}; 44};
44 45
45static int sh_csi2_try_fmt(struct v4l2_subdev *sd, 46static int sh_csi2_try_fmt(struct v4l2_subdev *sd,
@@ -127,9 +128,34 @@ static int sh_csi2_s_fmt(struct v4l2_subdev *sd,
127 return 0; 128 return 0;
128} 129}
129 130
131static int sh_csi2_g_mbus_config(struct v4l2_subdev *sd,
132 struct v4l2_mbus_config *cfg)
133{
134 cfg->flags = V4L2_MBUS_PCLK_SAMPLE_RISING |
135 V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_HIGH |
136 V4L2_MBUS_MASTER | V4L2_MBUS_DATA_ACTIVE_HIGH;
137 cfg->type = V4L2_MBUS_PARALLEL;
138
139 return 0;
140}
141
142static int sh_csi2_s_mbus_config(struct v4l2_subdev *sd,
143 const struct v4l2_mbus_config *cfg)
144{
145 struct sh_csi2 *priv = container_of(sd, struct sh_csi2, subdev);
146 struct soc_camera_device *icd = (struct soc_camera_device *)sd->grp_id;
147 struct v4l2_subdev *client_sd = soc_camera_to_subdev(icd);
148 struct v4l2_mbus_config client_cfg = {.type = V4L2_MBUS_CSI2,
149 .flags = priv->mipi_flags};
150
151 return v4l2_subdev_call(client_sd, video, s_mbus_config, &client_cfg);
152}
153
130static struct v4l2_subdev_video_ops sh_csi2_subdev_video_ops = { 154static struct v4l2_subdev_video_ops sh_csi2_subdev_video_ops = {
131 .s_mbus_fmt = sh_csi2_s_fmt, 155 .s_mbus_fmt = sh_csi2_s_fmt,
132 .try_mbus_fmt = sh_csi2_try_fmt, 156 .try_mbus_fmt = sh_csi2_try_fmt,
157 .g_mbus_config = sh_csi2_g_mbus_config,
158 .s_mbus_config = sh_csi2_s_mbus_config,
133}; 159};
134 160
135static void sh_csi2_hwinit(struct sh_csi2 *priv) 161static void sh_csi2_hwinit(struct sh_csi2 *priv)
@@ -144,11 +170,21 @@ static void sh_csi2_hwinit(struct sh_csi2 *priv)
144 udelay(5); 170 udelay(5);
145 iowrite32(0x00000000, priv->base + SH_CSI2_SRST); 171 iowrite32(0x00000000, priv->base + SH_CSI2_SRST);
146 172
147 if (priv->client->lanes & 3) 173 switch (pdata->type) {
148 tmp |= priv->client->lanes & 3; 174 case SH_CSI2C:
149 else 175 if (priv->client->lanes == 1)
150 /* Default - both lanes */ 176 tmp |= 1;
151 tmp |= 3; 177 else
178 /* Default - both lanes */
179 tmp |= 3;
180 break;
181 case SH_CSI2I:
182 if (!priv->client->lanes || priv->client->lanes > 4)
183 /* Default - all 4 lanes */
184 tmp |= 0xf;
185 else
186 tmp |= (1 << priv->client->lanes) - 1;
187 }
152 188
153 if (priv->client->phy == SH_CSI2_PHY_MAIN) 189 if (priv->client->phy == SH_CSI2_PHY_MAIN)
154 tmp |= 0x8000; 190 tmp |= 0x8000;
@@ -163,38 +199,18 @@ static void sh_csi2_hwinit(struct sh_csi2 *priv)
163 iowrite32(tmp, priv->base + SH_CSI2_CHKSUM); 199 iowrite32(tmp, priv->base + SH_CSI2_CHKSUM);
164} 200}
165 201
166static int sh_csi2_set_bus_param(struct soc_camera_device *icd,
167 unsigned long flags)
168{
169 return 0;
170}
171
172static unsigned long sh_csi2_query_bus_param(struct soc_camera_device *icd)
173{
174 struct soc_camera_link *icl = to_soc_camera_link(icd);
175 const unsigned long flags = SOCAM_PCLK_SAMPLE_RISING |
176 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH |
177 SOCAM_MASTER | SOCAM_DATAWIDTH_8 | SOCAM_DATA_ACTIVE_HIGH;
178
179 return soc_camera_apply_sensor_flags(icl, flags);
180}
181
182static int sh_csi2_client_connect(struct sh_csi2 *priv) 202static int sh_csi2_client_connect(struct sh_csi2 *priv)
183{ 203{
184 struct sh_csi2_pdata *pdata = priv->pdev->dev.platform_data; 204 struct sh_csi2_pdata *pdata = priv->pdev->dev.platform_data;
185 struct v4l2_subdev *sd, *csi2_sd = &priv->subdev; 205 struct soc_camera_device *icd = (struct soc_camera_device *)priv->subdev.grp_id;
186 struct soc_camera_device *icd = NULL; 206 struct v4l2_subdev *client_sd = soc_camera_to_subdev(icd);
187 struct device *dev = v4l2_get_subdevdata(&priv->subdev); 207 struct device *dev = v4l2_get_subdevdata(&priv->subdev);
188 int i; 208 struct v4l2_mbus_config cfg;
209 unsigned long common_flags, csi2_flags;
210 int i, ret;
189 211
190 v4l2_device_for_each_subdev(sd, csi2_sd->v4l2_dev) 212 if (priv->client)
191 if (sd->grp_id) { 213 return -EBUSY;
192 icd = (struct soc_camera_device *)sd->grp_id;
193 break;
194 }
195
196 if (!icd)
197 return -EINVAL;
198 214
199 for (i = 0; i < pdata->num_clients; i++) 215 for (i = 0; i < pdata->num_clients; i++)
200 if (&pdata->clients[i].pdev->dev == icd->pdev) 216 if (&pdata->clients[i].pdev->dev == icd->pdev)
@@ -205,14 +221,41 @@ static int sh_csi2_client_connect(struct sh_csi2 *priv)
205 if (i == pdata->num_clients) 221 if (i == pdata->num_clients)
206 return -ENODEV; 222 return -ENODEV;
207 223
208 priv->client = pdata->clients + i; 224 /* Check if we can support this camera */
225 csi2_flags = V4L2_MBUS_CSI2_CONTINUOUS_CLOCK | V4L2_MBUS_CSI2_1_LANE;
226
227 switch (pdata->type) {
228 case SH_CSI2C:
229 if (pdata->clients[i].lanes != 1)
230 csi2_flags |= V4L2_MBUS_CSI2_2_LANE;
231 break;
232 case SH_CSI2I:
233 switch (pdata->clients[i].lanes) {
234 default:
235 csi2_flags |= V4L2_MBUS_CSI2_4_LANE;
236 case 3:
237 csi2_flags |= V4L2_MBUS_CSI2_3_LANE;
238 case 2:
239 csi2_flags |= V4L2_MBUS_CSI2_2_LANE;
240 }
241 }
209 242
210 priv->set_bus_param = icd->ops->set_bus_param; 243 cfg.type = V4L2_MBUS_CSI2;
211 priv->query_bus_param = icd->ops->query_bus_param; 244 ret = v4l2_subdev_call(client_sd, video, g_mbus_config, &cfg);
212 icd->ops->set_bus_param = sh_csi2_set_bus_param; 245 if (ret == -ENOIOCTLCMD)
213 icd->ops->query_bus_param = sh_csi2_query_bus_param; 246 common_flags = csi2_flags;
247 else if (!ret)
248 common_flags = soc_mbus_config_compatible(&cfg,
249 csi2_flags);
250 else
251 common_flags = 0;
214 252
215 csi2_sd->grp_id = (long)icd; 253 if (!common_flags)
254 return -EINVAL;
255
256 /* All good: camera MIPI configuration supported */
257 priv->mipi_flags = common_flags;
258 priv->client = pdata->clients + i;
216 259
217 pm_runtime_get_sync(dev); 260 pm_runtime_get_sync(dev);
218 261
@@ -223,16 +266,10 @@ static int sh_csi2_client_connect(struct sh_csi2 *priv)
223 266
224static void sh_csi2_client_disconnect(struct sh_csi2 *priv) 267static void sh_csi2_client_disconnect(struct sh_csi2 *priv)
225{ 268{
226 struct soc_camera_device *icd = (struct soc_camera_device *)priv->subdev.grp_id; 269 if (!priv->client)
270 return;
227 271
228 priv->client = NULL; 272 priv->client = NULL;
229 priv->subdev.grp_id = 0;
230
231 /* Driver is about to be unbound */
232 icd->ops->set_bus_param = priv->set_bus_param;
233 icd->ops->query_bus_param = priv->query_bus_param;
234 priv->set_bus_param = NULL;
235 priv->query_bus_param = NULL;
236 273
237 pm_runtime_put(v4l2_get_subdevdata(&priv->subdev)); 274 pm_runtime_put(v4l2_get_subdevdata(&priv->subdev));
238} 275}
diff --git a/drivers/media/video/sh_vou.c b/drivers/media/video/sh_vou.c
index 6a729879d89e..9644bd861abc 100644
--- a/drivers/media/video/sh_vou.c
+++ b/drivers/media/video/sh_vou.c
@@ -20,6 +20,7 @@
20#include <linux/pm_runtime.h> 20#include <linux/pm_runtime.h>
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/videodev2.h> 22#include <linux/videodev2.h>
23#include <linux/module.h>
23 24
24#include <media/sh_vou.h> 25#include <media/sh_vou.h>
25#include <media/v4l2-common.h> 26#include <media/v4l2-common.h>
diff --git a/drivers/media/video/soc_camera.c b/drivers/media/video/soc_camera.c
index 5bdfe7e16bc1..b72580c38957 100644
--- a/drivers/media/video/soc_camera.c
+++ b/drivers/media/video/soc_camera.c
@@ -50,49 +50,65 @@ static LIST_HEAD(hosts);
50static LIST_HEAD(devices); 50static LIST_HEAD(devices);
51static DEFINE_MUTEX(list_lock); /* Protects the list of hosts */ 51static DEFINE_MUTEX(list_lock); /* Protects the list of hosts */
52 52
53static int soc_camera_power_set(struct soc_camera_device *icd, 53static int soc_camera_power_on(struct soc_camera_device *icd,
54 struct soc_camera_link *icl, 54 struct soc_camera_link *icl)
55 int power_on)
56{ 55{
57 int ret; 56 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
58 57 int ret = regulator_bulk_enable(icl->num_regulators,
59 if (power_on) { 58 icl->regulators);
60 ret = regulator_bulk_enable(icl->num_regulators, 59 if (ret < 0) {
61 icl->regulators); 60 dev_err(icd->pdev, "Cannot enable regulators\n");
62 if (ret < 0) { 61 return ret;
63 dev_err(icd->pdev, "Cannot enable regulators\n"); 62 }
64 return ret;
65 }
66 63
67 if (icl->power) 64 if (icl->power) {
68 ret = icl->power(icd->pdev, power_on); 65 ret = icl->power(icd->pdev, 1);
69 if (ret < 0) { 66 if (ret < 0) {
70 dev_err(icd->pdev, 67 dev_err(icd->pdev,
71 "Platform failed to power-on the camera.\n"); 68 "Platform failed to power-on the camera.\n");
72 69 goto elinkpwr;
73 regulator_bulk_disable(icl->num_regulators,
74 icl->regulators);
75 return ret;
76 } 70 }
77 } else { 71 }
78 ret = 0; 72
79 if (icl->power) 73 ret = v4l2_subdev_call(sd, core, s_power, 1);
80 ret = icl->power(icd->pdev, 0); 74 if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
75 goto esdpwr;
76
77 return 0;
78
79esdpwr:
80 if (icl->power)
81 icl->power(icd->pdev, 0);
82elinkpwr:
83 regulator_bulk_disable(icl->num_regulators,
84 icl->regulators);
85 return ret;
86}
87
88static int soc_camera_power_off(struct soc_camera_device *icd,
89 struct soc_camera_link *icl)
90{
91 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
92 int ret = v4l2_subdev_call(sd, core, s_power, 0);
93
94 if (ret < 0 && ret != -ENOIOCTLCMD && ret != -ENODEV)
95 return ret;
96
97 if (icl->power) {
98 ret = icl->power(icd->pdev, 0);
81 if (ret < 0) { 99 if (ret < 0) {
82 dev_err(icd->pdev, 100 dev_err(icd->pdev,
83 "Platform failed to power-off the camera.\n"); 101 "Platform failed to power-off the camera.\n");
84 return ret; 102 return ret;
85 } 103 }
86
87 ret = regulator_bulk_disable(icl->num_regulators,
88 icl->regulators);
89 if (ret < 0) {
90 dev_err(icd->pdev, "Cannot disable regulators\n");
91 return ret;
92 }
93 } 104 }
94 105
95 return 0; 106 ret = regulator_bulk_disable(icl->num_regulators,
107 icl->regulators);
108 if (ret < 0)
109 dev_err(icd->pdev, "Cannot disable regulators\n");
110
111 return ret;
96} 112}
97 113
98const struct soc_camera_format_xlate *soc_camera_xlate_by_fourcc( 114const struct soc_camera_format_xlate *soc_camera_xlate_by_fourcc(
@@ -108,38 +124,38 @@ const struct soc_camera_format_xlate *soc_camera_xlate_by_fourcc(
108EXPORT_SYMBOL(soc_camera_xlate_by_fourcc); 124EXPORT_SYMBOL(soc_camera_xlate_by_fourcc);
109 125
110/** 126/**
111 * soc_camera_apply_sensor_flags() - apply platform SOCAM_SENSOR_INVERT_* flags 127 * soc_camera_apply_board_flags() - apply platform SOCAM_SENSOR_INVERT_* flags
112 * @icl: camera platform parameters 128 * @icl: camera platform parameters
113 * @flags: flags to be inverted according to platform configuration 129 * @cfg: media bus configuration
114 * @return: resulting flags 130 * @return: resulting flags
115 */ 131 */
116unsigned long soc_camera_apply_sensor_flags(struct soc_camera_link *icl, 132unsigned long soc_camera_apply_board_flags(struct soc_camera_link *icl,
117 unsigned long flags) 133 const struct v4l2_mbus_config *cfg)
118{ 134{
119 unsigned long f; 135 unsigned long f, flags = cfg->flags;
120 136
121 /* If only one of the two polarities is supported, switch to the opposite */ 137 /* If only one of the two polarities is supported, switch to the opposite */
122 if (icl->flags & SOCAM_SENSOR_INVERT_HSYNC) { 138 if (icl->flags & SOCAM_SENSOR_INVERT_HSYNC) {
123 f = flags & (SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW); 139 f = flags & (V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_LOW);
124 if (f == SOCAM_HSYNC_ACTIVE_HIGH || f == SOCAM_HSYNC_ACTIVE_LOW) 140 if (f == V4L2_MBUS_HSYNC_ACTIVE_HIGH || f == V4L2_MBUS_HSYNC_ACTIVE_LOW)
125 flags ^= SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW; 141 flags ^= V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_LOW;
126 } 142 }
127 143
128 if (icl->flags & SOCAM_SENSOR_INVERT_VSYNC) { 144 if (icl->flags & SOCAM_SENSOR_INVERT_VSYNC) {
129 f = flags & (SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW); 145 f = flags & (V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW);
130 if (f == SOCAM_VSYNC_ACTIVE_HIGH || f == SOCAM_VSYNC_ACTIVE_LOW) 146 if (f == V4L2_MBUS_VSYNC_ACTIVE_HIGH || f == V4L2_MBUS_VSYNC_ACTIVE_LOW)
131 flags ^= SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW; 147 flags ^= V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW;
132 } 148 }
133 149
134 if (icl->flags & SOCAM_SENSOR_INVERT_PCLK) { 150 if (icl->flags & SOCAM_SENSOR_INVERT_PCLK) {
135 f = flags & (SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING); 151 f = flags & (V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING);
136 if (f == SOCAM_PCLK_SAMPLE_RISING || f == SOCAM_PCLK_SAMPLE_FALLING) 152 if (f == V4L2_MBUS_PCLK_SAMPLE_RISING || f == V4L2_MBUS_PCLK_SAMPLE_FALLING)
137 flags ^= SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING; 153 flags ^= V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_PCLK_SAMPLE_FALLING;
138 } 154 }
139 155
140 return flags; 156 return flags;
141} 157}
142EXPORT_SYMBOL(soc_camera_apply_sensor_flags); 158EXPORT_SYMBOL(soc_camera_apply_board_flags);
143 159
144#define pixfmtstr(x) (x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, \ 160#define pixfmtstr(x) (x) & 0xff, ((x) >> 8) & 0xff, ((x) >> 16) & 0xff, \
145 ((x) >> 24) & 0xff 161 ((x) >> 24) & 0xff
@@ -233,6 +249,14 @@ static int soc_camera_s_std(struct file *file, void *priv, v4l2_std_id *a)
233 return v4l2_subdev_call(sd, core, s_std, *a); 249 return v4l2_subdev_call(sd, core, s_std, *a);
234} 250}
235 251
252static int soc_camera_g_std(struct file *file, void *priv, v4l2_std_id *a)
253{
254 struct soc_camera_device *icd = file->private_data;
255 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
256
257 return v4l2_subdev_call(sd, core, g_std, a);
258}
259
236static int soc_camera_enum_fsizes(struct file *file, void *fh, 260static int soc_camera_enum_fsizes(struct file *file, void *fh,
237 struct v4l2_frmsizeenum *fsize) 261 struct v4l2_frmsizeenum *fsize)
238{ 262{
@@ -318,6 +342,32 @@ static int soc_camera_dqbuf(struct file *file, void *priv,
318 return vb2_dqbuf(&icd->vb2_vidq, p, file->f_flags & O_NONBLOCK); 342 return vb2_dqbuf(&icd->vb2_vidq, p, file->f_flags & O_NONBLOCK);
319} 343}
320 344
345static int soc_camera_create_bufs(struct file *file, void *priv,
346 struct v4l2_create_buffers *create)
347{
348 struct soc_camera_device *icd = file->private_data;
349 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
350
351 /* videobuf2 only */
352 if (ici->ops->init_videobuf)
353 return -EINVAL;
354 else
355 return vb2_create_bufs(&icd->vb2_vidq, create);
356}
357
358static int soc_camera_prepare_buf(struct file *file, void *priv,
359 struct v4l2_buffer *b)
360{
361 struct soc_camera_device *icd = file->private_data;
362 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
363
364 /* videobuf2 only */
365 if (ici->ops->init_videobuf)
366 return -EINVAL;
367 else
368 return vb2_prepare_buf(&icd->vb2_vidq, b);
369}
370
321/* Always entered with .video_lock held */ 371/* Always entered with .video_lock held */
322static int soc_camera_init_user_formats(struct soc_camera_device *icd) 372static int soc_camera_init_user_formats(struct soc_camera_device *icd)
323{ 373{
@@ -448,7 +498,7 @@ static int soc_camera_open(struct file *file)
448 struct soc_camera_host *ici; 498 struct soc_camera_host *ici;
449 int ret; 499 int ret;
450 500
451 if (!icd->ops) 501 if (!to_soc_camera_control(icd))
452 /* No device driver attached */ 502 /* No device driver attached */
453 return -ENODEV; 503 return -ENODEV;
454 504
@@ -476,7 +526,7 @@ static int soc_camera_open(struct file *file)
476 }, 526 },
477 }; 527 };
478 528
479 ret = soc_camera_power_set(icd, icl, 1); 529 ret = soc_camera_power_on(icd, icl);
480 if (ret < 0) 530 if (ret < 0)
481 goto epower; 531 goto epower;
482 532
@@ -512,6 +562,7 @@ static int soc_camera_open(struct file *file)
512 if (ret < 0) 562 if (ret < 0)
513 goto einitvb; 563 goto einitvb;
514 } 564 }
565 v4l2_ctrl_handler_setup(&icd->ctrl_handler);
515 } 566 }
516 567
517 file->private_data = icd; 568 file->private_data = icd;
@@ -529,7 +580,7 @@ esfmt:
529eresume: 580eresume:
530 ici->ops->remove(icd); 581 ici->ops->remove(icd);
531eiciadd: 582eiciadd:
532 soc_camera_power_set(icd, icl, 0); 583 soc_camera_power_off(icd, icl);
533epower: 584epower:
534 icd->use_count--; 585 icd->use_count--;
535 module_put(ici->ops->owner); 586 module_put(ici->ops->owner);
@@ -553,7 +604,7 @@ static int soc_camera_close(struct file *file)
553 if (ici->ops->init_videobuf2) 604 if (ici->ops->init_videobuf2)
554 vb2_queue_release(&icd->vb2_vidq); 605 vb2_queue_release(&icd->vb2_vidq);
555 606
556 soc_camera_power_set(icd, icl, 0); 607 soc_camera_power_off(icd, icl);
557 } 608 }
558 609
559 if (icd->streamer == file) 610 if (icd->streamer == file)
@@ -781,75 +832,6 @@ static int soc_camera_streamoff(struct file *file, void *priv,
781 return 0; 832 return 0;
782} 833}
783 834
784static int soc_camera_queryctrl(struct file *file, void *priv,
785 struct v4l2_queryctrl *qc)
786{
787 struct soc_camera_device *icd = file->private_data;
788 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
789 int i;
790
791 WARN_ON(priv != file->private_data);
792
793 if (!qc->id)
794 return -EINVAL;
795
796 /* First check host controls */
797 for (i = 0; i < ici->ops->num_controls; i++)
798 if (qc->id == ici->ops->controls[i].id) {
799 memcpy(qc, &(ici->ops->controls[i]),
800 sizeof(*qc));
801 return 0;
802 }
803
804 /* Then device controls */
805 for (i = 0; i < icd->ops->num_controls; i++)
806 if (qc->id == icd->ops->controls[i].id) {
807 memcpy(qc, &(icd->ops->controls[i]),
808 sizeof(*qc));
809 return 0;
810 }
811
812 return -EINVAL;
813}
814
815static int soc_camera_g_ctrl(struct file *file, void *priv,
816 struct v4l2_control *ctrl)
817{
818 struct soc_camera_device *icd = file->private_data;
819 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
820 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
821 int ret;
822
823 WARN_ON(priv != file->private_data);
824
825 if (ici->ops->get_ctrl) {
826 ret = ici->ops->get_ctrl(icd, ctrl);
827 if (ret != -ENOIOCTLCMD)
828 return ret;
829 }
830
831 return v4l2_subdev_call(sd, core, g_ctrl, ctrl);
832}
833
834static int soc_camera_s_ctrl(struct file *file, void *priv,
835 struct v4l2_control *ctrl)
836{
837 struct soc_camera_device *icd = file->private_data;
838 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
839 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
840 int ret;
841
842 WARN_ON(priv != file->private_data);
843
844 if (ici->ops->set_ctrl) {
845 ret = ici->ops->set_ctrl(icd, ctrl);
846 if (ret != -ENOIOCTLCMD)
847 return ret;
848 }
849
850 return v4l2_subdev_call(sd, core, s_ctrl, ctrl);
851}
852
853static int soc_camera_cropcap(struct file *file, void *fh, 835static int soc_camera_cropcap(struct file *file, void *fh,
854 struct v4l2_cropcap *a) 836 struct v4l2_cropcap *a)
855{ 837{
@@ -1003,7 +985,7 @@ static int soc_camera_init_i2c(struct soc_camera_device *icd,
1003 goto ei2cga; 985 goto ei2cga;
1004 } 986 }
1005 987
1006 icl->board_info->platform_data = icd; 988 icl->board_info->platform_data = icl;
1007 989
1008 subdev = v4l2_i2c_new_subdev_board(&ici->v4l2_dev, adap, 990 subdev = v4l2_i2c_new_subdev_board(&ici->v4l2_dev, adap,
1009 icl->board_info, NULL); 991 icl->board_info, NULL);
@@ -1052,12 +1034,29 @@ static int soc_camera_probe(struct soc_camera_device *icd)
1052 1034
1053 dev_info(icd->pdev, "Probing %s\n", dev_name(icd->pdev)); 1035 dev_info(icd->pdev, "Probing %s\n", dev_name(icd->pdev));
1054 1036
1037 /*
1038 * Currently the subdev with the largest number of controls (13) is
1039 * ov6550. So let's pick 16 as a hint for the control handler. Note
1040 * that this is a hint only: too large and you waste some memory, too
1041 * small and there is a (very) small performance hit when looking up
1042 * controls in the internal hash.
1043 */
1044 ret = v4l2_ctrl_handler_init(&icd->ctrl_handler, 16);
1045 if (ret < 0)
1046 return ret;
1047
1055 ret = regulator_bulk_get(icd->pdev, icl->num_regulators, 1048 ret = regulator_bulk_get(icd->pdev, icl->num_regulators,
1056 icl->regulators); 1049 icl->regulators);
1057 if (ret < 0) 1050 if (ret < 0)
1058 goto ereg; 1051 goto ereg;
1059 1052
1060 ret = soc_camera_power_set(icd, icl, 1); 1053 /*
1054 * This will not yet call v4l2_subdev_core_ops::s_power(1), because the
1055 * subdevice has not been initialised yet. We'll have to call it once
1056 * again after initialisation, even though it shouldn't be needed, we
1057 * don't do any IO here.
1058 */
1059 ret = soc_camera_power_on(icd, icl);
1061 if (ret < 0) 1060 if (ret < 0)
1062 goto epower; 1061 goto epower;
1063 1062
@@ -1098,6 +1097,7 @@ static int soc_camera_probe(struct soc_camera_device *icd)
1098 if (!control || !control->driver || !dev_get_drvdata(control) || 1097 if (!control || !control->driver || !dev_get_drvdata(control) ||
1099 !try_module_get(control->driver->owner)) { 1098 !try_module_get(control->driver->owner)) {
1100 icl->del_device(icd); 1099 icl->del_device(icd);
1100 ret = -ENODEV;
1101 goto enodrv; 1101 goto enodrv;
1102 } 1102 }
1103 } 1103 }
@@ -1105,6 +1105,9 @@ static int soc_camera_probe(struct soc_camera_device *icd)
1105 sd = soc_camera_to_subdev(icd); 1105 sd = soc_camera_to_subdev(icd);
1106 sd->grp_id = (long)icd; 1106 sd->grp_id = (long)icd;
1107 1107
1108 if (v4l2_ctrl_add_handler(&icd->ctrl_handler, sd->ctrl_handler))
1109 goto ectrl;
1110
1108 /* At this point client .probe() should have run already */ 1111 /* At this point client .probe() should have run already */
1109 ret = soc_camera_init_user_formats(icd); 1112 ret = soc_camera_init_user_formats(icd);
1110 if (ret < 0) 1113 if (ret < 0)
@@ -1123,6 +1126,10 @@ static int soc_camera_probe(struct soc_camera_device *icd)
1123 if (ret < 0) 1126 if (ret < 0)
1124 goto evidstart; 1127 goto evidstart;
1125 1128
1129 ret = v4l2_subdev_call(sd, core, s_power, 1);
1130 if (ret < 0 && ret != -ENOIOCTLCMD)
1131 goto esdpwr;
1132
1126 /* Try to improve our guess of a reasonable window format */ 1133 /* Try to improve our guess of a reasonable window format */
1127 if (!v4l2_subdev_call(sd, video, g_mbus_fmt, &mf)) { 1134 if (!v4l2_subdev_call(sd, video, g_mbus_fmt, &mf)) {
1128 icd->user_width = mf.width; 1135 icd->user_width = mf.width;
@@ -1133,16 +1140,19 @@ static int soc_camera_probe(struct soc_camera_device *icd)
1133 1140
1134 ici->ops->remove(icd); 1141 ici->ops->remove(icd);
1135 1142
1136 soc_camera_power_set(icd, icl, 0); 1143 soc_camera_power_off(icd, icl);
1137 1144
1138 mutex_unlock(&icd->video_lock); 1145 mutex_unlock(&icd->video_lock);
1139 1146
1140 return 0; 1147 return 0;
1141 1148
1149esdpwr:
1150 video_unregister_device(icd->vdev);
1142evidstart: 1151evidstart:
1143 mutex_unlock(&icd->video_lock); 1152 mutex_unlock(&icd->video_lock);
1144 soc_camera_free_user_formats(icd); 1153 soc_camera_free_user_formats(icd);
1145eiufmt: 1154eiufmt:
1155ectrl:
1146 if (icl->board_info) { 1156 if (icl->board_info) {
1147 soc_camera_free_i2c(icd); 1157 soc_camera_free_i2c(icd);
1148 } else { 1158 } else {
@@ -1152,13 +1162,15 @@ eiufmt:
1152enodrv: 1162enodrv:
1153eadddev: 1163eadddev:
1154 video_device_release(icd->vdev); 1164 video_device_release(icd->vdev);
1165 icd->vdev = NULL;
1155evdc: 1166evdc:
1156 ici->ops->remove(icd); 1167 ici->ops->remove(icd);
1157eadd: 1168eadd:
1158 soc_camera_power_set(icd, icl, 0); 1169 soc_camera_power_off(icd, icl);
1159epower: 1170epower:
1160 regulator_bulk_free(icl->num_regulators, icl->regulators); 1171 regulator_bulk_free(icl->num_regulators, icl->regulators);
1161ereg: 1172ereg:
1173 v4l2_ctrl_handler_free(&icd->ctrl_handler);
1162 return ret; 1174 return ret;
1163} 1175}
1164 1176
@@ -1173,6 +1185,7 @@ static int soc_camera_remove(struct soc_camera_device *icd)
1173 1185
1174 BUG_ON(!icd->parent); 1186 BUG_ON(!icd->parent);
1175 1187
1188 v4l2_ctrl_handler_free(&icd->ctrl_handler);
1176 if (vdev) { 1189 if (vdev) {
1177 video_unregister_device(vdev); 1190 video_unregister_device(vdev);
1178 icd->vdev = NULL; 1191 icd->vdev = NULL;
@@ -1363,24 +1376,24 @@ static int soc_camera_device_register(struct soc_camera_device *icd)
1363 1376
1364static const struct v4l2_ioctl_ops soc_camera_ioctl_ops = { 1377static const struct v4l2_ioctl_ops soc_camera_ioctl_ops = {
1365 .vidioc_querycap = soc_camera_querycap, 1378 .vidioc_querycap = soc_camera_querycap,
1379 .vidioc_try_fmt_vid_cap = soc_camera_try_fmt_vid_cap,
1366 .vidioc_g_fmt_vid_cap = soc_camera_g_fmt_vid_cap, 1380 .vidioc_g_fmt_vid_cap = soc_camera_g_fmt_vid_cap,
1367 .vidioc_enum_fmt_vid_cap = soc_camera_enum_fmt_vid_cap,
1368 .vidioc_s_fmt_vid_cap = soc_camera_s_fmt_vid_cap, 1381 .vidioc_s_fmt_vid_cap = soc_camera_s_fmt_vid_cap,
1382 .vidioc_enum_fmt_vid_cap = soc_camera_enum_fmt_vid_cap,
1369 .vidioc_enum_input = soc_camera_enum_input, 1383 .vidioc_enum_input = soc_camera_enum_input,
1370 .vidioc_g_input = soc_camera_g_input, 1384 .vidioc_g_input = soc_camera_g_input,
1371 .vidioc_s_input = soc_camera_s_input, 1385 .vidioc_s_input = soc_camera_s_input,
1372 .vidioc_s_std = soc_camera_s_std, 1386 .vidioc_s_std = soc_camera_s_std,
1387 .vidioc_g_std = soc_camera_g_std,
1373 .vidioc_enum_framesizes = soc_camera_enum_fsizes, 1388 .vidioc_enum_framesizes = soc_camera_enum_fsizes,
1374 .vidioc_reqbufs = soc_camera_reqbufs, 1389 .vidioc_reqbufs = soc_camera_reqbufs,
1375 .vidioc_try_fmt_vid_cap = soc_camera_try_fmt_vid_cap,
1376 .vidioc_querybuf = soc_camera_querybuf, 1390 .vidioc_querybuf = soc_camera_querybuf,
1377 .vidioc_qbuf = soc_camera_qbuf, 1391 .vidioc_qbuf = soc_camera_qbuf,
1378 .vidioc_dqbuf = soc_camera_dqbuf, 1392 .vidioc_dqbuf = soc_camera_dqbuf,
1393 .vidioc_create_bufs = soc_camera_create_bufs,
1394 .vidioc_prepare_buf = soc_camera_prepare_buf,
1379 .vidioc_streamon = soc_camera_streamon, 1395 .vidioc_streamon = soc_camera_streamon,
1380 .vidioc_streamoff = soc_camera_streamoff, 1396 .vidioc_streamoff = soc_camera_streamoff,
1381 .vidioc_queryctrl = soc_camera_queryctrl,
1382 .vidioc_g_ctrl = soc_camera_g_ctrl,
1383 .vidioc_s_ctrl = soc_camera_s_ctrl,
1384 .vidioc_cropcap = soc_camera_cropcap, 1397 .vidioc_cropcap = soc_camera_cropcap,
1385 .vidioc_g_crop = soc_camera_g_crop, 1398 .vidioc_g_crop = soc_camera_g_crop,
1386 .vidioc_s_crop = soc_camera_s_crop, 1399 .vidioc_s_crop = soc_camera_s_crop,
@@ -1409,6 +1422,7 @@ static int video_dev_create(struct soc_camera_device *icd)
1409 vdev->ioctl_ops = &soc_camera_ioctl_ops; 1422 vdev->ioctl_ops = &soc_camera_ioctl_ops;
1410 vdev->release = video_device_release; 1423 vdev->release = video_device_release;
1411 vdev->tvnorms = V4L2_STD_UNKNOWN; 1424 vdev->tvnorms = V4L2_STD_UNKNOWN;
1425 vdev->ctrl_handler = &icd->ctrl_handler;
1412 vdev->lock = &icd->video_lock; 1426 vdev->lock = &icd->video_lock;
1413 1427
1414 icd->vdev = vdev; 1428 icd->vdev = vdev;
@@ -1427,11 +1441,6 @@ static int soc_camera_video_start(struct soc_camera_device *icd)
1427 if (!icd->parent) 1441 if (!icd->parent)
1428 return -ENODEV; 1442 return -ENODEV;
1429 1443
1430 if (!icd->ops ||
1431 !icd->ops->query_bus_param ||
1432 !icd->ops->set_bus_param)
1433 return -EINVAL;
1434
1435 ret = video_register_device(icd->vdev, VFL_TYPE_GRABBER, -1); 1444 ret = video_register_device(icd->vdev, VFL_TYPE_GRABBER, -1);
1436 if (ret < 0) { 1445 if (ret < 0) {
1437 dev_err(icd->pdev, "video_register_device failed: %d\n", ret); 1446 dev_err(icd->pdev, "video_register_device failed: %d\n", ret);
diff --git a/drivers/media/video/soc_camera_platform.c b/drivers/media/video/soc_camera_platform.c
index 8069cd6bc5e8..4402a8a74f7a 100644
--- a/drivers/media/video/soc_camera_platform.c
+++ b/drivers/media/video/soc_camera_platform.c
@@ -30,32 +30,12 @@ static struct soc_camera_platform_priv *get_priv(struct platform_device *pdev)
30 return container_of(subdev, struct soc_camera_platform_priv, subdev); 30 return container_of(subdev, struct soc_camera_platform_priv, subdev);
31} 31}
32 32
33static struct soc_camera_platform_info *get_info(struct soc_camera_device *icd)
34{
35 struct platform_device *pdev =
36 to_platform_device(to_soc_camera_control(icd));
37 return pdev->dev.platform_data;
38}
39
40static int soc_camera_platform_s_stream(struct v4l2_subdev *sd, int enable) 33static int soc_camera_platform_s_stream(struct v4l2_subdev *sd, int enable)
41{ 34{
42 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd); 35 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
43 return p->set_capture(p, enable); 36 return p->set_capture(p, enable);
44} 37}
45 38
46static int soc_camera_platform_set_bus_param(struct soc_camera_device *icd,
47 unsigned long flags)
48{
49 return 0;
50}
51
52static unsigned long
53soc_camera_platform_query_bus_param(struct soc_camera_device *icd)
54{
55 struct soc_camera_platform_info *p = get_info(icd);
56 return p->bus_param;
57}
58
59static int soc_camera_platform_fill_fmt(struct v4l2_subdev *sd, 39static int soc_camera_platform_fill_fmt(struct v4l2_subdev *sd,
60 struct v4l2_mbus_framefmt *mf) 40 struct v4l2_mbus_framefmt *mf)
61{ 41{
@@ -115,6 +95,17 @@ static int soc_camera_platform_cropcap(struct v4l2_subdev *sd,
115 return 0; 95 return 0;
116} 96}
117 97
98static int soc_camera_platform_g_mbus_config(struct v4l2_subdev *sd,
99 struct v4l2_mbus_config *cfg)
100{
101 struct soc_camera_platform_info *p = v4l2_get_subdevdata(sd);
102
103 cfg->flags = p->mbus_param;
104 cfg->type = p->mbus_type;
105
106 return 0;
107}
108
118static struct v4l2_subdev_video_ops platform_subdev_video_ops = { 109static struct v4l2_subdev_video_ops platform_subdev_video_ops = {
119 .s_stream = soc_camera_platform_s_stream, 110 .s_stream = soc_camera_platform_s_stream,
120 .enum_mbus_fmt = soc_camera_platform_enum_fmt, 111 .enum_mbus_fmt = soc_camera_platform_enum_fmt,
@@ -123,6 +114,7 @@ static struct v4l2_subdev_video_ops platform_subdev_video_ops = {
123 .try_mbus_fmt = soc_camera_platform_fill_fmt, 114 .try_mbus_fmt = soc_camera_platform_fill_fmt,
124 .g_mbus_fmt = soc_camera_platform_fill_fmt, 115 .g_mbus_fmt = soc_camera_platform_fill_fmt,
125 .s_mbus_fmt = soc_camera_platform_fill_fmt, 116 .s_mbus_fmt = soc_camera_platform_fill_fmt,
117 .g_mbus_config = soc_camera_platform_g_mbus_config,
126}; 118};
127 119
128static struct v4l2_subdev_ops platform_subdev_ops = { 120static struct v4l2_subdev_ops platform_subdev_ops = {
@@ -130,11 +122,6 @@ static struct v4l2_subdev_ops platform_subdev_ops = {
130 .video = &platform_subdev_video_ops, 122 .video = &platform_subdev_video_ops,
131}; 123};
132 124
133static struct soc_camera_ops soc_camera_platform_ops = {
134 .set_bus_param = soc_camera_platform_set_bus_param,
135 .query_bus_param = soc_camera_platform_query_bus_param,
136};
137
138static int soc_camera_platform_probe(struct platform_device *pdev) 125static int soc_camera_platform_probe(struct platform_device *pdev)
139{ 126{
140 struct soc_camera_host *ici; 127 struct soc_camera_host *ici;
@@ -163,8 +150,6 @@ static int soc_camera_platform_probe(struct platform_device *pdev)
163 /* Set the control device reference */ 150 /* Set the control device reference */
164 icd->control = &pdev->dev; 151 icd->control = &pdev->dev;
165 152
166 icd->ops = &soc_camera_platform_ops;
167
168 ici = to_soc_camera_host(icd->parent); 153 ici = to_soc_camera_host(icd->parent);
169 154
170 v4l2_subdev_init(&priv->subdev, &platform_subdev_ops); 155 v4l2_subdev_init(&priv->subdev, &platform_subdev_ops);
@@ -178,7 +163,6 @@ static int soc_camera_platform_probe(struct platform_device *pdev)
178 return ret; 163 return ret;
179 164
180evdrs: 165evdrs:
181 icd->ops = NULL;
182 platform_set_drvdata(pdev, NULL); 166 platform_set_drvdata(pdev, NULL);
183 kfree(priv); 167 kfree(priv);
184 return ret; 168 return ret;
@@ -187,11 +171,10 @@ evdrs:
187static int soc_camera_platform_remove(struct platform_device *pdev) 171static int soc_camera_platform_remove(struct platform_device *pdev)
188{ 172{
189 struct soc_camera_platform_priv *priv = get_priv(pdev); 173 struct soc_camera_platform_priv *priv = get_priv(pdev);
190 struct soc_camera_platform_info *p = pdev->dev.platform_data; 174 struct soc_camera_platform_info *p = v4l2_get_subdevdata(&priv->subdev);
191 struct soc_camera_device *icd = p->icd;
192 175
176 p->icd->control = NULL;
193 v4l2_device_unregister_subdev(&priv->subdev); 177 v4l2_device_unregister_subdev(&priv->subdev);
194 icd->ops = NULL;
195 platform_set_drvdata(pdev, NULL); 178 platform_set_drvdata(pdev, NULL);
196 kfree(priv); 179 kfree(priv);
197 return 0; 180 return 0;
diff --git a/drivers/media/video/soc_mediabus.c b/drivers/media/video/soc_mediabus.c
index bea7c9cf4f88..cf7f2194ded4 100644
--- a/drivers/media/video/soc_mediabus.c
+++ b/drivers/media/video/soc_mediabus.c
@@ -383,6 +383,39 @@ const struct soc_mbus_pixelfmt *soc_mbus_get_fmtdesc(
383} 383}
384EXPORT_SYMBOL(soc_mbus_get_fmtdesc); 384EXPORT_SYMBOL(soc_mbus_get_fmtdesc);
385 385
386unsigned int soc_mbus_config_compatible(const struct v4l2_mbus_config *cfg,
387 unsigned int flags)
388{
389 unsigned long common_flags;
390 bool hsync = true, vsync = true, pclk, data, mode;
391 bool mipi_lanes, mipi_clock;
392
393 common_flags = cfg->flags & flags;
394
395 switch (cfg->type) {
396 case V4L2_MBUS_PARALLEL:
397 hsync = common_flags & (V4L2_MBUS_HSYNC_ACTIVE_HIGH |
398 V4L2_MBUS_HSYNC_ACTIVE_LOW);
399 vsync = common_flags & (V4L2_MBUS_VSYNC_ACTIVE_HIGH |
400 V4L2_MBUS_VSYNC_ACTIVE_LOW);
401 case V4L2_MBUS_BT656:
402 pclk = common_flags & (V4L2_MBUS_PCLK_SAMPLE_RISING |
403 V4L2_MBUS_PCLK_SAMPLE_FALLING);
404 data = common_flags & (V4L2_MBUS_DATA_ACTIVE_HIGH |
405 V4L2_MBUS_DATA_ACTIVE_LOW);
406 mode = common_flags & (V4L2_MBUS_MASTER | V4L2_MBUS_SLAVE);
407 return (!hsync || !vsync || !pclk || !data || !mode) ?
408 0 : common_flags;
409 case V4L2_MBUS_CSI2:
410 mipi_lanes = common_flags & V4L2_MBUS_CSI2_LANES;
411 mipi_clock = common_flags & (V4L2_MBUS_CSI2_NONCONTINUOUS_CLOCK |
412 V4L2_MBUS_CSI2_CONTINUOUS_CLOCK);
413 return (!mipi_lanes || !mipi_clock) ? 0 : common_flags;
414 }
415 return 0;
416}
417EXPORT_SYMBOL(soc_mbus_config_compatible);
418
386static int __init soc_mbus_init(void) 419static int __init soc_mbus_init(void)
387{ 420{
388 return 0; 421 return 0;
diff --git a/drivers/media/video/sr030pc30.c b/drivers/media/video/sr030pc30.c
index 10aff3f943a8..d1b07aceaf94 100644
--- a/drivers/media/video/sr030pc30.c
+++ b/drivers/media/video/sr030pc30.c
@@ -19,6 +19,7 @@
19#include <linux/i2c.h> 19#include <linux/i2c.h>
20#include <linux/delay.h> 20#include <linux/delay.h>
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/module.h>
22#include <media/v4l2-device.h> 23#include <media/v4l2-device.h>
23#include <media/v4l2-subdev.h> 24#include <media/v4l2-subdev.h>
24#include <media/v4l2-mediabus.h> 25#include <media/v4l2-mediabus.h>
diff --git a/drivers/media/video/tcm825x.c b/drivers/media/video/tcm825x.c
index b6ee1bd342dc..462caa44ae00 100644
--- a/drivers/media/video/tcm825x.c
+++ b/drivers/media/video/tcm825x.c
@@ -27,6 +27,7 @@
27 */ 27 */
28 28
29#include <linux/i2c.h> 29#include <linux/i2c.h>
30#include <linux/module.h>
30#include <media/v4l2-int-device.h> 31#include <media/v4l2-int-device.h>
31 32
32#include "tcm825x.h" 33#include "tcm825x.h"
diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
index 84cd1b65b765..a0895bf07487 100644
--- a/drivers/media/video/timblogiw.c
+++ b/drivers/media/video/timblogiw.c
@@ -27,6 +27,7 @@
27#include <linux/interrupt.h> 27#include <linux/interrupt.h>
28#include <linux/list.h> 28#include <linux/list.h>
29#include <linux/i2c.h> 29#include <linux/i2c.h>
30#include <linux/module.h>
30#include <media/v4l2-ioctl.h> 31#include <media/v4l2-ioctl.h>
31#include <media/v4l2-device.h> 32#include <media/v4l2-device.h>
32#include <media/videobuf-dma-contig.h> 33#include <media/videobuf-dma-contig.h>
diff --git a/drivers/media/video/tvp514x.c b/drivers/media/video/tvp514x.c
index 9b3e828b0775..926f03931156 100644
--- a/drivers/media/video/tvp514x.c
+++ b/drivers/media/video/tvp514x.c
@@ -32,6 +32,7 @@
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/delay.h> 33#include <linux/delay.h>
34#include <linux/videodev2.h> 34#include <linux/videodev2.h>
35#include <linux/module.h>
35 36
36#include <media/v4l2-device.h> 37#include <media/v4l2-device.h>
37#include <media/v4l2-common.h> 38#include <media/v4l2-common.h>
diff --git a/drivers/media/video/tvp5150.c b/drivers/media/video/tvp5150.c
index e927d25e0d35..6abaa16ae136 100644
--- a/drivers/media/video/tvp5150.c
+++ b/drivers/media/video/tvp5150.c
@@ -9,6 +9,7 @@
9#include <linux/slab.h> 9#include <linux/slab.h>
10#include <linux/videodev2.h> 10#include <linux/videodev2.h>
11#include <linux/delay.h> 11#include <linux/delay.h>
12#include <linux/module.h>
12#include <media/v4l2-device.h> 13#include <media/v4l2-device.h>
13#include <media/tvp5150.h> 14#include <media/tvp5150.h>
14#include <media/v4l2-chip-ident.h> 15#include <media/v4l2-chip-ident.h>
diff --git a/drivers/media/video/tvp7002.c b/drivers/media/video/tvp7002.c
index 2e6059a52e9f..7875e80cb2ff 100644
--- a/drivers/media/video/tvp7002.c
+++ b/drivers/media/video/tvp7002.c
@@ -28,6 +28,7 @@
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/videodev2.h> 30#include <linux/videodev2.h>
31#include <linux/module.h>
31#include <media/tvp7002.h> 32#include <media/tvp7002.h>
32#include <media/v4l2-device.h> 33#include <media/v4l2-device.h>
33#include <media/v4l2-chip-ident.h> 34#include <media/v4l2-chip-ident.h>
diff --git a/drivers/media/video/tw9910.c b/drivers/media/video/tw9910.c
index 742482e30011..a514fa61116c 100644
--- a/drivers/media/video/tw9910.c
+++ b/drivers/media/video/tw9910.c
@@ -22,11 +22,13 @@
22#include <linux/slab.h> 22#include <linux/slab.h>
23#include <linux/kernel.h> 23#include <linux/kernel.h>
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <linux/v4l2-mediabus.h>
25#include <linux/videodev2.h> 26#include <linux/videodev2.h>
26#include <media/v4l2-chip-ident.h> 27
27#include <media/v4l2-subdev.h>
28#include <media/soc_camera.h> 28#include <media/soc_camera.h>
29#include <media/tw9910.h> 29#include <media/tw9910.h>
30#include <media/v4l2-chip-ident.h>
31#include <media/v4l2-subdev.h>
30 32
31#define GET_ID(val) ((val & 0xF8) >> 3) 33#define GET_ID(val) ((val & 0xF8) >> 3)
32#define GET_REV(val) (val & 0x07) 34#define GET_REV(val) (val & 0x07)
@@ -203,6 +205,10 @@
203#define RTSEL_FIELD 0x06 /* 0110 = FIELD */ 205#define RTSEL_FIELD 0x06 /* 0110 = FIELD */
204#define RTSEL_RTCO 0x07 /* 0111 = RTCO ( Real Time Control ) */ 206#define RTSEL_RTCO 0x07 /* 0111 = RTCO ( Real Time Control ) */
205 207
208/* HSYNC start and end are constant for now */
209#define HSYNC_START 0x0260
210#define HSYNC_END 0x0300
211
206/* 212/*
207 * structure 213 * structure
208 */ 214 */
@@ -220,22 +226,11 @@ struct tw9910_scale_ctrl {
220 u16 vscale; 226 u16 vscale;
221}; 227};
222 228
223struct tw9910_cropping_ctrl {
224 u16 vdelay;
225 u16 vactive;
226 u16 hdelay;
227 u16 hactive;
228};
229
230struct tw9910_hsync_ctrl {
231 u16 start;
232 u16 end;
233};
234
235struct tw9910_priv { 229struct tw9910_priv {
236 struct v4l2_subdev subdev; 230 struct v4l2_subdev subdev;
237 struct tw9910_video_info *info; 231 struct tw9910_video_info *info;
238 const struct tw9910_scale_ctrl *scale; 232 const struct tw9910_scale_ctrl *scale;
233 v4l2_std_id norm;
239 u32 revision; 234 u32 revision;
240}; 235};
241 236
@@ -329,11 +324,6 @@ static const struct tw9910_scale_ctrl tw9910_pal_scales[] = {
329 }, 324 },
330}; 325};
331 326
332static const struct tw9910_hsync_ctrl tw9910_hsync_ctrl = {
333 .start = 0x0260,
334 .end = 0x0300,
335};
336
337/* 327/*
338 * general function 328 * general function
339 */ 329 */
@@ -378,21 +368,20 @@ static int tw9910_set_scale(struct i2c_client *client,
378 return ret; 368 return ret;
379} 369}
380 370
381static int tw9910_set_hsync(struct i2c_client *client, 371static int tw9910_set_hsync(struct i2c_client *client)
382 const struct tw9910_hsync_ctrl *hsync)
383{ 372{
384 struct tw9910_priv *priv = to_tw9910(client); 373 struct tw9910_priv *priv = to_tw9910(client);
385 int ret; 374 int ret;
386 375
387 /* bit 10 - 3 */ 376 /* bit 10 - 3 */
388 ret = i2c_smbus_write_byte_data(client, HSBEGIN, 377 ret = i2c_smbus_write_byte_data(client, HSBEGIN,
389 (hsync->start & 0x07F8) >> 3); 378 (HSYNC_START & 0x07F8) >> 3);
390 if (ret < 0) 379 if (ret < 0)
391 return ret; 380 return ret;
392 381
393 /* bit 10 - 3 */ 382 /* bit 10 - 3 */
394 ret = i2c_smbus_write_byte_data(client, HSEND, 383 ret = i2c_smbus_write_byte_data(client, HSEND,
395 (hsync->end & 0x07F8) >> 3); 384 (HSYNC_END & 0x07F8) >> 3);
396 if (ret < 0) 385 if (ret < 0)
397 return ret; 386 return ret;
398 387
@@ -400,8 +389,8 @@ static int tw9910_set_hsync(struct i2c_client *client,
400 /* bit 2 - 0 */ 389 /* bit 2 - 0 */
401 if (1 == priv->revision) 390 if (1 == priv->revision)
402 ret = tw9910_mask_set(client, HSLOWCTL, 0x77, 391 ret = tw9910_mask_set(client, HSLOWCTL, 0x77,
403 (hsync->start & 0x0007) << 4 | 392 (HSYNC_START & 0x0007) << 4 |
404 (hsync->end & 0x0007)); 393 (HSYNC_END & 0x0007));
405 394
406 return ret; 395 return ret;
407} 396}
@@ -433,12 +422,11 @@ static int tw9910_power(struct i2c_client *client, int enable)
433 return tw9910_mask_set(client, ACNTL2, ACNTL2_PDN_MASK, acntl2); 422 return tw9910_mask_set(client, ACNTL2, ACNTL2_PDN_MASK, acntl2);
434} 423}
435 424
436static const struct tw9910_scale_ctrl* 425static const struct tw9910_scale_ctrl *tw9910_select_norm(v4l2_std_id norm,
437tw9910_select_norm(struct soc_camera_device *icd, u32 width, u32 height) 426 u32 width, u32 height)
438{ 427{
439 const struct tw9910_scale_ctrl *scale; 428 const struct tw9910_scale_ctrl *scale;
440 const struct tw9910_scale_ctrl *ret = NULL; 429 const struct tw9910_scale_ctrl *ret = NULL;
441 v4l2_std_id norm = icd->vdev->current_norm;
442 __u32 diff = 0xffffffff, tmp; 430 __u32 diff = 0xffffffff, tmp;
443 int size, i; 431 int size, i;
444 432
@@ -465,7 +453,7 @@ tw9910_select_norm(struct soc_camera_device *icd, u32 width, u32 height)
465} 453}
466 454
467/* 455/*
468 * soc_camera_ops function 456 * subdevice operations
469 */ 457 */
470static int tw9910_s_stream(struct v4l2_subdev *sd, int enable) 458static int tw9910_s_stream(struct v4l2_subdev *sd, int enable)
471{ 459{
@@ -507,49 +495,27 @@ static int tw9910_s_stream(struct v4l2_subdev *sd, int enable)
507 return tw9910_power(client, enable); 495 return tw9910_power(client, enable);
508} 496}
509 497
510static int tw9910_set_bus_param(struct soc_camera_device *icd, 498static int tw9910_g_std(struct v4l2_subdev *sd, v4l2_std_id *norm)
511 unsigned long flags)
512{ 499{
513 struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
514 struct i2c_client *client = v4l2_get_subdevdata(sd); 500 struct i2c_client *client = v4l2_get_subdevdata(sd);
515 u8 val = VSSL_VVALID | HSSL_DVALID; 501 struct tw9910_priv *priv = to_tw9910(client);
516 502
517 /* 503 *norm = priv->norm;
518 * set OUTCTR1
519 *
520 * We use VVALID and DVALID signals to control VSYNC and HSYNC
521 * outputs, in this mode their polarity is inverted.
522 */
523 if (flags & SOCAM_HSYNC_ACTIVE_LOW)
524 val |= HSP_HI;
525 504
526 if (flags & SOCAM_VSYNC_ACTIVE_LOW) 505 return 0;
527 val |= VSP_HI;
528
529 return i2c_smbus_write_byte_data(client, OUTCTR1, val);
530} 506}
531 507
532static unsigned long tw9910_query_bus_param(struct soc_camera_device *icd) 508static int tw9910_s_std(struct v4l2_subdev *sd, v4l2_std_id norm)
533{ 509{
534 struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); 510 struct i2c_client *client = v4l2_get_subdevdata(sd);
535 struct tw9910_priv *priv = to_tw9910(client); 511 struct tw9910_priv *priv = to_tw9910(client);
536 struct soc_camera_link *icl = to_soc_camera_link(icd);
537 unsigned long flags = SOCAM_PCLK_SAMPLE_RISING | SOCAM_MASTER |
538 SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_HIGH |
539 SOCAM_VSYNC_ACTIVE_LOW | SOCAM_HSYNC_ACTIVE_LOW |
540 SOCAM_DATA_ACTIVE_HIGH | priv->info->buswidth;
541 512
542 return soc_camera_apply_sensor_flags(icl, flags); 513 if (!(norm & (V4L2_STD_NTSC | V4L2_STD_PAL)))
543} 514 return -EINVAL;
544
545static int tw9910_s_std(struct v4l2_subdev *sd, v4l2_std_id norm)
546{
547 int ret = -EINVAL;
548 515
549 if (norm & (V4L2_STD_NTSC | V4L2_STD_PAL)) 516 priv->norm = norm;
550 ret = 0;
551 517
552 return ret; 518 return 0;
553} 519}
554 520
555static int tw9910_g_chip_ident(struct v4l2_subdev *sd, 521static int tw9910_g_chip_ident(struct v4l2_subdev *sd,
@@ -600,19 +566,17 @@ static int tw9910_s_register(struct v4l2_subdev *sd,
600} 566}
601#endif 567#endif
602 568
603static int tw9910_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a) 569static int tw9910_set_frame(struct v4l2_subdev *sd, u32 *width, u32 *height)
604{ 570{
605 struct v4l2_rect *rect = &a->c;
606 struct i2c_client *client = v4l2_get_subdevdata(sd); 571 struct i2c_client *client = v4l2_get_subdevdata(sd);
607 struct tw9910_priv *priv = to_tw9910(client); 572 struct tw9910_priv *priv = to_tw9910(client);
608 struct soc_camera_device *icd = client->dev.platform_data; 573 int ret = -EINVAL;
609 int ret = -EINVAL; 574 u8 val;
610 u8 val;
611 575
612 /* 576 /*
613 * select suitable norm 577 * select suitable norm
614 */ 578 */
615 priv->scale = tw9910_select_norm(icd, rect->width, rect->height); 579 priv->scale = tw9910_select_norm(priv->norm, *width, *height);
616 if (!priv->scale) 580 if (!priv->scale)
617 goto tw9910_set_fmt_error; 581 goto tw9910_set_fmt_error;
618 582
@@ -670,14 +634,12 @@ static int tw9910_s_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
670 /* 634 /*
671 * set hsync 635 * set hsync
672 */ 636 */
673 ret = tw9910_set_hsync(client, &tw9910_hsync_ctrl); 637 ret = tw9910_set_hsync(client);
674 if (ret < 0) 638 if (ret < 0)
675 goto tw9910_set_fmt_error; 639 goto tw9910_set_fmt_error;
676 640
677 rect->width = priv->scale->width; 641 *width = priv->scale->width;
678 rect->height = priv->scale->height; 642 *height = priv->scale->height;
679 rect->left = 0;
680 rect->top = 0;
681 643
682 return ret; 644 return ret;
683 645
@@ -694,25 +656,15 @@ static int tw9910_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
694 struct i2c_client *client = v4l2_get_subdevdata(sd); 656 struct i2c_client *client = v4l2_get_subdevdata(sd);
695 struct tw9910_priv *priv = to_tw9910(client); 657 struct tw9910_priv *priv = to_tw9910(client);
696 658
697 if (!priv->scale) {
698 int ret;
699 struct v4l2_crop crop = {
700 .c = {
701 .left = 0,
702 .top = 0,
703 .width = 640,
704 .height = 480,
705 },
706 };
707 ret = tw9910_s_crop(sd, &crop);
708 if (ret < 0)
709 return ret;
710 }
711
712 a->c.left = 0; 659 a->c.left = 0;
713 a->c.top = 0; 660 a->c.top = 0;
714 a->c.width = priv->scale->width; 661 if (priv->norm & V4L2_STD_NTSC) {
715 a->c.height = priv->scale->height; 662 a->c.width = 640;
663 a->c.height = 480;
664 } else {
665 a->c.width = 768;
666 a->c.height = 576;
667 }
716 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 668 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
717 669
718 return 0; 670 return 0;
@@ -720,14 +672,19 @@ static int tw9910_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
720 672
721static int tw9910_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a) 673static int tw9910_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a)
722{ 674{
675 struct i2c_client *client = v4l2_get_subdevdata(sd);
676 struct tw9910_priv *priv = to_tw9910(client);
677
723 a->bounds.left = 0; 678 a->bounds.left = 0;
724 a->bounds.top = 0; 679 a->bounds.top = 0;
725 a->bounds.width = 768; 680 if (priv->norm & V4L2_STD_NTSC) {
726 a->bounds.height = 576; 681 a->bounds.width = 640;
727 a->defrect.left = 0; 682 a->bounds.height = 480;
728 a->defrect.top = 0; 683 } else {
729 a->defrect.width = 640; 684 a->bounds.width = 768;
730 a->defrect.height = 480; 685 a->bounds.height = 576;
686 }
687 a->defrect = a->bounds;
731 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 688 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
732 a->pixelaspect.numerator = 1; 689 a->pixelaspect.numerator = 1;
733 a->pixelaspect.denominator = 1; 690 a->pixelaspect.denominator = 1;
@@ -743,15 +700,8 @@ static int tw9910_g_fmt(struct v4l2_subdev *sd,
743 700
744 if (!priv->scale) { 701 if (!priv->scale) {
745 int ret; 702 int ret;
746 struct v4l2_crop crop = { 703 u32 width = 640, height = 480;
747 .c = { 704 ret = tw9910_set_frame(sd, &width, &height);
748 .left = 0,
749 .top = 0,
750 .width = 640,
751 .height = 480,
752 },
753 };
754 ret = tw9910_s_crop(sd, &crop);
755 if (ret < 0) 705 if (ret < 0)
756 return ret; 706 return ret;
757 } 707 }
@@ -768,17 +718,7 @@ static int tw9910_g_fmt(struct v4l2_subdev *sd,
768static int tw9910_s_fmt(struct v4l2_subdev *sd, 718static int tw9910_s_fmt(struct v4l2_subdev *sd,
769 struct v4l2_mbus_framefmt *mf) 719 struct v4l2_mbus_framefmt *mf)
770{ 720{
771 struct i2c_client *client = v4l2_get_subdevdata(sd); 721 u32 width = mf->width, height = mf->height;
772 struct tw9910_priv *priv = to_tw9910(client);
773 /* See tw9910_s_crop() - no proper cropping support */
774 struct v4l2_crop a = {
775 .c = {
776 .left = 0,
777 .top = 0,
778 .width = mf->width,
779 .height = mf->height,
780 },
781 };
782 int ret; 722 int ret;
783 723
784 WARN_ON(mf->field != V4L2_FIELD_ANY && 724 WARN_ON(mf->field != V4L2_FIELD_ANY &&
@@ -792,10 +732,10 @@ static int tw9910_s_fmt(struct v4l2_subdev *sd,
792 732
793 mf->colorspace = V4L2_COLORSPACE_JPEG; 733 mf->colorspace = V4L2_COLORSPACE_JPEG;
794 734
795 ret = tw9910_s_crop(sd, &a); 735 ret = tw9910_set_frame(sd, &width, &height);
796 if (!ret) { 736 if (!ret) {
797 mf->width = priv->scale->width; 737 mf->width = width;
798 mf->height = priv->scale->height; 738 mf->height = height;
799 } 739 }
800 return ret; 740 return ret;
801} 741}
@@ -804,7 +744,7 @@ static int tw9910_try_fmt(struct v4l2_subdev *sd,
804 struct v4l2_mbus_framefmt *mf) 744 struct v4l2_mbus_framefmt *mf)
805{ 745{
806 struct i2c_client *client = v4l2_get_subdevdata(sd); 746 struct i2c_client *client = v4l2_get_subdevdata(sd);
807 struct soc_camera_device *icd = client->dev.platform_data; 747 struct tw9910_priv *priv = to_tw9910(client);
808 const struct tw9910_scale_ctrl *scale; 748 const struct tw9910_scale_ctrl *scale;
809 749
810 if (V4L2_FIELD_ANY == mf->field) { 750 if (V4L2_FIELD_ANY == mf->field) {
@@ -820,7 +760,7 @@ static int tw9910_try_fmt(struct v4l2_subdev *sd,
820 /* 760 /*
821 * select suitable norm 761 * select suitable norm
822 */ 762 */
823 scale = tw9910_select_norm(icd, mf->width, mf->height); 763 scale = tw9910_select_norm(priv->norm, mf->width, mf->height);
824 if (!scale) 764 if (!scale)
825 return -EINVAL; 765 return -EINVAL;
826 766
@@ -830,16 +770,11 @@ static int tw9910_try_fmt(struct v4l2_subdev *sd,
830 return 0; 770 return 0;
831} 771}
832 772
833static int tw9910_video_probe(struct soc_camera_device *icd, 773static int tw9910_video_probe(struct i2c_client *client)
834 struct i2c_client *client)
835{ 774{
836 struct tw9910_priv *priv = to_tw9910(client); 775 struct tw9910_priv *priv = to_tw9910(client);
837 s32 id; 776 s32 id;
838 777
839 /* We must have a parent by now. And it cannot be a wrong one. */
840 BUG_ON(!icd->parent ||
841 to_soc_camera_host(icd->parent)->nr != icd->iface);
842
843 /* 778 /*
844 * tw9910 only use 8 or 16 bit bus width 779 * tw9910 only use 8 or 16 bit bus width
845 */ 780 */
@@ -868,20 +803,15 @@ static int tw9910_video_probe(struct soc_camera_device *icd,
868 dev_info(&client->dev, 803 dev_info(&client->dev,
869 "tw9910 Product ID %0x:%0x\n", id, priv->revision); 804 "tw9910 Product ID %0x:%0x\n", id, priv->revision);
870 805
871 icd->vdev->tvnorms = V4L2_STD_NTSC | V4L2_STD_PAL; 806 priv->norm = V4L2_STD_NTSC;
872 icd->vdev->current_norm = V4L2_STD_NTSC;
873 807
874 return 0; 808 return 0;
875} 809}
876 810
877static struct soc_camera_ops tw9910_ops = {
878 .set_bus_param = tw9910_set_bus_param,
879 .query_bus_param = tw9910_query_bus_param,
880};
881
882static struct v4l2_subdev_core_ops tw9910_subdev_core_ops = { 811static struct v4l2_subdev_core_ops tw9910_subdev_core_ops = {
883 .g_chip_ident = tw9910_g_chip_ident, 812 .g_chip_ident = tw9910_g_chip_ident,
884 .s_std = tw9910_s_std, 813 .s_std = tw9910_s_std,
814 .g_std = tw9910_g_std,
885#ifdef CONFIG_VIDEO_ADV_DEBUG 815#ifdef CONFIG_VIDEO_ADV_DEBUG
886 .g_register = tw9910_g_register, 816 .g_register = tw9910_g_register,
887 .s_register = tw9910_s_register, 817 .s_register = tw9910_s_register,
@@ -898,6 +828,45 @@ static int tw9910_enum_fmt(struct v4l2_subdev *sd, unsigned int index,
898 return 0; 828 return 0;
899} 829}
900 830
831static int tw9910_g_mbus_config(struct v4l2_subdev *sd,
832 struct v4l2_mbus_config *cfg)
833{
834 struct i2c_client *client = v4l2_get_subdevdata(sd);
835 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
836
837 cfg->flags = V4L2_MBUS_PCLK_SAMPLE_RISING | V4L2_MBUS_MASTER |
838 V4L2_MBUS_VSYNC_ACTIVE_HIGH | V4L2_MBUS_VSYNC_ACTIVE_LOW |
839 V4L2_MBUS_HSYNC_ACTIVE_HIGH | V4L2_MBUS_HSYNC_ACTIVE_LOW |
840 V4L2_MBUS_DATA_ACTIVE_HIGH;
841 cfg->type = V4L2_MBUS_PARALLEL;
842 cfg->flags = soc_camera_apply_board_flags(icl, cfg);
843
844 return 0;
845}
846
847static int tw9910_s_mbus_config(struct v4l2_subdev *sd,
848 const struct v4l2_mbus_config *cfg)
849{
850 struct i2c_client *client = v4l2_get_subdevdata(sd);
851 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
852 u8 val = VSSL_VVALID | HSSL_DVALID;
853 unsigned long flags = soc_camera_apply_board_flags(icl, cfg);
854
855 /*
856 * set OUTCTR1
857 *
858 * We use VVALID and DVALID signals to control VSYNC and HSYNC
859 * outputs, in this mode their polarity is inverted.
860 */
861 if (flags & V4L2_MBUS_HSYNC_ACTIVE_LOW)
862 val |= HSP_HI;
863
864 if (flags & V4L2_MBUS_VSYNC_ACTIVE_LOW)
865 val |= VSP_HI;
866
867 return i2c_smbus_write_byte_data(client, OUTCTR1, val);
868}
869
901static struct v4l2_subdev_video_ops tw9910_subdev_video_ops = { 870static struct v4l2_subdev_video_ops tw9910_subdev_video_ops = {
902 .s_stream = tw9910_s_stream, 871 .s_stream = tw9910_s_stream,
903 .g_mbus_fmt = tw9910_g_fmt, 872 .g_mbus_fmt = tw9910_g_fmt,
@@ -905,8 +874,9 @@ static struct v4l2_subdev_video_ops tw9910_subdev_video_ops = {
905 .try_mbus_fmt = tw9910_try_fmt, 874 .try_mbus_fmt = tw9910_try_fmt,
906 .cropcap = tw9910_cropcap, 875 .cropcap = tw9910_cropcap,
907 .g_crop = tw9910_g_crop, 876 .g_crop = tw9910_g_crop,
908 .s_crop = tw9910_s_crop,
909 .enum_mbus_fmt = tw9910_enum_fmt, 877 .enum_mbus_fmt = tw9910_enum_fmt,
878 .g_mbus_config = tw9910_g_mbus_config,
879 .s_mbus_config = tw9910_s_mbus_config,
910}; 880};
911 881
912static struct v4l2_subdev_ops tw9910_subdev_ops = { 882static struct v4l2_subdev_ops tw9910_subdev_ops = {
@@ -922,23 +892,18 @@ static int tw9910_probe(struct i2c_client *client,
922 const struct i2c_device_id *did) 892 const struct i2c_device_id *did)
923 893
924{ 894{
925 struct tw9910_priv *priv; 895 struct tw9910_priv *priv;
926 struct tw9910_video_info *info; 896 struct tw9910_video_info *info;
927 struct soc_camera_device *icd = client->dev.platform_data; 897 struct i2c_adapter *adapter =
928 struct i2c_adapter *adapter =
929 to_i2c_adapter(client->dev.parent); 898 to_i2c_adapter(client->dev.parent);
930 struct soc_camera_link *icl; 899 struct soc_camera_link *icl = soc_camera_i2c_to_link(client);
931 int ret; 900 int ret;
932 901
933 if (!icd) { 902 if (!icl || !icl->priv) {
934 dev_err(&client->dev, "TW9910: missing soc-camera data!\n"); 903 dev_err(&client->dev, "TW9910: missing platform data!\n");
935 return -EINVAL; 904 return -EINVAL;
936 } 905 }
937 906
938 icl = to_soc_camera_link(icd);
939 if (!icl || !icl->priv)
940 return -EINVAL;
941
942 info = icl->priv; 907 info = icl->priv;
943 908
944 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 909 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
@@ -956,14 +921,9 @@ static int tw9910_probe(struct i2c_client *client,
956 921
957 v4l2_i2c_subdev_init(&priv->subdev, client, &tw9910_subdev_ops); 922 v4l2_i2c_subdev_init(&priv->subdev, client, &tw9910_subdev_ops);
958 923
959 icd->ops = &tw9910_ops; 924 ret = tw9910_video_probe(client);
960 icd->iface = icl->bus_id; 925 if (ret)
961
962 ret = tw9910_video_probe(icd, client);
963 if (ret) {
964 icd->ops = NULL;
965 kfree(priv); 926 kfree(priv);
966 }
967 927
968 return ret; 928 return ret;
969} 929}
@@ -971,9 +931,7 @@ static int tw9910_probe(struct i2c_client *client,
971static int tw9910_remove(struct i2c_client *client) 931static int tw9910_remove(struct i2c_client *client)
972{ 932{
973 struct tw9910_priv *priv = to_tw9910(client); 933 struct tw9910_priv *priv = to_tw9910(client);
974 struct soc_camera_device *icd = client->dev.platform_data;
975 934
976 icd->ops = NULL;
977 kfree(priv); 935 kfree(priv);
978 return 0; 936 return 0;
979} 937}
diff --git a/drivers/media/video/usbvision/usbvision-cards.c b/drivers/media/video/usbvision/usbvision-cards.c
index 8f5266157f15..3103d0d020e8 100644
--- a/drivers/media/video/usbvision/usbvision-cards.c
+++ b/drivers/media/video/usbvision/usbvision-cards.c
@@ -24,6 +24,7 @@
24 24
25 25
26#include <linux/list.h> 26#include <linux/list.h>
27#include <linux/module.h>
27#include <media/v4l2-dev.h> 28#include <media/v4l2-dev.h>
28#include <media/tuner.h> 29#include <media/tuner.h>
29#include "usbvision.h" 30#include "usbvision.h"
diff --git a/drivers/media/video/v4l2-compat-ioctl32.c b/drivers/media/video/v4l2-compat-ioctl32.c
index 61979b70f388..c68531b88279 100644
--- a/drivers/media/video/v4l2-compat-ioctl32.c
+++ b/drivers/media/video/v4l2-compat-ioctl32.c
@@ -159,11 +159,25 @@ struct v4l2_format32 {
159 } fmt; 159 } fmt;
160}; 160};
161 161
162static int get_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up) 162/**
163 * struct v4l2_create_buffers32 - VIDIOC_CREATE_BUFS32 argument
164 * @index: on return, index of the first created buffer
165 * @count: entry: number of requested buffers,
166 * return: number of created buffers
167 * @memory: buffer memory type
168 * @format: frame format, for which buffers are requested
169 * @reserved: future extensions
170 */
171struct v4l2_create_buffers32 {
172 __u32 index;
173 __u32 count;
174 enum v4l2_memory memory;
175 struct v4l2_format32 format;
176 __u32 reserved[8];
177};
178
179static int __get_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up)
163{ 180{
164 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_format32)) ||
165 get_user(kp->type, &up->type))
166 return -EFAULT;
167 switch (kp->type) { 181 switch (kp->type) {
168 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 182 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
169 case V4L2_BUF_TYPE_VIDEO_OUTPUT: 183 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
@@ -192,11 +206,24 @@ static int get_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user
192 } 206 }
193} 207}
194 208
195static int put_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up) 209static int get_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up)
210{
211 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_format32)) ||
212 get_user(kp->type, &up->type))
213 return -EFAULT;
214 return __get_v4l2_format32(kp, up);
215}
216
217static int get_v4l2_create32(struct v4l2_create_buffers *kp, struct v4l2_create_buffers32 __user *up)
218{
219 if (!access_ok(VERIFY_READ, up, sizeof(struct v4l2_create_buffers32)) ||
220 copy_from_user(kp, up, offsetof(struct v4l2_create_buffers32, format.fmt)))
221 return -EFAULT;
222 return __get_v4l2_format32(&kp->format, &up->format);
223}
224
225static int __put_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up)
196{ 226{
197 if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_format32)) ||
198 put_user(kp->type, &up->type))
199 return -EFAULT;
200 switch (kp->type) { 227 switch (kp->type) {
201 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 228 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
202 case V4L2_BUF_TYPE_VIDEO_OUTPUT: 229 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
@@ -225,6 +252,22 @@ static int put_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user
225 } 252 }
226} 253}
227 254
255static int put_v4l2_format32(struct v4l2_format *kp, struct v4l2_format32 __user *up)
256{
257 if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_format32)) ||
258 put_user(kp->type, &up->type))
259 return -EFAULT;
260 return __put_v4l2_format32(kp, up);
261}
262
263static int put_v4l2_create32(struct v4l2_create_buffers *kp, struct v4l2_create_buffers32 __user *up)
264{
265 if (!access_ok(VERIFY_WRITE, up, sizeof(struct v4l2_create_buffers32)) ||
266 copy_to_user(up, kp, offsetof(struct v4l2_create_buffers32, format.fmt)))
267 return -EFAULT;
268 return __put_v4l2_format32(&kp->format, &up->format);
269}
270
228struct v4l2_standard32 { 271struct v4l2_standard32 {
229 __u32 index; 272 __u32 index;
230 __u32 id[2]; /* __u64 would get the alignment wrong */ 273 __u32 id[2]; /* __u64 would get the alignment wrong */
@@ -702,6 +745,8 @@ static int put_v4l2_event32(struct v4l2_event *kp, struct v4l2_event32 __user *u
702#define VIDIOC_S_EXT_CTRLS32 _IOWR('V', 72, struct v4l2_ext_controls32) 745#define VIDIOC_S_EXT_CTRLS32 _IOWR('V', 72, struct v4l2_ext_controls32)
703#define VIDIOC_TRY_EXT_CTRLS32 _IOWR('V', 73, struct v4l2_ext_controls32) 746#define VIDIOC_TRY_EXT_CTRLS32 _IOWR('V', 73, struct v4l2_ext_controls32)
704#define VIDIOC_DQEVENT32 _IOR ('V', 89, struct v4l2_event32) 747#define VIDIOC_DQEVENT32 _IOR ('V', 89, struct v4l2_event32)
748#define VIDIOC_CREATE_BUFS32 _IOWR('V', 92, struct v4l2_create_buffers32)
749#define VIDIOC_PREPARE_BUF32 _IOWR('V', 93, struct v4l2_buffer32)
705 750
706#define VIDIOC_OVERLAY32 _IOW ('V', 14, s32) 751#define VIDIOC_OVERLAY32 _IOW ('V', 14, s32)
707#define VIDIOC_STREAMON32 _IOW ('V', 18, s32) 752#define VIDIOC_STREAMON32 _IOW ('V', 18, s32)
@@ -721,6 +766,7 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar
721 struct v4l2_standard v2s; 766 struct v4l2_standard v2s;
722 struct v4l2_ext_controls v2ecs; 767 struct v4l2_ext_controls v2ecs;
723 struct v4l2_event v2ev; 768 struct v4l2_event v2ev;
769 struct v4l2_create_buffers v2crt;
724 unsigned long vx; 770 unsigned long vx;
725 int vi; 771 int vi;
726 } karg; 772 } karg;
@@ -751,6 +797,8 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar
751 case VIDIOC_S_INPUT32: cmd = VIDIOC_S_INPUT; break; 797 case VIDIOC_S_INPUT32: cmd = VIDIOC_S_INPUT; break;
752 case VIDIOC_G_OUTPUT32: cmd = VIDIOC_G_OUTPUT; break; 798 case VIDIOC_G_OUTPUT32: cmd = VIDIOC_G_OUTPUT; break;
753 case VIDIOC_S_OUTPUT32: cmd = VIDIOC_S_OUTPUT; break; 799 case VIDIOC_S_OUTPUT32: cmd = VIDIOC_S_OUTPUT; break;
800 case VIDIOC_CREATE_BUFS32: cmd = VIDIOC_CREATE_BUFS; break;
801 case VIDIOC_PREPARE_BUF32: cmd = VIDIOC_PREPARE_BUF; break;
754 } 802 }
755 803
756 switch (cmd) { 804 switch (cmd) {
@@ -775,6 +823,12 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar
775 compatible_arg = 0; 823 compatible_arg = 0;
776 break; 824 break;
777 825
826 case VIDIOC_CREATE_BUFS:
827 err = get_v4l2_create32(&karg.v2crt, up);
828 compatible_arg = 0;
829 break;
830
831 case VIDIOC_PREPARE_BUF:
778 case VIDIOC_QUERYBUF: 832 case VIDIOC_QUERYBUF:
779 case VIDIOC_QBUF: 833 case VIDIOC_QBUF:
780 case VIDIOC_DQBUF: 834 case VIDIOC_DQBUF:
@@ -860,6 +914,10 @@ static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long ar
860 err = put_v4l2_format32(&karg.v2f, up); 914 err = put_v4l2_format32(&karg.v2f, up);
861 break; 915 break;
862 916
917 case VIDIOC_CREATE_BUFS:
918 err = put_v4l2_create32(&karg.v2crt, up);
919 break;
920
863 case VIDIOC_QUERYBUF: 921 case VIDIOC_QUERYBUF:
864 case VIDIOC_QBUF: 922 case VIDIOC_QBUF:
865 case VIDIOC_DQBUF: 923 case VIDIOC_DQBUF:
@@ -959,6 +1017,8 @@ long v4l2_compat_ioctl32(struct file *file, unsigned int cmd, unsigned long arg)
959 case VIDIOC_DQEVENT32: 1017 case VIDIOC_DQEVENT32:
960 case VIDIOC_SUBSCRIBE_EVENT: 1018 case VIDIOC_SUBSCRIBE_EVENT:
961 case VIDIOC_UNSUBSCRIBE_EVENT: 1019 case VIDIOC_UNSUBSCRIBE_EVENT:
1020 case VIDIOC_CREATE_BUFS32:
1021 case VIDIOC_PREPARE_BUF32:
962 ret = do_video_ioctl(file, cmd, arg); 1022 ret = do_video_ioctl(file, cmd, arg);
963 break; 1023 break;
964 1024
diff --git a/drivers/media/video/v4l2-ctrls.c b/drivers/media/video/v4l2-ctrls.c
index fc8666ae408f..f17f92b86a30 100644
--- a/drivers/media/video/v4l2-ctrls.c
+++ b/drivers/media/video/v4l2-ctrls.c
@@ -20,6 +20,7 @@
20 20
21#include <linux/ctype.h> 21#include <linux/ctype.h>
22#include <linux/slab.h> 22#include <linux/slab.h>
23#include <linux/export.h>
23#include <media/v4l2-ioctl.h> 24#include <media/v4l2-ioctl.h>
24#include <media/v4l2-device.h> 25#include <media/v4l2-device.h>
25#include <media/v4l2-ctrls.h> 26#include <media/v4l2-ctrls.h>
@@ -210,6 +211,7 @@ const char * const *v4l2_ctrl_get_menu(u32 id)
210 "Disabled", 211 "Disabled",
211 "50 Hz", 212 "50 Hz",
212 "60 Hz", 213 "60 Hz",
214 "Auto",
213 NULL 215 NULL
214 }; 216 };
215 static const char * const camera_exposure_auto[] = { 217 static const char * const camera_exposure_auto[] = {
diff --git a/drivers/media/video/v4l2-device.c b/drivers/media/video/v4l2-device.c
index e6a2c3b302d4..0edd618b9ddf 100644
--- a/drivers/media/video/v4l2-device.c
+++ b/drivers/media/video/v4l2-device.c
@@ -20,7 +20,9 @@
20 20
21#include <linux/types.h> 21#include <linux/types.h>
22#include <linux/ioctl.h> 22#include <linux/ioctl.h>
23#include <linux/module.h>
23#include <linux/i2c.h> 24#include <linux/i2c.h>
25#include <linux/slab.h>
24#if defined(CONFIG_SPI) 26#if defined(CONFIG_SPI)
25#include <linux/spi/spi.h> 27#include <linux/spi/spi.h>
26#endif 28#endif
@@ -193,6 +195,13 @@ int v4l2_device_register_subdev(struct v4l2_device *v4l2_dev,
193} 195}
194EXPORT_SYMBOL_GPL(v4l2_device_register_subdev); 196EXPORT_SYMBOL_GPL(v4l2_device_register_subdev);
195 197
198static void v4l2_device_release_subdev_node(struct video_device *vdev)
199{
200 struct v4l2_subdev *sd = video_get_drvdata(vdev);
201 sd->devnode = NULL;
202 kfree(vdev);
203}
204
196int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev) 205int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
197{ 206{
198 struct video_device *vdev; 207 struct video_device *vdev;
@@ -206,22 +215,40 @@ int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
206 if (!(sd->flags & V4L2_SUBDEV_FL_HAS_DEVNODE)) 215 if (!(sd->flags & V4L2_SUBDEV_FL_HAS_DEVNODE))
207 continue; 216 continue;
208 217
209 vdev = &sd->devnode; 218 vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
219 if (!vdev) {
220 err = -ENOMEM;
221 goto clean_up;
222 }
223
224 video_set_drvdata(vdev, sd);
210 strlcpy(vdev->name, sd->name, sizeof(vdev->name)); 225 strlcpy(vdev->name, sd->name, sizeof(vdev->name));
211 vdev->v4l2_dev = v4l2_dev; 226 vdev->v4l2_dev = v4l2_dev;
212 vdev->fops = &v4l2_subdev_fops; 227 vdev->fops = &v4l2_subdev_fops;
213 vdev->release = video_device_release_empty; 228 vdev->release = v4l2_device_release_subdev_node;
214 vdev->ctrl_handler = sd->ctrl_handler; 229 vdev->ctrl_handler = sd->ctrl_handler;
215 err = __video_register_device(vdev, VFL_TYPE_SUBDEV, -1, 1, 230 err = __video_register_device(vdev, VFL_TYPE_SUBDEV, -1, 1,
216 sd->owner); 231 sd->owner);
217 if (err < 0) 232 if (err < 0) {
218 return err; 233 kfree(vdev);
234 goto clean_up;
235 }
219#if defined(CONFIG_MEDIA_CONTROLLER) 236#if defined(CONFIG_MEDIA_CONTROLLER)
220 sd->entity.v4l.major = VIDEO_MAJOR; 237 sd->entity.v4l.major = VIDEO_MAJOR;
221 sd->entity.v4l.minor = vdev->minor; 238 sd->entity.v4l.minor = vdev->minor;
222#endif 239#endif
240 sd->devnode = vdev;
223 } 241 }
224 return 0; 242 return 0;
243
244clean_up:
245 list_for_each_entry(sd, &v4l2_dev->subdevs, list) {
246 if (!sd->devnode)
247 break;
248 video_unregister_device(sd->devnode);
249 }
250
251 return err;
225} 252}
226EXPORT_SYMBOL_GPL(v4l2_device_register_subdev_nodes); 253EXPORT_SYMBOL_GPL(v4l2_device_register_subdev_nodes);
227 254
@@ -247,7 +274,7 @@ void v4l2_device_unregister_subdev(struct v4l2_subdev *sd)
247 if (v4l2_dev->mdev) 274 if (v4l2_dev->mdev)
248 media_device_unregister_entity(&sd->entity); 275 media_device_unregister_entity(&sd->entity);
249#endif 276#endif
250 video_unregister_device(&sd->devnode); 277 video_unregister_device(sd->devnode);
251 module_put(sd->owner); 278 module_put(sd->owner);
252} 279}
253EXPORT_SYMBOL_GPL(v4l2_device_unregister_subdev); 280EXPORT_SYMBOL_GPL(v4l2_device_unregister_subdev);
diff --git a/drivers/media/video/v4l2-event.c b/drivers/media/video/v4l2-event.c
index 53b190cf225e..46037f225529 100644
--- a/drivers/media/video/v4l2-event.c
+++ b/drivers/media/video/v4l2-event.c
@@ -29,6 +29,7 @@
29 29
30#include <linux/sched.h> 30#include <linux/sched.h>
31#include <linux/slab.h> 31#include <linux/slab.h>
32#include <linux/export.h>
32 33
33static unsigned sev_pos(const struct v4l2_subscribed_event *sev, unsigned idx) 34static unsigned sev_pos(const struct v4l2_subscribed_event *sev, unsigned idx)
34{ 35{
diff --git a/drivers/media/video/v4l2-fh.c b/drivers/media/video/v4l2-fh.c
index 122822d2b8b2..9e3fc040ea20 100644
--- a/drivers/media/video/v4l2-fh.c
+++ b/drivers/media/video/v4l2-fh.c
@@ -24,6 +24,7 @@
24 24
25#include <linux/bitops.h> 25#include <linux/bitops.h>
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/export.h>
27#include <media/v4l2-dev.h> 28#include <media/v4l2-dev.h>
28#include <media/v4l2-fh.h> 29#include <media/v4l2-fh.h>
29#include <media/v4l2-event.h> 30#include <media/v4l2-event.h>
diff --git a/drivers/media/video/v4l2-int-device.c b/drivers/media/video/v4l2-int-device.c
index a935bae538ef..f4473494af7a 100644
--- a/drivers/media/video/v4l2-int-device.c
+++ b/drivers/media/video/v4l2-int-device.c
@@ -26,6 +26,7 @@
26#include <linux/list.h> 26#include <linux/list.h>
27#include <linux/sort.h> 27#include <linux/sort.h>
28#include <linux/string.h> 28#include <linux/string.h>
29#include <linux/module.h>
29 30
30#include <media/v4l2-int-device.h> 31#include <media/v4l2-int-device.h>
31 32
diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index 24fd43322150..e1da8fc9dd2f 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -273,6 +273,8 @@ static const char *v4l2_ioctls[] = {
273 [_IOC_NR(VIDIOC_DQEVENT)] = "VIDIOC_DQEVENT", 273 [_IOC_NR(VIDIOC_DQEVENT)] = "VIDIOC_DQEVENT",
274 [_IOC_NR(VIDIOC_SUBSCRIBE_EVENT)] = "VIDIOC_SUBSCRIBE_EVENT", 274 [_IOC_NR(VIDIOC_SUBSCRIBE_EVENT)] = "VIDIOC_SUBSCRIBE_EVENT",
275 [_IOC_NR(VIDIOC_UNSUBSCRIBE_EVENT)] = "VIDIOC_UNSUBSCRIBE_EVENT", 275 [_IOC_NR(VIDIOC_UNSUBSCRIBE_EVENT)] = "VIDIOC_UNSUBSCRIBE_EVENT",
276 [_IOC_NR(VIDIOC_CREATE_BUFS)] = "VIDIOC_CREATE_BUFS",
277 [_IOC_NR(VIDIOC_PREPARE_BUF)] = "VIDIOC_PREPARE_BUF",
276}; 278};
277#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls) 279#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
278 280
@@ -2104,6 +2106,40 @@ static long __video_do_ioctl(struct file *file,
2104 dbgarg(cmd, "type=0x%8.8x", sub->type); 2106 dbgarg(cmd, "type=0x%8.8x", sub->type);
2105 break; 2107 break;
2106 } 2108 }
2109 case VIDIOC_CREATE_BUFS:
2110 {
2111 struct v4l2_create_buffers *create = arg;
2112
2113 if (!ops->vidioc_create_bufs)
2114 break;
2115 if (ret_prio) {
2116 ret = ret_prio;
2117 break;
2118 }
2119 ret = check_fmt(ops, create->format.type);
2120 if (ret)
2121 break;
2122
2123 ret = ops->vidioc_create_bufs(file, fh, create);
2124
2125 dbgarg(cmd, "count=%d @ %d\n", create->count, create->index);
2126 break;
2127 }
2128 case VIDIOC_PREPARE_BUF:
2129 {
2130 struct v4l2_buffer *b = arg;
2131
2132 if (!ops->vidioc_prepare_buf)
2133 break;
2134 ret = check_fmt(ops, b->type);
2135 if (ret)
2136 break;
2137
2138 ret = ops->vidioc_prepare_buf(file, fh, b);
2139
2140 dbgarg(cmd, "index=%d", b->index);
2141 break;
2142 }
2107 default: 2143 default:
2108 if (!ops->vidioc_default) 2144 if (!ops->vidioc_default)
2109 break; 2145 break;
diff --git a/drivers/media/video/v4l2-subdev.c b/drivers/media/video/v4l2-subdev.c
index 179e20e23fc4..65ade5f03c2e 100644
--- a/drivers/media/video/v4l2-subdev.c
+++ b/drivers/media/video/v4l2-subdev.c
@@ -24,6 +24,7 @@
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/types.h> 25#include <linux/types.h>
26#include <linux/videodev2.h> 26#include <linux/videodev2.h>
27#include <linux/export.h>
27 28
28#include <media/v4l2-ctrls.h> 29#include <media/v4l2-ctrls.h>
29#include <media/v4l2-device.h> 30#include <media/v4l2-device.h>
diff --git a/drivers/media/video/videobuf2-core.c b/drivers/media/video/videobuf2-core.c
index 3f5c7a38e6e8..979e544388cb 100644
--- a/drivers/media/video/videobuf2-core.c
+++ b/drivers/media/video/videobuf2-core.c
@@ -38,7 +38,8 @@ module_param(debug, int, 0644);
38 (((q)->ops->op) ? ((q)->ops->op(args)) : 0) 38 (((q)->ops->op) ? ((q)->ops->op(args)) : 0)
39 39
40#define V4L2_BUFFER_STATE_FLAGS (V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_QUEUED | \ 40#define V4L2_BUFFER_STATE_FLAGS (V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_QUEUED | \
41 V4L2_BUF_FLAG_DONE | V4L2_BUF_FLAG_ERROR) 41 V4L2_BUF_FLAG_DONE | V4L2_BUF_FLAG_ERROR | \
42 V4L2_BUF_FLAG_PREPARED)
42 43
43/** 44/**
44 * __vb2_buf_mem_alloc() - allocate video memory for the given buffer 45 * __vb2_buf_mem_alloc() - allocate video memory for the given buffer
@@ -109,13 +110,22 @@ static void __vb2_buf_userptr_put(struct vb2_buffer *vb)
109 * __setup_offsets() - setup unique offsets ("cookies") for every plane in 110 * __setup_offsets() - setup unique offsets ("cookies") for every plane in
110 * every buffer on the queue 111 * every buffer on the queue
111 */ 112 */
112static void __setup_offsets(struct vb2_queue *q) 113static void __setup_offsets(struct vb2_queue *q, unsigned int n)
113{ 114{
114 unsigned int buffer, plane; 115 unsigned int buffer, plane;
115 struct vb2_buffer *vb; 116 struct vb2_buffer *vb;
116 unsigned long off = 0; 117 unsigned long off;
117 118
118 for (buffer = 0; buffer < q->num_buffers; ++buffer) { 119 if (q->num_buffers) {
120 struct v4l2_plane *p;
121 vb = q->bufs[q->num_buffers - 1];
122 p = &vb->v4l2_planes[vb->num_planes - 1];
123 off = PAGE_ALIGN(p->m.mem_offset + p->length);
124 } else {
125 off = 0;
126 }
127
128 for (buffer = q->num_buffers; buffer < q->num_buffers + n; ++buffer) {
119 vb = q->bufs[buffer]; 129 vb = q->bufs[buffer];
120 if (!vb) 130 if (!vb)
121 continue; 131 continue;
@@ -161,7 +171,7 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory,
161 vb->state = VB2_BUF_STATE_DEQUEUED; 171 vb->state = VB2_BUF_STATE_DEQUEUED;
162 vb->vb2_queue = q; 172 vb->vb2_queue = q;
163 vb->num_planes = num_planes; 173 vb->num_planes = num_planes;
164 vb->v4l2_buf.index = buffer; 174 vb->v4l2_buf.index = q->num_buffers + buffer;
165 vb->v4l2_buf.type = q->type; 175 vb->v4l2_buf.type = q->type;
166 vb->v4l2_buf.memory = memory; 176 vb->v4l2_buf.memory = memory;
167 177
@@ -189,15 +199,13 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory,
189 } 199 }
190 } 200 }
191 201
192 q->bufs[buffer] = vb; 202 q->bufs[q->num_buffers + buffer] = vb;
193 } 203 }
194 204
195 q->num_buffers = buffer; 205 __setup_offsets(q, buffer);
196
197 __setup_offsets(q);
198 206
199 dprintk(1, "Allocated %d buffers, %d plane(s) each\n", 207 dprintk(1, "Allocated %d buffers, %d plane(s) each\n",
200 q->num_buffers, num_planes); 208 buffer, num_planes);
201 209
202 return buffer; 210 return buffer;
203} 211}
@@ -205,12 +213,13 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory,
205/** 213/**
206 * __vb2_free_mem() - release all video buffer memory for a given queue 214 * __vb2_free_mem() - release all video buffer memory for a given queue
207 */ 215 */
208static void __vb2_free_mem(struct vb2_queue *q) 216static void __vb2_free_mem(struct vb2_queue *q, unsigned int buffers)
209{ 217{
210 unsigned int buffer; 218 unsigned int buffer;
211 struct vb2_buffer *vb; 219 struct vb2_buffer *vb;
212 220
213 for (buffer = 0; buffer < q->num_buffers; ++buffer) { 221 for (buffer = q->num_buffers - buffers; buffer < q->num_buffers;
222 ++buffer) {
214 vb = q->bufs[buffer]; 223 vb = q->bufs[buffer];
215 if (!vb) 224 if (!vb)
216 continue; 225 continue;
@@ -224,17 +233,18 @@ static void __vb2_free_mem(struct vb2_queue *q)
224} 233}
225 234
226/** 235/**
227 * __vb2_queue_free() - free the queue - video memory and related information 236 * __vb2_queue_free() - free buffers at the end of the queue - video memory and
228 * and return the queue to an uninitialized state. Might be called even if the 237 * related information, if no buffers are left return the queue to an
229 * queue has already been freed. 238 * uninitialized state. Might be called even if the queue has already been freed.
230 */ 239 */
231static void __vb2_queue_free(struct vb2_queue *q) 240static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers)
232{ 241{
233 unsigned int buffer; 242 unsigned int buffer;
234 243
235 /* Call driver-provided cleanup function for each buffer, if provided */ 244 /* Call driver-provided cleanup function for each buffer, if provided */
236 if (q->ops->buf_cleanup) { 245 if (q->ops->buf_cleanup) {
237 for (buffer = 0; buffer < q->num_buffers; ++buffer) { 246 for (buffer = q->num_buffers - buffers; buffer < q->num_buffers;
247 ++buffer) {
238 if (NULL == q->bufs[buffer]) 248 if (NULL == q->bufs[buffer])
239 continue; 249 continue;
240 q->ops->buf_cleanup(q->bufs[buffer]); 250 q->ops->buf_cleanup(q->bufs[buffer]);
@@ -242,23 +252,25 @@ static void __vb2_queue_free(struct vb2_queue *q)
242 } 252 }
243 253
244 /* Release video buffer memory */ 254 /* Release video buffer memory */
245 __vb2_free_mem(q); 255 __vb2_free_mem(q, buffers);
246 256
247 /* Free videobuf buffers */ 257 /* Free videobuf buffers */
248 for (buffer = 0; buffer < q->num_buffers; ++buffer) { 258 for (buffer = q->num_buffers - buffers; buffer < q->num_buffers;
259 ++buffer) {
249 kfree(q->bufs[buffer]); 260 kfree(q->bufs[buffer]);
250 q->bufs[buffer] = NULL; 261 q->bufs[buffer] = NULL;
251 } 262 }
252 263
253 q->num_buffers = 0; 264 q->num_buffers -= buffers;
254 q->memory = 0; 265 if (!q->num_buffers)
266 q->memory = 0;
255} 267}
256 268
257/** 269/**
258 * __verify_planes_array() - verify that the planes array passed in struct 270 * __verify_planes_array() - verify that the planes array passed in struct
259 * v4l2_buffer from userspace can be safely used 271 * v4l2_buffer from userspace can be safely used
260 */ 272 */
261static int __verify_planes_array(struct vb2_buffer *vb, struct v4l2_buffer *b) 273static int __verify_planes_array(struct vb2_buffer *vb, const struct v4l2_buffer *b)
262{ 274{
263 /* Is memory for copying plane information present? */ 275 /* Is memory for copying plane information present? */
264 if (NULL == b->m.planes) { 276 if (NULL == b->m.planes) {
@@ -318,7 +330,7 @@ static bool __buffers_in_use(struct vb2_queue *q)
318static int __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b) 330static int __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b)
319{ 331{
320 struct vb2_queue *q = vb->vb2_queue; 332 struct vb2_queue *q = vb->vb2_queue;
321 int ret = 0; 333 int ret;
322 334
323 /* Copy back data such as timestamp, flags, input, etc. */ 335 /* Copy back data such as timestamp, flags, input, etc. */
324 memcpy(b, &vb->v4l2_buf, offsetof(struct v4l2_buffer, m)); 336 memcpy(b, &vb->v4l2_buf, offsetof(struct v4l2_buffer, m));
@@ -365,6 +377,9 @@ static int __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b)
365 case VB2_BUF_STATE_DONE: 377 case VB2_BUF_STATE_DONE:
366 b->flags |= V4L2_BUF_FLAG_DONE; 378 b->flags |= V4L2_BUF_FLAG_DONE;
367 break; 379 break;
380 case VB2_BUF_STATE_PREPARED:
381 b->flags |= V4L2_BUF_FLAG_PREPARED;
382 break;
368 case VB2_BUF_STATE_DEQUEUED: 383 case VB2_BUF_STATE_DEQUEUED:
369 /* nothing */ 384 /* nothing */
370 break; 385 break;
@@ -373,7 +388,7 @@ static int __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b)
373 if (__buffer_in_use(q, vb)) 388 if (__buffer_in_use(q, vb))
374 b->flags |= V4L2_BUF_FLAG_MAPPED; 389 b->flags |= V4L2_BUF_FLAG_MAPPED;
375 390
376 return ret; 391 return 0;
377} 392}
378 393
379/** 394/**
@@ -459,7 +474,7 @@ static int __verify_mmap_ops(struct vb2_queue *q)
459 */ 474 */
460int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req) 475int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
461{ 476{
462 unsigned int num_buffers, num_planes; 477 unsigned int num_buffers, allocated_buffers, num_planes = 0;
463 int ret = 0; 478 int ret = 0;
464 479
465 if (q->fileio) { 480 if (q->fileio) {
@@ -507,7 +522,7 @@ int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
507 return -EBUSY; 522 return -EBUSY;
508 } 523 }
509 524
510 __vb2_queue_free(q); 525 __vb2_queue_free(q, q->num_buffers);
511 526
512 /* 527 /*
513 * In case of REQBUFS(0) return immediately without calling 528 * In case of REQBUFS(0) return immediately without calling
@@ -529,7 +544,7 @@ int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
529 * Ask the driver how many buffers and planes per buffer it requires. 544 * Ask the driver how many buffers and planes per buffer it requires.
530 * Driver also sets the size and allocator context for each plane. 545 * Driver also sets the size and allocator context for each plane.
531 */ 546 */
532 ret = call_qop(q, queue_setup, q, &num_buffers, &num_planes, 547 ret = call_qop(q, queue_setup, q, NULL, &num_buffers, &num_planes,
533 q->plane_sizes, q->alloc_ctx); 548 q->plane_sizes, q->alloc_ctx);
534 if (ret) 549 if (ret)
535 return ret; 550 return ret;
@@ -541,44 +556,168 @@ int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
541 return -ENOMEM; 556 return -ENOMEM;
542 } 557 }
543 558
559 allocated_buffers = ret;
560
544 /* 561 /*
545 * Check if driver can handle the allocated number of buffers. 562 * Check if driver can handle the allocated number of buffers.
546 */ 563 */
547 if (ret < num_buffers) { 564 if (allocated_buffers < num_buffers) {
548 unsigned int orig_num_buffers; 565 num_buffers = allocated_buffers;
549 566
550 orig_num_buffers = num_buffers = ret; 567 ret = call_qop(q, queue_setup, q, NULL, &num_buffers,
551 ret = call_qop(q, queue_setup, q, &num_buffers, &num_planes, 568 &num_planes, q->plane_sizes, q->alloc_ctx);
552 q->plane_sizes, q->alloc_ctx);
553 if (ret)
554 goto free_mem;
555 569
556 if (orig_num_buffers < num_buffers) { 570 if (!ret && allocated_buffers < num_buffers)
557 ret = -ENOMEM; 571 ret = -ENOMEM;
558 goto free_mem;
559 }
560 572
561 /* 573 /*
562 * Ok, driver accepted smaller number of buffers. 574 * Either the driver has accepted a smaller number of buffers,
575 * or .queue_setup() returned an error
563 */ 576 */
564 ret = num_buffers; 577 }
578
579 q->num_buffers = allocated_buffers;
580
581 if (ret < 0) {
582 __vb2_queue_free(q, allocated_buffers);
583 return ret;
565 } 584 }
566 585
567 /* 586 /*
568 * Return the number of successfully allocated buffers 587 * Return the number of successfully allocated buffers
569 * to the userspace. 588 * to the userspace.
570 */ 589 */
571 req->count = ret; 590 req->count = allocated_buffers;
572 591
573 return 0; 592 return 0;
574
575free_mem:
576 __vb2_queue_free(q);
577 return ret;
578} 593}
579EXPORT_SYMBOL_GPL(vb2_reqbufs); 594EXPORT_SYMBOL_GPL(vb2_reqbufs);
580 595
581/** 596/**
597 * vb2_create_bufs() - Allocate buffers and any required auxiliary structs
598 * @q: videobuf2 queue
599 * @create: creation parameters, passed from userspace to vidioc_create_bufs
600 * handler in driver
601 *
602 * Should be called from vidioc_create_bufs ioctl handler of a driver.
603 * This function:
604 * 1) verifies parameter sanity
605 * 2) calls the .queue_setup() queue operation
606 * 3) performs any necessary memory allocations
607 *
608 * The return values from this function are intended to be directly returned
609 * from vidioc_create_bufs handler in driver.
610 */
611int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create)
612{
613 unsigned int num_planes = 0, num_buffers, allocated_buffers;
614 int ret = 0;
615
616 if (q->fileio) {
617 dprintk(1, "%s(): file io in progress\n", __func__);
618 return -EBUSY;
619 }
620
621 if (create->memory != V4L2_MEMORY_MMAP
622 && create->memory != V4L2_MEMORY_USERPTR) {
623 dprintk(1, "%s(): unsupported memory type\n", __func__);
624 return -EINVAL;
625 }
626
627 if (create->format.type != q->type) {
628 dprintk(1, "%s(): requested type is incorrect\n", __func__);
629 return -EINVAL;
630 }
631
632 /*
633 * Make sure all the required memory ops for given memory type
634 * are available.
635 */
636 if (create->memory == V4L2_MEMORY_MMAP && __verify_mmap_ops(q)) {
637 dprintk(1, "%s(): MMAP for current setup unsupported\n", __func__);
638 return -EINVAL;
639 }
640
641 if (create->memory == V4L2_MEMORY_USERPTR && __verify_userptr_ops(q)) {
642 dprintk(1, "%s(): USERPTR for current setup unsupported\n", __func__);
643 return -EINVAL;
644 }
645
646 if (q->num_buffers == VIDEO_MAX_FRAME) {
647 dprintk(1, "%s(): maximum number of buffers already allocated\n",
648 __func__);
649 return -ENOBUFS;
650 }
651
652 create->index = q->num_buffers;
653
654 if (!q->num_buffers) {
655 memset(q->plane_sizes, 0, sizeof(q->plane_sizes));
656 memset(q->alloc_ctx, 0, sizeof(q->alloc_ctx));
657 q->memory = create->memory;
658 }
659
660 num_buffers = min(create->count, VIDEO_MAX_FRAME - q->num_buffers);
661
662 /*
663 * Ask the driver, whether the requested number of buffers, planes per
664 * buffer and their sizes are acceptable
665 */
666 ret = call_qop(q, queue_setup, q, &create->format, &num_buffers,
667 &num_planes, q->plane_sizes, q->alloc_ctx);
668 if (ret)
669 return ret;
670
671 /* Finally, allocate buffers and video memory */
672 ret = __vb2_queue_alloc(q, create->memory, num_buffers,
673 num_planes);
674 if (ret < 0) {
675 dprintk(1, "Memory allocation failed with error: %d\n", ret);
676 return ret;
677 }
678
679 allocated_buffers = ret;
680
681 /*
682 * Check if driver can handle the so far allocated number of buffers.
683 */
684 if (ret < num_buffers) {
685 num_buffers = ret;
686
687 /*
688 * q->num_buffers contains the total number of buffers, that the
689 * queue driver has set up
690 */
691 ret = call_qop(q, queue_setup, q, &create->format, &num_buffers,
692 &num_planes, q->plane_sizes, q->alloc_ctx);
693
694 if (!ret && allocated_buffers < num_buffers)
695 ret = -ENOMEM;
696
697 /*
698 * Either the driver has accepted a smaller number of buffers,
699 * or .queue_setup() returned an error
700 */
701 }
702
703 q->num_buffers += allocated_buffers;
704
705 if (ret < 0) {
706 __vb2_queue_free(q, allocated_buffers);
707 return ret;
708 }
709
710 /*
711 * Return the number of successfully allocated buffers
712 * to the userspace.
713 */
714 create->count = allocated_buffers;
715
716 return 0;
717}
718EXPORT_SYMBOL_GPL(vb2_create_bufs);
719
720/**
582 * vb2_plane_vaddr() - Return a kernel virtual address of a given plane 721 * vb2_plane_vaddr() - Return a kernel virtual address of a given plane
583 * @vb: vb2_buffer to which the plane in question belongs to 722 * @vb: vb2_buffer to which the plane in question belongs to
584 * @plane_no: plane number for which the address is to be returned 723 * @plane_no: plane number for which the address is to be returned
@@ -662,7 +801,7 @@ EXPORT_SYMBOL_GPL(vb2_buffer_done);
662 * __fill_vb2_buffer() - fill a vb2_buffer with information provided in 801 * __fill_vb2_buffer() - fill a vb2_buffer with information provided in
663 * a v4l2_buffer by the userspace 802 * a v4l2_buffer by the userspace
664 */ 803 */
665static int __fill_vb2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b, 804static int __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b,
666 struct v4l2_plane *v4l2_planes) 805 struct v4l2_plane *v4l2_planes)
667{ 806{
668 unsigned int plane; 807 unsigned int plane;
@@ -726,7 +865,7 @@ static int __fill_vb2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b,
726/** 865/**
727 * __qbuf_userptr() - handle qbuf of a USERPTR buffer 866 * __qbuf_userptr() - handle qbuf of a USERPTR buffer
728 */ 867 */
729static int __qbuf_userptr(struct vb2_buffer *vb, struct v4l2_buffer *b) 868static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b)
730{ 869{
731 struct v4l2_plane planes[VIDEO_MAX_PLANES]; 870 struct v4l2_plane planes[VIDEO_MAX_PLANES];
732 struct vb2_queue *q = vb->vb2_queue; 871 struct vb2_queue *q = vb->vb2_queue;
@@ -815,7 +954,7 @@ err:
815/** 954/**
816 * __qbuf_mmap() - handle qbuf of an MMAP buffer 955 * __qbuf_mmap() - handle qbuf of an MMAP buffer
817 */ 956 */
818static int __qbuf_mmap(struct vb2_buffer *vb, struct v4l2_buffer *b) 957static int __qbuf_mmap(struct vb2_buffer *vb, const struct v4l2_buffer *b)
819{ 958{
820 return __fill_vb2_buffer(vb, b, vb->v4l2_planes); 959 return __fill_vb2_buffer(vb, b, vb->v4l2_planes);
821} 960}
@@ -832,6 +971,95 @@ static void __enqueue_in_driver(struct vb2_buffer *vb)
832 q->ops->buf_queue(vb); 971 q->ops->buf_queue(vb);
833} 972}
834 973
974static int __buf_prepare(struct vb2_buffer *vb, const struct v4l2_buffer *b)
975{
976 struct vb2_queue *q = vb->vb2_queue;
977 int ret;
978
979 switch (q->memory) {
980 case V4L2_MEMORY_MMAP:
981 ret = __qbuf_mmap(vb, b);
982 break;
983 case V4L2_MEMORY_USERPTR:
984 ret = __qbuf_userptr(vb, b);
985 break;
986 default:
987 WARN(1, "Invalid queue type\n");
988 ret = -EINVAL;
989 }
990
991 if (!ret)
992 ret = call_qop(q, buf_prepare, vb);
993 if (ret)
994 dprintk(1, "qbuf: buffer preparation failed: %d\n", ret);
995 else
996 vb->state = VB2_BUF_STATE_PREPARED;
997
998 return ret;
999}
1000
1001/**
1002 * vb2_prepare_buf() - Pass ownership of a buffer from userspace to the kernel
1003 * @q: videobuf2 queue
1004 * @b: buffer structure passed from userspace to vidioc_prepare_buf
1005 * handler in driver
1006 *
1007 * Should be called from vidioc_prepare_buf ioctl handler of a driver.
1008 * This function:
1009 * 1) verifies the passed buffer,
1010 * 2) calls buf_prepare callback in the driver (if provided), in which
1011 * driver-specific buffer initialization can be performed,
1012 *
1013 * The return values from this function are intended to be directly returned
1014 * from vidioc_prepare_buf handler in driver.
1015 */
1016int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b)
1017{
1018 struct vb2_buffer *vb;
1019 int ret;
1020
1021 if (q->fileio) {
1022 dprintk(1, "%s(): file io in progress\n", __func__);
1023 return -EBUSY;
1024 }
1025
1026 if (b->type != q->type) {
1027 dprintk(1, "%s(): invalid buffer type\n", __func__);
1028 return -EINVAL;
1029 }
1030
1031 if (b->index >= q->num_buffers) {
1032 dprintk(1, "%s(): buffer index out of range\n", __func__);
1033 return -EINVAL;
1034 }
1035
1036 vb = q->bufs[b->index];
1037 if (NULL == vb) {
1038 /* Should never happen */
1039 dprintk(1, "%s(): buffer is NULL\n", __func__);
1040 return -EINVAL;
1041 }
1042
1043 if (b->memory != q->memory) {
1044 dprintk(1, "%s(): invalid memory type\n", __func__);
1045 return -EINVAL;
1046 }
1047
1048 if (vb->state != VB2_BUF_STATE_DEQUEUED) {
1049 dprintk(1, "%s(): invalid buffer state %d\n", __func__, vb->state);
1050 return -EINVAL;
1051 }
1052
1053 ret = __buf_prepare(vb, b);
1054 if (ret < 0)
1055 return ret;
1056
1057 __fill_v4l2_buffer(vb, b);
1058
1059 return 0;
1060}
1061EXPORT_SYMBOL_GPL(vb2_prepare_buf);
1062
835/** 1063/**
836 * vb2_qbuf() - Queue a buffer from userspace 1064 * vb2_qbuf() - Queue a buffer from userspace
837 * @q: videobuf2 queue 1065 * @q: videobuf2 queue
@@ -841,8 +1069,8 @@ static void __enqueue_in_driver(struct vb2_buffer *vb)
841 * Should be called from vidioc_qbuf ioctl handler of a driver. 1069 * Should be called from vidioc_qbuf ioctl handler of a driver.
842 * This function: 1070 * This function:
843 * 1) verifies the passed buffer, 1071 * 1) verifies the passed buffer,
844 * 2) calls buf_prepare callback in the driver (if provided), in which 1072 * 2) if necessary, calls buf_prepare callback in the driver (if provided), in
845 * driver-specific buffer initialization can be performed, 1073 * which driver-specific buffer initialization can be performed,
846 * 3) if streaming is on, queues the buffer in driver by the means of buf_queue 1074 * 3) if streaming is on, queues the buffer in driver by the means of buf_queue
847 * callback for processing. 1075 * callback for processing.
848 * 1076 *
@@ -852,7 +1080,7 @@ static void __enqueue_in_driver(struct vb2_buffer *vb)
852int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b) 1080int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
853{ 1081{
854 struct vb2_buffer *vb; 1082 struct vb2_buffer *vb;
855 int ret = 0; 1083 int ret;
856 1084
857 if (q->fileio) { 1085 if (q->fileio) {
858 dprintk(1, "qbuf: file io in progress\n"); 1086 dprintk(1, "qbuf: file io in progress\n");
@@ -881,29 +1109,18 @@ int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
881 return -EINVAL; 1109 return -EINVAL;
882 } 1110 }
883 1111
884 if (vb->state != VB2_BUF_STATE_DEQUEUED) { 1112 switch (vb->state) {
1113 case VB2_BUF_STATE_DEQUEUED:
1114 ret = __buf_prepare(vb, b);
1115 if (ret)
1116 return ret;
1117 case VB2_BUF_STATE_PREPARED:
1118 break;
1119 default:
885 dprintk(1, "qbuf: buffer already in use\n"); 1120 dprintk(1, "qbuf: buffer already in use\n");
886 return -EINVAL; 1121 return -EINVAL;
887 } 1122 }
888 1123
889 if (q->memory == V4L2_MEMORY_MMAP)
890 ret = __qbuf_mmap(vb, b);
891 else if (q->memory == V4L2_MEMORY_USERPTR)
892 ret = __qbuf_userptr(vb, b);
893 else {
894 WARN(1, "Invalid queue type\n");
895 return -EINVAL;
896 }
897
898 if (ret)
899 return ret;
900
901 ret = call_qop(q, buf_prepare, vb);
902 if (ret) {
903 dprintk(1, "qbuf: buffer preparation failed\n");
904 return ret;
905 }
906
907 /* 1124 /*
908 * Add to the queued buffers list, a buffer will stay on it until 1125 * Add to the queued buffers list, a buffer will stay on it until
909 * dequeued in dqbuf. 1126 * dequeued in dqbuf.
@@ -918,6 +1135,9 @@ int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b)
918 if (q->streaming) 1135 if (q->streaming)
919 __enqueue_in_driver(vb); 1136 __enqueue_in_driver(vb);
920 1137
1138 /* Fill buffer information for the userspace */
1139 __fill_v4l2_buffer(vb, b);
1140
921 dprintk(1, "qbuf of buffer %d succeeded\n", vb->v4l2_buf.index); 1141 dprintk(1, "qbuf of buffer %d succeeded\n", vb->v4l2_buf.index);
922 return 0; 1142 return 0;
923} 1143}
@@ -1347,6 +1567,37 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma)
1347} 1567}
1348EXPORT_SYMBOL_GPL(vb2_mmap); 1568EXPORT_SYMBOL_GPL(vb2_mmap);
1349 1569
1570#ifndef CONFIG_MMU
1571unsigned long vb2_get_unmapped_area(struct vb2_queue *q,
1572 unsigned long addr,
1573 unsigned long len,
1574 unsigned long pgoff,
1575 unsigned long flags)
1576{
1577 unsigned long off = pgoff << PAGE_SHIFT;
1578 struct vb2_buffer *vb;
1579 unsigned int buffer, plane;
1580 int ret;
1581
1582 if (q->memory != V4L2_MEMORY_MMAP) {
1583 dprintk(1, "Queue is not currently set up for mmap\n");
1584 return -EINVAL;
1585 }
1586
1587 /*
1588 * Find the plane corresponding to the offset passed by userspace.
1589 */
1590 ret = __find_plane_by_offset(q, off, &buffer, &plane);
1591 if (ret)
1592 return ret;
1593
1594 vb = q->bufs[buffer];
1595
1596 return (unsigned long)vb2_plane_vaddr(vb, plane);
1597}
1598EXPORT_SYMBOL_GPL(vb2_get_unmapped_area);
1599#endif
1600
1350static int __vb2_init_fileio(struct vb2_queue *q, int read); 1601static int __vb2_init_fileio(struct vb2_queue *q, int read);
1351static int __vb2_cleanup_fileio(struct vb2_queue *q); 1602static int __vb2_cleanup_fileio(struct vb2_queue *q);
1352 1603
@@ -1464,7 +1715,7 @@ void vb2_queue_release(struct vb2_queue *q)
1464{ 1715{
1465 __vb2_cleanup_fileio(q); 1716 __vb2_cleanup_fileio(q);
1466 __vb2_queue_cancel(q); 1717 __vb2_queue_cancel(q);
1467 __vb2_queue_free(q); 1718 __vb2_queue_free(q, q->num_buffers);
1468} 1719}
1469EXPORT_SYMBOL_GPL(vb2_queue_release); 1720EXPORT_SYMBOL_GPL(vb2_queue_release);
1470 1721
diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
index 7cf94c09d99a..7d754fbcccbf 100644
--- a/drivers/media/video/vivi.c
+++ b/drivers/media/video/vivi.c
@@ -650,9 +650,9 @@ static void vivi_stop_generating(struct vivi_dev *dev)
650/* ------------------------------------------------------------------ 650/* ------------------------------------------------------------------
651 Videobuf operations 651 Videobuf operations
652 ------------------------------------------------------------------*/ 652 ------------------------------------------------------------------*/
653static int queue_setup(struct vb2_queue *vq, unsigned int *nbuffers, 653static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
654 unsigned int *nplanes, unsigned int sizes[], 654 unsigned int *nbuffers, unsigned int *nplanes,
655 void *alloc_ctxs[]) 655 unsigned int sizes[], void *alloc_ctxs[])
656{ 656{
657 struct vivi_dev *dev = vb2_get_drv_priv(vq); 657 struct vivi_dev *dev = vb2_get_drv_priv(vq);
658 unsigned long size; 658 unsigned long size;
diff --git a/drivers/memstick/core/memstick.c b/drivers/memstick/core/memstick.c
index 8c1d85e27be4..56ff19cdc2ad 100644
--- a/drivers/memstick/core/memstick.c
+++ b/drivers/memstick/core/memstick.c
@@ -17,6 +17,7 @@
17#include <linux/fs.h> 17#include <linux/fs.h>
18#include <linux/delay.h> 18#include <linux/delay.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/module.h>
20 21
21#define DRIVER_NAME "memstick" 22#define DRIVER_NAME "memstick"
22 23
diff --git a/drivers/memstick/core/mspro_block.c b/drivers/memstick/core/mspro_block.c
index 4a1909a32b60..9729b92fbfdd 100644
--- a/drivers/memstick/core/mspro_block.c
+++ b/drivers/memstick/core/mspro_block.c
@@ -20,6 +20,7 @@
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/mutex.h> 21#include <linux/mutex.h>
22#include <linux/memstick.h> 22#include <linux/memstick.h>
23#include <linux/module.h>
23 24
24#define DRIVER_NAME "mspro_block" 25#define DRIVER_NAME "mspro_block"
25 26
diff --git a/drivers/memstick/host/jmb38x_ms.c b/drivers/memstick/host/jmb38x_ms.c
index d89d925caecf..6ce70e9615d3 100644
--- a/drivers/memstick/host/jmb38x_ms.c
+++ b/drivers/memstick/host/jmb38x_ms.c
@@ -17,6 +17,7 @@
17#include <linux/highmem.h> 17#include <linux/highmem.h>
18#include <linux/memstick.h> 18#include <linux/memstick.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/module.h>
20 21
21#define DRIVER_NAME "jmb38x_ms" 22#define DRIVER_NAME "jmb38x_ms"
22 23
diff --git a/drivers/memstick/host/tifm_ms.c b/drivers/memstick/host/tifm_ms.c
index 03f71a431c82..b7aacf47703a 100644
--- a/drivers/memstick/host/tifm_ms.c
+++ b/drivers/memstick/host/tifm_ms.c
@@ -17,6 +17,7 @@
17#include <linux/highmem.h> 17#include <linux/highmem.h>
18#include <linux/scatterlist.h> 18#include <linux/scatterlist.h>
19#include <linux/log2.h> 19#include <linux/log2.h>
20#include <linux/module.h>
20#include <asm/io.h> 21#include <asm/io.h>
21 22
22#define DRIVER_NAME "tifm_ms" 23#define DRIVER_NAME "tifm_ms"
diff --git a/drivers/message/i2o/pci.c b/drivers/message/i2o/pci.c
index 73e4658af53c..7190d5239b4f 100644
--- a/drivers/message/i2o/pci.c
+++ b/drivers/message/i2o/pci.c
@@ -31,6 +31,7 @@
31#include <linux/interrupt.h> 31#include <linux/interrupt.h>
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/i2o.h> 33#include <linux/i2o.h>
34#include <linux/module.h>
34#include "core.h" 35#include "core.h"
35 36
36#define OSM_DESCRIPTION "I2O-subsystem" 37#define OSM_DESCRIPTION "I2O-subsystem"
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index a67adcbd0fa1..f1391c21ef26 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -2,23 +2,8 @@
2# Multifunction miscellaneous devices 2# Multifunction miscellaneous devices
3# 3#
4 4
5menuconfig MFD_SUPPORT 5if HAS_IOMEM
6 bool "Multifunction device drivers" 6menu "Multifunction device drivers"
7 depends on HAS_IOMEM
8 default y
9 help
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.
20
21if MFD_SUPPORT
22 7
23config MFD_CORE 8config MFD_CORE
24 tristate 9 tristate
@@ -390,6 +375,7 @@ config MFD_WM8400
390 tristate "Support Wolfson Microelectronics WM8400" 375 tristate "Support Wolfson Microelectronics WM8400"
391 select MFD_CORE 376 select MFD_CORE
392 depends on I2C 377 depends on I2C
378 select REGMAP_I2C
393 help 379 help
394 Support for the Wolfson Microelecronics WM8400 PMIC and audio 380 Support for the Wolfson Microelecronics WM8400 PMIC and audio
395 CODEC. This driver provides common support for accessing 381 CODEC. This driver provides common support for accessing
@@ -503,6 +489,7 @@ config MFD_WM8994
503config MFD_PCF50633 489config MFD_PCF50633
504 tristate "Support for NXP PCF50633" 490 tristate "Support for NXP PCF50633"
505 depends on I2C 491 depends on I2C
492 select REGMAP_I2C
506 help 493 help
507 Say yes here if you have NXP PCF50633 chip on your board. 494 Say yes here if you have NXP PCF50633 chip on your board.
508 This core driver provides register access and IRQ handling 495 This core driver provides register access and IRQ handling
@@ -579,6 +566,23 @@ config EZX_PCAP
579 This enables the PCAP ASIC present on EZX Phones. This is 566 This enables the PCAP ASIC present on EZX Phones. This is
580 needed for MMC, TouchScreen, Sound, USB, etc.. 567 needed for MMC, TouchScreen, Sound, USB, etc..
581 568
569config AB5500_CORE
570 bool "ST-Ericsson AB5500 Mixed Signal Power Management chip"
571 depends on ABX500_CORE && MFD_DB5500_PRCMU
572 select MFD_CORE
573 help
574 Select this option to enable access to AB5500 power management
575 chip. This connects to the db5500 chip via the I2C bus via PRCMU.
576 This chip embeds various other multimedia funtionalities as well.
577
578config AB5500_DEBUG
579 bool "Enable debug info via debugfs"
580 depends on AB5500_CORE && DEBUG_FS
581 default y if DEBUG_FS
582 help
583 Select this option if you want debug information from the AB5500
584 using the debug filesystem, debugfs.
585
582config AB8500_CORE 586config AB8500_CORE
583 bool "ST-Ericsson AB8500 Mixed Signal Power Management chip" 587 bool "ST-Ericsson AB8500 Mixed Signal Power Management chip"
584 depends on GENERIC_HARDIRQS && ABX500_CORE 588 depends on GENERIC_HARDIRQS && ABX500_CORE
@@ -615,20 +619,6 @@ config AB8500_GPADC
615 help 619 help
616 AB8500 GPADC driver used to convert Acc and battery/ac/usb voltage 620 AB8500 GPADC driver used to convert Acc and battery/ac/usb voltage
617 621
618config AB3550_CORE
619 bool "ST-Ericsson AB3550 Mixed Signal Circuit core functions"
620 select MFD_CORE
621 depends on I2C=y && GENERIC_HARDIRQS && ABX500_CORE
622 help
623 Select this to enable the AB3550 Mixed Signal IC core
624 functionality. This connects to a AB3550 on the I2C bus
625 and expose a number of symbols needed for dependent devices
626 to read and write registers and subscribe to events from
627 this multi-functional IC. This is needed to use other features
628 of the AB3550 such as battery-backed RTC, charging control,
629 LEDs, vibrator, system power and temperature, power management
630 and ALSA sound.
631
632config MFD_DB8500_PRCMU 622config MFD_DB8500_PRCMU
633 bool "ST-Ericsson DB8500 Power Reset Control Management Unit" 623 bool "ST-Ericsson DB8500 Power Reset Control Management Unit"
634 depends on UX500_SOC_DB8500 624 depends on UX500_SOC_DB8500
@@ -773,7 +763,17 @@ config MFD_AAT2870_CORE
773 additional drivers must be enabled in order to use the 763 additional drivers must be enabled in order to use the
774 functionality of the device. 764 functionality of the device.
775 765
776endif # MFD_SUPPORT 766config MFD_INTEL_MSIC
767 bool "Support for Intel MSIC"
768 depends on INTEL_SCU_IPC
769 select MFD_CORE
770 help
771 Select this option to enable access to Intel MSIC (Avatele
772 Passage) chip. This chip embeds audio, battery, GPIO, etc.
773 devices used in Intel Medfield platforms.
774
775endmenu
776endif
777 777
778menu "Multimedia Capabilities Port drivers" 778menu "Multimedia Capabilities Port drivers"
779 depends on ARCH_SA1100 779 depends on ARCH_SA1100
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index c58020303d18..b2292eb75242 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -79,7 +79,8 @@ obj-$(CONFIG_PCF50633_GPIO) += pcf50633-gpio.o
79obj-$(CONFIG_ABX500_CORE) += abx500-core.o 79obj-$(CONFIG_ABX500_CORE) += abx500-core.o
80obj-$(CONFIG_AB3100_CORE) += ab3100-core.o 80obj-$(CONFIG_AB3100_CORE) += ab3100-core.o
81obj-$(CONFIG_AB3100_OTP) += ab3100-otp.o 81obj-$(CONFIG_AB3100_OTP) += ab3100-otp.o
82obj-$(CONFIG_AB3550_CORE) += ab3550-core.o 82obj-$(CONFIG_AB5500_CORE) += ab5500-core.o
83obj-$(CONFIG_AB5500_DEBUG) += ab5500-debugfs.o
83obj-$(CONFIG_AB8500_CORE) += ab8500-core.o ab8500-sysctrl.o 84obj-$(CONFIG_AB8500_CORE) += ab8500-core.o ab8500-sysctrl.o
84obj-$(CONFIG_AB8500_DEBUG) += ab8500-debugfs.o 85obj-$(CONFIG_AB8500_DEBUG) += ab8500-debugfs.o
85obj-$(CONFIG_AB8500_GPADC) += ab8500-gpadc.o 86obj-$(CONFIG_AB8500_GPADC) += ab8500-gpadc.o
@@ -102,3 +103,4 @@ obj-$(CONFIG_MFD_PM8921_CORE) += pm8921-core.o
102obj-$(CONFIG_MFD_PM8XXX_IRQ) += pm8xxx-irq.o 103obj-$(CONFIG_MFD_PM8XXX_IRQ) += pm8xxx-irq.o
103obj-$(CONFIG_TPS65911_COMPARATOR) += tps65911-comparator.o 104obj-$(CONFIG_TPS65911_COMPARATOR) += tps65911-comparator.o
104obj-$(CONFIG_MFD_AAT2870_CORE) += aat2870-core.o 105obj-$(CONFIG_MFD_AAT2870_CORE) += aat2870-core.o
106obj-$(CONFIG_MFD_INTEL_MSIC) += intel_msic.o
diff --git a/drivers/mfd/aat2870-core.c b/drivers/mfd/aat2870-core.c
index 345dc658ef06..02c42015ba51 100644
--- a/drivers/mfd/aat2870-core.c
+++ b/drivers/mfd/aat2870-core.c
@@ -295,7 +295,7 @@ static ssize_t aat2870_reg_write_file(struct file *file,
295{ 295{
296 struct aat2870_data *aat2870 = file->private_data; 296 struct aat2870_data *aat2870 = file->private_data;
297 char buf[32]; 297 char buf[32];
298 int buf_size; 298 ssize_t buf_size;
299 char *start = buf; 299 char *start = buf;
300 unsigned long addr, val; 300 unsigned long addr, val;
301 int ret; 301 int ret;
diff --git a/drivers/mfd/ab3100-core.c b/drivers/mfd/ab3100-core.c
index a20e1c41bed2..60107ee166fc 100644
--- a/drivers/mfd/ab3100-core.c
+++ b/drivers/mfd/ab3100-core.c
@@ -12,6 +12,7 @@
12#include <linux/notifier.h> 12#include <linux/notifier.h>
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/err.h> 14#include <linux/err.h>
15#include <linux/module.h>
15#include <linux/platform_device.h> 16#include <linux/platform_device.h>
16#include <linux/device.h> 17#include <linux/device.h>
17#include <linux/interrupt.h> 18#include <linux/interrupt.h>
@@ -809,7 +810,7 @@ struct ab_family_id {
809 char *name; 810 char *name;
810}; 811};
811 812
812static const struct ab_family_id ids[] __devinitdata = { 813static const struct ab_family_id ids[] __devinitconst = {
813 /* AB3100 */ 814 /* AB3100 */
814 { 815 {
815 .id = 0xc0, 816 .id = 0xc0,
diff --git a/drivers/mfd/ab3550-core.c b/drivers/mfd/ab3550-core.c
deleted file mode 100644
index 56ba1943c91d..000000000000
--- a/drivers/mfd/ab3550-core.c
+++ /dev/null
@@ -1,1380 +0,0 @@
1/*
2 * Copyright (C) 2007-2010 ST-Ericsson
3 * License terms: GNU General Public License (GPL) version 2
4 * Low-level core for exclusive access to the AB3550 IC on the I2C bus
5 * and some basic chip-configuration.
6 * Author: Bengt Jonsson <bengt.g.jonsson@stericsson.com>
7 * Author: Mattias Nilsson <mattias.i.nilsson@stericsson.com>
8 * Author: Mattias Wallin <mattias.wallin@stericsson.com>
9 * Author: Rickard Andersson <rickard.andersson@stericsson.com>
10 */
11
12#include <linux/i2c.h>
13#include <linux/mutex.h>
14#include <linux/err.h>
15#include <linux/platform_device.h>
16#include <linux/slab.h>
17#include <linux/device.h>
18#include <linux/irq.h>
19#include <linux/interrupt.h>
20#include <linux/random.h>
21#include <linux/workqueue.h>
22#include <linux/debugfs.h>
23#include <linux/seq_file.h>
24#include <linux/uaccess.h>
25#include <linux/mfd/abx500.h>
26#include <linux/list.h>
27#include <linux/bitops.h>
28#include <linux/spinlock.h>
29#include <linux/mfd/core.h>
30
31#define AB3550_NAME_STRING "ab3550"
32#define AB3550_ID_FORMAT_STRING "AB3550 %s"
33#define AB3550_NUM_BANKS 2
34#define AB3550_NUM_EVENT_REG 5
35
36/* These are the only registers inside AB3550 used in this main file */
37
38/* Chip ID register */
39#define AB3550_CID_REG 0x20
40
41/* Interrupt event registers */
42#define AB3550_EVENT_BANK 0
43#define AB3550_EVENT_REG 0x22
44
45/* Read/write operation values. */
46#define AB3550_PERM_RD (0x01)
47#define AB3550_PERM_WR (0x02)
48
49/* Read/write permissions. */
50#define AB3550_PERM_RO (AB3550_PERM_RD)
51#define AB3550_PERM_RW (AB3550_PERM_RD | AB3550_PERM_WR)
52
53/**
54 * struct ab3550
55 * @access_mutex: lock out concurrent accesses to the AB registers
56 * @i2c_client: I2C client for this chip
57 * @chip_name: name of this chip variant
58 * @chip_id: 8 bit chip ID for this chip variant
59 * @mask_work: a worker for writing to mask registers
60 * @event_lock: a lock to protect the event_mask
61 * @event_mask: a local copy of the mask event registers
62 * @startup_events: a copy of the first reading of the event registers
63 * @startup_events_read: whether the first events have been read
64 */
65struct ab3550 {
66 struct mutex access_mutex;
67 struct i2c_client *i2c_client[AB3550_NUM_BANKS];
68 char chip_name[32];
69 u8 chip_id;
70 struct work_struct mask_work;
71 spinlock_t event_lock;
72 u8 event_mask[AB3550_NUM_EVENT_REG];
73 u8 startup_events[AB3550_NUM_EVENT_REG];
74 bool startup_events_read;
75#ifdef CONFIG_DEBUG_FS
76 unsigned int debug_bank;
77 unsigned int debug_address;
78#endif
79};
80
81/**
82 * struct ab3550_reg_range
83 * @first: the first address of the range
84 * @last: the last address of the range
85 * @perm: access permissions for the range
86 */
87struct ab3550_reg_range {
88 u8 first;
89 u8 last;
90 u8 perm;
91};
92
93/**
94 * struct ab3550_reg_ranges
95 * @count: the number of ranges in the list
96 * @range: the list of register ranges
97 */
98struct ab3550_reg_ranges {
99 u8 count;
100 const struct ab3550_reg_range *range;
101};
102
103/*
104 * Permissible register ranges for reading and writing per device and bank.
105 *
106 * The ranges must be listed in increasing address order, and no overlaps are
107 * allowed. It is assumed that write permission implies read permission
108 * (i.e. only RO and RW permissions should be used). Ranges with write
109 * permission must not be split up.
110 */
111
112#define NO_RANGE {.count = 0, .range = NULL,}
113
114static struct
115ab3550_reg_ranges ab3550_reg_ranges[AB3550_NUM_DEVICES][AB3550_NUM_BANKS] = {
116 [AB3550_DEVID_DAC] = {
117 NO_RANGE,
118 {
119 .count = 2,
120 .range = (struct ab3550_reg_range[]) {
121 {
122 .first = 0xb0,
123 .last = 0xba,
124 .perm = AB3550_PERM_RW,
125 },
126 {
127 .first = 0xbc,
128 .last = 0xc3,
129 .perm = AB3550_PERM_RW,
130 },
131 },
132 },
133 },
134 [AB3550_DEVID_LEDS] = {
135 NO_RANGE,
136 {
137 .count = 2,
138 .range = (struct ab3550_reg_range[]) {
139 {
140 .first = 0x5a,
141 .last = 0x88,
142 .perm = AB3550_PERM_RW,
143 },
144 {
145 .first = 0x8a,
146 .last = 0xad,
147 .perm = AB3550_PERM_RW,
148 },
149 }
150 },
151 },
152 [AB3550_DEVID_POWER] = {
153 {
154 .count = 1,
155 .range = (struct ab3550_reg_range[]) {
156 {
157 .first = 0x21,
158 .last = 0x21,
159 .perm = AB3550_PERM_RO,
160 },
161 }
162 },
163 NO_RANGE,
164 },
165 [AB3550_DEVID_REGULATORS] = {
166 {
167 .count = 1,
168 .range = (struct ab3550_reg_range[]) {
169 {
170 .first = 0x69,
171 .last = 0xa3,
172 .perm = AB3550_PERM_RW,
173 },
174 }
175 },
176 {
177 .count = 1,
178 .range = (struct ab3550_reg_range[]) {
179 {
180 .first = 0x14,
181 .last = 0x16,
182 .perm = AB3550_PERM_RW,
183 },
184 }
185 },
186 },
187 [AB3550_DEVID_SIM] = {
188 {
189 .count = 1,
190 .range = (struct ab3550_reg_range[]) {
191 {
192 .first = 0x21,
193 .last = 0x21,
194 .perm = AB3550_PERM_RO,
195 },
196 }
197 },
198 {
199 .count = 1,
200 .range = (struct ab3550_reg_range[]) {
201 {
202 .first = 0x14,
203 .last = 0x17,
204 .perm = AB3550_PERM_RW,
205 },
206 }
207
208 },
209 },
210 [AB3550_DEVID_UART] = {
211 NO_RANGE,
212 NO_RANGE,
213 },
214 [AB3550_DEVID_RTC] = {
215 {
216 .count = 1,
217 .range = (struct ab3550_reg_range[]) {
218 {
219 .first = 0x00,
220 .last = 0x0c,
221 .perm = AB3550_PERM_RW,
222 },
223 }
224 },
225 NO_RANGE,
226 },
227 [AB3550_DEVID_CHARGER] = {
228 {
229 .count = 2,
230 .range = (struct ab3550_reg_range[]) {
231 {
232 .first = 0x10,
233 .last = 0x1a,
234 .perm = AB3550_PERM_RW,
235 },
236 {
237 .first = 0x21,
238 .last = 0x21,
239 .perm = AB3550_PERM_RO,
240 },
241 }
242 },
243 NO_RANGE,
244 },
245 [AB3550_DEVID_ADC] = {
246 NO_RANGE,
247 {
248 .count = 1,
249 .range = (struct ab3550_reg_range[]) {
250 {
251 .first = 0x20,
252 .last = 0x56,
253 .perm = AB3550_PERM_RW,
254 },
255
256 }
257 },
258 },
259 [AB3550_DEVID_FUELGAUGE] = {
260 {
261 .count = 1,
262 .range = (struct ab3550_reg_range[]) {
263 {
264 .first = 0x21,
265 .last = 0x21,
266 .perm = AB3550_PERM_RO,
267 },
268 }
269 },
270 {
271 .count = 1,
272 .range = (struct ab3550_reg_range[]) {
273 {
274 .first = 0x00,
275 .last = 0x0e,
276 .perm = AB3550_PERM_RW,
277 },
278 }
279 },
280 },
281 [AB3550_DEVID_VIBRATOR] = {
282 NO_RANGE,
283 {
284 .count = 1,
285 .range = (struct ab3550_reg_range[]) {
286 {
287 .first = 0x10,
288 .last = 0x13,
289 .perm = AB3550_PERM_RW,
290 },
291
292 }
293 },
294 },
295 [AB3550_DEVID_CODEC] = {
296 {
297 .count = 2,
298 .range = (struct ab3550_reg_range[]) {
299 {
300 .first = 0x31,
301 .last = 0x63,
302 .perm = AB3550_PERM_RW,
303 },
304 {
305 .first = 0x65,
306 .last = 0x68,
307 .perm = AB3550_PERM_RW,
308 },
309 }
310 },
311 NO_RANGE,
312 },
313};
314
315static struct mfd_cell ab3550_devs[AB3550_NUM_DEVICES] = {
316 [AB3550_DEVID_DAC] = {
317 .name = "ab3550-dac",
318 .id = AB3550_DEVID_DAC,
319 .num_resources = 0,
320 },
321 [AB3550_DEVID_LEDS] = {
322 .name = "ab3550-leds",
323 .id = AB3550_DEVID_LEDS,
324 },
325 [AB3550_DEVID_POWER] = {
326 .name = "ab3550-power",
327 .id = AB3550_DEVID_POWER,
328 },
329 [AB3550_DEVID_REGULATORS] = {
330 .name = "ab3550-regulators",
331 .id = AB3550_DEVID_REGULATORS,
332 },
333 [AB3550_DEVID_SIM] = {
334 .name = "ab3550-sim",
335 .id = AB3550_DEVID_SIM,
336 },
337 [AB3550_DEVID_UART] = {
338 .name = "ab3550-uart",
339 .id = AB3550_DEVID_UART,
340 },
341 [AB3550_DEVID_RTC] = {
342 .name = "ab3550-rtc",
343 .id = AB3550_DEVID_RTC,
344 },
345 [AB3550_DEVID_CHARGER] = {
346 .name = "ab3550-charger",
347 .id = AB3550_DEVID_CHARGER,
348 },
349 [AB3550_DEVID_ADC] = {
350 .name = "ab3550-adc",
351 .id = AB3550_DEVID_ADC,
352 .num_resources = 10,
353 .resources = (struct resource[]) {
354 {
355 .name = "TRIGGER-0",
356 .flags = IORESOURCE_IRQ,
357 .start = 16,
358 .end = 16,
359 },
360 {
361 .name = "TRIGGER-1",
362 .flags = IORESOURCE_IRQ,
363 .start = 17,
364 .end = 17,
365 },
366 {
367 .name = "TRIGGER-2",
368 .flags = IORESOURCE_IRQ,
369 .start = 18,
370 .end = 18,
371 },
372 {
373 .name = "TRIGGER-3",
374 .flags = IORESOURCE_IRQ,
375 .start = 19,
376 .end = 19,
377 },
378 {
379 .name = "TRIGGER-4",
380 .flags = IORESOURCE_IRQ,
381 .start = 20,
382 .end = 20,
383 },
384 {
385 .name = "TRIGGER-5",
386 .flags = IORESOURCE_IRQ,
387 .start = 21,
388 .end = 21,
389 },
390 {
391 .name = "TRIGGER-6",
392 .flags = IORESOURCE_IRQ,
393 .start = 22,
394 .end = 22,
395 },
396 {
397 .name = "TRIGGER-7",
398 .flags = IORESOURCE_IRQ,
399 .start = 23,
400 .end = 23,
401 },
402 {
403 .name = "TRIGGER-VBAT-TXON",
404 .flags = IORESOURCE_IRQ,
405 .start = 13,
406 .end = 13,
407 },
408 {
409 .name = "TRIGGER-VBAT",
410 .flags = IORESOURCE_IRQ,
411 .start = 12,
412 .end = 12,
413 },
414 },
415 },
416 [AB3550_DEVID_FUELGAUGE] = {
417 .name = "ab3550-fuelgauge",
418 .id = AB3550_DEVID_FUELGAUGE,
419 },
420 [AB3550_DEVID_VIBRATOR] = {
421 .name = "ab3550-vibrator",
422 .id = AB3550_DEVID_VIBRATOR,
423 },
424 [AB3550_DEVID_CODEC] = {
425 .name = "ab3550-codec",
426 .id = AB3550_DEVID_CODEC,
427 },
428};
429
430/*
431 * I2C transactions with error messages.
432 */
433static int ab3550_i2c_master_send(struct ab3550 *ab, u8 bank, u8 *data,
434 u8 count)
435{
436 int err;
437
438 err = i2c_master_send(ab->i2c_client[bank], data, count);
439 if (err < 0) {
440 dev_err(&ab->i2c_client[0]->dev, "send error: %d\n", err);
441 return err;
442 }
443 return 0;
444}
445
446static int ab3550_i2c_master_recv(struct ab3550 *ab, u8 bank, u8 *data,
447 u8 count)
448{
449 int err;
450
451 err = i2c_master_recv(ab->i2c_client[bank], data, count);
452 if (err < 0) {
453 dev_err(&ab->i2c_client[0]->dev, "receive error: %d\n", err);
454 return err;
455 }
456 return 0;
457}
458
459/*
460 * Functionality for getting/setting register values.
461 */
462static int get_register_interruptible(struct ab3550 *ab, u8 bank, u8 reg,
463 u8 *value)
464{
465 int err;
466
467 err = mutex_lock_interruptible(&ab->access_mutex);
468 if (err)
469 return err;
470
471 err = ab3550_i2c_master_send(ab, bank, &reg, 1);
472 if (!err)
473 err = ab3550_i2c_master_recv(ab, bank, value, 1);
474
475 mutex_unlock(&ab->access_mutex);
476 return err;
477}
478
479static int get_register_page_interruptible(struct ab3550 *ab, u8 bank,
480 u8 first_reg, u8 *regvals, u8 numregs)
481{
482 int err;
483
484 err = mutex_lock_interruptible(&ab->access_mutex);
485 if (err)
486 return err;
487
488 err = ab3550_i2c_master_send(ab, bank, &first_reg, 1);
489 if (!err)
490 err = ab3550_i2c_master_recv(ab, bank, regvals, numregs);
491
492 mutex_unlock(&ab->access_mutex);
493 return err;
494}
495
496static int mask_and_set_register_interruptible(struct ab3550 *ab, u8 bank,
497 u8 reg, u8 bitmask, u8 bitvalues)
498{
499 int err = 0;
500
501 if (likely(bitmask)) {
502 u8 reg_bits[2] = {reg, 0};
503
504 err = mutex_lock_interruptible(&ab->access_mutex);
505 if (err)
506 return err;
507
508 if (bitmask == 0xFF) /* No need to read in this case. */
509 reg_bits[1] = bitvalues;
510 else { /* Read and modify the register value. */
511 u8 bits;
512
513 err = ab3550_i2c_master_send(ab, bank, &reg, 1);
514 if (err)
515 goto unlock_and_return;
516 err = ab3550_i2c_master_recv(ab, bank, &bits, 1);
517 if (err)
518 goto unlock_and_return;
519 reg_bits[1] = ((~bitmask & bits) |
520 (bitmask & bitvalues));
521 }
522 /* Write the new value. */
523 err = ab3550_i2c_master_send(ab, bank, reg_bits, 2);
524unlock_and_return:
525 mutex_unlock(&ab->access_mutex);
526 }
527 return err;
528}
529
530/*
531 * Read/write permission checking functions.
532 */
533static bool page_write_allowed(const struct ab3550_reg_ranges *ranges,
534 u8 first_reg, u8 last_reg)
535{
536 u8 i;
537
538 if (last_reg < first_reg)
539 return false;
540
541 for (i = 0; i < ranges->count; i++) {
542 if (first_reg < ranges->range[i].first)
543 break;
544 if ((last_reg <= ranges->range[i].last) &&
545 (ranges->range[i].perm & AB3550_PERM_WR))
546 return true;
547 }
548 return false;
549}
550
551static bool reg_write_allowed(const struct ab3550_reg_ranges *ranges, u8 reg)
552{
553 return page_write_allowed(ranges, reg, reg);
554}
555
556static bool page_read_allowed(const struct ab3550_reg_ranges *ranges,
557 u8 first_reg, u8 last_reg)
558{
559 u8 i;
560
561 if (last_reg < first_reg)
562 return false;
563 /* Find the range (if it exists in the list) that includes first_reg. */
564 for (i = 0; i < ranges->count; i++) {
565 if (first_reg < ranges->range[i].first)
566 return false;
567 if (first_reg <= ranges->range[i].last)
568 break;
569 }
570 /* Make sure that the entire range up to and including last_reg is
571 * readable. This may span several of the ranges in the list.
572 */
573 while ((i < ranges->count) &&
574 (ranges->range[i].perm & AB3550_PERM_RD)) {
575 if (last_reg <= ranges->range[i].last)
576 return true;
577 if ((++i >= ranges->count) ||
578 (ranges->range[i].first !=
579 (ranges->range[i - 1].last + 1))) {
580 break;
581 }
582 }
583 return false;
584}
585
586static bool reg_read_allowed(const struct ab3550_reg_ranges *ranges, u8 reg)
587{
588 return page_read_allowed(ranges, reg, reg);
589}
590
591/*
592 * The register access functionality.
593 */
594static int ab3550_get_chip_id(struct device *dev)
595{
596 struct ab3550 *ab = dev_get_drvdata(dev->parent);
597 return (int)ab->chip_id;
598}
599
600static int ab3550_mask_and_set_register_interruptible(struct device *dev,
601 u8 bank, u8 reg, u8 bitmask, u8 bitvalues)
602{
603 struct ab3550 *ab;
604 struct platform_device *pdev = to_platform_device(dev);
605
606 if ((AB3550_NUM_BANKS <= bank) ||
607 !reg_write_allowed(&ab3550_reg_ranges[pdev->id][bank], reg))
608 return -EINVAL;
609
610 ab = dev_get_drvdata(dev->parent);
611 return mask_and_set_register_interruptible(ab, bank, reg,
612 bitmask, bitvalues);
613}
614
615static int ab3550_set_register_interruptible(struct device *dev, u8 bank,
616 u8 reg, u8 value)
617{
618 return ab3550_mask_and_set_register_interruptible(dev, bank, reg, 0xFF,
619 value);
620}
621
622static int ab3550_get_register_interruptible(struct device *dev, u8 bank,
623 u8 reg, u8 *value)
624{
625 struct ab3550 *ab;
626 struct platform_device *pdev = to_platform_device(dev);
627
628 if ((AB3550_NUM_BANKS <= bank) ||
629 !reg_read_allowed(&ab3550_reg_ranges[pdev->id][bank], reg))
630 return -EINVAL;
631
632 ab = dev_get_drvdata(dev->parent);
633 return get_register_interruptible(ab, bank, reg, value);
634}
635
636static int ab3550_get_register_page_interruptible(struct device *dev, u8 bank,
637 u8 first_reg, u8 *regvals, u8 numregs)
638{
639 struct ab3550 *ab;
640 struct platform_device *pdev = to_platform_device(dev);
641
642 if ((AB3550_NUM_BANKS <= bank) ||
643 !page_read_allowed(&ab3550_reg_ranges[pdev->id][bank],
644 first_reg, (first_reg + numregs - 1)))
645 return -EINVAL;
646
647 ab = dev_get_drvdata(dev->parent);
648 return get_register_page_interruptible(ab, bank, first_reg, regvals,
649 numregs);
650}
651
652static int ab3550_event_registers_startup_state_get(struct device *dev,
653 u8 *event)
654{
655 struct ab3550 *ab;
656
657 ab = dev_get_drvdata(dev->parent);
658 if (!ab->startup_events_read)
659 return -EAGAIN; /* Try again later */
660
661 memcpy(event, ab->startup_events, AB3550_NUM_EVENT_REG);
662 return 0;
663}
664
665static int ab3550_startup_irq_enabled(struct device *dev, unsigned int irq)
666{
667 struct ab3550 *ab;
668 struct ab3550_platform_data *plf_data;
669 bool val;
670
671 ab = irq_get_chip_data(irq);
672 plf_data = ab->i2c_client[0]->dev.platform_data;
673 irq -= plf_data->irq.base;
674 val = ((ab->startup_events[irq / 8] & BIT(irq % 8)) != 0);
675
676 return val;
677}
678
679static struct abx500_ops ab3550_ops = {
680 .get_chip_id = ab3550_get_chip_id,
681 .get_register = ab3550_get_register_interruptible,
682 .set_register = ab3550_set_register_interruptible,
683 .get_register_page = ab3550_get_register_page_interruptible,
684 .set_register_page = NULL,
685 .mask_and_set_register = ab3550_mask_and_set_register_interruptible,
686 .event_registers_startup_state_get =
687 ab3550_event_registers_startup_state_get,
688 .startup_irq_enabled = ab3550_startup_irq_enabled,
689};
690
691static irqreturn_t ab3550_irq_handler(int irq, void *data)
692{
693 struct ab3550 *ab = data;
694 int err;
695 unsigned int i;
696 u8 e[AB3550_NUM_EVENT_REG];
697 u8 *events;
698 unsigned long flags;
699
700 events = (ab->startup_events_read ? e : ab->startup_events);
701
702 err = get_register_page_interruptible(ab, AB3550_EVENT_BANK,
703 AB3550_EVENT_REG, events, AB3550_NUM_EVENT_REG);
704 if (err)
705 goto err_event_rd;
706
707 if (!ab->startup_events_read) {
708 dev_info(&ab->i2c_client[0]->dev,
709 "startup events 0x%x,0x%x,0x%x,0x%x,0x%x\n",
710 ab->startup_events[0], ab->startup_events[1],
711 ab->startup_events[2], ab->startup_events[3],
712 ab->startup_events[4]);
713 ab->startup_events_read = true;
714 goto out;
715 }
716
717 /* The two highest bits in event[4] are not used. */
718 events[4] &= 0x3f;
719
720 spin_lock_irqsave(&ab->event_lock, flags);
721 for (i = 0; i < AB3550_NUM_EVENT_REG; i++)
722 events[i] &= ~ab->event_mask[i];
723 spin_unlock_irqrestore(&ab->event_lock, flags);
724
725 for (i = 0; i < AB3550_NUM_EVENT_REG; i++) {
726 u8 bit;
727 u8 event_reg;
728
729 dev_dbg(&ab->i2c_client[0]->dev, "IRQ Event[%d]: 0x%2x\n",
730 i, events[i]);
731
732 event_reg = events[i];
733 for (bit = 0; event_reg; bit++, event_reg /= 2) {
734 if (event_reg % 2) {
735 unsigned int irq;
736 struct ab3550_platform_data *plf_data;
737
738 plf_data = ab->i2c_client[0]->dev.platform_data;
739 irq = plf_data->irq.base + (i * 8) + bit;
740 handle_nested_irq(irq);
741 }
742 }
743 }
744out:
745 return IRQ_HANDLED;
746
747err_event_rd:
748 dev_dbg(&ab->i2c_client[0]->dev, "error reading event registers\n");
749 return IRQ_HANDLED;
750}
751
752#ifdef CONFIG_DEBUG_FS
753static struct ab3550_reg_ranges debug_ranges[AB3550_NUM_BANKS] = {
754 {
755 .count = 6,
756 .range = (struct ab3550_reg_range[]) {
757 {
758 .first = 0x00,
759 .last = 0x0e,
760 },
761 {
762 .first = 0x10,
763 .last = 0x1a,
764 },
765 {
766 .first = 0x1e,
767 .last = 0x4f,
768 },
769 {
770 .first = 0x51,
771 .last = 0x63,
772 },
773 {
774 .first = 0x65,
775 .last = 0xa3,
776 },
777 {
778 .first = 0xa5,
779 .last = 0xa8,
780 },
781 }
782 },
783 {
784 .count = 8,
785 .range = (struct ab3550_reg_range[]) {
786 {
787 .first = 0x00,
788 .last = 0x0e,
789 },
790 {
791 .first = 0x10,
792 .last = 0x17,
793 },
794 {
795 .first = 0x1a,
796 .last = 0x1c,
797 },
798 {
799 .first = 0x20,
800 .last = 0x56,
801 },
802 {
803 .first = 0x5a,
804 .last = 0x88,
805 },
806 {
807 .first = 0x8a,
808 .last = 0xad,
809 },
810 {
811 .first = 0xb0,
812 .last = 0xba,
813 },
814 {
815 .first = 0xbc,
816 .last = 0xc3,
817 },
818 }
819 },
820};
821
822static int ab3550_registers_print(struct seq_file *s, void *p)
823{
824 struct ab3550 *ab = s->private;
825 int bank;
826
827 seq_printf(s, AB3550_NAME_STRING " register values:\n");
828
829 for (bank = 0; bank < AB3550_NUM_BANKS; bank++) {
830 unsigned int i;
831
832 seq_printf(s, " bank %d:\n", bank);
833 for (i = 0; i < debug_ranges[bank].count; i++) {
834 u8 reg;
835
836 for (reg = debug_ranges[bank].range[i].first;
837 reg <= debug_ranges[bank].range[i].last;
838 reg++) {
839 u8 value;
840
841 get_register_interruptible(ab, bank, reg,
842 &value);
843 seq_printf(s, " [%d/0x%02X]: 0x%02X\n", bank,
844 reg, value);
845 }
846 }
847 }
848 return 0;
849}
850
851static int ab3550_registers_open(struct inode *inode, struct file *file)
852{
853 return single_open(file, ab3550_registers_print, inode->i_private);
854}
855
856static const struct file_operations ab3550_registers_fops = {
857 .open = ab3550_registers_open,
858 .read = seq_read,
859 .llseek = seq_lseek,
860 .release = single_release,
861 .owner = THIS_MODULE,
862};
863
864static int ab3550_bank_print(struct seq_file *s, void *p)
865{
866 struct ab3550 *ab = s->private;
867
868 seq_printf(s, "%d\n", ab->debug_bank);
869 return 0;
870}
871
872static int ab3550_bank_open(struct inode *inode, struct file *file)
873{
874 return single_open(file, ab3550_bank_print, inode->i_private);
875}
876
877static ssize_t ab3550_bank_write(struct file *file,
878 const char __user *user_buf,
879 size_t count, loff_t *ppos)
880{
881 struct ab3550 *ab = ((struct seq_file *)(file->private_data))->private;
882 unsigned long user_bank;
883 int err;
884
885 /* Get userspace string and assure termination */
886 err = kstrtoul_from_user(user_buf, count, 0, &user_bank);
887 if (err)
888 return err;
889
890 if (user_bank >= AB3550_NUM_BANKS) {
891 dev_err(&ab->i2c_client[0]->dev,
892 "debugfs error input > number of banks\n");
893 return -EINVAL;
894 }
895
896 ab->debug_bank = user_bank;
897
898 return count;
899}
900
901static int ab3550_address_print(struct seq_file *s, void *p)
902{
903 struct ab3550 *ab = s->private;
904
905 seq_printf(s, "0x%02X\n", ab->debug_address);
906 return 0;
907}
908
909static int ab3550_address_open(struct inode *inode, struct file *file)
910{
911 return single_open(file, ab3550_address_print, inode->i_private);
912}
913
914static ssize_t ab3550_address_write(struct file *file,
915 const char __user *user_buf,
916 size_t count, loff_t *ppos)
917{
918 struct ab3550 *ab = ((struct seq_file *)(file->private_data))->private;
919 unsigned long user_address;
920 int err;
921
922 /* Get userspace string and assure termination */
923 err = kstrtoul_from_user(user_buf, count, 0, &user_address);
924 if (err)
925 return err;
926
927 if (user_address > 0xff) {
928 dev_err(&ab->i2c_client[0]->dev,
929 "debugfs error input > 0xff\n");
930 return -EINVAL;
931 }
932 ab->debug_address = user_address;
933 return count;
934}
935
936static int ab3550_val_print(struct seq_file *s, void *p)
937{
938 struct ab3550 *ab = s->private;
939 int err;
940 u8 regvalue;
941
942 err = get_register_interruptible(ab, (u8)ab->debug_bank,
943 (u8)ab->debug_address, &regvalue);
944 if (err)
945 return -EINVAL;
946 seq_printf(s, "0x%02X\n", regvalue);
947
948 return 0;
949}
950
951static int ab3550_val_open(struct inode *inode, struct file *file)
952{
953 return single_open(file, ab3550_val_print, inode->i_private);
954}
955
956static ssize_t ab3550_val_write(struct file *file,
957 const char __user *user_buf,
958 size_t count, loff_t *ppos)
959{
960 struct ab3550 *ab = ((struct seq_file *)(file->private_data))->private;
961 unsigned long user_val;
962 int err;
963 u8 regvalue;
964
965 /* Get userspace string and assure termination */
966 err = kstrtoul_from_user(user_buf, count, 0, &user_val);
967 if (err)
968 return err;
969
970 if (user_val > 0xff) {
971 dev_err(&ab->i2c_client[0]->dev,
972 "debugfs error input > 0xff\n");
973 return -EINVAL;
974 }
975 err = mask_and_set_register_interruptible(
976 ab, (u8)ab->debug_bank,
977 (u8)ab->debug_address, 0xFF, (u8)user_val);
978 if (err)
979 return -EINVAL;
980
981 get_register_interruptible(ab, (u8)ab->debug_bank,
982 (u8)ab->debug_address, &regvalue);
983 if (err)
984 return -EINVAL;
985
986 return count;
987}
988
989static const struct file_operations ab3550_bank_fops = {
990 .open = ab3550_bank_open,
991 .write = ab3550_bank_write,
992 .read = seq_read,
993 .llseek = seq_lseek,
994 .release = single_release,
995 .owner = THIS_MODULE,
996};
997
998static const struct file_operations ab3550_address_fops = {
999 .open = ab3550_address_open,
1000 .write = ab3550_address_write,
1001 .read = seq_read,
1002 .llseek = seq_lseek,
1003 .release = single_release,
1004 .owner = THIS_MODULE,
1005};
1006
1007static const struct file_operations ab3550_val_fops = {
1008 .open = ab3550_val_open,
1009 .write = ab3550_val_write,
1010 .read = seq_read,
1011 .llseek = seq_lseek,
1012 .release = single_release,
1013 .owner = THIS_MODULE,
1014};
1015
1016static struct dentry *ab3550_dir;
1017static struct dentry *ab3550_reg_file;
1018static struct dentry *ab3550_bank_file;
1019static struct dentry *ab3550_address_file;
1020static struct dentry *ab3550_val_file;
1021
1022static inline void ab3550_setup_debugfs(struct ab3550 *ab)
1023{
1024 ab->debug_bank = 0;
1025 ab->debug_address = 0x00;
1026
1027 ab3550_dir = debugfs_create_dir(AB3550_NAME_STRING, NULL);
1028 if (!ab3550_dir)
1029 goto exit_no_debugfs;
1030
1031 ab3550_reg_file = debugfs_create_file("all-registers",
1032 S_IRUGO, ab3550_dir, ab, &ab3550_registers_fops);
1033 if (!ab3550_reg_file)
1034 goto exit_destroy_dir;
1035
1036 ab3550_bank_file = debugfs_create_file("register-bank",
1037 (S_IRUGO | S_IWUSR), ab3550_dir, ab, &ab3550_bank_fops);
1038 if (!ab3550_bank_file)
1039 goto exit_destroy_reg;
1040
1041 ab3550_address_file = debugfs_create_file("register-address",
1042 (S_IRUGO | S_IWUSR), ab3550_dir, ab, &ab3550_address_fops);
1043 if (!ab3550_address_file)
1044 goto exit_destroy_bank;
1045
1046 ab3550_val_file = debugfs_create_file("register-value",
1047 (S_IRUGO | S_IWUSR), ab3550_dir, ab, &ab3550_val_fops);
1048 if (!ab3550_val_file)
1049 goto exit_destroy_address;
1050
1051 return;
1052
1053exit_destroy_address:
1054 debugfs_remove(ab3550_address_file);
1055exit_destroy_bank:
1056 debugfs_remove(ab3550_bank_file);
1057exit_destroy_reg:
1058 debugfs_remove(ab3550_reg_file);
1059exit_destroy_dir:
1060 debugfs_remove(ab3550_dir);
1061exit_no_debugfs:
1062 dev_err(&ab->i2c_client[0]->dev, "failed to create debugfs entries.\n");
1063 return;
1064}
1065
1066static inline void ab3550_remove_debugfs(void)
1067{
1068 debugfs_remove(ab3550_val_file);
1069 debugfs_remove(ab3550_address_file);
1070 debugfs_remove(ab3550_bank_file);
1071 debugfs_remove(ab3550_reg_file);
1072 debugfs_remove(ab3550_dir);
1073}
1074
1075#else /* !CONFIG_DEBUG_FS */
1076static inline void ab3550_setup_debugfs(struct ab3550 *ab)
1077{
1078}
1079static inline void ab3550_remove_debugfs(void)
1080{
1081}
1082#endif
1083
1084/*
1085 * Basic set-up, datastructure creation/destruction and I2C interface.
1086 * This sets up a default config in the AB3550 chip so that it
1087 * will work as expected.
1088 */
1089static int __init ab3550_setup(struct ab3550 *ab)
1090{
1091 int err = 0;
1092 int i;
1093 struct ab3550_platform_data *plf_data;
1094 struct abx500_init_settings *settings;
1095
1096 plf_data = ab->i2c_client[0]->dev.platform_data;
1097 settings = plf_data->init_settings;
1098
1099 for (i = 0; i < plf_data->init_settings_sz; i++) {
1100 err = mask_and_set_register_interruptible(ab,
1101 settings[i].bank,
1102 settings[i].reg,
1103 0xFF, settings[i].setting);
1104 if (err)
1105 goto exit_no_setup;
1106
1107 /* If event mask register update the event mask in ab3550 */
1108 if ((settings[i].bank == 0) &&
1109 (AB3550_IMR1 <= settings[i].reg) &&
1110 (settings[i].reg <= AB3550_IMR5)) {
1111 ab->event_mask[settings[i].reg - AB3550_IMR1] =
1112 settings[i].setting;
1113 }
1114 }
1115exit_no_setup:
1116 return err;
1117}
1118
1119static void ab3550_mask_work(struct work_struct *work)
1120{
1121 struct ab3550 *ab = container_of(work, struct ab3550, mask_work);
1122 int i;
1123 unsigned long flags;
1124 u8 mask[AB3550_NUM_EVENT_REG];
1125
1126 spin_lock_irqsave(&ab->event_lock, flags);
1127 for (i = 0; i < AB3550_NUM_EVENT_REG; i++)
1128 mask[i] = ab->event_mask[i];
1129 spin_unlock_irqrestore(&ab->event_lock, flags);
1130
1131 for (i = 0; i < AB3550_NUM_EVENT_REG; i++) {
1132 int err;
1133
1134 err = mask_and_set_register_interruptible(ab, 0,
1135 (AB3550_IMR1 + i), ~0, mask[i]);
1136 if (err)
1137 dev_err(&ab->i2c_client[0]->dev,
1138 "ab3550_mask_work failed 0x%x,0x%x\n",
1139 (AB3550_IMR1 + i), mask[i]);
1140 }
1141}
1142
1143static void ab3550_mask(struct irq_data *data)
1144{
1145 unsigned long flags;
1146 struct ab3550 *ab;
1147 struct ab3550_platform_data *plf_data;
1148 int irq;
1149
1150 ab = irq_data_get_irq_chip_data(data);
1151 plf_data = ab->i2c_client[0]->dev.platform_data;
1152 irq = data->irq - plf_data->irq.base;
1153
1154 spin_lock_irqsave(&ab->event_lock, flags);
1155 ab->event_mask[irq / 8] |= BIT(irq % 8);
1156 spin_unlock_irqrestore(&ab->event_lock, flags);
1157
1158 schedule_work(&ab->mask_work);
1159}
1160
1161static void ab3550_unmask(struct irq_data *data)
1162{
1163 unsigned long flags;
1164 struct ab3550 *ab;
1165 struct ab3550_platform_data *plf_data;
1166 int irq;
1167
1168 ab = irq_data_get_irq_chip_data(data);
1169 plf_data = ab->i2c_client[0]->dev.platform_data;
1170 irq = data->irq - plf_data->irq.base;
1171
1172 spin_lock_irqsave(&ab->event_lock, flags);
1173 ab->event_mask[irq / 8] &= ~BIT(irq % 8);
1174 spin_unlock_irqrestore(&ab->event_lock, flags);
1175
1176 schedule_work(&ab->mask_work);
1177}
1178
1179static void noop(struct irq_data *data)
1180{
1181}
1182
1183static struct irq_chip ab3550_irq_chip = {
1184 .name = "ab3550-core", /* Keep the same name as the request */
1185 .irq_disable = ab3550_mask, /* No default to mask in chip.c */
1186 .irq_ack = noop,
1187 .irq_mask = ab3550_mask,
1188 .irq_unmask = ab3550_unmask,
1189};
1190
1191struct ab_family_id {
1192 u8 id;
1193 char *name;
1194};
1195
1196static const struct ab_family_id ids[] __initdata = {
1197 /* AB3550 */
1198 {
1199 .id = AB3550_P1A,
1200 .name = "P1A"
1201 },
1202 /* Terminator */
1203 {
1204 .id = 0x00,
1205 }
1206};
1207
1208static int __init ab3550_probe(struct i2c_client *client,
1209 const struct i2c_device_id *id)
1210{
1211 struct ab3550 *ab;
1212 struct ab3550_platform_data *ab3550_plf_data =
1213 client->dev.platform_data;
1214 int err;
1215 int i;
1216 int num_i2c_clients = 0;
1217
1218 ab = kzalloc(sizeof(struct ab3550), GFP_KERNEL);
1219 if (!ab) {
1220 dev_err(&client->dev,
1221 "could not allocate " AB3550_NAME_STRING " device\n");
1222 return -ENOMEM;
1223 }
1224
1225 /* Initialize data structure */
1226 mutex_init(&ab->access_mutex);
1227 spin_lock_init(&ab->event_lock);
1228 ab->i2c_client[0] = client;
1229
1230 i2c_set_clientdata(client, ab);
1231
1232 /* Read chip ID register */
1233 err = get_register_interruptible(ab, 0, AB3550_CID_REG, &ab->chip_id);
1234 if (err) {
1235 dev_err(&client->dev, "could not communicate with the analog "
1236 "baseband chip\n");
1237 goto exit_no_detect;
1238 }
1239
1240 for (i = 0; ids[i].id != 0x0; i++) {
1241 if (ids[i].id == ab->chip_id) {
1242 snprintf(&ab->chip_name[0], sizeof(ab->chip_name) - 1,
1243 AB3550_ID_FORMAT_STRING, ids[i].name);
1244 break;
1245 }
1246 }
1247
1248 if (ids[i].id == 0x0) {
1249 dev_err(&client->dev, "unknown analog baseband chip id: 0x%x\n",
1250 ab->chip_id);
1251 dev_err(&client->dev, "driver not started!\n");
1252 goto exit_no_detect;
1253 }
1254
1255 dev_info(&client->dev, "detected AB chip: %s\n", &ab->chip_name[0]);
1256
1257 /* Attach other dummy I2C clients. */
1258 while (++num_i2c_clients < AB3550_NUM_BANKS) {
1259 ab->i2c_client[num_i2c_clients] =
1260 i2c_new_dummy(client->adapter,
1261 (client->addr + num_i2c_clients));
1262 if (!ab->i2c_client[num_i2c_clients]) {
1263 err = -ENOMEM;
1264 goto exit_no_dummy_client;
1265 }
1266 strlcpy(ab->i2c_client[num_i2c_clients]->name, id->name,
1267 sizeof(ab->i2c_client[num_i2c_clients]->name));
1268 }
1269
1270 err = ab3550_setup(ab);
1271 if (err)
1272 goto exit_no_setup;
1273
1274 INIT_WORK(&ab->mask_work, ab3550_mask_work);
1275
1276 for (i = 0; i < ab3550_plf_data->irq.count; i++) {
1277 unsigned int irq;
1278
1279 irq = ab3550_plf_data->irq.base + i;
1280 irq_set_chip_data(irq, ab);
1281 irq_set_chip_and_handler(irq, &ab3550_irq_chip,
1282 handle_simple_irq);
1283 irq_set_nested_thread(irq, 1);
1284#ifdef CONFIG_ARM
1285 set_irq_flags(irq, IRQF_VALID);
1286#else
1287 irq_set_noprobe(irq);
1288#endif
1289 }
1290
1291 err = request_threaded_irq(client->irq, NULL, ab3550_irq_handler,
1292 IRQF_ONESHOT, "ab3550-core", ab);
1293 /* This real unpredictable IRQ is of course sampled for entropy */
1294 rand_initialize_irq(client->irq);
1295
1296 if (err)
1297 goto exit_no_irq;
1298
1299 err = abx500_register_ops(&client->dev, &ab3550_ops);
1300 if (err)
1301 goto exit_no_ops;
1302
1303 /* Set up and register the platform devices. */
1304 for (i = 0; i < AB3550_NUM_DEVICES; i++) {
1305 ab3550_devs[i].platform_data = ab3550_plf_data->dev_data[i];
1306 ab3550_devs[i].pdata_size = ab3550_plf_data->dev_data_sz[i];
1307 }
1308
1309 err = mfd_add_devices(&client->dev, 0, ab3550_devs,
1310 ARRAY_SIZE(ab3550_devs), NULL,
1311 ab3550_plf_data->irq.base);
1312
1313 ab3550_setup_debugfs(ab);
1314
1315 return 0;
1316
1317exit_no_ops:
1318exit_no_irq:
1319exit_no_setup:
1320exit_no_dummy_client:
1321 /* Unregister the dummy i2c clients. */
1322 while (--num_i2c_clients)
1323 i2c_unregister_device(ab->i2c_client[num_i2c_clients]);
1324exit_no_detect:
1325 kfree(ab);
1326 return err;
1327}
1328
1329static int __exit ab3550_remove(struct i2c_client *client)
1330{
1331 struct ab3550 *ab = i2c_get_clientdata(client);
1332 int num_i2c_clients = AB3550_NUM_BANKS;
1333
1334 mfd_remove_devices(&client->dev);
1335 ab3550_remove_debugfs();
1336
1337 while (--num_i2c_clients)
1338 i2c_unregister_device(ab->i2c_client[num_i2c_clients]);
1339
1340 /*
1341 * At this point, all subscribers should have unregistered
1342 * their notifiers so deactivate IRQ
1343 */
1344 free_irq(client->irq, ab);
1345 kfree(ab);
1346 return 0;
1347}
1348
1349static const struct i2c_device_id ab3550_id[] = {
1350 {AB3550_NAME_STRING, 0},
1351 {}
1352};
1353MODULE_DEVICE_TABLE(i2c, ab3550_id);
1354
1355static struct i2c_driver ab3550_driver = {
1356 .driver = {
1357 .name = AB3550_NAME_STRING,
1358 .owner = THIS_MODULE,
1359 },
1360 .id_table = ab3550_id,
1361 .probe = ab3550_probe,
1362 .remove = __exit_p(ab3550_remove),
1363};
1364
1365static int __init ab3550_i2c_init(void)
1366{
1367 return i2c_add_driver(&ab3550_driver);
1368}
1369
1370static void __exit ab3550_i2c_exit(void)
1371{
1372 i2c_del_driver(&ab3550_driver);
1373}
1374
1375subsys_initcall(ab3550_i2c_init);
1376module_exit(ab3550_i2c_exit);
1377
1378MODULE_AUTHOR("Mattias Wallin <mattias.wallin@stericsson.com>");
1379MODULE_DESCRIPTION("AB3550 core driver");
1380MODULE_LICENSE("GPL");
diff --git a/drivers/mfd/ab5500-core.c b/drivers/mfd/ab5500-core.c
new file mode 100644
index 000000000000..4175544b491b
--- /dev/null
+++ b/drivers/mfd/ab5500-core.c
@@ -0,0 +1,1439 @@
1/*
2 * Copyright (C) 2007-2011 ST-Ericsson
3 * License terms: GNU General Public License (GPL) version 2
4 * Low-level core for exclusive access to the AB5500 IC on the I2C bus
5 * and some basic chip-configuration.
6 * Author: Bengt Jonsson <bengt.g.jonsson@stericsson.com>
7 * Author: Mattias Nilsson <mattias.i.nilsson@stericsson.com>
8 * Author: Mattias Wallin <mattias.wallin@stericsson.com>
9 * Author: Rickard Andersson <rickard.andersson@stericsson.com>
10 * Author: Karl Komierowski <karl.komierowski@stericsson.com>
11 * Author: Bibek Basu <bibek.basu@stericsson.com>
12 *
13 * TODO: Event handling with irq_chip. Waiting for PRCMU fw support.
14 */
15
16#include <linux/mutex.h>
17#include <linux/err.h>
18#include <linux/platform_device.h>
19#include <linux/slab.h>
20#include <linux/device.h>
21#include <linux/irq.h>
22#include <linux/interrupt.h>
23#include <linux/random.h>
24#include <linux/mfd/ab5500/ab5500.h>
25#include <linux/mfd/abx500.h>
26#include <linux/list.h>
27#include <linux/bitops.h>
28#include <linux/spinlock.h>
29#include <linux/mfd/core.h>
30#include <linux/version.h>
31#include <linux/mfd/db5500-prcmu.h>
32
33#include "ab5500-core.h"
34#include "ab5500-debugfs.h"
35
36#define AB5500_NUM_EVENT_REG 23
37#define AB5500_IT_LATCH0_REG 0x40
38#define AB5500_IT_MASK0_REG 0x60
39
40/*
41 * Permissible register ranges for reading and writing per device and bank.
42 *
43 * The ranges must be listed in increasing address order, and no overlaps are
44 * allowed. It is assumed that write permission implies read permission
45 * (i.e. only RO and RW permissions should be used). Ranges with write
46 * permission must not be split up.
47 */
48
49#define NO_RANGE {.count = 0, .range = NULL,}
50static struct ab5500_i2c_banks ab5500_bank_ranges[AB5500_NUM_DEVICES] = {
51 [AB5500_DEVID_USB] = {
52 .nbanks = 1,
53 .bank = (struct ab5500_i2c_ranges []) {
54 {
55 .bankid = AB5500_BANK_USB,
56 .nranges = 12,
57 .range = (struct ab5500_reg_range[]) {
58 {
59 .first = 0x01,
60 .last = 0x01,
61 .perm = AB5500_PERM_RW,
62 },
63 {
64 .first = 0x80,
65 .last = 0x83,
66 .perm = AB5500_PERM_RW,
67 },
68 {
69 .first = 0x87,
70 .last = 0x8A,
71 .perm = AB5500_PERM_RW,
72 },
73 {
74 .first = 0x8B,
75 .last = 0x8B,
76 .perm = AB5500_PERM_RO,
77 },
78 {
79 .first = 0x91,
80 .last = 0x92,
81 .perm = AB5500_PERM_RO,
82 },
83 {
84 .first = 0x93,
85 .last = 0x93,
86 .perm = AB5500_PERM_RW,
87 },
88 {
89 .first = 0x94,
90 .last = 0x94,
91 .perm = AB5500_PERM_RO,
92 },
93 {
94 .first = 0xA8,
95 .last = 0xB0,
96 .perm = AB5500_PERM_RO,
97 },
98 {
99 .first = 0xB2,
100 .last = 0xB2,
101 .perm = AB5500_PERM_RO,
102 },
103 {
104 .first = 0xB4,
105 .last = 0xBC,
106 .perm = AB5500_PERM_RO,
107 },
108 {
109 .first = 0xBF,
110 .last = 0xBF,
111 .perm = AB5500_PERM_RO,
112 },
113 {
114 .first = 0xC1,
115 .last = 0xC5,
116 .perm = AB5500_PERM_RO,
117 },
118 },
119 },
120 },
121 },
122 [AB5500_DEVID_ADC] = {
123 .nbanks = 1,
124 .bank = (struct ab5500_i2c_ranges []) {
125 {
126 .bankid = AB5500_BANK_ADC,
127 .nranges = 6,
128 .range = (struct ab5500_reg_range[]) {
129 {
130 .first = 0x1F,
131 .last = 0x22,
132 .perm = AB5500_PERM_RO,
133 },
134 {
135 .first = 0x23,
136 .last = 0x24,
137 .perm = AB5500_PERM_RW,
138 },
139 {
140 .first = 0x26,
141 .last = 0x2D,
142 .perm = AB5500_PERM_RO,
143 },
144 {
145 .first = 0x2F,
146 .last = 0x34,
147 .perm = AB5500_PERM_RW,
148 },
149 {
150 .first = 0x37,
151 .last = 0x57,
152 .perm = AB5500_PERM_RW,
153 },
154 {
155 .first = 0x58,
156 .last = 0x58,
157 .perm = AB5500_PERM_RO,
158 },
159 },
160 },
161 },
162 },
163 [AB5500_DEVID_LEDS] = {
164 .nbanks = 1,
165 .bank = (struct ab5500_i2c_ranges []) {
166 {
167 .bankid = AB5500_BANK_LED,
168 .nranges = 1,
169 .range = (struct ab5500_reg_range[]) {
170 {
171 .first = 0x00,
172 .last = 0x0C,
173 .perm = AB5500_PERM_RW,
174 },
175 },
176 },
177 },
178 },
179 [AB5500_DEVID_VIDEO] = {
180 .nbanks = 1,
181 .bank = (struct ab5500_i2c_ranges []) {
182 {
183 .bankid = AB5500_BANK_VDENC,
184 .nranges = 12,
185 .range = (struct ab5500_reg_range[]) {
186 {
187 .first = 0x00,
188 .last = 0x08,
189 .perm = AB5500_PERM_RW,
190 },
191 {
192 .first = 0x09,
193 .last = 0x09,
194 .perm = AB5500_PERM_RO,
195 },
196 {
197 .first = 0x0A,
198 .last = 0x12,
199 .perm = AB5500_PERM_RW,
200 },
201 {
202 .first = 0x15,
203 .last = 0x19,
204 .perm = AB5500_PERM_RW,
205 },
206 {
207 .first = 0x1B,
208 .last = 0x21,
209 .perm = AB5500_PERM_RW,
210 },
211 {
212 .first = 0x27,
213 .last = 0x2C,
214 .perm = AB5500_PERM_RW,
215 },
216 {
217 .first = 0x41,
218 .last = 0x41,
219 .perm = AB5500_PERM_RW,
220 },
221 {
222 .first = 0x45,
223 .last = 0x5B,
224 .perm = AB5500_PERM_RW,
225 },
226 {
227 .first = 0x5D,
228 .last = 0x5D,
229 .perm = AB5500_PERM_RW,
230 },
231 {
232 .first = 0x69,
233 .last = 0x69,
234 .perm = AB5500_PERM_RW,
235 },
236 {
237 .first = 0x6C,
238 .last = 0x6D,
239 .perm = AB5500_PERM_RW,
240 },
241 {
242 .first = 0x80,
243 .last = 0x81,
244 .perm = AB5500_PERM_RW,
245 },
246 },
247 },
248 },
249 },
250 [AB5500_DEVID_REGULATORS] = {
251 .nbanks = 2,
252 .bank = (struct ab5500_i2c_ranges []) {
253 {
254 .bankid = AB5500_BANK_STARTUP,
255 .nranges = 12,
256 .range = (struct ab5500_reg_range[]) {
257 {
258 .first = 0x00,
259 .last = 0x01,
260 .perm = AB5500_PERM_RW,
261 },
262 {
263 .first = 0x1F,
264 .last = 0x1F,
265 .perm = AB5500_PERM_RW,
266 },
267 {
268 .first = 0x2E,
269 .last = 0x2E,
270 .perm = AB5500_PERM_RO,
271 },
272 {
273 .first = 0x2F,
274 .last = 0x30,
275 .perm = AB5500_PERM_RW,
276 },
277 {
278 .first = 0x50,
279 .last = 0x51,
280 .perm = AB5500_PERM_RW,
281 },
282 {
283 .first = 0x60,
284 .last = 0x61,
285 .perm = AB5500_PERM_RW,
286 },
287 {
288 .first = 0x66,
289 .last = 0x8A,
290 .perm = AB5500_PERM_RW,
291 },
292 {
293 .first = 0x8C,
294 .last = 0x96,
295 .perm = AB5500_PERM_RW,
296 },
297 {
298 .first = 0xAA,
299 .last = 0xB4,
300 .perm = AB5500_PERM_RW,
301 },
302 {
303 .first = 0xB7,
304 .last = 0xBF,
305 .perm = AB5500_PERM_RW,
306 },
307 {
308 .first = 0xC1,
309 .last = 0xCA,
310 .perm = AB5500_PERM_RW,
311 },
312 {
313 .first = 0xD3,
314 .last = 0xE0,
315 .perm = AB5500_PERM_RW,
316 },
317 },
318 },
319 {
320 .bankid = AB5500_BANK_SIM_USBSIM,
321 .nranges = 1,
322 .range = (struct ab5500_reg_range[]) {
323 {
324 .first = 0x13,
325 .last = 0x19,
326 .perm = AB5500_PERM_RW,
327 },
328 },
329 },
330 },
331 },
332 [AB5500_DEVID_SIM] = {
333 .nbanks = 1,
334 .bank = (struct ab5500_i2c_ranges []) {
335 {
336 .bankid = AB5500_BANK_SIM_USBSIM,
337 .nranges = 1,
338 .range = (struct ab5500_reg_range[]) {
339 {
340 .first = 0x13,
341 .last = 0x19,
342 .perm = AB5500_PERM_RW,
343 },
344 },
345 },
346 },
347 },
348 [AB5500_DEVID_RTC] = {
349 .nbanks = 1,
350 .bank = (struct ab5500_i2c_ranges []) {
351 {
352 .bankid = AB5500_BANK_RTC,
353 .nranges = 2,
354 .range = (struct ab5500_reg_range[]) {
355 {
356 .first = 0x00,
357 .last = 0x04,
358 .perm = AB5500_PERM_RW,
359 },
360 {
361 .first = 0x06,
362 .last = 0x0C,
363 .perm = AB5500_PERM_RW,
364 },
365 },
366 },
367 },
368 },
369 [AB5500_DEVID_CHARGER] = {
370 .nbanks = 1,
371 .bank = (struct ab5500_i2c_ranges []) {
372 {
373 .bankid = AB5500_BANK_CHG,
374 .nranges = 2,
375 .range = (struct ab5500_reg_range[]) {
376 {
377 .first = 0x11,
378 .last = 0x11,
379 .perm = AB5500_PERM_RO,
380 },
381 {
382 .first = 0x12,
383 .last = 0x1B,
384 .perm = AB5500_PERM_RW,
385 },
386 },
387 },
388 },
389 },
390 [AB5500_DEVID_FUELGAUGE] = {
391 .nbanks = 1,
392 .bank = (struct ab5500_i2c_ranges []) {
393 {
394 .bankid = AB5500_BANK_FG_BATTCOM_ACC,
395 .nranges = 2,
396 .range = (struct ab5500_reg_range[]) {
397 {
398 .first = 0x00,
399 .last = 0x0B,
400 .perm = AB5500_PERM_RO,
401 },
402 {
403 .first = 0x0C,
404 .last = 0x10,
405 .perm = AB5500_PERM_RW,
406 },
407 },
408 },
409 },
410 },
411 [AB5500_DEVID_VIBRATOR] = {
412 .nbanks = 1,
413 .bank = (struct ab5500_i2c_ranges []) {
414 {
415 .bankid = AB5500_BANK_VIBRA,
416 .nranges = 2,
417 .range = (struct ab5500_reg_range[]) {
418 {
419 .first = 0x10,
420 .last = 0x13,
421 .perm = AB5500_PERM_RW,
422 },
423 {
424 .first = 0xFE,
425 .last = 0xFE,
426 .perm = AB5500_PERM_RW,
427 },
428 },
429 },
430 },
431 },
432 [AB5500_DEVID_CODEC] = {
433 .nbanks = 1,
434 .bank = (struct ab5500_i2c_ranges []) {
435 {
436 .bankid = AB5500_BANK_AUDIO_HEADSETUSB,
437 .nranges = 2,
438 .range = (struct ab5500_reg_range[]) {
439 {
440 .first = 0x00,
441 .last = 0x48,
442 .perm = AB5500_PERM_RW,
443 },
444 {
445 .first = 0xEB,
446 .last = 0xFB,
447 .perm = AB5500_PERM_RW,
448 },
449 },
450 },
451 },
452 },
453 [AB5500_DEVID_POWER] = {
454 .nbanks = 2,
455 .bank = (struct ab5500_i2c_ranges []) {
456 {
457 .bankid = AB5500_BANK_STARTUP,
458 .nranges = 1,
459 .range = (struct ab5500_reg_range[]) {
460 {
461 .first = 0x30,
462 .last = 0x30,
463 .perm = AB5500_PERM_RW,
464 },
465 },
466 },
467 {
468 .bankid = AB5500_BANK_VIT_IO_I2C_CLK_TST_OTP,
469 .nranges = 1,
470 .range = (struct ab5500_reg_range[]) {
471 {
472 .first = 0x01,
473 .last = 0x01,
474 .perm = AB5500_PERM_RW,
475 },
476 },
477 },
478 },
479 },
480};
481
482#define AB5500_IRQ(bank, bit) ((bank) * 8 + (bit))
483
484/* I appologize for the resource names beeing a mix of upper case
485 * and lower case but I want them to be exact as the documentation */
486static struct mfd_cell ab5500_devs[AB5500_NUM_DEVICES] = {
487 [AB5500_DEVID_LEDS] = {
488 .name = "ab5500-leds",
489 .id = AB5500_DEVID_LEDS,
490 },
491 [AB5500_DEVID_POWER] = {
492 .name = "ab5500-power",
493 .id = AB5500_DEVID_POWER,
494 },
495 [AB5500_DEVID_REGULATORS] = {
496 .name = "ab5500-regulator",
497 .id = AB5500_DEVID_REGULATORS,
498 },
499 [AB5500_DEVID_SIM] = {
500 .name = "ab5500-sim",
501 .id = AB5500_DEVID_SIM,
502 .num_resources = 1,
503 .resources = (struct resource[]) {
504 {
505 .name = "SIMOFF",
506 .flags = IORESOURCE_IRQ,
507 .start = AB5500_IRQ(2, 0), /*rising*/
508 .end = AB5500_IRQ(2, 1), /*falling*/
509 },
510 },
511 },
512 [AB5500_DEVID_RTC] = {
513 .name = "ab5500-rtc",
514 .id = AB5500_DEVID_RTC,
515 .num_resources = 1,
516 .resources = (struct resource[]) {
517 {
518 .name = "RTC_Alarm",
519 .flags = IORESOURCE_IRQ,
520 .start = AB5500_IRQ(1, 7),
521 .end = AB5500_IRQ(1, 7),
522 }
523 },
524 },
525 [AB5500_DEVID_CHARGER] = {
526 .name = "ab5500-charger",
527 .id = AB5500_DEVID_CHARGER,
528 },
529 [AB5500_DEVID_ADC] = {
530 .name = "ab5500-adc",
531 .id = AB5500_DEVID_ADC,
532 .num_resources = 10,
533 .resources = (struct resource[]) {
534 {
535 .name = "TRIGGER-0",
536 .flags = IORESOURCE_IRQ,
537 .start = AB5500_IRQ(0, 0),
538 .end = AB5500_IRQ(0, 0),
539 },
540 {
541 .name = "TRIGGER-1",
542 .flags = IORESOURCE_IRQ,
543 .start = AB5500_IRQ(0, 1),
544 .end = AB5500_IRQ(0, 1),
545 },
546 {
547 .name = "TRIGGER-2",
548 .flags = IORESOURCE_IRQ,
549 .start = AB5500_IRQ(0, 2),
550 .end = AB5500_IRQ(0, 2),
551 },
552 {
553 .name = "TRIGGER-3",
554 .flags = IORESOURCE_IRQ,
555 .start = AB5500_IRQ(0, 3),
556 .end = AB5500_IRQ(0, 3),
557 },
558 {
559 .name = "TRIGGER-4",
560 .flags = IORESOURCE_IRQ,
561 .start = AB5500_IRQ(0, 4),
562 .end = AB5500_IRQ(0, 4),
563 },
564 {
565 .name = "TRIGGER-5",
566 .flags = IORESOURCE_IRQ,
567 .start = AB5500_IRQ(0, 5),
568 .end = AB5500_IRQ(0, 5),
569 },
570 {
571 .name = "TRIGGER-6",
572 .flags = IORESOURCE_IRQ,
573 .start = AB5500_IRQ(0, 6),
574 .end = AB5500_IRQ(0, 6),
575 },
576 {
577 .name = "TRIGGER-7",
578 .flags = IORESOURCE_IRQ,
579 .start = AB5500_IRQ(0, 7),
580 .end = AB5500_IRQ(0, 7),
581 },
582 {
583 .name = "TRIGGER-VBAT",
584 .flags = IORESOURCE_IRQ,
585 .start = AB5500_IRQ(0, 8),
586 .end = AB5500_IRQ(0, 8),
587 },
588 {
589 .name = "TRIGGER-VBAT-TXON",
590 .flags = IORESOURCE_IRQ,
591 .start = AB5500_IRQ(0, 9),
592 .end = AB5500_IRQ(0, 9),
593 },
594 },
595 },
596 [AB5500_DEVID_FUELGAUGE] = {
597 .name = "ab5500-fuelgauge",
598 .id = AB5500_DEVID_FUELGAUGE,
599 .num_resources = 6,
600 .resources = (struct resource[]) {
601 {
602 .name = "Batt_attach",
603 .flags = IORESOURCE_IRQ,
604 .start = AB5500_IRQ(7, 5),
605 .end = AB5500_IRQ(7, 5),
606 },
607 {
608 .name = "Batt_removal",
609 .flags = IORESOURCE_IRQ,
610 .start = AB5500_IRQ(7, 6),
611 .end = AB5500_IRQ(7, 6),
612 },
613 {
614 .name = "UART_framing",
615 .flags = IORESOURCE_IRQ,
616 .start = AB5500_IRQ(7, 7),
617 .end = AB5500_IRQ(7, 7),
618 },
619 {
620 .name = "UART_overrun",
621 .flags = IORESOURCE_IRQ,
622 .start = AB5500_IRQ(8, 0),
623 .end = AB5500_IRQ(8, 0),
624 },
625 {
626 .name = "UART_Rdy_RX",
627 .flags = IORESOURCE_IRQ,
628 .start = AB5500_IRQ(8, 1),
629 .end = AB5500_IRQ(8, 1),
630 },
631 {
632 .name = "UART_Rdy_TX",
633 .flags = IORESOURCE_IRQ,
634 .start = AB5500_IRQ(8, 2),
635 .end = AB5500_IRQ(8, 2),
636 },
637 },
638 },
639 [AB5500_DEVID_VIBRATOR] = {
640 .name = "ab5500-vibrator",
641 .id = AB5500_DEVID_VIBRATOR,
642 },
643 [AB5500_DEVID_CODEC] = {
644 .name = "ab5500-codec",
645 .id = AB5500_DEVID_CODEC,
646 .num_resources = 3,
647 .resources = (struct resource[]) {
648 {
649 .name = "audio_spkr1_ovc",
650 .flags = IORESOURCE_IRQ,
651 .start = AB5500_IRQ(9, 5),
652 .end = AB5500_IRQ(9, 5),
653 },
654 {
655 .name = "audio_plllocked",
656 .flags = IORESOURCE_IRQ,
657 .start = AB5500_IRQ(9, 6),
658 .end = AB5500_IRQ(9, 6),
659 },
660 {
661 .name = "audio_spkr2_ovc",
662 .flags = IORESOURCE_IRQ,
663 .start = AB5500_IRQ(17, 4),
664 .end = AB5500_IRQ(17, 4),
665 },
666 },
667 },
668 [AB5500_DEVID_USB] = {
669 .name = "ab5500-usb",
670 .id = AB5500_DEVID_USB,
671 .num_resources = 36,
672 .resources = (struct resource[]) {
673 {
674 .name = "Link_Update",
675 .flags = IORESOURCE_IRQ,
676 .start = AB5500_IRQ(22, 1),
677 .end = AB5500_IRQ(22, 1),
678 },
679 {
680 .name = "DCIO",
681 .flags = IORESOURCE_IRQ,
682 .start = AB5500_IRQ(8, 3),
683 .end = AB5500_IRQ(8, 4),
684 },
685 {
686 .name = "VBUS_R",
687 .flags = IORESOURCE_IRQ,
688 .start = AB5500_IRQ(8, 5),
689 .end = AB5500_IRQ(8, 5),
690 },
691 {
692 .name = "VBUS_F",
693 .flags = IORESOURCE_IRQ,
694 .start = AB5500_IRQ(8, 6),
695 .end = AB5500_IRQ(8, 6),
696 },
697 {
698 .name = "CHGstate_10_PCVBUSchg",
699 .flags = IORESOURCE_IRQ,
700 .start = AB5500_IRQ(8, 7),
701 .end = AB5500_IRQ(8, 7),
702 },
703 {
704 .name = "DCIOreverse_ovc",
705 .flags = IORESOURCE_IRQ,
706 .start = AB5500_IRQ(9, 0),
707 .end = AB5500_IRQ(9, 0),
708 },
709 {
710 .name = "USBCharDetDone",
711 .flags = IORESOURCE_IRQ,
712 .start = AB5500_IRQ(9, 1),
713 .end = AB5500_IRQ(9, 1),
714 },
715 {
716 .name = "DCIO_no_limit",
717 .flags = IORESOURCE_IRQ,
718 .start = AB5500_IRQ(9, 2),
719 .end = AB5500_IRQ(9, 2),
720 },
721 {
722 .name = "USB_suspend",
723 .flags = IORESOURCE_IRQ,
724 .start = AB5500_IRQ(9, 3),
725 .end = AB5500_IRQ(9, 3),
726 },
727 {
728 .name = "DCIOreverse_fwdcurrent",
729 .flags = IORESOURCE_IRQ,
730 .start = AB5500_IRQ(9, 4),
731 .end = AB5500_IRQ(9, 4),
732 },
733 {
734 .name = "Vbus_Imeasmax_change",
735 .flags = IORESOURCE_IRQ,
736 .start = AB5500_IRQ(9, 5),
737 .end = AB5500_IRQ(9, 6),
738 },
739 {
740 .name = "OVV",
741 .flags = IORESOURCE_IRQ,
742 .start = AB5500_IRQ(14, 5),
743 .end = AB5500_IRQ(14, 5),
744 },
745 {
746 .name = "USBcharging_NOTok",
747 .flags = IORESOURCE_IRQ,
748 .start = AB5500_IRQ(15, 3),
749 .end = AB5500_IRQ(15, 3),
750 },
751 {
752 .name = "usb_adp_sensoroff",
753 .flags = IORESOURCE_IRQ,
754 .start = AB5500_IRQ(15, 6),
755 .end = AB5500_IRQ(15, 6),
756 },
757 {
758 .name = "usb_adp_probeplug",
759 .flags = IORESOURCE_IRQ,
760 .start = AB5500_IRQ(15, 7),
761 .end = AB5500_IRQ(15, 7),
762 },
763 {
764 .name = "usb_adp_sinkerror",
765 .flags = IORESOURCE_IRQ,
766 .start = AB5500_IRQ(16, 0),
767 .end = AB5500_IRQ(16, 6),
768 },
769 {
770 .name = "usb_adp_sourceerror",
771 .flags = IORESOURCE_IRQ,
772 .start = AB5500_IRQ(16, 1),
773 .end = AB5500_IRQ(16, 1),
774 },
775 {
776 .name = "usb_idgnd_r",
777 .flags = IORESOURCE_IRQ,
778 .start = AB5500_IRQ(16, 2),
779 .end = AB5500_IRQ(16, 2),
780 },
781 {
782 .name = "usb_idgnd_f",
783 .flags = IORESOURCE_IRQ,
784 .start = AB5500_IRQ(16, 3),
785 .end = AB5500_IRQ(16, 3),
786 },
787 {
788 .name = "usb_iddetR1",
789 .flags = IORESOURCE_IRQ,
790 .start = AB5500_IRQ(16, 4),
791 .end = AB5500_IRQ(16, 5),
792 },
793 {
794 .name = "usb_iddetR2",
795 .flags = IORESOURCE_IRQ,
796 .start = AB5500_IRQ(16, 6),
797 .end = AB5500_IRQ(16, 7),
798 },
799 {
800 .name = "usb_iddetR3",
801 .flags = IORESOURCE_IRQ,
802 .start = AB5500_IRQ(17, 0),
803 .end = AB5500_IRQ(17, 1),
804 },
805 {
806 .name = "usb_iddetR4",
807 .flags = IORESOURCE_IRQ,
808 .start = AB5500_IRQ(17, 2),
809 .end = AB5500_IRQ(17, 3),
810 },
811 {
812 .name = "CharTempWindowOk",
813 .flags = IORESOURCE_IRQ,
814 .start = AB5500_IRQ(17, 7),
815 .end = AB5500_IRQ(18, 0),
816 },
817 {
818 .name = "USB_SprDetect",
819 .flags = IORESOURCE_IRQ,
820 .start = AB5500_IRQ(18, 1),
821 .end = AB5500_IRQ(18, 1),
822 },
823 {
824 .name = "usb_adp_probe_unplug",
825 .flags = IORESOURCE_IRQ,
826 .start = AB5500_IRQ(18, 2),
827 .end = AB5500_IRQ(18, 2),
828 },
829 {
830 .name = "VBUSChDrop",
831 .flags = IORESOURCE_IRQ,
832 .start = AB5500_IRQ(18, 3),
833 .end = AB5500_IRQ(18, 4),
834 },
835 {
836 .name = "dcio_char_rec_done",
837 .flags = IORESOURCE_IRQ,
838 .start = AB5500_IRQ(18, 5),
839 .end = AB5500_IRQ(18, 5),
840 },
841 {
842 .name = "Charging_stopped_by_temp",
843 .flags = IORESOURCE_IRQ,
844 .start = AB5500_IRQ(18, 6),
845 .end = AB5500_IRQ(18, 6),
846 },
847 {
848 .name = "CHGstate_11_SafeModeVBUS",
849 .flags = IORESOURCE_IRQ,
850 .start = AB5500_IRQ(21, 1),
851 .end = AB5500_IRQ(21, 2),
852 },
853 {
854 .name = "CHGstate_12_comletedVBUS",
855 .flags = IORESOURCE_IRQ,
856 .start = AB5500_IRQ(21, 2),
857 .end = AB5500_IRQ(21, 2),
858 },
859 {
860 .name = "CHGstate_13_completedVBUS",
861 .flags = IORESOURCE_IRQ,
862 .start = AB5500_IRQ(21, 3),
863 .end = AB5500_IRQ(21, 3),
864 },
865 {
866 .name = "CHGstate_14_FullChgDCIO",
867 .flags = IORESOURCE_IRQ,
868 .start = AB5500_IRQ(21, 4),
869 .end = AB5500_IRQ(21, 4),
870 },
871 {
872 .name = "CHGstate_15_SafeModeDCIO",
873 .flags = IORESOURCE_IRQ,
874 .start = AB5500_IRQ(21, 5),
875 .end = AB5500_IRQ(21, 5),
876 },
877 {
878 .name = "CHGstate_16_OFFsuspendDCIO",
879 .flags = IORESOURCE_IRQ,
880 .start = AB5500_IRQ(21, 6),
881 .end = AB5500_IRQ(21, 6),
882 },
883 {
884 .name = "CHGstate_17_completedDCIO",
885 .flags = IORESOURCE_IRQ,
886 .start = AB5500_IRQ(21, 7),
887 .end = AB5500_IRQ(21, 7),
888 },
889 },
890 },
891 [AB5500_DEVID_OTP] = {
892 .name = "ab5500-otp",
893 .id = AB5500_DEVID_OTP,
894 },
895 [AB5500_DEVID_VIDEO] = {
896 .name = "ab5500-video",
897 .id = AB5500_DEVID_VIDEO,
898 .num_resources = 1,
899 .resources = (struct resource[]) {
900 {
901 .name = "plugTVdet",
902 .flags = IORESOURCE_IRQ,
903 .start = AB5500_IRQ(22, 2),
904 .end = AB5500_IRQ(22, 2),
905 },
906 },
907 },
908 [AB5500_DEVID_DBIECI] = {
909 .name = "ab5500-dbieci",
910 .id = AB5500_DEVID_DBIECI,
911 .num_resources = 10,
912 .resources = (struct resource[]) {
913 {
914 .name = "COLL",
915 .flags = IORESOURCE_IRQ,
916 .start = AB5500_IRQ(14, 0),
917 .end = AB5500_IRQ(14, 0),
918 },
919 {
920 .name = "RESERR",
921 .flags = IORESOURCE_IRQ,
922 .start = AB5500_IRQ(14, 1),
923 .end = AB5500_IRQ(14, 1),
924 },
925 {
926 .name = "FRAERR",
927 .flags = IORESOURCE_IRQ,
928 .start = AB5500_IRQ(14, 2),
929 .end = AB5500_IRQ(14, 2),
930 },
931 {
932 .name = "COMERR",
933 .flags = IORESOURCE_IRQ,
934 .start = AB5500_IRQ(14, 3),
935 .end = AB5500_IRQ(14, 3),
936 },
937 {
938 .name = "BSI_indicator",
939 .flags = IORESOURCE_IRQ,
940 .start = AB5500_IRQ(14, 4),
941 .end = AB5500_IRQ(14, 4),
942 },
943 {
944 .name = "SPDSET",
945 .flags = IORESOURCE_IRQ,
946 .start = AB5500_IRQ(14, 6),
947 .end = AB5500_IRQ(14, 6),
948 },
949 {
950 .name = "DSENT",
951 .flags = IORESOURCE_IRQ,
952 .start = AB5500_IRQ(14, 7),
953 .end = AB5500_IRQ(14, 7),
954 },
955 {
956 .name = "DREC",
957 .flags = IORESOURCE_IRQ,
958 .start = AB5500_IRQ(15, 0),
959 .end = AB5500_IRQ(15, 0),
960 },
961 {
962 .name = "ACCINT",
963 .flags = IORESOURCE_IRQ,
964 .start = AB5500_IRQ(15, 1),
965 .end = AB5500_IRQ(15, 1),
966 },
967 {
968 .name = "NOPINT",
969 .flags = IORESOURCE_IRQ,
970 .start = AB5500_IRQ(15, 2),
971 .end = AB5500_IRQ(15, 2),
972 },
973 },
974 },
975 [AB5500_DEVID_ONSWA] = {
976 .name = "ab5500-onswa",
977 .id = AB5500_DEVID_ONSWA,
978 .num_resources = 2,
979 .resources = (struct resource[]) {
980 {
981 .name = "ONSWAn_rising",
982 .flags = IORESOURCE_IRQ,
983 .start = AB5500_IRQ(1, 3),
984 .end = AB5500_IRQ(1, 3),
985 },
986 {
987 .name = "ONSWAn_falling",
988 .flags = IORESOURCE_IRQ,
989 .start = AB5500_IRQ(1, 4),
990 .end = AB5500_IRQ(1, 4),
991 },
992 },
993 },
994};
995
996/*
997 * Functionality for getting/setting register values.
998 */
999int ab5500_get_register_interruptible_raw(struct ab5500 *ab,
1000 u8 bank, u8 reg,
1001 u8 *value)
1002{
1003 int err;
1004
1005 if (bank >= AB5500_NUM_BANKS)
1006 return -EINVAL;
1007
1008 err = mutex_lock_interruptible(&ab->access_mutex);
1009 if (err)
1010 return err;
1011 err = db5500_prcmu_abb_read(bankinfo[bank].slave_addr, reg, value, 1);
1012
1013 mutex_unlock(&ab->access_mutex);
1014 return err;
1015}
1016
1017static int get_register_page_interruptible(struct ab5500 *ab, u8 bank,
1018 u8 first_reg, u8 *regvals, u8 numregs)
1019{
1020 int err;
1021
1022 if (bank >= AB5500_NUM_BANKS)
1023 return -EINVAL;
1024
1025 err = mutex_lock_interruptible(&ab->access_mutex);
1026 if (err)
1027 return err;
1028
1029 while (numregs) {
1030 /* The hardware limit for get page is 4 */
1031 u8 curnum = min_t(u8, numregs, 4u);
1032
1033 err = db5500_prcmu_abb_read(bankinfo[bank].slave_addr,
1034 first_reg, regvals, curnum);
1035 if (err)
1036 goto out;
1037
1038 numregs -= curnum;
1039 first_reg += curnum;
1040 regvals += curnum;
1041 }
1042
1043out:
1044 mutex_unlock(&ab->access_mutex);
1045 return err;
1046}
1047
1048int ab5500_mask_and_set_register_interruptible_raw(struct ab5500 *ab, u8 bank,
1049 u8 reg, u8 bitmask, u8 bitvalues)
1050{
1051 int err = 0;
1052
1053 if (bank >= AB5500_NUM_BANKS)
1054 return -EINVAL;
1055
1056 if (bitmask) {
1057 u8 buf;
1058
1059 err = mutex_lock_interruptible(&ab->access_mutex);
1060 if (err)
1061 return err;
1062
1063 if (bitmask == 0xFF) /* No need to read in this case. */
1064 buf = bitvalues;
1065 else { /* Read and modify the register value. */
1066 err = db5500_prcmu_abb_read(bankinfo[bank].slave_addr,
1067 reg, &buf, 1);
1068 if (err)
1069 return err;
1070
1071 buf = ((~bitmask & buf) | (bitmask & bitvalues));
1072 }
1073 /* Write the new value. */
1074 err = db5500_prcmu_abb_write(bankinfo[bank].slave_addr, reg,
1075 &buf, 1);
1076
1077 mutex_unlock(&ab->access_mutex);
1078 }
1079 return err;
1080}
1081
1082static int
1083set_register_interruptible(struct ab5500 *ab, u8 bank, u8 reg, u8 value)
1084{
1085 return ab5500_mask_and_set_register_interruptible_raw(ab, bank, reg,
1086 0xff, value);
1087}
1088
1089/*
1090 * Read/write permission checking functions.
1091 */
1092static const struct ab5500_i2c_ranges *get_bankref(u8 devid, u8 bank)
1093{
1094 u8 i;
1095
1096 if (devid < AB5500_NUM_DEVICES) {
1097 for (i = 0; i < ab5500_bank_ranges[devid].nbanks; i++) {
1098 if (ab5500_bank_ranges[devid].bank[i].bankid == bank)
1099 return &ab5500_bank_ranges[devid].bank[i];
1100 }
1101 }
1102 return NULL;
1103}
1104
1105static bool page_write_allowed(u8 devid, u8 bank, u8 first_reg, u8 last_reg)
1106{
1107 u8 i; /* range loop index */
1108 const struct ab5500_i2c_ranges *bankref;
1109
1110 bankref = get_bankref(devid, bank);
1111 if (bankref == NULL || last_reg < first_reg)
1112 return false;
1113
1114 for (i = 0; i < bankref->nranges; i++) {
1115 if (first_reg < bankref->range[i].first)
1116 break;
1117 if ((last_reg <= bankref->range[i].last) &&
1118 (bankref->range[i].perm & AB5500_PERM_WR))
1119 return true;
1120 }
1121 return false;
1122}
1123
1124static bool reg_write_allowed(u8 devid, u8 bank, u8 reg)
1125{
1126 return page_write_allowed(devid, bank, reg, reg);
1127}
1128
1129static bool page_read_allowed(u8 devid, u8 bank, u8 first_reg, u8 last_reg)
1130{
1131 u8 i;
1132 const struct ab5500_i2c_ranges *bankref;
1133
1134 bankref = get_bankref(devid, bank);
1135 if (bankref == NULL || last_reg < first_reg)
1136 return false;
1137
1138
1139 /* Find the range (if it exists in the list) that includes first_reg. */
1140 for (i = 0; i < bankref->nranges; i++) {
1141 if (first_reg < bankref->range[i].first)
1142 return false;
1143 if (first_reg <= bankref->range[i].last)
1144 break;
1145 }
1146 /* Make sure that the entire range up to and including last_reg is
1147 * readable. This may span several of the ranges in the list.
1148 */
1149 while ((i < bankref->nranges) &&
1150 (bankref->range[i].perm & AB5500_PERM_RD)) {
1151 if (last_reg <= bankref->range[i].last)
1152 return true;
1153 if ((++i >= bankref->nranges) ||
1154 (bankref->range[i].first !=
1155 (bankref->range[i - 1].last + 1))) {
1156 break;
1157 }
1158 }
1159 return false;
1160}
1161
1162static bool reg_read_allowed(u8 devid, u8 bank, u8 reg)
1163{
1164 return page_read_allowed(devid, bank, reg, reg);
1165}
1166
1167
1168/*
1169 * The exported register access functionality.
1170 */
1171static int ab5500_get_chip_id(struct device *dev)
1172{
1173 struct ab5500 *ab = dev_get_drvdata(dev->parent);
1174
1175 return (int)ab->chip_id;
1176}
1177
1178static int ab5500_mask_and_set_register_interruptible(struct device *dev,
1179 u8 bank, u8 reg, u8 bitmask, u8 bitvalues)
1180{
1181 struct ab5500 *ab;
1182 struct platform_device *pdev = to_platform_device(dev);
1183
1184 if ((AB5500_NUM_BANKS <= bank) ||
1185 !reg_write_allowed(pdev->id, bank, reg))
1186 return -EINVAL;
1187
1188 ab = dev_get_drvdata(dev->parent);
1189 return ab5500_mask_and_set_register_interruptible_raw(ab, bank, reg,
1190 bitmask, bitvalues);
1191}
1192
1193static int ab5500_set_register_interruptible(struct device *dev, u8 bank,
1194 u8 reg, u8 value)
1195{
1196 return ab5500_mask_and_set_register_interruptible(dev, bank, reg, 0xFF,
1197 value);
1198}
1199
1200static int ab5500_get_register_interruptible(struct device *dev, u8 bank,
1201 u8 reg, u8 *value)
1202{
1203 struct ab5500 *ab;
1204 struct platform_device *pdev = to_platform_device(dev);
1205
1206 if ((AB5500_NUM_BANKS <= bank) ||
1207 !reg_read_allowed(pdev->id, bank, reg))
1208 return -EINVAL;
1209
1210 ab = dev_get_drvdata(dev->parent);
1211 return ab5500_get_register_interruptible_raw(ab, bank, reg, value);
1212}
1213
1214static int ab5500_get_register_page_interruptible(struct device *dev, u8 bank,
1215 u8 first_reg, u8 *regvals, u8 numregs)
1216{
1217 struct ab5500 *ab;
1218 struct platform_device *pdev = to_platform_device(dev);
1219
1220 if ((AB5500_NUM_BANKS <= bank) ||
1221 !page_read_allowed(pdev->id, bank,
1222 first_reg, (first_reg + numregs - 1)))
1223 return -EINVAL;
1224
1225 ab = dev_get_drvdata(dev->parent);
1226 return get_register_page_interruptible(ab, bank, first_reg, regvals,
1227 numregs);
1228}
1229
1230static int
1231ab5500_event_registers_startup_state_get(struct device *dev, u8 *event)
1232{
1233 struct ab5500 *ab;
1234
1235 ab = dev_get_drvdata(dev->parent);
1236 if (!ab->startup_events_read)
1237 return -EAGAIN; /* Try again later */
1238
1239 memcpy(event, ab->startup_events, AB5500_NUM_EVENT_REG);
1240 return 0;
1241}
1242
1243static struct abx500_ops ab5500_ops = {
1244 .get_chip_id = ab5500_get_chip_id,
1245 .get_register = ab5500_get_register_interruptible,
1246 .set_register = ab5500_set_register_interruptible,
1247 .get_register_page = ab5500_get_register_page_interruptible,
1248 .set_register_page = NULL,
1249 .mask_and_set_register = ab5500_mask_and_set_register_interruptible,
1250 .event_registers_startup_state_get =
1251 ab5500_event_registers_startup_state_get,
1252 .startup_irq_enabled = NULL,
1253};
1254
1255/*
1256 * ab5500_setup : Basic set-up, datastructure creation/destruction
1257 * and I2C interface.This sets up a default config
1258 * in the AB5500 chip so that it will work as expected.
1259 * @ab : Pointer to ab5500 structure
1260 * @settings : Pointer to struct abx500_init_settings
1261 * @size : Size of init data
1262 */
1263static int __init ab5500_setup(struct ab5500 *ab,
1264 struct abx500_init_settings *settings, unsigned int size)
1265{
1266 int err = 0;
1267 int i;
1268
1269 for (i = 0; i < size; i++) {
1270 err = ab5500_mask_and_set_register_interruptible_raw(ab,
1271 settings[i].bank,
1272 settings[i].reg,
1273 0xFF, settings[i].setting);
1274 if (err)
1275 goto exit_no_setup;
1276
1277 /* If event mask register update the event mask in ab5500 */
1278 if ((settings[i].bank == AB5500_BANK_IT) &&
1279 (AB5500_MASK_BASE <= settings[i].reg) &&
1280 (settings[i].reg <= AB5500_MASK_END)) {
1281 ab->mask[settings[i].reg - AB5500_MASK_BASE] =
1282 settings[i].setting;
1283 }
1284 }
1285exit_no_setup:
1286 return err;
1287}
1288
1289struct ab_family_id {
1290 u8 id;
1291 char *name;
1292};
1293
1294static const struct ab_family_id ids[] __initdata = {
1295 /* AB5500 */
1296 {
1297 .id = AB5500_1_0,
1298 .name = "1.0"
1299 },
1300 {
1301 .id = AB5500_1_1,
1302 .name = "1.1"
1303 },
1304 /* Terminator */
1305 {
1306 .id = 0x00,
1307 }
1308};
1309
1310static int __init ab5500_probe(struct platform_device *pdev)
1311{
1312 struct ab5500 *ab;
1313 struct ab5500_platform_data *ab5500_plf_data =
1314 pdev->dev.platform_data;
1315 int err;
1316 int i;
1317
1318 ab = kzalloc(sizeof(struct ab5500), GFP_KERNEL);
1319 if (!ab) {
1320 dev_err(&pdev->dev,
1321 "could not allocate ab5500 device\n");
1322 return -ENOMEM;
1323 }
1324
1325 /* Initialize data structure */
1326 mutex_init(&ab->access_mutex);
1327 mutex_init(&ab->irq_lock);
1328 ab->dev = &pdev->dev;
1329
1330 platform_set_drvdata(pdev, ab);
1331
1332 /* Read chip ID register */
1333 err = ab5500_get_register_interruptible_raw(ab,
1334 AB5500_BANK_VIT_IO_I2C_CLK_TST_OTP,
1335 AB5500_CHIP_ID, &ab->chip_id);
1336 if (err) {
1337 dev_err(&pdev->dev, "could not communicate with the analog "
1338 "baseband chip\n");
1339 goto exit_no_detect;
1340 }
1341
1342 for (i = 0; ids[i].id != 0x0; i++) {
1343 if (ids[i].id == ab->chip_id) {
1344 snprintf(&ab->chip_name[0], sizeof(ab->chip_name) - 1,
1345 "AB5500 %s", ids[i].name);
1346 break;
1347 }
1348 }
1349 if (ids[i].id == 0x0) {
1350 dev_err(&pdev->dev, "unknown analog baseband chip id: 0x%x\n",
1351 ab->chip_id);
1352 dev_err(&pdev->dev, "driver not started!\n");
1353 goto exit_no_detect;
1354 }
1355
1356 /* Clear and mask all interrupts */
1357 for (i = 0; i < AB5500_NUM_IRQ_REGS; i++) {
1358 u8 latchreg = AB5500_IT_LATCH0_REG + i;
1359 u8 maskreg = AB5500_IT_MASK0_REG + i;
1360 u8 val;
1361
1362 ab5500_get_register_interruptible_raw(ab, AB5500_BANK_IT,
1363 latchreg, &val);
1364 set_register_interruptible(ab, AB5500_BANK_IT, maskreg, 0xff);
1365 ab->mask[i] = ab->oldmask[i] = 0xff;
1366 }
1367
1368 err = abx500_register_ops(&pdev->dev, &ab5500_ops);
1369 if (err) {
1370 dev_err(&pdev->dev, "ab5500_register ops error\n");
1371 goto exit_no_detect;
1372 }
1373
1374 /* Set up and register the platform devices. */
1375 for (i = 0; i < AB5500_NUM_DEVICES; i++) {
1376 ab5500_devs[i].platform_data = ab5500_plf_data->dev_data[i];
1377 ab5500_devs[i].pdata_size =
1378 sizeof(ab5500_plf_data->dev_data[i]);
1379 }
1380
1381 err = mfd_add_devices(&pdev->dev, 0, ab5500_devs,
1382 ARRAY_SIZE(ab5500_devs), NULL,
1383 ab5500_plf_data->irq.base);
1384 if (err) {
1385 dev_err(&pdev->dev, "ab5500_mfd_add_device error\n");
1386 goto exit_no_detect;
1387 }
1388
1389 err = ab5500_setup(ab, ab5500_plf_data->init_settings,
1390 ab5500_plf_data->init_settings_sz);
1391 if (err) {
1392 dev_err(&pdev->dev, "ab5500_setup error\n");
1393 goto exit_no_detect;
1394 }
1395
1396 ab5500_setup_debugfs(ab);
1397
1398 dev_info(&pdev->dev, "detected AB chip: %s\n", &ab->chip_name[0]);
1399 return 0;
1400
1401exit_no_detect:
1402 kfree(ab);
1403 return err;
1404}
1405
1406static int __exit ab5500_remove(struct platform_device *pdev)
1407{
1408 struct ab5500 *ab = platform_get_drvdata(pdev);
1409
1410 ab5500_remove_debugfs();
1411 mfd_remove_devices(&pdev->dev);
1412 kfree(ab);
1413 return 0;
1414}
1415
1416static struct platform_driver ab5500_driver = {
1417 .driver = {
1418 .name = "ab5500-core",
1419 .owner = THIS_MODULE,
1420 },
1421 .remove = __exit_p(ab5500_remove),
1422};
1423
1424static int __init ab5500_core_init(void)
1425{
1426 return platform_driver_probe(&ab5500_driver, ab5500_probe);
1427}
1428
1429static void __exit ab5500_core_exit(void)
1430{
1431 platform_driver_unregister(&ab5500_driver);
1432}
1433
1434subsys_initcall(ab5500_core_init);
1435module_exit(ab5500_core_exit);
1436
1437MODULE_AUTHOR("Mattias Wallin <mattias.wallin@stericsson.com>");
1438MODULE_DESCRIPTION("AB5500 core driver");
1439MODULE_LICENSE("GPL");
diff --git a/drivers/mfd/ab5500-core.h b/drivers/mfd/ab5500-core.h
new file mode 100644
index 000000000000..63b30b17e4f3
--- /dev/null
+++ b/drivers/mfd/ab5500-core.h
@@ -0,0 +1,87 @@
1/*
2 * Copyright (C) 2011 ST-Ericsson
3 * License terms: GNU General Public License (GPL) version 2
4 * Shared definitions and data structures for the AB5500 MFD driver
5 */
6
7/* Read/write operation values. */
8#define AB5500_PERM_RD (0x01)
9#define AB5500_PERM_WR (0x02)
10
11/* Read/write permissions. */
12#define AB5500_PERM_RO (AB5500_PERM_RD)
13#define AB5500_PERM_RW (AB5500_PERM_RD | AB5500_PERM_WR)
14
15#define AB5500_MASK_BASE (0x60)
16#define AB5500_MASK_END (0x79)
17#define AB5500_CHIP_ID (0x20)
18
19/**
20 * struct ab5500_reg_range
21 * @first: the first address of the range
22 * @last: the last address of the range
23 * @perm: access permissions for the range
24 */
25struct ab5500_reg_range {
26 u8 first;
27 u8 last;
28 u8 perm;
29};
30
31/**
32 * struct ab5500_i2c_ranges
33 * @count: the number of ranges in the list
34 * @range: the list of register ranges
35 */
36struct ab5500_i2c_ranges {
37 u8 nranges;
38 u8 bankid;
39 const struct ab5500_reg_range *range;
40};
41
42/**
43 * struct ab5500_i2c_banks
44 * @count: the number of ranges in the list
45 * @range: the list of register ranges
46 */
47struct ab5500_i2c_banks {
48 u8 nbanks;
49 const struct ab5500_i2c_ranges *bank;
50};
51
52/**
53 * struct ab5500_bank
54 * @slave_addr: I2C slave_addr found in AB5500 specification
55 * @name: Documentation name of the bank. For reference
56 */
57struct ab5500_bank {
58 u8 slave_addr;
59 const char *name;
60};
61
62static const struct ab5500_bank bankinfo[AB5500_NUM_BANKS] = {
63 [AB5500_BANK_VIT_IO_I2C_CLK_TST_OTP] = {
64 AB5500_ADDR_VIT_IO_I2C_CLK_TST_OTP, "VIT_IO_I2C_CLK_TST_OTP"},
65 [AB5500_BANK_VDDDIG_IO_I2C_CLK_TST] = {
66 AB5500_ADDR_VDDDIG_IO_I2C_CLK_TST, "VDDDIG_IO_I2C_CLK_TST"},
67 [AB5500_BANK_VDENC] = {AB5500_ADDR_VDENC, "VDENC"},
68 [AB5500_BANK_SIM_USBSIM] = {AB5500_ADDR_SIM_USBSIM, "SIM_USBSIM"},
69 [AB5500_BANK_LED] = {AB5500_ADDR_LED, "LED"},
70 [AB5500_BANK_ADC] = {AB5500_ADDR_ADC, "ADC"},
71 [AB5500_BANK_RTC] = {AB5500_ADDR_RTC, "RTC"},
72 [AB5500_BANK_STARTUP] = {AB5500_ADDR_STARTUP, "STARTUP"},
73 [AB5500_BANK_DBI_ECI] = {AB5500_ADDR_DBI_ECI, "DBI-ECI"},
74 [AB5500_BANK_CHG] = {AB5500_ADDR_CHG, "CHG"},
75 [AB5500_BANK_FG_BATTCOM_ACC] = {
76 AB5500_ADDR_FG_BATTCOM_ACC, "FG_BATCOM_ACC"},
77 [AB5500_BANK_USB] = {AB5500_ADDR_USB, "USB"},
78 [AB5500_BANK_IT] = {AB5500_ADDR_IT, "IT"},
79 [AB5500_BANK_VIBRA] = {AB5500_ADDR_VIBRA, "VIBRA"},
80 [AB5500_BANK_AUDIO_HEADSETUSB] = {
81 AB5500_ADDR_AUDIO_HEADSETUSB, "AUDIO_HEADSETUSB"},
82};
83
84int ab5500_get_register_interruptible_raw(struct ab5500 *ab, u8 bank, u8 reg,
85 u8 *value);
86int ab5500_mask_and_set_register_interruptible_raw(struct ab5500 *ab, u8 bank,
87 u8 reg, u8 bitmask, u8 bitvalues);
diff --git a/drivers/mfd/ab5500-debugfs.c b/drivers/mfd/ab5500-debugfs.c
new file mode 100644
index 000000000000..6be1fe6b5f9a
--- /dev/null
+++ b/drivers/mfd/ab5500-debugfs.c
@@ -0,0 +1,806 @@
1/*
2 * Copyright (C) 2011 ST-Ericsson
3 * License terms: GNU General Public License (GPL) version 2
4 * Debugfs support for the AB5500 MFD driver
5 */
6
7#include <linux/debugfs.h>
8#include <linux/seq_file.h>
9#include <linux/mfd/ab5500/ab5500.h>
10#include <linux/mfd/abx500.h>
11#include <linux/uaccess.h>
12
13#include "ab5500-core.h"
14#include "ab5500-debugfs.h"
15
16static struct ab5500_i2c_ranges ab5500_reg_ranges[AB5500_NUM_BANKS] = {
17 [AB5500_BANK_LED] = {
18 .bankid = AB5500_BANK_LED,
19 .nranges = 1,
20 .range = (struct ab5500_reg_range[]) {
21 {
22 .first = 0x00,
23 .last = 0x0C,
24 .perm = AB5500_PERM_RW,
25 },
26 },
27 },
28 [AB5500_BANK_ADC] = {
29 .bankid = AB5500_BANK_ADC,
30 .nranges = 6,
31 .range = (struct ab5500_reg_range[]) {
32 {
33 .first = 0x1F,
34 .last = 0x22,
35 .perm = AB5500_PERM_RO,
36 },
37 {
38 .first = 0x23,
39 .last = 0x24,
40 .perm = AB5500_PERM_RW,
41 },
42 {
43 .first = 0x26,
44 .last = 0x2D,
45 .perm = AB5500_PERM_RO,
46 },
47 {
48 .first = 0x2F,
49 .last = 0x34,
50 .perm = AB5500_PERM_RW,
51 },
52 {
53 .first = 0x37,
54 .last = 0x57,
55 .perm = AB5500_PERM_RW,
56 },
57 {
58 .first = 0x58,
59 .last = 0x58,
60 .perm = AB5500_PERM_RO,
61 },
62 },
63 },
64 [AB5500_BANK_RTC] = {
65 .bankid = AB5500_BANK_RTC,
66 .nranges = 2,
67 .range = (struct ab5500_reg_range[]) {
68 {
69 .first = 0x00,
70 .last = 0x04,
71 .perm = AB5500_PERM_RW,
72 },
73 {
74 .first = 0x06,
75 .last = 0x0C,
76 .perm = AB5500_PERM_RW,
77 },
78 },
79 },
80 [AB5500_BANK_STARTUP] = {
81 .bankid = AB5500_BANK_STARTUP,
82 .nranges = 12,
83 .range = (struct ab5500_reg_range[]) {
84 {
85 .first = 0x00,
86 .last = 0x01,
87 .perm = AB5500_PERM_RW,
88 },
89 {
90 .first = 0x1F,
91 .last = 0x1F,
92 .perm = AB5500_PERM_RW,
93 },
94 {
95 .first = 0x2E,
96 .last = 0x2E,
97 .perm = AB5500_PERM_RO,
98 },
99 {
100 .first = 0x2F,
101 .last = 0x30,
102 .perm = AB5500_PERM_RW,
103 },
104 {
105 .first = 0x50,
106 .last = 0x51,
107 .perm = AB5500_PERM_RW,
108 },
109 {
110 .first = 0x60,
111 .last = 0x61,
112 .perm = AB5500_PERM_RW,
113 },
114 {
115 .first = 0x66,
116 .last = 0x8A,
117 .perm = AB5500_PERM_RW,
118 },
119 {
120 .first = 0x8C,
121 .last = 0x96,
122 .perm = AB5500_PERM_RW,
123 },
124 {
125 .first = 0xAA,
126 .last = 0xB4,
127 .perm = AB5500_PERM_RW,
128 },
129 {
130 .first = 0xB7,
131 .last = 0xBF,
132 .perm = AB5500_PERM_RW,
133 },
134 {
135 .first = 0xC1,
136 .last = 0xCA,
137 .perm = AB5500_PERM_RW,
138 },
139 {
140 .first = 0xD3,
141 .last = 0xE0,
142 .perm = AB5500_PERM_RW,
143 },
144 },
145 },
146 [AB5500_BANK_DBI_ECI] = {
147 .bankid = AB5500_BANK_DBI_ECI,
148 .nranges = 3,
149 .range = (struct ab5500_reg_range[]) {
150 {
151 .first = 0x00,
152 .last = 0x07,
153 .perm = AB5500_PERM_RW,
154 },
155 {
156 .first = 0x10,
157 .last = 0x10,
158 .perm = AB5500_PERM_RW,
159 },
160 {
161 .first = 0x13,
162 .last = 0x13,
163 .perm = AB5500_PERM_RW,
164 },
165 },
166 },
167 [AB5500_BANK_CHG] = {
168 .bankid = AB5500_BANK_CHG,
169 .nranges = 2,
170 .range = (struct ab5500_reg_range[]) {
171 {
172 .first = 0x11,
173 .last = 0x11,
174 .perm = AB5500_PERM_RO,
175 },
176 {
177 .first = 0x12,
178 .last = 0x1B,
179 .perm = AB5500_PERM_RW,
180 },
181 },
182 },
183 [AB5500_BANK_FG_BATTCOM_ACC] = {
184 .bankid = AB5500_BANK_FG_BATTCOM_ACC,
185 .nranges = 2,
186 .range = (struct ab5500_reg_range[]) {
187 {
188 .first = 0x00,
189 .last = 0x0B,
190 .perm = AB5500_PERM_RO,
191 },
192 {
193 .first = 0x0C,
194 .last = 0x10,
195 .perm = AB5500_PERM_RW,
196 },
197 },
198 },
199 [AB5500_BANK_USB] = {
200 .bankid = AB5500_BANK_USB,
201 .nranges = 12,
202 .range = (struct ab5500_reg_range[]) {
203 {
204 .first = 0x01,
205 .last = 0x01,
206 .perm = AB5500_PERM_RW,
207 },
208 {
209 .first = 0x80,
210 .last = 0x83,
211 .perm = AB5500_PERM_RW,
212 },
213 {
214 .first = 0x87,
215 .last = 0x8A,
216 .perm = AB5500_PERM_RW,
217 },
218 {
219 .first = 0x8B,
220 .last = 0x8B,
221 .perm = AB5500_PERM_RO,
222 },
223 {
224 .first = 0x91,
225 .last = 0x92,
226 .perm = AB5500_PERM_RO,
227 },
228 {
229 .first = 0x93,
230 .last = 0x93,
231 .perm = AB5500_PERM_RW,
232 },
233 {
234 .first = 0x94,
235 .last = 0x94,
236 .perm = AB5500_PERM_RO,
237 },
238 {
239 .first = 0xA8,
240 .last = 0xB0,
241 .perm = AB5500_PERM_RO,
242 },
243 {
244 .first = 0xB2,
245 .last = 0xB2,
246 .perm = AB5500_PERM_RO,
247 },
248 {
249 .first = 0xB4,
250 .last = 0xBC,
251 .perm = AB5500_PERM_RO,
252 },
253 {
254 .first = 0xBF,
255 .last = 0xBF,
256 .perm = AB5500_PERM_RO,
257 },
258 {
259 .first = 0xC1,
260 .last = 0xC5,
261 .perm = AB5500_PERM_RO,
262 },
263 },
264 },
265 [AB5500_BANK_IT] = {
266 .bankid = AB5500_BANK_IT,
267 .nranges = 4,
268 .range = (struct ab5500_reg_range[]) {
269 {
270 .first = 0x00,
271 .last = 0x02,
272 .perm = AB5500_PERM_RO,
273 },
274 {
275 .first = 0x20,
276 .last = 0x36,
277 .perm = AB5500_PERM_RO,
278 },
279 {
280 .first = 0x40,
281 .last = 0x56,
282 .perm = AB5500_PERM_RO,
283 },
284 {
285 .first = 0x60,
286 .last = 0x76,
287 .perm = AB5500_PERM_RO,
288 },
289 },
290 },
291 [AB5500_BANK_VDDDIG_IO_I2C_CLK_TST] = {
292 .bankid = AB5500_BANK_VDDDIG_IO_I2C_CLK_TST,
293 .nranges = 7,
294 .range = (struct ab5500_reg_range[]) {
295 {
296 .first = 0x02,
297 .last = 0x02,
298 .perm = AB5500_PERM_RW,
299 },
300 {
301 .first = 0x12,
302 .last = 0x12,
303 .perm = AB5500_PERM_RW,
304 },
305 {
306 .first = 0x30,
307 .last = 0x34,
308 .perm = AB5500_PERM_RW,
309 },
310 {
311 .first = 0x40,
312 .last = 0x44,
313 .perm = AB5500_PERM_RW,
314 },
315 {
316 .first = 0x50,
317 .last = 0x54,
318 .perm = AB5500_PERM_RW,
319 },
320 {
321 .first = 0x60,
322 .last = 0x64,
323 .perm = AB5500_PERM_RW,
324 },
325 {
326 .first = 0x70,
327 .last = 0x74,
328 .perm = AB5500_PERM_RW,
329 },
330 },
331 },
332 [AB5500_BANK_VIT_IO_I2C_CLK_TST_OTP] = {
333 .bankid = AB5500_BANK_VIT_IO_I2C_CLK_TST_OTP,
334 .nranges = 13,
335 .range = (struct ab5500_reg_range[]) {
336 {
337 .first = 0x01,
338 .last = 0x01,
339 .perm = AB5500_PERM_RW,
340 },
341 {
342 .first = 0x02,
343 .last = 0x02,
344 .perm = AB5500_PERM_RO,
345 },
346 {
347 .first = 0x0D,
348 .last = 0x0F,
349 .perm = AB5500_PERM_RW,
350 },
351 {
352 .first = 0x1C,
353 .last = 0x1C,
354 .perm = AB5500_PERM_RW,
355 },
356 {
357 .first = 0x1E,
358 .last = 0x1E,
359 .perm = AB5500_PERM_RW,
360 },
361 {
362 .first = 0x20,
363 .last = 0x21,
364 .perm = AB5500_PERM_RW,
365 },
366 {
367 .first = 0x25,
368 .last = 0x25,
369 .perm = AB5500_PERM_RW,
370 },
371 {
372 .first = 0x28,
373 .last = 0x2A,
374 .perm = AB5500_PERM_RW,
375 },
376 {
377 .first = 0x30,
378 .last = 0x33,
379 .perm = AB5500_PERM_RW,
380 },
381 {
382 .first = 0x40,
383 .last = 0x43,
384 .perm = AB5500_PERM_RW,
385 },
386 {
387 .first = 0x50,
388 .last = 0x53,
389 .perm = AB5500_PERM_RW,
390 },
391 {
392 .first = 0x60,
393 .last = 0x63,
394 .perm = AB5500_PERM_RW,
395 },
396 {
397 .first = 0x70,
398 .last = 0x73,
399 .perm = AB5500_PERM_RW,
400 },
401 },
402 },
403 [AB5500_BANK_VIBRA] = {
404 .bankid = AB5500_BANK_VIBRA,
405 .nranges = 2,
406 .range = (struct ab5500_reg_range[]) {
407 {
408 .first = 0x10,
409 .last = 0x13,
410 .perm = AB5500_PERM_RW,
411 },
412 {
413 .first = 0xFE,
414 .last = 0xFE,
415 .perm = AB5500_PERM_RW,
416 },
417 },
418 },
419 [AB5500_BANK_AUDIO_HEADSETUSB] = {
420 .bankid = AB5500_BANK_AUDIO_HEADSETUSB,
421 .nranges = 2,
422 .range = (struct ab5500_reg_range[]) {
423 {
424 .first = 0x00,
425 .last = 0x48,
426 .perm = AB5500_PERM_RW,
427 },
428 {
429 .first = 0xEB,
430 .last = 0xFB,
431 .perm = AB5500_PERM_RW,
432 },
433 },
434 },
435 [AB5500_BANK_SIM_USBSIM] = {
436 .bankid = AB5500_BANK_SIM_USBSIM,
437 .nranges = 1,
438 .range = (struct ab5500_reg_range[]) {
439 {
440 .first = 0x13,
441 .last = 0x19,
442 .perm = AB5500_PERM_RW,
443 },
444 },
445 },
446 [AB5500_BANK_VDENC] = {
447 .bankid = AB5500_BANK_VDENC,
448 .nranges = 12,
449 .range = (struct ab5500_reg_range[]) {
450 {
451 .first = 0x00,
452 .last = 0x08,
453 .perm = AB5500_PERM_RW,
454 },
455 {
456 .first = 0x09,
457 .last = 0x09,
458 .perm = AB5500_PERM_RO,
459 },
460 {
461 .first = 0x0A,
462 .last = 0x12,
463 .perm = AB5500_PERM_RW,
464 },
465 {
466 .first = 0x15,
467 .last = 0x19,
468 .perm = AB5500_PERM_RW,
469 },
470 {
471 .first = 0x1B,
472 .last = 0x21,
473 .perm = AB5500_PERM_RW,
474 },
475 {
476 .first = 0x27,
477 .last = 0x2C,
478 .perm = AB5500_PERM_RW,
479 },
480 {
481 .first = 0x41,
482 .last = 0x41,
483 .perm = AB5500_PERM_RW,
484 },
485 {
486 .first = 0x45,
487 .last = 0x5B,
488 .perm = AB5500_PERM_RW,
489 },
490 {
491 .first = 0x5D,
492 .last = 0x5D,
493 .perm = AB5500_PERM_RW,
494 },
495 {
496 .first = 0x69,
497 .last = 0x69,
498 .perm = AB5500_PERM_RW,
499 },
500 {
501 .first = 0x6C,
502 .last = 0x6D,
503 .perm = AB5500_PERM_RW,
504 },
505 {
506 .first = 0x80,
507 .last = 0x81,
508 .perm = AB5500_PERM_RW,
509 },
510 },
511 },
512};
513
514static int ab5500_registers_print(struct seq_file *s, void *p)
515{
516 struct ab5500 *ab = s->private;
517 unsigned int i;
518 u8 bank = (u8)ab->debug_bank;
519
520 seq_printf(s, "ab5500 register values:\n");
521 for (bank = 0; bank < AB5500_NUM_BANKS; bank++) {
522 seq_printf(s, " bank %u, %s (0x%x):\n", bank,
523 bankinfo[bank].name,
524 bankinfo[bank].slave_addr);
525 for (i = 0; i < ab5500_reg_ranges[bank].nranges; i++) {
526 u8 reg;
527 int err;
528
529 for (reg = ab5500_reg_ranges[bank].range[i].first;
530 reg <= ab5500_reg_ranges[bank].range[i].last;
531 reg++) {
532 u8 value;
533
534 err = ab5500_get_register_interruptible_raw(ab,
535 bank, reg,
536 &value);
537 if (err < 0) {
538 dev_err(ab->dev, "get_reg failed %d"
539 "bank 0x%x reg 0x%x\n",
540 err, bank, reg);
541 return err;
542 }
543
544 err = seq_printf(s, "[%d/0x%02X]: 0x%02X\n",
545 bank, reg, value);
546 if (err < 0) {
547 dev_err(ab->dev,
548 "seq_printf overflow\n");
549 /*
550 * Error is not returned here since
551 * the output is wanted in any case
552 */
553 return 0;
554 }
555 }
556 }
557 }
558 return 0;
559}
560
561static int ab5500_registers_open(struct inode *inode, struct file *file)
562{
563 return single_open(file, ab5500_registers_print, inode->i_private);
564}
565
566static const struct file_operations ab5500_registers_fops = {
567 .open = ab5500_registers_open,
568 .read = seq_read,
569 .llseek = seq_lseek,
570 .release = single_release,
571 .owner = THIS_MODULE,
572};
573
574static int ab5500_bank_print(struct seq_file *s, void *p)
575{
576 struct ab5500 *ab = s->private;
577
578 seq_printf(s, "%d\n", ab->debug_bank);
579 return 0;
580}
581
582static int ab5500_bank_open(struct inode *inode, struct file *file)
583{
584 return single_open(file, ab5500_bank_print, inode->i_private);
585}
586
587static ssize_t ab5500_bank_write(struct file *file,
588 const char __user *user_buf,
589 size_t count, loff_t *ppos)
590{
591 struct ab5500 *ab = ((struct seq_file *)(file->private_data))->private;
592 char buf[32];
593 int buf_size;
594 unsigned long user_bank;
595 int err;
596
597 /* Get userspace string and assure termination */
598 buf_size = min(count, (sizeof(buf) - 1));
599 if (copy_from_user(buf, user_buf, buf_size))
600 return -EFAULT;
601 buf[buf_size] = 0;
602
603 err = strict_strtoul(buf, 0, &user_bank);
604 if (err)
605 return -EINVAL;
606
607 if (user_bank >= AB5500_NUM_BANKS) {
608 dev_err(ab->dev,
609 "debugfs error input > number of banks\n");
610 return -EINVAL;
611 }
612
613 ab->debug_bank = user_bank;
614
615 return buf_size;
616}
617
618static int ab5500_address_print(struct seq_file *s, void *p)
619{
620 struct ab5500 *ab = s->private;
621
622 seq_printf(s, "0x%02X\n", ab->debug_address);
623 return 0;
624}
625
626static int ab5500_address_open(struct inode *inode, struct file *file)
627{
628 return single_open(file, ab5500_address_print, inode->i_private);
629}
630
631static ssize_t ab5500_address_write(struct file *file,
632 const char __user *user_buf,
633 size_t count, loff_t *ppos)
634{
635 struct ab5500 *ab = ((struct seq_file *)(file->private_data))->private;
636 char buf[32];
637 int buf_size;
638 unsigned long user_address;
639 int err;
640
641 /* Get userspace string and assure termination */
642 buf_size = min(count, (sizeof(buf) - 1));
643 if (copy_from_user(buf, user_buf, buf_size))
644 return -EFAULT;
645 buf[buf_size] = 0;
646
647 err = strict_strtoul(buf, 0, &user_address);
648 if (err)
649 return -EINVAL;
650 if (user_address > 0xff) {
651 dev_err(ab->dev,
652 "debugfs error input > 0xff\n");
653 return -EINVAL;
654 }
655 ab->debug_address = user_address;
656 return buf_size;
657}
658
659static int ab5500_val_print(struct seq_file *s, void *p)
660{
661 struct ab5500 *ab = s->private;
662 int err;
663 u8 regvalue;
664
665 err = ab5500_get_register_interruptible_raw(ab, (u8)ab->debug_bank,
666 (u8)ab->debug_address, &regvalue);
667 if (err) {
668 dev_err(ab->dev, "get_reg failed %d, bank 0x%x"
669 ", reg 0x%x\n", err, ab->debug_bank,
670 ab->debug_address);
671 return -EINVAL;
672 }
673 seq_printf(s, "0x%02X\n", regvalue);
674
675 return 0;
676}
677
678static int ab5500_val_open(struct inode *inode, struct file *file)
679{
680 return single_open(file, ab5500_val_print, inode->i_private);
681}
682
683static ssize_t ab5500_val_write(struct file *file,
684 const char __user *user_buf,
685 size_t count, loff_t *ppos)
686{
687 struct ab5500 *ab = ((struct seq_file *)(file->private_data))->private;
688 char buf[32];
689 int buf_size;
690 unsigned long user_val;
691 int err;
692 u8 regvalue;
693
694 /* Get userspace string and assure termination */
695 buf_size = min(count, (sizeof(buf)-1));
696 if (copy_from_user(buf, user_buf, buf_size))
697 return -EFAULT;
698 buf[buf_size] = 0;
699
700 err = strict_strtoul(buf, 0, &user_val);
701 if (err)
702 return -EINVAL;
703 if (user_val > 0xff) {
704 dev_err(ab->dev,
705 "debugfs error input > 0xff\n");
706 return -EINVAL;
707 }
708 err = ab5500_mask_and_set_register_interruptible_raw(
709 ab, (u8)ab->debug_bank,
710 (u8)ab->debug_address, 0xFF, (u8)user_val);
711 if (err)
712 return -EINVAL;
713
714 ab5500_get_register_interruptible_raw(ab, (u8)ab->debug_bank,
715 (u8)ab->debug_address, &regvalue);
716 if (err)
717 return -EINVAL;
718
719 return buf_size;
720}
721
722static const struct file_operations ab5500_bank_fops = {
723 .open = ab5500_bank_open,
724 .write = ab5500_bank_write,
725 .read = seq_read,
726 .llseek = seq_lseek,
727 .release = single_release,
728 .owner = THIS_MODULE,
729};
730
731static const struct file_operations ab5500_address_fops = {
732 .open = ab5500_address_open,
733 .write = ab5500_address_write,
734 .read = seq_read,
735 .llseek = seq_lseek,
736 .release = single_release,
737 .owner = THIS_MODULE,
738};
739
740static const struct file_operations ab5500_val_fops = {
741 .open = ab5500_val_open,
742 .write = ab5500_val_write,
743 .read = seq_read,
744 .llseek = seq_lseek,
745 .release = single_release,
746 .owner = THIS_MODULE,
747};
748
749static struct dentry *ab5500_dir;
750static struct dentry *ab5500_reg_file;
751static struct dentry *ab5500_bank_file;
752static struct dentry *ab5500_address_file;
753static struct dentry *ab5500_val_file;
754
755void __init ab5500_setup_debugfs(struct ab5500 *ab)
756{
757 ab->debug_bank = AB5500_BANK_VIT_IO_I2C_CLK_TST_OTP;
758 ab->debug_address = AB5500_CHIP_ID;
759
760 ab5500_dir = debugfs_create_dir("ab5500", NULL);
761 if (!ab5500_dir)
762 goto exit_no_debugfs;
763
764 ab5500_reg_file = debugfs_create_file("all-bank-registers",
765 S_IRUGO, ab5500_dir, ab, &ab5500_registers_fops);
766 if (!ab5500_reg_file)
767 goto exit_destroy_dir;
768
769 ab5500_bank_file = debugfs_create_file("register-bank",
770 (S_IRUGO | S_IWUGO), ab5500_dir, ab, &ab5500_bank_fops);
771 if (!ab5500_bank_file)
772 goto exit_destroy_reg;
773
774 ab5500_address_file = debugfs_create_file("register-address",
775 (S_IRUGO | S_IWUGO), ab5500_dir, ab, &ab5500_address_fops);
776 if (!ab5500_address_file)
777 goto exit_destroy_bank;
778
779 ab5500_val_file = debugfs_create_file("register-value",
780 (S_IRUGO | S_IWUGO), ab5500_dir, ab, &ab5500_val_fops);
781 if (!ab5500_val_file)
782 goto exit_destroy_address;
783
784 return;
785
786exit_destroy_address:
787 debugfs_remove(ab5500_address_file);
788exit_destroy_bank:
789 debugfs_remove(ab5500_bank_file);
790exit_destroy_reg:
791 debugfs_remove(ab5500_reg_file);
792exit_destroy_dir:
793 debugfs_remove(ab5500_dir);
794exit_no_debugfs:
795 dev_err(ab->dev, "failed to create debugfs entries.\n");
796 return;
797}
798
799void __exit ab5500_remove_debugfs(void)
800{
801 debugfs_remove(ab5500_val_file);
802 debugfs_remove(ab5500_address_file);
803 debugfs_remove(ab5500_bank_file);
804 debugfs_remove(ab5500_reg_file);
805 debugfs_remove(ab5500_dir);
806}
diff --git a/drivers/mfd/ab5500-debugfs.h b/drivers/mfd/ab5500-debugfs.h
new file mode 100644
index 000000000000..7330a9b6afa6
--- /dev/null
+++ b/drivers/mfd/ab5500-debugfs.h
@@ -0,0 +1,22 @@
1/*
2 * Copyright (C) 2011 ST-Ericsson
3 * License terms: GNU General Public License (GPL) version 2
4 * Debugfs interface to the AB5500 core driver
5 */
6
7#ifdef CONFIG_DEBUG_FS
8
9void ab5500_setup_debugfs(struct ab5500 *ab);
10void ab5500_remove_debugfs(void);
11
12#else /* !CONFIG_DEBUG_FS */
13
14static inline void ab5500_setup_debugfs(struct ab5500 *ab)
15{
16}
17
18static inline void ab5500_remove_debugfs(void)
19{
20}
21
22#endif
diff --git a/drivers/mfd/ab8500-core.c b/drivers/mfd/ab8500-core.c
index 387705e494b9..1e9173804ede 100644
--- a/drivers/mfd/ab8500-core.c
+++ b/drivers/mfd/ab8500-core.c
@@ -92,6 +92,8 @@
92#define AB8500_REV_REG 0x80 92#define AB8500_REV_REG 0x80
93#define AB8500_SWITCH_OFF_STATUS 0x00 93#define AB8500_SWITCH_OFF_STATUS 0x00
94 94
95#define AB8500_TURN_ON_STATUS 0x00
96
95/* 97/*
96 * Map interrupt numbers to the LATCH and MASK register offsets, Interrupt 98 * Map interrupt numbers to the LATCH and MASK register offsets, Interrupt
97 * numbers are indexed into this array with (num / 8). 99 * numbers are indexed into this array with (num / 8).
@@ -293,6 +295,7 @@ static struct irq_chip ab8500_irq_chip = {
293 .irq_bus_lock = ab8500_irq_lock, 295 .irq_bus_lock = ab8500_irq_lock,
294 .irq_bus_sync_unlock = ab8500_irq_sync_unlock, 296 .irq_bus_sync_unlock = ab8500_irq_sync_unlock,
295 .irq_mask = ab8500_irq_mask, 297 .irq_mask = ab8500_irq_mask,
298 .irq_disable = ab8500_irq_mask,
296 .irq_unmask = ab8500_irq_unmask, 299 .irq_unmask = ab8500_irq_unmask,
297}; 300};
298 301
@@ -811,12 +814,40 @@ static ssize_t show_switch_off_status(struct device *dev,
811 return sprintf(buf, "%#x\n", value); 814 return sprintf(buf, "%#x\n", value);
812} 815}
813 816
817/*
818 * ab8500 has turned on due to (TURN_ON_STATUS):
819 * 0x01 PORnVbat
820 * 0x02 PonKey1dbF
821 * 0x04 PonKey2dbF
822 * 0x08 RTCAlarm
823 * 0x10 MainChDet
824 * 0x20 VbusDet
825 * 0x40 UsbIDDetect
826 * 0x80 Reserved
827 */
828static ssize_t show_turn_on_status(struct device *dev,
829 struct device_attribute *attr, char *buf)
830{
831 int ret;
832 u8 value;
833 struct ab8500 *ab8500;
834
835 ab8500 = dev_get_drvdata(dev);
836 ret = get_register_interruptible(ab8500, AB8500_SYS_CTRL1_BLOCK,
837 AB8500_TURN_ON_STATUS, &value);
838 if (ret < 0)
839 return ret;
840 return sprintf(buf, "%#x\n", value);
841}
842
814static DEVICE_ATTR(chip_id, S_IRUGO, show_chip_id, NULL); 843static DEVICE_ATTR(chip_id, S_IRUGO, show_chip_id, NULL);
815static DEVICE_ATTR(switch_off_status, S_IRUGO, show_switch_off_status, NULL); 844static DEVICE_ATTR(switch_off_status, S_IRUGO, show_switch_off_status, NULL);
845static DEVICE_ATTR(turn_on_status, S_IRUGO, show_turn_on_status, NULL);
816 846
817static struct attribute *ab8500_sysfs_entries[] = { 847static struct attribute *ab8500_sysfs_entries[] = {
818 &dev_attr_chip_id.attr, 848 &dev_attr_chip_id.attr,
819 &dev_attr_switch_off_status.attr, 849 &dev_attr_switch_off_status.attr,
850 &dev_attr_turn_on_status.attr,
820 NULL, 851 NULL,
821}; 852};
822 853
@@ -843,11 +874,11 @@ int __devinit ab8500_init(struct ab8500 *ab8500)
843 return ret; 874 return ret;
844 875
845 switch (value) { 876 switch (value) {
846 case AB8500_CUTEARLY:
847 case AB8500_CUT1P0: 877 case AB8500_CUT1P0:
848 case AB8500_CUT1P1: 878 case AB8500_CUT1P1:
849 case AB8500_CUT2P0: 879 case AB8500_CUT2P0:
850 case AB8500_CUT3P0: 880 case AB8500_CUT3P0:
881 case AB8500_CUT3P3:
851 dev_info(ab8500->dev, "detected chip, revision: %#x\n", value); 882 dev_info(ab8500->dev, "detected chip, revision: %#x\n", value);
852 break; 883 break;
853 default: 884 default:
diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
index 64bdeeb1c11a..dedb7f65cea6 100644
--- a/drivers/mfd/ab8500-debugfs.c
+++ b/drivers/mfd/ab8500-debugfs.c
@@ -8,6 +8,7 @@
8#include <linux/seq_file.h> 8#include <linux/seq_file.h>
9#include <linux/uaccess.h> 9#include <linux/uaccess.h>
10#include <linux/fs.h> 10#include <linux/fs.h>
11#include <linux/module.h>
11#include <linux/debugfs.h> 12#include <linux/debugfs.h>
12#include <linux/platform_device.h> 13#include <linux/platform_device.h>
13 14
diff --git a/drivers/mfd/ab8500-gpadc.c b/drivers/mfd/ab8500-gpadc.c
index f16afb234ff9..e985d1701a83 100644
--- a/drivers/mfd/ab8500-gpadc.c
+++ b/drivers/mfd/ab8500-gpadc.c
@@ -143,12 +143,15 @@ struct ab8500_gpadc *ab8500_gpadc_get(char *name)
143} 143}
144EXPORT_SYMBOL(ab8500_gpadc_get); 144EXPORT_SYMBOL(ab8500_gpadc_get);
145 145
146static int ab8500_gpadc_ad_to_voltage(struct ab8500_gpadc *gpadc, u8 input, 146/**
147 * ab8500_gpadc_ad_to_voltage() - Convert a raw ADC value to a voltage
148 */
149int ab8500_gpadc_ad_to_voltage(struct ab8500_gpadc *gpadc, u8 channel,
147 int ad_value) 150 int ad_value)
148{ 151{
149 int res; 152 int res;
150 153
151 switch (input) { 154 switch (channel) {
152 case MAIN_CHARGER_V: 155 case MAIN_CHARGER_V:
153 /* For some reason we don't have calibrated data */ 156 /* For some reason we don't have calibrated data */
154 if (!gpadc->cal_data[ADC_INPUT_VMAIN].gain) { 157 if (!gpadc->cal_data[ADC_INPUT_VMAIN].gain) {
@@ -232,18 +235,46 @@ static int ab8500_gpadc_ad_to_voltage(struct ab8500_gpadc *gpadc, u8 input,
232 } 235 }
233 return res; 236 return res;
234} 237}
238EXPORT_SYMBOL(ab8500_gpadc_ad_to_voltage);
235 239
236/** 240/**
237 * ab8500_gpadc_convert() - gpadc conversion 241 * ab8500_gpadc_convert() - gpadc conversion
238 * @input: analog input to be converted to digital data 242 * @channel: analog channel to be converted to digital data
239 * 243 *
240 * This function converts the selected analog i/p to digital 244 * This function converts the selected analog i/p to digital
241 * data. 245 * data.
242 */ 246 */
243int ab8500_gpadc_convert(struct ab8500_gpadc *gpadc, u8 input) 247int ab8500_gpadc_convert(struct ab8500_gpadc *gpadc, u8 channel)
248{
249 int ad_value;
250 int voltage;
251
252 ad_value = ab8500_gpadc_read_raw(gpadc, channel);
253 if (ad_value < 0) {
254 dev_err(gpadc->dev, "GPADC raw value failed ch: %d\n", channel);
255 return ad_value;
256 }
257
258 voltage = ab8500_gpadc_ad_to_voltage(gpadc, channel, ad_value);
259
260 if (voltage < 0)
261 dev_err(gpadc->dev, "GPADC to voltage conversion failed ch:"
262 " %d AD: 0x%x\n", channel, ad_value);
263
264 return voltage;
265}
266EXPORT_SYMBOL(ab8500_gpadc_convert);
267
268/**
269 * ab8500_gpadc_read_raw() - gpadc read
270 * @channel: analog channel to be read
271 *
272 * This function obtains the raw ADC value, this then needs
273 * to be converted by calling ab8500_gpadc_ad_to_voltage()
274 */
275int ab8500_gpadc_read_raw(struct ab8500_gpadc *gpadc, u8 channel)
244{ 276{
245 int ret; 277 int ret;
246 u16 data = 0;
247 int looplimit = 0; 278 int looplimit = 0;
248 u8 val, low_data, high_data; 279 u8 val, low_data, high_data;
249 280
@@ -278,9 +309,9 @@ int ab8500_gpadc_convert(struct ab8500_gpadc *gpadc, u8 input)
278 goto out; 309 goto out;
279 } 310 }
280 311
281 /* Select the input source and set average samples to 16 */ 312 /* Select the channel source and set average samples to 16 */
282 ret = abx500_set_register_interruptible(gpadc->dev, AB8500_GPADC, 313 ret = abx500_set_register_interruptible(gpadc->dev, AB8500_GPADC,
283 AB8500_GPADC_CTRL2_REG, (input | SW_AVG_16)); 314 AB8500_GPADC_CTRL2_REG, (channel | SW_AVG_16));
284 if (ret < 0) { 315 if (ret < 0) {
285 dev_err(gpadc->dev, 316 dev_err(gpadc->dev,
286 "gpadc_conversion: set avg samples failed\n"); 317 "gpadc_conversion: set avg samples failed\n");
@@ -292,7 +323,7 @@ int ab8500_gpadc_convert(struct ab8500_gpadc *gpadc, u8 input)
292 * charging current sense if it needed, ABB 3.0 needs some special 323 * charging current sense if it needed, ABB 3.0 needs some special
293 * treatment too. 324 * treatment too.
294 */ 325 */
295 switch (input) { 326 switch (channel) {
296 case MAIN_CHARGER_C: 327 case MAIN_CHARGER_C:
297 case USB_CHARGER_C: 328 case USB_CHARGER_C:
298 ret = abx500_mask_and_set_register_interruptible(gpadc->dev, 329 ret = abx500_mask_and_set_register_interruptible(gpadc->dev,
@@ -359,7 +390,6 @@ int ab8500_gpadc_convert(struct ab8500_gpadc *gpadc, u8 input)
359 goto out; 390 goto out;
360 } 391 }
361 392
362 data = (high_data << 8) | low_data;
363 /* Disable GPADC */ 393 /* Disable GPADC */
364 ret = abx500_set_register_interruptible(gpadc->dev, AB8500_GPADC, 394 ret = abx500_set_register_interruptible(gpadc->dev, AB8500_GPADC,
365 AB8500_GPADC_CTRL1_REG, DIS_GPADC); 395 AB8500_GPADC_CTRL1_REG, DIS_GPADC);
@@ -370,8 +400,8 @@ int ab8500_gpadc_convert(struct ab8500_gpadc *gpadc, u8 input)
370 /* Disable VTVout LDO this is required for GPADC */ 400 /* Disable VTVout LDO this is required for GPADC */
371 regulator_disable(gpadc->regu); 401 regulator_disable(gpadc->regu);
372 mutex_unlock(&gpadc->ab8500_gpadc_lock); 402 mutex_unlock(&gpadc->ab8500_gpadc_lock);
373 ret = ab8500_gpadc_ad_to_voltage(gpadc, input, data); 403
374 return ret; 404 return (high_data << 8) | low_data;
375 405
376out: 406out:
377 /* 407 /*
@@ -385,10 +415,10 @@ out:
385 regulator_disable(gpadc->regu); 415 regulator_disable(gpadc->regu);
386 mutex_unlock(&gpadc->ab8500_gpadc_lock); 416 mutex_unlock(&gpadc->ab8500_gpadc_lock);
387 dev_err(gpadc->dev, 417 dev_err(gpadc->dev,
388 "gpadc_conversion: Failed to AD convert channel %d\n", input); 418 "gpadc_conversion: Failed to AD convert channel %d\n", channel);
389 return ret; 419 return ret;
390} 420}
391EXPORT_SYMBOL(ab8500_gpadc_convert); 421EXPORT_SYMBOL(ab8500_gpadc_read_raw);
392 422
393/** 423/**
394 * ab8500_bm_gpswadcconvend_handler() - isr for s/w gpadc conversion completion 424 * ab8500_bm_gpswadcconvend_handler() - isr for s/w gpadc conversion completion
diff --git a/drivers/mfd/ab8500-sysctrl.c b/drivers/mfd/ab8500-sysctrl.c
index 392185965b39..f20feefac190 100644
--- a/drivers/mfd/ab8500-sysctrl.c
+++ b/drivers/mfd/ab8500-sysctrl.c
@@ -5,6 +5,7 @@
5 */ 5 */
6 6
7#include <linux/err.h> 7#include <linux/err.h>
8#include <linux/module.h>
8#include <linux/platform_device.h> 9#include <linux/platform_device.h>
9#include <linux/mfd/ab8500.h> 10#include <linux/mfd/ab8500.h>
10#include <linux/mfd/abx500.h> 11#include <linux/mfd/abx500.h>
diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
index f12720dbe126..7ce65f49480f 100644
--- a/drivers/mfd/abx500-core.c
+++ b/drivers/mfd/abx500-core.c
@@ -8,6 +8,7 @@
8#include <linux/list.h> 8#include <linux/list.h>
9#include <linux/slab.h> 9#include <linux/slab.h>
10#include <linux/err.h> 10#include <linux/err.h>
11#include <linux/module.h>
11#include <linux/mfd/abx500.h> 12#include <linux/mfd/abx500.h>
12 13
13static LIST_HEAD(abx500_list); 14static LIST_HEAD(abx500_list);
diff --git a/drivers/mfd/asic3.c b/drivers/mfd/asic3.c
index c71ae09430c5..b85bbd7f0d19 100644
--- a/drivers/mfd/asic3.c
+++ b/drivers/mfd/asic3.c
@@ -20,6 +20,7 @@
20#include <linux/delay.h> 20#include <linux/delay.h>
21#include <linux/irq.h> 21#include <linux/irq.h>
22#include <linux/gpio.h> 22#include <linux/gpio.h>
23#include <linux/export.h>
23#include <linux/io.h> 24#include <linux/io.h>
24#include <linux/slab.h> 25#include <linux/slab.h>
25#include <linux/spinlock.h> 26#include <linux/spinlock.h>
@@ -584,7 +585,7 @@ static int asic3_gpio_remove(struct platform_device *pdev)
584 return gpiochip_remove(&asic->gpio); 585 return gpiochip_remove(&asic->gpio);
585} 586}
586 587
587static int asic3_clk_enable(struct asic3 *asic, struct asic3_clk *clk) 588static void asic3_clk_enable(struct asic3 *asic, struct asic3_clk *clk)
588{ 589{
589 unsigned long flags; 590 unsigned long flags;
590 u32 cdex; 591 u32 cdex;
@@ -596,8 +597,6 @@ static int asic3_clk_enable(struct asic3 *asic, struct asic3_clk *clk)
596 asic3_write_register(asic, ASIC3_OFFSET(CLOCK, CDEX), cdex); 597 asic3_write_register(asic, ASIC3_OFFSET(CLOCK, CDEX), cdex);
597 } 598 }
598 spin_unlock_irqrestore(&asic->lock, flags); 599 spin_unlock_irqrestore(&asic->lock, flags);
599
600 return 0;
601} 600}
602 601
603static void asic3_clk_disable(struct asic3 *asic, struct asic3_clk *clk) 602static void asic3_clk_disable(struct asic3 *asic, struct asic3_clk *clk)
@@ -779,6 +778,8 @@ static struct mfd_cell asic3_cell_mmc = {
779 .name = "tmio-mmc", 778 .name = "tmio-mmc",
780 .enable = asic3_mmc_enable, 779 .enable = asic3_mmc_enable,
781 .disable = asic3_mmc_disable, 780 .disable = asic3_mmc_disable,
781 .suspend = asic3_mmc_disable,
782 .resume = asic3_mmc_enable,
782 .platform_data = &asic3_mmc_data, 783 .platform_data = &asic3_mmc_data,
783 .pdata_size = sizeof(asic3_mmc_data), 784 .pdata_size = sizeof(asic3_mmc_data),
784 .num_resources = ARRAY_SIZE(asic3_mmc_resources), 785 .num_resources = ARRAY_SIZE(asic3_mmc_resources),
@@ -811,24 +812,43 @@ static int asic3_leds_disable(struct platform_device *pdev)
811 return 0; 812 return 0;
812} 813}
813 814
815static int asic3_leds_suspend(struct platform_device *pdev)
816{
817 const struct mfd_cell *cell = mfd_get_cell(pdev);
818 struct asic3 *asic = dev_get_drvdata(pdev->dev.parent);
819
820 while (asic3_gpio_get(&asic->gpio, ASIC3_GPIO(C, cell->id)) != 0)
821 msleep(1);
822
823 asic3_clk_disable(asic, &asic->clocks[clock_ledn[cell->id]]);
824
825 return 0;
826}
827
814static struct mfd_cell asic3_cell_leds[ASIC3_NUM_LEDS] = { 828static struct mfd_cell asic3_cell_leds[ASIC3_NUM_LEDS] = {
815 [0] = { 829 [0] = {
816 .name = "leds-asic3", 830 .name = "leds-asic3",
817 .id = 0, 831 .id = 0,
818 .enable = asic3_leds_enable, 832 .enable = asic3_leds_enable,
819 .disable = asic3_leds_disable, 833 .disable = asic3_leds_disable,
834 .suspend = asic3_leds_suspend,
835 .resume = asic3_leds_enable,
820 }, 836 },
821 [1] = { 837 [1] = {
822 .name = "leds-asic3", 838 .name = "leds-asic3",
823 .id = 1, 839 .id = 1,
824 .enable = asic3_leds_enable, 840 .enable = asic3_leds_enable,
825 .disable = asic3_leds_disable, 841 .disable = asic3_leds_disable,
842 .suspend = asic3_leds_suspend,
843 .resume = asic3_leds_enable,
826 }, 844 },
827 [2] = { 845 [2] = {
828 .name = "leds-asic3", 846 .name = "leds-asic3",
829 .id = 2, 847 .id = 2,
830 .enable = asic3_leds_enable, 848 .enable = asic3_leds_enable,
831 .disable = asic3_leds_disable, 849 .disable = asic3_leds_disable,
850 .suspend = asic3_leds_suspend,
851 .resume = asic3_leds_enable,
832 }, 852 },
833}; 853};
834 854
@@ -949,6 +969,7 @@ static int __init asic3_probe(struct platform_device *pdev)
949 goto out_unmap; 969 goto out_unmap;
950 } 970 }
951 971
972 asic->gpio.label = "asic3";
952 asic->gpio.base = pdata->gpio_base; 973 asic->gpio.base = pdata->gpio_base;
953 asic->gpio.ngpio = ASIC3_NUM_GPIOS; 974 asic->gpio.ngpio = ASIC3_NUM_GPIOS;
954 asic->gpio.get = asic3_gpio_get; 975 asic->gpio.get = asic3_gpio_get;
diff --git a/drivers/mfd/da903x.c b/drivers/mfd/da903x.c
index 2fadbaeb1cb1..1b79c37fd599 100644
--- a/drivers/mfd/da903x.c
+++ b/drivers/mfd/da903x.c
@@ -523,7 +523,7 @@ static int __devinit da903x_probe(struct i2c_client *client,
523 chip->ops->read_events(chip, &tmp); 523 chip->ops->read_events(chip, &tmp);
524 524
525 ret = request_irq(client->irq, da903x_irq_handler, 525 ret = request_irq(client->irq, da903x_irq_handler,
526 IRQF_DISABLED | IRQF_TRIGGER_FALLING, 526 IRQF_TRIGGER_FALLING,
527 "da903x", chip); 527 "da903x", chip);
528 if (ret) { 528 if (ret) {
529 dev_err(&client->dev, "failed to request irq %d\n", 529 dev_err(&client->dev, "failed to request irq %d\n",
diff --git a/drivers/mfd/db5500-prcmu.c b/drivers/mfd/db5500-prcmu.c
index 9dbb3cab4a6f..bb115b2f04e9 100644
--- a/drivers/mfd/db5500-prcmu.c
+++ b/drivers/mfd/db5500-prcmu.c
@@ -20,11 +20,11 @@
20#include <linux/jiffies.h> 20#include <linux/jiffies.h>
21#include <linux/bitops.h> 21#include <linux/bitops.h>
22#include <linux/interrupt.h> 22#include <linux/interrupt.h>
23#include <linux/mfd/db5500-prcmu.h> 23#include <linux/mfd/dbx500-prcmu.h>
24#include <mach/hardware.h> 24#include <mach/hardware.h>
25#include <mach/irqs.h> 25#include <mach/irqs.h>
26#include <mach/db5500-regs.h> 26#include <mach/db5500-regs.h>
27#include "db5500-prcmu-regs.h" 27#include "dbx500-prcmu-regs.h"
28 28
29#define _PRCM_MB_HEADER (tcdm_base + 0xFE8) 29#define _PRCM_MB_HEADER (tcdm_base + 0xFE8)
30#define PRCM_REQ_MB0_HEADER (_PRCM_MB_HEADER + 0x0) 30#define PRCM_REQ_MB0_HEADER (_PRCM_MB_HEADER + 0x0)
@@ -109,15 +109,18 @@ enum mb5_header {
109#define PRCMU_DSI_CLOCK_SETTING 0x00000128 109#define PRCMU_DSI_CLOCK_SETTING 0x00000128
110/* TVCLK_MGT PLLSW=001 (PLLSOC0) PLLDIV=0x13, = 19.05 MHZ */ 110/* TVCLK_MGT PLLSW=001 (PLLSOC0) PLLDIV=0x13, = 19.05 MHZ */
111#define PRCMU_DSI_LP_CLOCK_SETTING 0x00000135 111#define PRCMU_DSI_LP_CLOCK_SETTING 0x00000135
112#define PRCMU_PLLDSI_FREQ_SETTING 0x0004013C 112#define PRCMU_PLLDSI_FREQ_SETTING 0x00020121
113#define PRCMU_DSI_PLLOUT_SEL_SETTING 0x00000002 113#define PRCMU_DSI_PLLOUT_SEL_SETTING 0x00000002
114#define PRCMU_ENABLE_ESCAPE_CLOCK_DIV 0x03000101 114#define PRCMU_ENABLE_ESCAPE_CLOCK_DIV 0x03000201
115#define PRCMU_DISABLE_ESCAPE_CLOCK_DIV 0x00000101 115#define PRCMU_DISABLE_ESCAPE_CLOCK_DIV 0x00000101
116 116
117#define PRCMU_ENABLE_PLLDSI 0x00000001 117#define PRCMU_ENABLE_PLLDSI 0x00000001
118#define PRCMU_DISABLE_PLLDSI 0x00000000 118#define PRCMU_DISABLE_PLLDSI 0x00000000
119 119
120#define PRCMU_DSI_RESET_SW 0x00000003 120#define PRCMU_DSI_RESET_SW 0x00000003
121#define PRCMU_RESOUTN0_PIN 0x00000001
122#define PRCMU_RESOUTN1_PIN 0x00000002
123#define PRCMU_RESOUTN2_PIN 0x00000004
121 124
122#define PRCMU_PLLDSI_LOCKP_LOCKED 0x3 125#define PRCMU_PLLDSI_LOCKP_LOCKED 0x3
123 126
@@ -315,31 +318,31 @@ static bool read_mailbox_0(void)
315 r = false; 318 r = false;
316 break; 319 break;
317 } 320 }
318 writel(MBOX_BIT(0), PRCM_ARM_IT1_CLEAR); 321 writel(MBOX_BIT(0), PRCM_ARM_IT1_CLR);
319 return r; 322 return r;
320} 323}
321 324
322static bool read_mailbox_1(void) 325static bool read_mailbox_1(void)
323{ 326{
324 writel(MBOX_BIT(1), PRCM_ARM_IT1_CLEAR); 327 writel(MBOX_BIT(1), PRCM_ARM_IT1_CLR);
325 return false; 328 return false;
326} 329}
327 330
328static bool read_mailbox_2(void) 331static bool read_mailbox_2(void)
329{ 332{
330 writel(MBOX_BIT(2), PRCM_ARM_IT1_CLEAR); 333 writel(MBOX_BIT(2), PRCM_ARM_IT1_CLR);
331 return false; 334 return false;
332} 335}
333 336
334static bool read_mailbox_3(void) 337static bool read_mailbox_3(void)
335{ 338{
336 writel(MBOX_BIT(3), PRCM_ARM_IT1_CLEAR); 339 writel(MBOX_BIT(3), PRCM_ARM_IT1_CLR);
337 return false; 340 return false;
338} 341}
339 342
340static bool read_mailbox_4(void) 343static bool read_mailbox_4(void)
341{ 344{
342 writel(MBOX_BIT(4), PRCM_ARM_IT1_CLEAR); 345 writel(MBOX_BIT(4), PRCM_ARM_IT1_CLR);
343 return false; 346 return false;
344} 347}
345 348
@@ -360,19 +363,19 @@ static bool read_mailbox_5(void)
360 print_unknown_header_warning(5, header); 363 print_unknown_header_warning(5, header);
361 break; 364 break;
362 } 365 }
363 writel(MBOX_BIT(5), PRCM_ARM_IT1_CLEAR); 366 writel(MBOX_BIT(5), PRCM_ARM_IT1_CLR);
364 return false; 367 return false;
365} 368}
366 369
367static bool read_mailbox_6(void) 370static bool read_mailbox_6(void)
368{ 371{
369 writel(MBOX_BIT(6), PRCM_ARM_IT1_CLEAR); 372 writel(MBOX_BIT(6), PRCM_ARM_IT1_CLR);
370 return false; 373 return false;
371} 374}
372 375
373static bool read_mailbox_7(void) 376static bool read_mailbox_7(void)
374{ 377{
375 writel(MBOX_BIT(7), PRCM_ARM_IT1_CLEAR); 378 writel(MBOX_BIT(7), PRCM_ARM_IT1_CLR);
376 return false; 379 return false;
377} 380}
378 381
@@ -434,7 +437,7 @@ int __init db5500_prcmu_init(void)
434 return -ENODEV; 437 return -ENODEV;
435 438
436 /* Clean up the mailbox interrupts after pre-kernel code. */ 439 /* Clean up the mailbox interrupts after pre-kernel code. */
437 writel(ALL_MBOX_BITS, PRCM_ARM_IT1_CLEAR); 440 writel(ALL_MBOX_BITS, PRCM_ARM_IT1_CLR);
438 441
439 r = request_threaded_irq(IRQ_DB5500_PRCMU1, prcmu_irq_handler, 442 r = request_threaded_irq(IRQ_DB5500_PRCMU1, prcmu_irq_handler,
440 prcmu_irq_thread_fn, 0, "prcmu", NULL); 443 prcmu_irq_thread_fn, 0, "prcmu", NULL);
diff --git a/drivers/mfd/db8500-prcmu-regs.h b/drivers/mfd/db8500-prcmu-regs.h
deleted file mode 100644
index 3bbf04d58043..000000000000
--- a/drivers/mfd/db8500-prcmu-regs.h
+++ /dev/null
@@ -1,166 +0,0 @@
1/*
2 * Copyright (C) STMicroelectronics 2009
3 * Copyright (C) ST-Ericsson SA 2010
4 *
5 * Author: Kumar Sanghvi <kumar.sanghvi@stericsson.com>
6 * Author: Sundar Iyer <sundar.iyer@stericsson.com>
7 *
8 * License Terms: GNU General Public License v2
9 *
10 * PRCM Unit registers
11 */
12#ifndef __DB8500_PRCMU_REGS_H
13#define __DB8500_PRCMU_REGS_H
14
15#include <linux/bitops.h>
16#include <mach/hardware.h>
17
18#define BITS(_start, _end) ((BIT(_end) - BIT(_start)) + BIT(_end))
19
20#define PRCM_ARM_PLLDIVPS 0x118
21#define PRCM_ARM_PLLDIVPS_ARM_BRM_RATE BITS(0, 5)
22#define PRCM_ARM_PLLDIVPS_MAX_MASK 0xF
23
24#define PRCM_PLLARM_LOCKP 0x0A8
25#define PRCM_PLLARM_LOCKP_PRCM_PLLARM_LOCKP3 BIT(1)
26
27#define PRCM_ARM_CHGCLKREQ 0x114
28#define PRCM_ARM_CHGCLKREQ_PRCM_ARM_CHGCLKREQ BIT(0)
29
30#define PRCM_PLLARM_ENABLE 0x98
31#define PRCM_PLLARM_ENABLE_PRCM_PLLARM_ENABLE BIT(0)
32#define PRCM_PLLARM_ENABLE_PRCM_PLLARM_COUNTON BIT(8)
33
34#define PRCM_ARMCLKFIX_MGT 0x0
35#define PRCM_A9_RESETN_CLR 0x1f4
36#define PRCM_A9_RESETN_SET 0x1f0
37#define PRCM_ARM_LS_CLAMP 0x30C
38#define PRCM_SRAM_A9 0x308
39
40/* ARM WFI Standby signal register */
41#define PRCM_ARM_WFI_STANDBY 0x130
42#define PRCM_IOCR 0x310
43#define PRCM_IOCR_IOFORCE BIT(0)
44
45/* CPU mailbox registers */
46#define PRCM_MBOX_CPU_VAL 0x0FC
47#define PRCM_MBOX_CPU_SET 0x100
48
49/* Dual A9 core interrupt management unit registers */
50#define PRCM_A9_MASK_REQ 0x328
51#define PRCM_A9_MASK_REQ_PRCM_A9_MASK_REQ BIT(0)
52
53#define PRCM_A9_MASK_ACK 0x32C
54#define PRCM_ARMITMSK31TO0 0x11C
55#define PRCM_ARMITMSK63TO32 0x120
56#define PRCM_ARMITMSK95TO64 0x124
57#define PRCM_ARMITMSK127TO96 0x128
58#define PRCM_POWER_STATE_VAL 0x25C
59#define PRCM_ARMITVAL31TO0 0x260
60#define PRCM_ARMITVAL63TO32 0x264
61#define PRCM_ARMITVAL95TO64 0x268
62#define PRCM_ARMITVAL127TO96 0x26C
63
64#define PRCM_HOSTACCESS_REQ 0x334
65#define PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ BIT(0)
66
67#define PRCM_ARM_IT1_CLR 0x48C
68#define PRCM_ARM_IT1_VAL 0x494
69
70#define PRCM_ITSTATUS0 0x148
71#define PRCM_ITSTATUS1 0x150
72#define PRCM_ITSTATUS2 0x158
73#define PRCM_ITSTATUS3 0x160
74#define PRCM_ITSTATUS4 0x168
75#define PRCM_ITSTATUS5 0x484
76#define PRCM_ITCLEAR5 0x488
77#define PRCM_ARMIT_MASKXP70_IT 0x1018
78
79/* System reset register */
80#define PRCM_APE_SOFTRST 0x228
81
82/* Level shifter and clamp control registers */
83#define PRCM_MMIP_LS_CLAMP_SET 0x420
84#define PRCM_MMIP_LS_CLAMP_CLR 0x424
85
86/* PRCMU HW semaphore */
87#define PRCM_SEM 0x400
88#define PRCM_SEM_PRCM_SEM BIT(0)
89
90/* PRCMU clock/PLL/reset registers */
91#define PRCM_PLLDSI_FREQ 0x500
92#define PRCM_PLLDSI_ENABLE 0x504
93#define PRCM_PLLDSI_LOCKP 0x508
94#define PRCM_DSI_PLLOUT_SEL 0x530
95#define PRCM_DSITVCLK_DIV 0x52C
96#define PRCM_APE_RESETN_SET 0x1E4
97#define PRCM_APE_RESETN_CLR 0x1E8
98
99#define PRCM_TCR 0x1C8
100#define PRCM_TCR_TENSEL_MASK BITS(0, 7)
101#define PRCM_TCR_STOP_TIMERS BIT(16)
102#define PRCM_TCR_DOZE_MODE BIT(17)
103
104#define PRCM_CLKOCR 0x1CC
105#define PRCM_CLKOCR_CLKODIV0_SHIFT 0
106#define PRCM_CLKOCR_CLKODIV0_MASK BITS(0, 5)
107#define PRCM_CLKOCR_CLKOSEL0_SHIFT 6
108#define PRCM_CLKOCR_CLKOSEL0_MASK BITS(6, 8)
109#define PRCM_CLKOCR_CLKODIV1_SHIFT 16
110#define PRCM_CLKOCR_CLKODIV1_MASK BITS(16, 21)
111#define PRCM_CLKOCR_CLKOSEL1_SHIFT 22
112#define PRCM_CLKOCR_CLKOSEL1_MASK BITS(22, 24)
113#define PRCM_CLKOCR_CLK1TYPE BIT(28)
114
115#define PRCM_SGACLK_MGT 0x014
116#define PRCM_UARTCLK_MGT 0x018
117#define PRCM_MSP02CLK_MGT 0x01C
118#define PRCM_MSP1CLK_MGT 0x288
119#define PRCM_I2CCLK_MGT 0x020
120#define PRCM_SDMMCCLK_MGT 0x024
121#define PRCM_SLIMCLK_MGT 0x028
122#define PRCM_PER1CLK_MGT 0x02C
123#define PRCM_PER2CLK_MGT 0x030
124#define PRCM_PER3CLK_MGT 0x034
125#define PRCM_PER5CLK_MGT 0x038
126#define PRCM_PER6CLK_MGT 0x03C
127#define PRCM_PER7CLK_MGT 0x040
128#define PRCM_LCDCLK_MGT 0x044
129#define PRCM_BMLCLK_MGT 0x04C
130#define PRCM_HSITXCLK_MGT 0x050
131#define PRCM_HSIRXCLK_MGT 0x054
132#define PRCM_HDMICLK_MGT 0x058
133#define PRCM_APEATCLK_MGT 0x05C
134#define PRCM_APETRACECLK_MGT 0x060
135#define PRCM_MCDECLK_MGT 0x064
136#define PRCM_IPI2CCLK_MGT 0x068
137#define PRCM_DSIALTCLK_MGT 0x06C
138#define PRCM_DMACLK_MGT 0x074
139#define PRCM_B2R2CLK_MGT 0x078
140#define PRCM_TVCLK_MGT 0x07C
141#define PRCM_UNIPROCLK_MGT 0x278
142#define PRCM_SSPCLK_MGT 0x280
143#define PRCM_RNGCLK_MGT 0x284
144#define PRCM_UICCCLK_MGT 0x27C
145
146#define PRCM_CLK_MGT_CLKPLLDIV_MASK BITS(0, 4)
147#define PRCM_CLK_MGT_CLKPLLSW_MASK BITS(5, 7)
148#define PRCM_CLK_MGT_CLKEN BIT(8)
149
150/* ePOD and memory power signal control registers */
151#define PRCM_EPOD_C_SET 0x410
152#define PRCM_SRAM_LS_SLEEP 0x304
153
154/* Debug power control unit registers */
155#define PRCM_POWER_STATE_SET 0x254
156
157/* Miscellaneous unit registers */
158#define PRCM_DSI_SW_RESET 0x324
159#define PRCM_GPIOCR 0x138
160
161/* GPIOCR register */
162#define PRCM_GPIOCR_SPI2_SELECT BIT(23)
163
164#define PRCM_DDR_SUBSYS_APE_MINBW 0x438
165
166#endif /* __DB8500_PRCMU_REGS_H */
diff --git a/drivers/mfd/db8500-prcmu.c b/drivers/mfd/db8500-prcmu.c
index 02a15d7cb3b0..a25ab9c6b5af 100644
--- a/drivers/mfd/db8500-prcmu.c
+++ b/drivers/mfd/db8500-prcmu.c
@@ -27,14 +27,14 @@
27#include <linux/platform_device.h> 27#include <linux/platform_device.h>
28#include <linux/uaccess.h> 28#include <linux/uaccess.h>
29#include <linux/mfd/core.h> 29#include <linux/mfd/core.h>
30#include <linux/mfd/db8500-prcmu.h> 30#include <linux/mfd/dbx500-prcmu.h>
31#include <linux/regulator/db8500-prcmu.h> 31#include <linux/regulator/db8500-prcmu.h>
32#include <linux/regulator/machine.h> 32#include <linux/regulator/machine.h>
33#include <mach/hardware.h> 33#include <mach/hardware.h>
34#include <mach/irqs.h> 34#include <mach/irqs.h>
35#include <mach/db8500-regs.h> 35#include <mach/db8500-regs.h>
36#include <mach/id.h> 36#include <mach/id.h>
37#include "db8500-prcmu-regs.h" 37#include "dbx500-prcmu-regs.h"
38 38
39/* Offset for the firmware version within the TCPM */ 39/* Offset for the firmware version within the TCPM */
40#define PRCMU_FW_VERSION_OFFSET 0xA4 40#define PRCMU_FW_VERSION_OFFSET 0xA4
@@ -131,12 +131,14 @@
131#define MB1H_REQUEST_APE_OPP_100_VOLT 0x3 131#define MB1H_REQUEST_APE_OPP_100_VOLT 0x3
132#define MB1H_RELEASE_APE_OPP_100_VOLT 0x4 132#define MB1H_RELEASE_APE_OPP_100_VOLT 0x4
133#define MB1H_RELEASE_USB_WAKEUP 0x5 133#define MB1H_RELEASE_USB_WAKEUP 0x5
134#define MB1H_PLL_ON_OFF 0x6
134 135
135/* Mailbox 1 Requests */ 136/* Mailbox 1 Requests */
136#define PRCM_REQ_MB1_ARM_OPP (PRCM_REQ_MB1 + 0x0) 137#define PRCM_REQ_MB1_ARM_OPP (PRCM_REQ_MB1 + 0x0)
137#define PRCM_REQ_MB1_APE_OPP (PRCM_REQ_MB1 + 0x1) 138#define PRCM_REQ_MB1_APE_OPP (PRCM_REQ_MB1 + 0x1)
138#define PRCM_REQ_MB1_APE_OPP_100_RESTORE (PRCM_REQ_MB1 + 0x4) 139#define PRCM_REQ_MB1_PLL_ON_OFF (PRCM_REQ_MB1 + 0x4)
139#define PRCM_REQ_MB1_ARM_OPP_100_RESTORE (PRCM_REQ_MB1 + 0x8) 140#define PLL_SOC1_OFF 0x4
141#define PLL_SOC1_ON 0x8
140 142
141/* Mailbox 1 ACKs */ 143/* Mailbox 1 ACKs */
142#define PRCM_ACK_MB1_CURRENT_ARM_OPP (PRCM_ACK_MB1 + 0x0) 144#define PRCM_ACK_MB1_CURRENT_ARM_OPP (PRCM_ACK_MB1 + 0x0)
@@ -184,6 +186,11 @@
184#define MB4H_HOTDOG 0x12 186#define MB4H_HOTDOG 0x12
185#define MB4H_HOTMON 0x13 187#define MB4H_HOTMON 0x13
186#define MB4H_HOT_PERIOD 0x14 188#define MB4H_HOT_PERIOD 0x14
189#define MB4H_A9WDOG_CONF 0x16
190#define MB4H_A9WDOG_EN 0x17
191#define MB4H_A9WDOG_DIS 0x18
192#define MB4H_A9WDOG_LOAD 0x19
193#define MB4H_A9WDOG_KICK 0x20
187 194
188/* Mailbox 4 Requests */ 195/* Mailbox 4 Requests */
189#define PRCM_REQ_MB4_DDR_ST_AP_SLEEP_IDLE (PRCM_REQ_MB4 + 0x0) 196#define PRCM_REQ_MB4_DDR_ST_AP_SLEEP_IDLE (PRCM_REQ_MB4 + 0x0)
@@ -196,6 +203,13 @@
196#define PRCM_REQ_MB4_HOT_PERIOD (PRCM_REQ_MB4 + 0x0) 203#define PRCM_REQ_MB4_HOT_PERIOD (PRCM_REQ_MB4 + 0x0)
197#define HOTMON_CONFIG_LOW BIT(0) 204#define HOTMON_CONFIG_LOW BIT(0)
198#define HOTMON_CONFIG_HIGH BIT(1) 205#define HOTMON_CONFIG_HIGH BIT(1)
206#define PRCM_REQ_MB4_A9WDOG_0 (PRCM_REQ_MB4 + 0x0)
207#define PRCM_REQ_MB4_A9WDOG_1 (PRCM_REQ_MB4 + 0x1)
208#define PRCM_REQ_MB4_A9WDOG_2 (PRCM_REQ_MB4 + 0x2)
209#define PRCM_REQ_MB4_A9WDOG_3 (PRCM_REQ_MB4 + 0x3)
210#define A9WDOG_AUTO_OFF_EN BIT(7)
211#define A9WDOG_AUTO_OFF_DIS 0
212#define A9WDOG_ID_MASK 0xf
199 213
200/* Mailbox 5 Requests */ 214/* Mailbox 5 Requests */
201#define PRCM_REQ_MB5_I2C_SLAVE_OP (PRCM_REQ_MB5 + 0x0) 215#define PRCM_REQ_MB5_I2C_SLAVE_OP (PRCM_REQ_MB5 + 0x0)
@@ -412,7 +426,7 @@ struct clk_mgt {
412 426
413static DEFINE_SPINLOCK(clk_mgt_lock); 427static DEFINE_SPINLOCK(clk_mgt_lock);
414 428
415#define CLK_MGT_ENTRY(_name)[PRCMU_##_name] = { (PRCM_##_name##_MGT), 0 } 429#define CLK_MGT_ENTRY(_name)[PRCMU_##_name] = { (PRCM_##_name##_MGT_OFF), 0 }
416struct clk_mgt clk_mgt[PRCMU_NUM_REG_CLOCKS] = { 430struct clk_mgt clk_mgt[PRCMU_NUM_REG_CLOCKS] = {
417 CLK_MGT_ENTRY(SGACLK), 431 CLK_MGT_ENTRY(SGACLK),
418 CLK_MGT_ENTRY(UARTCLK), 432 CLK_MGT_ENTRY(UARTCLK),
@@ -445,6 +459,35 @@ struct clk_mgt clk_mgt[PRCMU_NUM_REG_CLOCKS] = {
445 CLK_MGT_ENTRY(UICCCLK), 459 CLK_MGT_ENTRY(UICCCLK),
446}; 460};
447 461
462static struct regulator *hwacc_regulator[NUM_HW_ACC];
463static struct regulator *hwacc_ret_regulator[NUM_HW_ACC];
464
465static bool hwacc_enabled[NUM_HW_ACC];
466static bool hwacc_ret_enabled[NUM_HW_ACC];
467
468static const char *hwacc_regulator_name[NUM_HW_ACC] = {
469 [HW_ACC_SVAMMDSP] = "hwacc-sva-mmdsp",
470 [HW_ACC_SVAPIPE] = "hwacc-sva-pipe",
471 [HW_ACC_SIAMMDSP] = "hwacc-sia-mmdsp",
472 [HW_ACC_SIAPIPE] = "hwacc-sia-pipe",
473 [HW_ACC_SGA] = "hwacc-sga",
474 [HW_ACC_B2R2] = "hwacc-b2r2",
475 [HW_ACC_MCDE] = "hwacc-mcde",
476 [HW_ACC_ESRAM1] = "hwacc-esram1",
477 [HW_ACC_ESRAM2] = "hwacc-esram2",
478 [HW_ACC_ESRAM3] = "hwacc-esram3",
479 [HW_ACC_ESRAM4] = "hwacc-esram4",
480};
481
482static const char *hwacc_ret_regulator_name[NUM_HW_ACC] = {
483 [HW_ACC_SVAMMDSP] = "hwacc-sva-mmdsp-ret",
484 [HW_ACC_SIAMMDSP] = "hwacc-sia-mmdsp-ret",
485 [HW_ACC_ESRAM1] = "hwacc-esram1-ret",
486 [HW_ACC_ESRAM2] = "hwacc-esram2-ret",
487 [HW_ACC_ESRAM3] = "hwacc-esram3-ret",
488 [HW_ACC_ESRAM4] = "hwacc-esram4-ret",
489};
490
448/* 491/*
449* Used by MCDE to setup all necessary PRCMU registers 492* Used by MCDE to setup all necessary PRCMU registers
450*/ 493*/
@@ -493,55 +536,51 @@ static struct {
493} prcmu_version; 536} prcmu_version;
494 537
495 538
496int prcmu_enable_dsipll(void) 539int db8500_prcmu_enable_dsipll(void)
497{ 540{
498 int i; 541 int i;
499 unsigned int plldsifreq; 542 unsigned int plldsifreq;
500 543
501 /* Clear DSIPLL_RESETN */ 544 /* Clear DSIPLL_RESETN */
502 writel(PRCMU_RESET_DSIPLL, (_PRCMU_BASE + PRCM_APE_RESETN_CLR)); 545 writel(PRCMU_RESET_DSIPLL, PRCM_APE_RESETN_CLR);
503 /* Unclamp DSIPLL in/out */ 546 /* Unclamp DSIPLL in/out */
504 writel(PRCMU_UNCLAMP_DSIPLL, (_PRCMU_BASE + PRCM_MMIP_LS_CLAMP_CLR)); 547 writel(PRCMU_UNCLAMP_DSIPLL, PRCM_MMIP_LS_CLAMP_CLR);
505 548
506 if (prcmu_is_u8400()) 549 if (prcmu_is_u8400())
507 plldsifreq = PRCMU_PLLDSI_FREQ_SETTING_U8400; 550 plldsifreq = PRCMU_PLLDSI_FREQ_SETTING_U8400;
508 else 551 else
509 plldsifreq = PRCMU_PLLDSI_FREQ_SETTING; 552 plldsifreq = PRCMU_PLLDSI_FREQ_SETTING;
510 /* Set DSI PLL FREQ */ 553 /* Set DSI PLL FREQ */
511 writel(plldsifreq, (_PRCMU_BASE + PRCM_PLLDSI_FREQ)); 554 writel(plldsifreq, PRCM_PLLDSI_FREQ);
512 writel(PRCMU_DSI_PLLOUT_SEL_SETTING, 555 writel(PRCMU_DSI_PLLOUT_SEL_SETTING, PRCM_DSI_PLLOUT_SEL);
513 (_PRCMU_BASE + PRCM_DSI_PLLOUT_SEL));
514 /* Enable Escape clocks */ 556 /* Enable Escape clocks */
515 writel(PRCMU_ENABLE_ESCAPE_CLOCK_DIV, 557 writel(PRCMU_ENABLE_ESCAPE_CLOCK_DIV, PRCM_DSITVCLK_DIV);
516 (_PRCMU_BASE + PRCM_DSITVCLK_DIV));
517 558
518 /* Start DSI PLL */ 559 /* Start DSI PLL */
519 writel(PRCMU_ENABLE_PLLDSI, (_PRCMU_BASE + PRCM_PLLDSI_ENABLE)); 560 writel(PRCMU_ENABLE_PLLDSI, PRCM_PLLDSI_ENABLE);
520 /* Reset DSI PLL */ 561 /* Reset DSI PLL */
521 writel(PRCMU_DSI_RESET_SW, (_PRCMU_BASE + PRCM_DSI_SW_RESET)); 562 writel(PRCMU_DSI_RESET_SW, PRCM_DSI_SW_RESET);
522 for (i = 0; i < 10; i++) { 563 for (i = 0; i < 10; i++) {
523 if ((readl(_PRCMU_BASE + PRCM_PLLDSI_LOCKP) & 564 if ((readl(PRCM_PLLDSI_LOCKP) & PRCMU_PLLDSI_LOCKP_LOCKED)
524 PRCMU_PLLDSI_LOCKP_LOCKED)
525 == PRCMU_PLLDSI_LOCKP_LOCKED) 565 == PRCMU_PLLDSI_LOCKP_LOCKED)
526 break; 566 break;
527 udelay(100); 567 udelay(100);
528 } 568 }
529 /* Set DSIPLL_RESETN */ 569 /* Set DSIPLL_RESETN */
530 writel(PRCMU_RESET_DSIPLL, (_PRCMU_BASE + PRCM_APE_RESETN_SET)); 570 writel(PRCMU_RESET_DSIPLL, PRCM_APE_RESETN_SET);
531 return 0; 571 return 0;
532} 572}
533 573
534int prcmu_disable_dsipll(void) 574int db8500_prcmu_disable_dsipll(void)
535{ 575{
536 /* Disable dsi pll */ 576 /* Disable dsi pll */
537 writel(PRCMU_DISABLE_PLLDSI, (_PRCMU_BASE + PRCM_PLLDSI_ENABLE)); 577 writel(PRCMU_DISABLE_PLLDSI, PRCM_PLLDSI_ENABLE);
538 /* Disable escapeclock */ 578 /* Disable escapeclock */
539 writel(PRCMU_DISABLE_ESCAPE_CLOCK_DIV, 579 writel(PRCMU_DISABLE_ESCAPE_CLOCK_DIV, PRCM_DSITVCLK_DIV);
540 (_PRCMU_BASE + PRCM_DSITVCLK_DIV));
541 return 0; 580 return 0;
542} 581}
543 582
544int prcmu_set_display_clocks(void) 583int db8500_prcmu_set_display_clocks(void)
545{ 584{
546 unsigned long flags; 585 unsigned long flags;
547 unsigned int dsiclk; 586 unsigned int dsiclk;
@@ -554,15 +593,15 @@ int prcmu_set_display_clocks(void)
554 spin_lock_irqsave(&clk_mgt_lock, flags); 593 spin_lock_irqsave(&clk_mgt_lock, flags);
555 594
556 /* Grab the HW semaphore. */ 595 /* Grab the HW semaphore. */
557 while ((readl(_PRCMU_BASE + PRCM_SEM) & PRCM_SEM_PRCM_SEM) != 0) 596 while ((readl(PRCM_SEM) & PRCM_SEM_PRCM_SEM) != 0)
558 cpu_relax(); 597 cpu_relax();
559 598
560 writel(dsiclk, (_PRCMU_BASE + PRCM_HDMICLK_MGT)); 599 writel(dsiclk, PRCM_HDMICLK_MGT);
561 writel(PRCMU_DSI_LP_CLOCK_SETTING, (_PRCMU_BASE + PRCM_TVCLK_MGT)); 600 writel(PRCMU_DSI_LP_CLOCK_SETTING, PRCM_TVCLK_MGT);
562 writel(PRCMU_DPI_CLOCK_SETTING, (_PRCMU_BASE + PRCM_LCDCLK_MGT)); 601 writel(PRCMU_DPI_CLOCK_SETTING, PRCM_LCDCLK_MGT);
563 602
564 /* Release the HW semaphore. */ 603 /* Release the HW semaphore. */
565 writel(0, (_PRCMU_BASE + PRCM_SEM)); 604 writel(0, PRCM_SEM);
566 605
567 spin_unlock_irqrestore(&clk_mgt_lock, flags); 606 spin_unlock_irqrestore(&clk_mgt_lock, flags);
568 607
@@ -578,8 +617,8 @@ void prcmu_enable_spi2(void)
578 unsigned long flags; 617 unsigned long flags;
579 618
580 spin_lock_irqsave(&gpiocr_lock, flags); 619 spin_lock_irqsave(&gpiocr_lock, flags);
581 reg = readl(_PRCMU_BASE + PRCM_GPIOCR); 620 reg = readl(PRCM_GPIOCR);
582 writel(reg | PRCM_GPIOCR_SPI2_SELECT, _PRCMU_BASE + PRCM_GPIOCR); 621 writel(reg | PRCM_GPIOCR_SPI2_SELECT, PRCM_GPIOCR);
583 spin_unlock_irqrestore(&gpiocr_lock, flags); 622 spin_unlock_irqrestore(&gpiocr_lock, flags);
584} 623}
585 624
@@ -592,8 +631,8 @@ void prcmu_disable_spi2(void)
592 unsigned long flags; 631 unsigned long flags;
593 632
594 spin_lock_irqsave(&gpiocr_lock, flags); 633 spin_lock_irqsave(&gpiocr_lock, flags);
595 reg = readl(_PRCMU_BASE + PRCM_GPIOCR); 634 reg = readl(PRCM_GPIOCR);
596 writel(reg & ~PRCM_GPIOCR_SPI2_SELECT, _PRCMU_BASE + PRCM_GPIOCR); 635 writel(reg & ~PRCM_GPIOCR_SPI2_SELECT, PRCM_GPIOCR);
597 spin_unlock_irqrestore(&gpiocr_lock, flags); 636 spin_unlock_irqrestore(&gpiocr_lock, flags);
598} 637}
599 638
@@ -701,7 +740,7 @@ int prcmu_config_clkout(u8 clkout, u8 source, u8 div)
701 740
702 spin_lock_irqsave(&clkout_lock, flags); 741 spin_lock_irqsave(&clkout_lock, flags);
703 742
704 val = readl(_PRCMU_BASE + PRCM_CLKOCR); 743 val = readl(PRCM_CLKOCR);
705 if (val & div_mask) { 744 if (val & div_mask) {
706 if (div) { 745 if (div) {
707 if ((val & mask) != bits) { 746 if ((val & mask) != bits) {
@@ -715,7 +754,7 @@ int prcmu_config_clkout(u8 clkout, u8 source, u8 div)
715 } 754 }
716 } 755 }
717 } 756 }
718 writel((bits | (val & ~mask)), (_PRCMU_BASE + PRCM_CLKOCR)); 757 writel((bits | (val & ~mask)), PRCM_CLKOCR);
719 requests[clkout] += (div ? 1 : -1); 758 requests[clkout] += (div ? 1 : -1);
720 759
721unlock_and_return: 760unlock_and_return:
@@ -724,7 +763,7 @@ unlock_and_return:
724 return r; 763 return r;
725} 764}
726 765
727int prcmu_set_power_state(u8 state, bool keep_ulp_clk, bool keep_ap_pll) 766int db8500_prcmu_set_power_state(u8 state, bool keep_ulp_clk, bool keep_ap_pll)
728{ 767{
729 unsigned long flags; 768 unsigned long flags;
730 769
@@ -732,7 +771,7 @@ int prcmu_set_power_state(u8 state, bool keep_ulp_clk, bool keep_ap_pll)
732 771
733 spin_lock_irqsave(&mb0_transfer.lock, flags); 772 spin_lock_irqsave(&mb0_transfer.lock, flags);
734 773
735 while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(0)) 774 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(0))
736 cpu_relax(); 775 cpu_relax();
737 776
738 writeb(MB0H_POWER_STATE_TRANS, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB0)); 777 writeb(MB0H_POWER_STATE_TRANS, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB0));
@@ -741,7 +780,7 @@ int prcmu_set_power_state(u8 state, bool keep_ulp_clk, bool keep_ap_pll)
741 writeb((keep_ulp_clk ? 1 : 0), 780 writeb((keep_ulp_clk ? 1 : 0),
742 (tcdm_base + PRCM_REQ_MB0_ULP_CLOCK_STATE)); 781 (tcdm_base + PRCM_REQ_MB0_ULP_CLOCK_STATE));
743 writeb(0, (tcdm_base + PRCM_REQ_MB0_DO_NOT_WFI)); 782 writeb(0, (tcdm_base + PRCM_REQ_MB0_DO_NOT_WFI));
744 writel(MBOX_BIT(0), (_PRCMU_BASE + PRCM_MBOX_CPU_SET)); 783 writel(MBOX_BIT(0), PRCM_MBOX_CPU_SET);
745 784
746 spin_unlock_irqrestore(&mb0_transfer.lock, flags); 785 spin_unlock_irqrestore(&mb0_transfer.lock, flags);
747 786
@@ -770,18 +809,18 @@ static void config_wakeups(void)
770 return; 809 return;
771 810
772 for (i = 0; i < 2; i++) { 811 for (i = 0; i < 2; i++) {
773 while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(0)) 812 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(0))
774 cpu_relax(); 813 cpu_relax();
775 writel(dbb_events, (tcdm_base + PRCM_REQ_MB0_WAKEUP_8500)); 814 writel(dbb_events, (tcdm_base + PRCM_REQ_MB0_WAKEUP_8500));
776 writel(abb_events, (tcdm_base + PRCM_REQ_MB0_WAKEUP_4500)); 815 writel(abb_events, (tcdm_base + PRCM_REQ_MB0_WAKEUP_4500));
777 writeb(header[i], (tcdm_base + PRCM_MBOX_HEADER_REQ_MB0)); 816 writeb(header[i], (tcdm_base + PRCM_MBOX_HEADER_REQ_MB0));
778 writel(MBOX_BIT(0), (_PRCMU_BASE + PRCM_MBOX_CPU_SET)); 817 writel(MBOX_BIT(0), PRCM_MBOX_CPU_SET);
779 } 818 }
780 last_dbb_events = dbb_events; 819 last_dbb_events = dbb_events;
781 last_abb_events = abb_events; 820 last_abb_events = abb_events;
782} 821}
783 822
784void prcmu_enable_wakeups(u32 wakeups) 823void db8500_prcmu_enable_wakeups(u32 wakeups)
785{ 824{
786 unsigned long flags; 825 unsigned long flags;
787 u32 bits; 826 u32 bits;
@@ -802,7 +841,7 @@ void prcmu_enable_wakeups(u32 wakeups)
802 spin_unlock_irqrestore(&mb0_transfer.lock, flags); 841 spin_unlock_irqrestore(&mb0_transfer.lock, flags);
803} 842}
804 843
805void prcmu_config_abb_event_readout(u32 abb_events) 844void db8500_prcmu_config_abb_event_readout(u32 abb_events)
806{ 845{
807 unsigned long flags; 846 unsigned long flags;
808 847
@@ -814,7 +853,7 @@ void prcmu_config_abb_event_readout(u32 abb_events)
814 spin_unlock_irqrestore(&mb0_transfer.lock, flags); 853 spin_unlock_irqrestore(&mb0_transfer.lock, flags);
815} 854}
816 855
817void prcmu_get_abb_event_buffer(void __iomem **buf) 856void db8500_prcmu_get_abb_event_buffer(void __iomem **buf)
818{ 857{
819 if (readb(tcdm_base + PRCM_ACK_MB0_READ_POINTER) & 1) 858 if (readb(tcdm_base + PRCM_ACK_MB0_READ_POINTER) & 1)
820 *buf = (tcdm_base + PRCM_ACK_MB0_WAKEUP_1_4500); 859 *buf = (tcdm_base + PRCM_ACK_MB0_WAKEUP_1_4500);
@@ -823,13 +862,13 @@ void prcmu_get_abb_event_buffer(void __iomem **buf)
823} 862}
824 863
825/** 864/**
826 * prcmu_set_arm_opp - set the appropriate ARM OPP 865 * db8500_prcmu_set_arm_opp - set the appropriate ARM OPP
827 * @opp: The new ARM operating point to which transition is to be made 866 * @opp: The new ARM operating point to which transition is to be made
828 * Returns: 0 on success, non-zero on failure 867 * Returns: 0 on success, non-zero on failure
829 * 868 *
830 * This function sets the the operating point of the ARM. 869 * This function sets the the operating point of the ARM.
831 */ 870 */
832int prcmu_set_arm_opp(u8 opp) 871int db8500_prcmu_set_arm_opp(u8 opp)
833{ 872{
834 int r; 873 int r;
835 874
@@ -840,14 +879,14 @@ int prcmu_set_arm_opp(u8 opp)
840 879
841 mutex_lock(&mb1_transfer.lock); 880 mutex_lock(&mb1_transfer.lock);
842 881
843 while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(1)) 882 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
844 cpu_relax(); 883 cpu_relax();
845 884
846 writeb(MB1H_ARM_APE_OPP, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1)); 885 writeb(MB1H_ARM_APE_OPP, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
847 writeb(opp, (tcdm_base + PRCM_REQ_MB1_ARM_OPP)); 886 writeb(opp, (tcdm_base + PRCM_REQ_MB1_ARM_OPP));
848 writeb(APE_NO_CHANGE, (tcdm_base + PRCM_REQ_MB1_APE_OPP)); 887 writeb(APE_NO_CHANGE, (tcdm_base + PRCM_REQ_MB1_APE_OPP));
849 888
850 writel(MBOX_BIT(1), (_PRCMU_BASE + PRCM_MBOX_CPU_SET)); 889 writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET);
851 wait_for_completion(&mb1_transfer.work); 890 wait_for_completion(&mb1_transfer.work);
852 891
853 if ((mb1_transfer.ack.header != MB1H_ARM_APE_OPP) || 892 if ((mb1_transfer.ack.header != MB1H_ARM_APE_OPP) ||
@@ -860,11 +899,11 @@ int prcmu_set_arm_opp(u8 opp)
860} 899}
861 900
862/** 901/**
863 * prcmu_get_arm_opp - get the current ARM OPP 902 * db8500_prcmu_get_arm_opp - get the current ARM OPP
864 * 903 *
865 * Returns: the current ARM OPP 904 * Returns: the current ARM OPP
866 */ 905 */
867int prcmu_get_arm_opp(void) 906int db8500_prcmu_get_arm_opp(void)
868{ 907{
869 return readb(tcdm_base + PRCM_ACK_MB1_CURRENT_ARM_OPP); 908 return readb(tcdm_base + PRCM_ACK_MB1_CURRENT_ARM_OPP);
870} 909}
@@ -876,7 +915,7 @@ int prcmu_get_arm_opp(void)
876 */ 915 */
877int prcmu_get_ddr_opp(void) 916int prcmu_get_ddr_opp(void)
878{ 917{
879 return readb(_PRCMU_BASE + PRCM_DDR_SUBSYS_APE_MINBW); 918 return readb(PRCM_DDR_SUBSYS_APE_MINBW);
880} 919}
881 920
882/** 921/**
@@ -892,7 +931,7 @@ int prcmu_set_ddr_opp(u8 opp)
892 return -EINVAL; 931 return -EINVAL;
893 /* Changing the DDR OPP can hang the hardware pre-v21 */ 932 /* Changing the DDR OPP can hang the hardware pre-v21 */
894 if (cpu_is_u8500v20_or_later() && !cpu_is_u8500v20()) 933 if (cpu_is_u8500v20_or_later() && !cpu_is_u8500v20())
895 writeb(opp, (_PRCMU_BASE + PRCM_DDR_SUBSYS_APE_MINBW)); 934 writeb(opp, PRCM_DDR_SUBSYS_APE_MINBW);
896 935
897 return 0; 936 return 0;
898} 937}
@@ -909,14 +948,14 @@ int prcmu_set_ape_opp(u8 opp)
909 948
910 mutex_lock(&mb1_transfer.lock); 949 mutex_lock(&mb1_transfer.lock);
911 950
912 while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(1)) 951 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
913 cpu_relax(); 952 cpu_relax();
914 953
915 writeb(MB1H_ARM_APE_OPP, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1)); 954 writeb(MB1H_ARM_APE_OPP, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
916 writeb(ARM_NO_CHANGE, (tcdm_base + PRCM_REQ_MB1_ARM_OPP)); 955 writeb(ARM_NO_CHANGE, (tcdm_base + PRCM_REQ_MB1_ARM_OPP));
917 writeb(opp, (tcdm_base + PRCM_REQ_MB1_APE_OPP)); 956 writeb(opp, (tcdm_base + PRCM_REQ_MB1_APE_OPP));
918 957
919 writel(MBOX_BIT(1), (_PRCMU_BASE + PRCM_MBOX_CPU_SET)); 958 writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET);
920 wait_for_completion(&mb1_transfer.work); 959 wait_for_completion(&mb1_transfer.work);
921 960
922 if ((mb1_transfer.ack.header != MB1H_ARM_APE_OPP) || 961 if ((mb1_transfer.ack.header != MB1H_ARM_APE_OPP) ||
@@ -966,12 +1005,12 @@ int prcmu_request_ape_opp_100_voltage(bool enable)
966 header = MB1H_RELEASE_APE_OPP_100_VOLT; 1005 header = MB1H_RELEASE_APE_OPP_100_VOLT;
967 } 1006 }
968 1007
969 while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(1)) 1008 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
970 cpu_relax(); 1009 cpu_relax();
971 1010
972 writeb(header, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1)); 1011 writeb(header, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
973 1012
974 writel(MBOX_BIT(1), (_PRCMU_BASE + PRCM_MBOX_CPU_SET)); 1013 writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET);
975 wait_for_completion(&mb1_transfer.work); 1014 wait_for_completion(&mb1_transfer.work);
976 1015
977 if ((mb1_transfer.ack.header != header) || 1016 if ((mb1_transfer.ack.header != header) ||
@@ -995,13 +1034,13 @@ int prcmu_release_usb_wakeup_state(void)
995 1034
996 mutex_lock(&mb1_transfer.lock); 1035 mutex_lock(&mb1_transfer.lock);
997 1036
998 while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(1)) 1037 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
999 cpu_relax(); 1038 cpu_relax();
1000 1039
1001 writeb(MB1H_RELEASE_USB_WAKEUP, 1040 writeb(MB1H_RELEASE_USB_WAKEUP,
1002 (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1)); 1041 (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
1003 1042
1004 writel(MBOX_BIT(1), (_PRCMU_BASE + PRCM_MBOX_CPU_SET)); 1043 writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET);
1005 wait_for_completion(&mb1_transfer.work); 1044 wait_for_completion(&mb1_transfer.work);
1006 1045
1007 if ((mb1_transfer.ack.header != MB1H_RELEASE_USB_WAKEUP) || 1046 if ((mb1_transfer.ack.header != MB1H_RELEASE_USB_WAKEUP) ||
@@ -1013,15 +1052,169 @@ int prcmu_release_usb_wakeup_state(void)
1013 return r; 1052 return r;
1014} 1053}
1015 1054
1055static int request_pll(u8 clock, bool enable)
1056{
1057 int r = 0;
1058
1059 if (clock == PRCMU_PLLSOC1)
1060 clock = (enable ? PLL_SOC1_ON : PLL_SOC1_OFF);
1061 else
1062 return -EINVAL;
1063
1064 mutex_lock(&mb1_transfer.lock);
1065
1066 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
1067 cpu_relax();
1068
1069 writeb(MB1H_PLL_ON_OFF, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
1070 writeb(clock, (tcdm_base + PRCM_REQ_MB1_PLL_ON_OFF));
1071
1072 writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET);
1073 wait_for_completion(&mb1_transfer.work);
1074
1075 if (mb1_transfer.ack.header != MB1H_PLL_ON_OFF)
1076 r = -EIO;
1077
1078 mutex_unlock(&mb1_transfer.lock);
1079
1080 return r;
1081}
1082
1016/** 1083/**
1017 * prcmu_set_epod - set the state of a EPOD (power domain) 1084 * prcmu_set_hwacc - set the power state of a h/w accelerator
1085 * @hwacc_dev: The hardware accelerator (enum hw_acc_dev).
1086 * @state: The new power state (enum hw_acc_state).
1087 *
1088 * This function sets the power state of a hardware accelerator.
1089 * This function should not be called from interrupt context.
1090 *
1091 * NOTE! Deprecated, to be removed when all users switched over to use the
1092 * regulator framework API.
1093 */
1094int prcmu_set_hwacc(u16 hwacc_dev, u8 state)
1095{
1096 int r = 0;
1097 bool ram_retention = false;
1098 bool enable, enable_ret;
1099
1100 /* check argument */
1101 BUG_ON(hwacc_dev >= NUM_HW_ACC);
1102
1103 /* get state of switches */
1104 enable = hwacc_enabled[hwacc_dev];
1105 enable_ret = hwacc_ret_enabled[hwacc_dev];
1106
1107 /* set flag if retention is possible */
1108 switch (hwacc_dev) {
1109 case HW_ACC_SVAMMDSP:
1110 case HW_ACC_SIAMMDSP:
1111 case HW_ACC_ESRAM1:
1112 case HW_ACC_ESRAM2:
1113 case HW_ACC_ESRAM3:
1114 case HW_ACC_ESRAM4:
1115 ram_retention = true;
1116 break;
1117 }
1118
1119 /* check argument */
1120 BUG_ON(state > HW_ON);
1121 BUG_ON(state == HW_OFF_RAMRET && !ram_retention);
1122
1123 /* modify enable flags */
1124 switch (state) {
1125 case HW_OFF:
1126 enable_ret = false;
1127 enable = false;
1128 break;
1129 case HW_ON:
1130 enable = true;
1131 break;
1132 case HW_OFF_RAMRET:
1133 enable_ret = true;
1134 enable = false;
1135 break;
1136 }
1137
1138 /* get regulator (lazy) */
1139 if (hwacc_regulator[hwacc_dev] == NULL) {
1140 hwacc_regulator[hwacc_dev] = regulator_get(NULL,
1141 hwacc_regulator_name[hwacc_dev]);
1142 if (IS_ERR(hwacc_regulator[hwacc_dev])) {
1143 pr_err("prcmu: failed to get supply %s\n",
1144 hwacc_regulator_name[hwacc_dev]);
1145 r = PTR_ERR(hwacc_regulator[hwacc_dev]);
1146 goto out;
1147 }
1148 }
1149
1150 if (ram_retention) {
1151 if (hwacc_ret_regulator[hwacc_dev] == NULL) {
1152 hwacc_ret_regulator[hwacc_dev] = regulator_get(NULL,
1153 hwacc_ret_regulator_name[hwacc_dev]);
1154 if (IS_ERR(hwacc_ret_regulator[hwacc_dev])) {
1155 pr_err("prcmu: failed to get supply %s\n",
1156 hwacc_ret_regulator_name[hwacc_dev]);
1157 r = PTR_ERR(hwacc_ret_regulator[hwacc_dev]);
1158 goto out;
1159 }
1160 }
1161 }
1162
1163 /* set regulators */
1164 if (ram_retention) {
1165 if (enable_ret && !hwacc_ret_enabled[hwacc_dev]) {
1166 r = regulator_enable(hwacc_ret_regulator[hwacc_dev]);
1167 if (r < 0) {
1168 pr_err("prcmu_set_hwacc: ret enable failed\n");
1169 goto out;
1170 }
1171 hwacc_ret_enabled[hwacc_dev] = true;
1172 }
1173 }
1174
1175 if (enable && !hwacc_enabled[hwacc_dev]) {
1176 r = regulator_enable(hwacc_regulator[hwacc_dev]);
1177 if (r < 0) {
1178 pr_err("prcmu_set_hwacc: enable failed\n");
1179 goto out;
1180 }
1181 hwacc_enabled[hwacc_dev] = true;
1182 }
1183
1184 if (!enable && hwacc_enabled[hwacc_dev]) {
1185 r = regulator_disable(hwacc_regulator[hwacc_dev]);
1186 if (r < 0) {
1187 pr_err("prcmu_set_hwacc: disable failed\n");
1188 goto out;
1189 }
1190 hwacc_enabled[hwacc_dev] = false;
1191 }
1192
1193 if (ram_retention) {
1194 if (!enable_ret && hwacc_ret_enabled[hwacc_dev]) {
1195 r = regulator_disable(hwacc_ret_regulator[hwacc_dev]);
1196 if (r < 0) {
1197 pr_err("prcmu_set_hwacc: ret disable failed\n");
1198 goto out;
1199 }
1200 hwacc_ret_enabled[hwacc_dev] = false;
1201 }
1202 }
1203
1204out:
1205 return r;
1206}
1207EXPORT_SYMBOL(prcmu_set_hwacc);
1208
1209/**
1210 * db8500_prcmu_set_epod - set the state of a EPOD (power domain)
1018 * @epod_id: The EPOD to set 1211 * @epod_id: The EPOD to set
1019 * @epod_state: The new EPOD state 1212 * @epod_state: The new EPOD state
1020 * 1213 *
1021 * This function sets the state of a EPOD (power domain). It may not be called 1214 * This function sets the state of a EPOD (power domain). It may not be called
1022 * from interrupt context. 1215 * from interrupt context.
1023 */ 1216 */
1024int prcmu_set_epod(u16 epod_id, u8 epod_state) 1217int db8500_prcmu_set_epod(u16 epod_id, u8 epod_state)
1025{ 1218{
1026 int r = 0; 1219 int r = 0;
1027 bool ram_retention = false; 1220 bool ram_retention = false;
@@ -1048,7 +1241,7 @@ int prcmu_set_epod(u16 epod_id, u8 epod_state)
1048 mutex_lock(&mb2_transfer.lock); 1241 mutex_lock(&mb2_transfer.lock);
1049 1242
1050 /* wait for mailbox */ 1243 /* wait for mailbox */
1051 while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(2)) 1244 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(2))
1052 cpu_relax(); 1245 cpu_relax();
1053 1246
1054 /* fill in mailbox */ 1247 /* fill in mailbox */
@@ -1058,7 +1251,7 @@ int prcmu_set_epod(u16 epod_id, u8 epod_state)
1058 1251
1059 writeb(MB2H_DPS, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB2)); 1252 writeb(MB2H_DPS, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB2));
1060 1253
1061 writel(MBOX_BIT(2), (_PRCMU_BASE + PRCM_MBOX_CPU_SET)); 1254 writel(MBOX_BIT(2), PRCM_MBOX_CPU_SET);
1062 1255
1063 /* 1256 /*
1064 * The current firmware version does not handle errors correctly, 1257 * The current firmware version does not handle errors correctly,
@@ -1145,13 +1338,13 @@ static int request_sysclk(bool enable)
1145 1338
1146 spin_lock_irqsave(&mb3_transfer.lock, flags); 1339 spin_lock_irqsave(&mb3_transfer.lock, flags);
1147 1340
1148 while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(3)) 1341 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(3))
1149 cpu_relax(); 1342 cpu_relax();
1150 1343
1151 writeb((enable ? ON : OFF), (tcdm_base + PRCM_REQ_MB3_SYSCLK_MGT)); 1344 writeb((enable ? ON : OFF), (tcdm_base + PRCM_REQ_MB3_SYSCLK_MGT));
1152 1345
1153 writeb(MB3H_SYSCLK, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB3)); 1346 writeb(MB3H_SYSCLK, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB3));
1154 writel(MBOX_BIT(3), (_PRCMU_BASE + PRCM_MBOX_CPU_SET)); 1347 writel(MBOX_BIT(3), PRCM_MBOX_CPU_SET);
1155 1348
1156 spin_unlock_irqrestore(&mb3_transfer.lock, flags); 1349 spin_unlock_irqrestore(&mb3_transfer.lock, flags);
1157 1350
@@ -1177,7 +1370,7 @@ static int request_timclk(bool enable)
1177 1370
1178 if (!enable) 1371 if (!enable)
1179 val |= PRCM_TCR_STOP_TIMERS; 1372 val |= PRCM_TCR_STOP_TIMERS;
1180 writel(val, (_PRCMU_BASE + PRCM_TCR)); 1373 writel(val, PRCM_TCR);
1181 1374
1182 return 0; 1375 return 0;
1183} 1376}
@@ -1190,7 +1383,7 @@ static int request_reg_clock(u8 clock, bool enable)
1190 spin_lock_irqsave(&clk_mgt_lock, flags); 1383 spin_lock_irqsave(&clk_mgt_lock, flags);
1191 1384
1192 /* Grab the HW semaphore. */ 1385 /* Grab the HW semaphore. */
1193 while ((readl(_PRCMU_BASE + PRCM_SEM) & PRCM_SEM_PRCM_SEM) != 0) 1386 while ((readl(PRCM_SEM) & PRCM_SEM_PRCM_SEM) != 0)
1194 cpu_relax(); 1387 cpu_relax();
1195 1388
1196 val = readl(_PRCMU_BASE + clk_mgt[clock].offset); 1389 val = readl(_PRCMU_BASE + clk_mgt[clock].offset);
@@ -1203,34 +1396,61 @@ static int request_reg_clock(u8 clock, bool enable)
1203 writel(val, (_PRCMU_BASE + clk_mgt[clock].offset)); 1396 writel(val, (_PRCMU_BASE + clk_mgt[clock].offset));
1204 1397
1205 /* Release the HW semaphore. */ 1398 /* Release the HW semaphore. */
1206 writel(0, (_PRCMU_BASE + PRCM_SEM)); 1399 writel(0, PRCM_SEM);
1207 1400
1208 spin_unlock_irqrestore(&clk_mgt_lock, flags); 1401 spin_unlock_irqrestore(&clk_mgt_lock, flags);
1209 1402
1210 return 0; 1403 return 0;
1211} 1404}
1212 1405
1406static int request_sga_clock(u8 clock, bool enable)
1407{
1408 u32 val;
1409 int ret;
1410
1411 if (enable) {
1412 val = readl(PRCM_CGATING_BYPASS);
1413 writel(val | PRCM_CGATING_BYPASS_ICN2, PRCM_CGATING_BYPASS);
1414 }
1415
1416 ret = request_reg_clock(clock, enable);
1417
1418 if (!ret && !enable) {
1419 val = readl(PRCM_CGATING_BYPASS);
1420 writel(val & ~PRCM_CGATING_BYPASS_ICN2, PRCM_CGATING_BYPASS);
1421 }
1422
1423 return ret;
1424}
1425
1213/** 1426/**
1214 * prcmu_request_clock() - Request for a clock to be enabled or disabled. 1427 * db8500_prcmu_request_clock() - Request for a clock to be enabled or disabled.
1215 * @clock: The clock for which the request is made. 1428 * @clock: The clock for which the request is made.
1216 * @enable: Whether the clock should be enabled (true) or disabled (false). 1429 * @enable: Whether the clock should be enabled (true) or disabled (false).
1217 * 1430 *
1218 * This function should only be used by the clock implementation. 1431 * This function should only be used by the clock implementation.
1219 * Do not use it from any other place! 1432 * Do not use it from any other place!
1220 */ 1433 */
1221int prcmu_request_clock(u8 clock, bool enable) 1434int db8500_prcmu_request_clock(u8 clock, bool enable)
1222{ 1435{
1223 if (clock < PRCMU_NUM_REG_CLOCKS) 1436 switch(clock) {
1224 return request_reg_clock(clock, enable); 1437 case PRCMU_SGACLK:
1225 else if (clock == PRCMU_TIMCLK) 1438 return request_sga_clock(clock, enable);
1439 case PRCMU_TIMCLK:
1226 return request_timclk(enable); 1440 return request_timclk(enable);
1227 else if (clock == PRCMU_SYSCLK) 1441 case PRCMU_SYSCLK:
1228 return request_sysclk(enable); 1442 return request_sysclk(enable);
1229 else 1443 case PRCMU_PLLSOC1:
1230 return -EINVAL; 1444 return request_pll(clock, enable);
1445 default:
1446 break;
1447 }
1448 if (clock < PRCMU_NUM_REG_CLOCKS)
1449 return request_reg_clock(clock, enable);
1450 return -EINVAL;
1231} 1451}
1232 1452
1233int prcmu_config_esram0_deep_sleep(u8 state) 1453int db8500_prcmu_config_esram0_deep_sleep(u8 state)
1234{ 1454{
1235 if ((state > ESRAM0_DEEP_SLEEP_STATE_RET) || 1455 if ((state > ESRAM0_DEEP_SLEEP_STATE_RET) ||
1236 (state < ESRAM0_DEEP_SLEEP_STATE_OFF)) 1456 (state < ESRAM0_DEEP_SLEEP_STATE_OFF))
@@ -1238,7 +1458,7 @@ int prcmu_config_esram0_deep_sleep(u8 state)
1238 1458
1239 mutex_lock(&mb4_transfer.lock); 1459 mutex_lock(&mb4_transfer.lock);
1240 1460
1241 while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(4)) 1461 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
1242 cpu_relax(); 1462 cpu_relax();
1243 1463
1244 writeb(MB4H_MEM_ST, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4)); 1464 writeb(MB4H_MEM_ST, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
@@ -1248,7 +1468,7 @@ int prcmu_config_esram0_deep_sleep(u8 state)
1248 (tcdm_base + PRCM_REQ_MB4_DDR_ST_AP_DEEP_IDLE)); 1468 (tcdm_base + PRCM_REQ_MB4_DDR_ST_AP_DEEP_IDLE));
1249 writeb(state, (tcdm_base + PRCM_REQ_MB4_ESRAM0_ST)); 1469 writeb(state, (tcdm_base + PRCM_REQ_MB4_ESRAM0_ST));
1250 1470
1251 writel(MBOX_BIT(4), (_PRCMU_BASE + PRCM_MBOX_CPU_SET)); 1471 writel(MBOX_BIT(4), PRCM_MBOX_CPU_SET);
1252 wait_for_completion(&mb4_transfer.work); 1472 wait_for_completion(&mb4_transfer.work);
1253 1473
1254 mutex_unlock(&mb4_transfer.lock); 1474 mutex_unlock(&mb4_transfer.lock);
@@ -1260,13 +1480,13 @@ int prcmu_config_hotdog(u8 threshold)
1260{ 1480{
1261 mutex_lock(&mb4_transfer.lock); 1481 mutex_lock(&mb4_transfer.lock);
1262 1482
1263 while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(4)) 1483 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
1264 cpu_relax(); 1484 cpu_relax();
1265 1485
1266 writeb(threshold, (tcdm_base + PRCM_REQ_MB4_HOTDOG_THRESHOLD)); 1486 writeb(threshold, (tcdm_base + PRCM_REQ_MB4_HOTDOG_THRESHOLD));
1267 writeb(MB4H_HOTDOG, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4)); 1487 writeb(MB4H_HOTDOG, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
1268 1488
1269 writel(MBOX_BIT(4), (_PRCMU_BASE + PRCM_MBOX_CPU_SET)); 1489 writel(MBOX_BIT(4), PRCM_MBOX_CPU_SET);
1270 wait_for_completion(&mb4_transfer.work); 1490 wait_for_completion(&mb4_transfer.work);
1271 1491
1272 mutex_unlock(&mb4_transfer.lock); 1492 mutex_unlock(&mb4_transfer.lock);
@@ -1278,7 +1498,7 @@ int prcmu_config_hotmon(u8 low, u8 high)
1278{ 1498{
1279 mutex_lock(&mb4_transfer.lock); 1499 mutex_lock(&mb4_transfer.lock);
1280 1500
1281 while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(4)) 1501 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
1282 cpu_relax(); 1502 cpu_relax();
1283 1503
1284 writeb(low, (tcdm_base + PRCM_REQ_MB4_HOTMON_LOW)); 1504 writeb(low, (tcdm_base + PRCM_REQ_MB4_HOTMON_LOW));
@@ -1287,7 +1507,7 @@ int prcmu_config_hotmon(u8 low, u8 high)
1287 (tcdm_base + PRCM_REQ_MB4_HOTMON_CONFIG)); 1507 (tcdm_base + PRCM_REQ_MB4_HOTMON_CONFIG));
1288 writeb(MB4H_HOTMON, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4)); 1508 writeb(MB4H_HOTMON, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
1289 1509
1290 writel(MBOX_BIT(4), (_PRCMU_BASE + PRCM_MBOX_CPU_SET)); 1510 writel(MBOX_BIT(4), PRCM_MBOX_CPU_SET);
1291 wait_for_completion(&mb4_transfer.work); 1511 wait_for_completion(&mb4_transfer.work);
1292 1512
1293 mutex_unlock(&mb4_transfer.lock); 1513 mutex_unlock(&mb4_transfer.lock);
@@ -1299,13 +1519,13 @@ static int config_hot_period(u16 val)
1299{ 1519{
1300 mutex_lock(&mb4_transfer.lock); 1520 mutex_lock(&mb4_transfer.lock);
1301 1521
1302 while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(4)) 1522 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
1303 cpu_relax(); 1523 cpu_relax();
1304 1524
1305 writew(val, (tcdm_base + PRCM_REQ_MB4_HOT_PERIOD)); 1525 writew(val, (tcdm_base + PRCM_REQ_MB4_HOT_PERIOD));
1306 writeb(MB4H_HOT_PERIOD, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4)); 1526 writeb(MB4H_HOT_PERIOD, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
1307 1527
1308 writel(MBOX_BIT(4), (_PRCMU_BASE + PRCM_MBOX_CPU_SET)); 1528 writel(MBOX_BIT(4), PRCM_MBOX_CPU_SET);
1309 wait_for_completion(&mb4_transfer.work); 1529 wait_for_completion(&mb4_transfer.work);
1310 1530
1311 mutex_unlock(&mb4_transfer.lock); 1531 mutex_unlock(&mb4_transfer.lock);
@@ -1326,6 +1546,78 @@ int prcmu_stop_temp_sense(void)
1326 return config_hot_period(0xFFFF); 1546 return config_hot_period(0xFFFF);
1327} 1547}
1328 1548
1549static int prcmu_a9wdog(u8 cmd, u8 d0, u8 d1, u8 d2, u8 d3)
1550{
1551
1552 mutex_lock(&mb4_transfer.lock);
1553
1554 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(4))
1555 cpu_relax();
1556
1557 writeb(d0, (tcdm_base + PRCM_REQ_MB4_A9WDOG_0));
1558 writeb(d1, (tcdm_base + PRCM_REQ_MB4_A9WDOG_1));
1559 writeb(d2, (tcdm_base + PRCM_REQ_MB4_A9WDOG_2));
1560 writeb(d3, (tcdm_base + PRCM_REQ_MB4_A9WDOG_3));
1561
1562 writeb(cmd, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB4));
1563
1564 writel(MBOX_BIT(4), PRCM_MBOX_CPU_SET);
1565 wait_for_completion(&mb4_transfer.work);
1566
1567 mutex_unlock(&mb4_transfer.lock);
1568
1569 return 0;
1570
1571}
1572
1573int prcmu_config_a9wdog(u8 num, bool sleep_auto_off)
1574{
1575 BUG_ON(num == 0 || num > 0xf);
1576 return prcmu_a9wdog(MB4H_A9WDOG_CONF, num, 0, 0,
1577 sleep_auto_off ? A9WDOG_AUTO_OFF_EN :
1578 A9WDOG_AUTO_OFF_DIS);
1579}
1580
1581int prcmu_enable_a9wdog(u8 id)
1582{
1583 return prcmu_a9wdog(MB4H_A9WDOG_EN, id, 0, 0, 0);
1584}
1585
1586int prcmu_disable_a9wdog(u8 id)
1587{
1588 return prcmu_a9wdog(MB4H_A9WDOG_DIS, id, 0, 0, 0);
1589}
1590
1591int prcmu_kick_a9wdog(u8 id)
1592{
1593 return prcmu_a9wdog(MB4H_A9WDOG_KICK, id, 0, 0, 0);
1594}
1595
1596/*
1597 * timeout is 28 bit, in ms.
1598 */
1599#define MAX_WATCHDOG_TIMEOUT 131000
1600int prcmu_load_a9wdog(u8 id, u32 timeout)
1601{
1602 if (timeout > MAX_WATCHDOG_TIMEOUT)
1603 /*
1604 * Due to calculation bug in prcmu fw, timeouts
1605 * can't be bigger than 131 seconds.
1606 */
1607 return -EINVAL;
1608
1609 return prcmu_a9wdog(MB4H_A9WDOG_LOAD,
1610 (id & A9WDOG_ID_MASK) |
1611 /*
1612 * Put the lowest 28 bits of timeout at
1613 * offset 4. Four first bits are used for id.
1614 */
1615 (u8)((timeout << 4) & 0xf0),
1616 (u8)((timeout >> 4) & 0xff),
1617 (u8)((timeout >> 12) & 0xff),
1618 (u8)((timeout >> 20) & 0xff));
1619}
1620
1329/** 1621/**
1330 * prcmu_set_clock_divider() - Configure the clock divider. 1622 * prcmu_set_clock_divider() - Configure the clock divider.
1331 * @clock: The clock for which the request is made. 1623 * @clock: The clock for which the request is made.
@@ -1345,7 +1637,7 @@ int prcmu_set_clock_divider(u8 clock, u8 divider)
1345 spin_lock_irqsave(&clk_mgt_lock, flags); 1637 spin_lock_irqsave(&clk_mgt_lock, flags);
1346 1638
1347 /* Grab the HW semaphore. */ 1639 /* Grab the HW semaphore. */
1348 while ((readl(_PRCMU_BASE + PRCM_SEM) & PRCM_SEM_PRCM_SEM) != 0) 1640 while ((readl(PRCM_SEM) & PRCM_SEM_PRCM_SEM) != 0)
1349 cpu_relax(); 1641 cpu_relax();
1350 1642
1351 val = readl(_PRCMU_BASE + clk_mgt[clock].offset); 1643 val = readl(_PRCMU_BASE + clk_mgt[clock].offset);
@@ -1354,7 +1646,7 @@ int prcmu_set_clock_divider(u8 clock, u8 divider)
1354 writel(val, (_PRCMU_BASE + clk_mgt[clock].offset)); 1646 writel(val, (_PRCMU_BASE + clk_mgt[clock].offset));
1355 1647
1356 /* Release the HW semaphore. */ 1648 /* Release the HW semaphore. */
1357 writel(0, (_PRCMU_BASE + PRCM_SEM)); 1649 writel(0, PRCM_SEM);
1358 1650
1359 spin_unlock_irqrestore(&clk_mgt_lock, flags); 1651 spin_unlock_irqrestore(&clk_mgt_lock, flags);
1360 1652
@@ -1380,7 +1672,7 @@ int prcmu_abb_read(u8 slave, u8 reg, u8 *value, u8 size)
1380 1672
1381 mutex_lock(&mb5_transfer.lock); 1673 mutex_lock(&mb5_transfer.lock);
1382 1674
1383 while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(5)) 1675 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(5))
1384 cpu_relax(); 1676 cpu_relax();
1385 1677
1386 writeb(PRCMU_I2C_READ(slave), (tcdm_base + PRCM_REQ_MB5_I2C_SLAVE_OP)); 1678 writeb(PRCMU_I2C_READ(slave), (tcdm_base + PRCM_REQ_MB5_I2C_SLAVE_OP));
@@ -1388,7 +1680,7 @@ int prcmu_abb_read(u8 slave, u8 reg, u8 *value, u8 size)
1388 writeb(reg, (tcdm_base + PRCM_REQ_MB5_I2C_REG)); 1680 writeb(reg, (tcdm_base + PRCM_REQ_MB5_I2C_REG));
1389 writeb(0, (tcdm_base + PRCM_REQ_MB5_I2C_VAL)); 1681 writeb(0, (tcdm_base + PRCM_REQ_MB5_I2C_VAL));
1390 1682
1391 writel(MBOX_BIT(5), (_PRCMU_BASE + PRCM_MBOX_CPU_SET)); 1683 writel(MBOX_BIT(5), PRCM_MBOX_CPU_SET);
1392 1684
1393 if (!wait_for_completion_timeout(&mb5_transfer.work, 1685 if (!wait_for_completion_timeout(&mb5_transfer.work,
1394 msecs_to_jiffies(20000))) { 1686 msecs_to_jiffies(20000))) {
@@ -1426,7 +1718,7 @@ int prcmu_abb_write(u8 slave, u8 reg, u8 *value, u8 size)
1426 1718
1427 mutex_lock(&mb5_transfer.lock); 1719 mutex_lock(&mb5_transfer.lock);
1428 1720
1429 while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(5)) 1721 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(5))
1430 cpu_relax(); 1722 cpu_relax();
1431 1723
1432 writeb(PRCMU_I2C_WRITE(slave), (tcdm_base + PRCM_REQ_MB5_I2C_SLAVE_OP)); 1724 writeb(PRCMU_I2C_WRITE(slave), (tcdm_base + PRCM_REQ_MB5_I2C_SLAVE_OP));
@@ -1434,7 +1726,7 @@ int prcmu_abb_write(u8 slave, u8 reg, u8 *value, u8 size)
1434 writeb(reg, (tcdm_base + PRCM_REQ_MB5_I2C_REG)); 1726 writeb(reg, (tcdm_base + PRCM_REQ_MB5_I2C_REG));
1435 writeb(*value, (tcdm_base + PRCM_REQ_MB5_I2C_VAL)); 1727 writeb(*value, (tcdm_base + PRCM_REQ_MB5_I2C_VAL));
1436 1728
1437 writel(MBOX_BIT(5), (_PRCMU_BASE + PRCM_MBOX_CPU_SET)); 1729 writel(MBOX_BIT(5), PRCM_MBOX_CPU_SET);
1438 1730
1439 if (!wait_for_completion_timeout(&mb5_transfer.work, 1731 if (!wait_for_completion_timeout(&mb5_transfer.work,
1440 msecs_to_jiffies(20000))) { 1732 msecs_to_jiffies(20000))) {
@@ -1456,21 +1748,44 @@ int prcmu_abb_write(u8 slave, u8 reg, u8 *value, u8 size)
1456void prcmu_ac_wake_req(void) 1748void prcmu_ac_wake_req(void)
1457{ 1749{
1458 u32 val; 1750 u32 val;
1751 u32 status;
1459 1752
1460 mutex_lock(&mb0_transfer.ac_wake_lock); 1753 mutex_lock(&mb0_transfer.ac_wake_lock);
1461 1754
1462 val = readl(_PRCMU_BASE + PRCM_HOSTACCESS_REQ); 1755 val = readl(PRCM_HOSTACCESS_REQ);
1463 if (val & PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ) 1756 if (val & PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ)
1464 goto unlock_and_return; 1757 goto unlock_and_return;
1465 1758
1466 atomic_set(&ac_wake_req_state, 1); 1759 atomic_set(&ac_wake_req_state, 1);
1467 1760
1468 writel((val | PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ), 1761retry:
1469 (_PRCMU_BASE + PRCM_HOSTACCESS_REQ)); 1762 writel((val | PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ), PRCM_HOSTACCESS_REQ);
1470 1763
1471 if (!wait_for_completion_timeout(&mb0_transfer.ac_wake_work, 1764 if (!wait_for_completion_timeout(&mb0_transfer.ac_wake_work,
1472 msecs_to_jiffies(20000))) { 1765 msecs_to_jiffies(5000))) {
1473 pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n", 1766 pr_crit("prcmu: %s timed out (5 s) waiting for a reply.\n",
1767 __func__);
1768 goto unlock_and_return;
1769 }
1770
1771 /*
1772 * The modem can generate an AC_WAKE_ACK, and then still go to sleep.
1773 * As a workaround, we wait, and then check that the modem is indeed
1774 * awake (in terms of the value of the PRCM_MOD_AWAKE_STATUS
1775 * register, which may not be the whole truth).
1776 */
1777 udelay(400);
1778 status = (readl(PRCM_MOD_AWAKE_STATUS) & BITS(0, 2));
1779 if (status != (PRCM_MOD_AWAKE_STATUS_PRCM_MOD_AAPD_AWAKE |
1780 PRCM_MOD_AWAKE_STATUS_PRCM_MOD_COREPD_AWAKE)) {
1781 pr_err("prcmu: %s received ack, but modem not awake (0x%X).\n",
1782 __func__, status);
1783 udelay(1200);
1784 writel(val, PRCM_HOSTACCESS_REQ);
1785 if (wait_for_completion_timeout(&mb0_transfer.ac_wake_work,
1786 msecs_to_jiffies(5000)))
1787 goto retry;
1788 pr_crit("prcmu: %s timed out (5 s) waiting for AC_SLEEP_ACK.\n",
1474 __func__); 1789 __func__);
1475 } 1790 }
1476 1791
@@ -1487,16 +1802,16 @@ void prcmu_ac_sleep_req()
1487 1802
1488 mutex_lock(&mb0_transfer.ac_wake_lock); 1803 mutex_lock(&mb0_transfer.ac_wake_lock);
1489 1804
1490 val = readl(_PRCMU_BASE + PRCM_HOSTACCESS_REQ); 1805 val = readl(PRCM_HOSTACCESS_REQ);
1491 if (!(val & PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ)) 1806 if (!(val & PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ))
1492 goto unlock_and_return; 1807 goto unlock_and_return;
1493 1808
1494 writel((val & ~PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ), 1809 writel((val & ~PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ),
1495 (_PRCMU_BASE + PRCM_HOSTACCESS_REQ)); 1810 PRCM_HOSTACCESS_REQ);
1496 1811
1497 if (!wait_for_completion_timeout(&mb0_transfer.ac_wake_work, 1812 if (!wait_for_completion_timeout(&mb0_transfer.ac_wake_work,
1498 msecs_to_jiffies(20000))) { 1813 msecs_to_jiffies(5000))) {
1499 pr_err("prcmu: %s timed out (20 s) waiting for a reply.\n", 1814 pr_crit("prcmu: %s timed out (5 s) waiting for a reply.\n",
1500 __func__); 1815 __func__);
1501 } 1816 }
1502 1817
@@ -1506,21 +1821,32 @@ unlock_and_return:
1506 mutex_unlock(&mb0_transfer.ac_wake_lock); 1821 mutex_unlock(&mb0_transfer.ac_wake_lock);
1507} 1822}
1508 1823
1509bool prcmu_is_ac_wake_requested(void) 1824bool db8500_prcmu_is_ac_wake_requested(void)
1510{ 1825{
1511 return (atomic_read(&ac_wake_req_state) != 0); 1826 return (atomic_read(&ac_wake_req_state) != 0);
1512} 1827}
1513 1828
1514/** 1829/**
1515 * prcmu_system_reset - System reset 1830 * db8500_prcmu_system_reset - System reset
1516 * 1831 *
1517 * Saves the reset reason code and then sets the APE_SOFRST register which 1832 * Saves the reset reason code and then sets the APE_SOFTRST register which
1518 * fires interrupt to fw 1833 * fires interrupt to fw
1519 */ 1834 */
1520void prcmu_system_reset(u16 reset_code) 1835void db8500_prcmu_system_reset(u16 reset_code)
1521{ 1836{
1522 writew(reset_code, (tcdm_base + PRCM_SW_RST_REASON)); 1837 writew(reset_code, (tcdm_base + PRCM_SW_RST_REASON));
1523 writel(1, (_PRCMU_BASE + PRCM_APE_SOFTRST)); 1838 writel(1, PRCM_APE_SOFTRST);
1839}
1840
1841/**
1842 * db8500_prcmu_get_reset_code - Retrieve SW reset reason code
1843 *
1844 * Retrieves the reset reason code stored by prcmu_system_reset() before
1845 * last restart.
1846 */
1847u16 db8500_prcmu_get_reset_code(void)
1848{
1849 return readw(tcdm_base + PRCM_SW_RST_REASON);
1524} 1850}
1525 1851
1526/** 1852/**
@@ -1530,11 +1856,11 @@ void prcmu_modem_reset(void)
1530{ 1856{
1531 mutex_lock(&mb1_transfer.lock); 1857 mutex_lock(&mb1_transfer.lock);
1532 1858
1533 while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(1)) 1859 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(1))
1534 cpu_relax(); 1860 cpu_relax();
1535 1861
1536 writeb(MB1H_RESET_MODEM, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1)); 1862 writeb(MB1H_RESET_MODEM, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB1));
1537 writel(MBOX_BIT(1), (_PRCMU_BASE + PRCM_MBOX_CPU_SET)); 1863 writel(MBOX_BIT(1), PRCM_MBOX_CPU_SET);
1538 wait_for_completion(&mb1_transfer.work); 1864 wait_for_completion(&mb1_transfer.work);
1539 1865
1540 /* 1866 /*
@@ -1551,11 +1877,11 @@ static void ack_dbb_wakeup(void)
1551 1877
1552 spin_lock_irqsave(&mb0_transfer.lock, flags); 1878 spin_lock_irqsave(&mb0_transfer.lock, flags);
1553 1879
1554 while (readl(_PRCMU_BASE + PRCM_MBOX_CPU_VAL) & MBOX_BIT(0)) 1880 while (readl(PRCM_MBOX_CPU_VAL) & MBOX_BIT(0))
1555 cpu_relax(); 1881 cpu_relax();
1556 1882
1557 writeb(MB0H_READ_WAKEUP_ACK, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB0)); 1883 writeb(MB0H_READ_WAKEUP_ACK, (tcdm_base + PRCM_MBOX_HEADER_REQ_MB0));
1558 writel(MBOX_BIT(0), (_PRCMU_BASE + PRCM_MBOX_CPU_SET)); 1884 writel(MBOX_BIT(0), PRCM_MBOX_CPU_SET);
1559 1885
1560 spin_unlock_irqrestore(&mb0_transfer.lock, flags); 1886 spin_unlock_irqrestore(&mb0_transfer.lock, flags);
1561} 1887}
@@ -1600,7 +1926,7 @@ static bool read_mailbox_0(void)
1600 r = false; 1926 r = false;
1601 break; 1927 break;
1602 } 1928 }
1603 writel(MBOX_BIT(0), (_PRCMU_BASE + PRCM_ARM_IT1_CLR)); 1929 writel(MBOX_BIT(0), PRCM_ARM_IT1_CLR);
1604 return r; 1930 return r;
1605} 1931}
1606 1932
@@ -1613,7 +1939,7 @@ static bool read_mailbox_1(void)
1613 PRCM_ACK_MB1_CURRENT_APE_OPP); 1939 PRCM_ACK_MB1_CURRENT_APE_OPP);
1614 mb1_transfer.ack.ape_voltage_status = readb(tcdm_base + 1940 mb1_transfer.ack.ape_voltage_status = readb(tcdm_base +
1615 PRCM_ACK_MB1_APE_VOLTAGE_STATUS); 1941 PRCM_ACK_MB1_APE_VOLTAGE_STATUS);
1616 writel(MBOX_BIT(1), (_PRCMU_BASE + PRCM_ARM_IT1_CLR)); 1942 writel(MBOX_BIT(1), PRCM_ARM_IT1_CLR);
1617 complete(&mb1_transfer.work); 1943 complete(&mb1_transfer.work);
1618 return false; 1944 return false;
1619} 1945}
@@ -1621,14 +1947,14 @@ static bool read_mailbox_1(void)
1621static bool read_mailbox_2(void) 1947static bool read_mailbox_2(void)
1622{ 1948{
1623 mb2_transfer.ack.status = readb(tcdm_base + PRCM_ACK_MB2_DPS_STATUS); 1949 mb2_transfer.ack.status = readb(tcdm_base + PRCM_ACK_MB2_DPS_STATUS);
1624 writel(MBOX_BIT(2), (_PRCMU_BASE + PRCM_ARM_IT1_CLR)); 1950 writel(MBOX_BIT(2), PRCM_ARM_IT1_CLR);
1625 complete(&mb2_transfer.work); 1951 complete(&mb2_transfer.work);
1626 return false; 1952 return false;
1627} 1953}
1628 1954
1629static bool read_mailbox_3(void) 1955static bool read_mailbox_3(void)
1630{ 1956{
1631 writel(MBOX_BIT(3), (_PRCMU_BASE + PRCM_ARM_IT1_CLR)); 1957 writel(MBOX_BIT(3), PRCM_ARM_IT1_CLR);
1632 return false; 1958 return false;
1633} 1959}
1634 1960
@@ -1643,6 +1969,11 @@ static bool read_mailbox_4(void)
1643 case MB4H_HOTDOG: 1969 case MB4H_HOTDOG:
1644 case MB4H_HOTMON: 1970 case MB4H_HOTMON:
1645 case MB4H_HOT_PERIOD: 1971 case MB4H_HOT_PERIOD:
1972 case MB4H_A9WDOG_CONF:
1973 case MB4H_A9WDOG_EN:
1974 case MB4H_A9WDOG_DIS:
1975 case MB4H_A9WDOG_LOAD:
1976 case MB4H_A9WDOG_KICK:
1646 break; 1977 break;
1647 default: 1978 default:
1648 print_unknown_header_warning(4, header); 1979 print_unknown_header_warning(4, header);
@@ -1650,7 +1981,7 @@ static bool read_mailbox_4(void)
1650 break; 1981 break;
1651 } 1982 }
1652 1983
1653 writel(MBOX_BIT(4), (_PRCMU_BASE + PRCM_ARM_IT1_CLR)); 1984 writel(MBOX_BIT(4), PRCM_ARM_IT1_CLR);
1654 1985
1655 if (do_complete) 1986 if (do_complete)
1656 complete(&mb4_transfer.work); 1987 complete(&mb4_transfer.work);
@@ -1662,20 +1993,20 @@ static bool read_mailbox_5(void)
1662{ 1993{
1663 mb5_transfer.ack.status = readb(tcdm_base + PRCM_ACK_MB5_I2C_STATUS); 1994 mb5_transfer.ack.status = readb(tcdm_base + PRCM_ACK_MB5_I2C_STATUS);
1664 mb5_transfer.ack.value = readb(tcdm_base + PRCM_ACK_MB5_I2C_VAL); 1995 mb5_transfer.ack.value = readb(tcdm_base + PRCM_ACK_MB5_I2C_VAL);
1665 writel(MBOX_BIT(5), (_PRCMU_BASE + PRCM_ARM_IT1_CLR)); 1996 writel(MBOX_BIT(5), PRCM_ARM_IT1_CLR);
1666 complete(&mb5_transfer.work); 1997 complete(&mb5_transfer.work);
1667 return false; 1998 return false;
1668} 1999}
1669 2000
1670static bool read_mailbox_6(void) 2001static bool read_mailbox_6(void)
1671{ 2002{
1672 writel(MBOX_BIT(6), (_PRCMU_BASE + PRCM_ARM_IT1_CLR)); 2003 writel(MBOX_BIT(6), PRCM_ARM_IT1_CLR);
1673 return false; 2004 return false;
1674} 2005}
1675 2006
1676static bool read_mailbox_7(void) 2007static bool read_mailbox_7(void)
1677{ 2008{
1678 writel(MBOX_BIT(7), (_PRCMU_BASE + PRCM_ARM_IT1_CLR)); 2009 writel(MBOX_BIT(7), PRCM_ARM_IT1_CLR);
1679 return false; 2010 return false;
1680} 2011}
1681 2012
@@ -1696,7 +2027,7 @@ static irqreturn_t prcmu_irq_handler(int irq, void *data)
1696 u8 n; 2027 u8 n;
1697 irqreturn_t r; 2028 irqreturn_t r;
1698 2029
1699 bits = (readl(_PRCMU_BASE + PRCM_ARM_IT1_VAL) & ALL_MBOX_BITS); 2030 bits = (readl(PRCM_ARM_IT1_VAL) & ALL_MBOX_BITS);
1700 if (unlikely(!bits)) 2031 if (unlikely(!bits))
1701 return IRQ_NONE; 2032 return IRQ_NONE;
1702 2033
@@ -1768,7 +2099,7 @@ static struct irq_chip prcmu_irq_chip = {
1768 .irq_unmask = prcmu_irq_unmask, 2099 .irq_unmask = prcmu_irq_unmask,
1769}; 2100};
1770 2101
1771void __init prcmu_early_init(void) 2102void __init db8500_prcmu_early_init(void)
1772{ 2103{
1773 unsigned int i; 2104 unsigned int i;
1774 2105
@@ -1826,6 +2157,16 @@ void __init prcmu_early_init(void)
1826 } 2157 }
1827} 2158}
1828 2159
2160static void __init db8500_prcmu_init_clkforce(void)
2161{
2162 u32 val;
2163
2164 val = readl(PRCM_A9PL_FORCE_CLKEN);
2165 val &= ~(PRCM_A9PL_FORCE_CLKEN_PRCM_A9PL_FORCE_CLKEN |
2166 PRCM_A9PL_FORCE_CLKEN_PRCM_A9AXI_FORCE_CLKEN);
2167 writel(val, (PRCM_A9PL_FORCE_CLKEN));
2168}
2169
1829/* 2170/*
1830 * Power domain switches (ePODs) modeled as regulators for the DB8500 SoC 2171 * Power domain switches (ePODs) modeled as regulators for the DB8500 SoC
1831 */ 2172 */
@@ -1861,7 +2202,42 @@ static struct regulator_consumer_supply db8500_vsmps2_consumers[] = {
1861 2202
1862static struct regulator_consumer_supply db8500_b2r2_mcde_consumers[] = { 2203static struct regulator_consumer_supply db8500_b2r2_mcde_consumers[] = {
1863 REGULATOR_SUPPLY("vsupply", "b2r2.0"), 2204 REGULATOR_SUPPLY("vsupply", "b2r2.0"),
1864 REGULATOR_SUPPLY("vsupply", "mcde.0"), 2205 REGULATOR_SUPPLY("vsupply", "mcde"),
2206};
2207
2208/* SVA MMDSP regulator switch */
2209static struct regulator_consumer_supply db8500_svammdsp_consumers[] = {
2210 REGULATOR_SUPPLY("sva-mmdsp", "cm_control"),
2211};
2212
2213/* SVA pipe regulator switch */
2214static struct regulator_consumer_supply db8500_svapipe_consumers[] = {
2215 REGULATOR_SUPPLY("sva-pipe", "cm_control"),
2216};
2217
2218/* SIA MMDSP regulator switch */
2219static struct regulator_consumer_supply db8500_siammdsp_consumers[] = {
2220 REGULATOR_SUPPLY("sia-mmdsp", "cm_control"),
2221};
2222
2223/* SIA pipe regulator switch */
2224static struct regulator_consumer_supply db8500_siapipe_consumers[] = {
2225 REGULATOR_SUPPLY("sia-pipe", "cm_control"),
2226};
2227
2228static struct regulator_consumer_supply db8500_sga_consumers[] = {
2229 REGULATOR_SUPPLY("v-mali", NULL),
2230};
2231
2232/* ESRAM1 and 2 regulator switch */
2233static struct regulator_consumer_supply db8500_esram12_consumers[] = {
2234 REGULATOR_SUPPLY("esram12", "cm_control"),
2235};
2236
2237/* ESRAM3 and 4 regulator switch */
2238static struct regulator_consumer_supply db8500_esram34_consumers[] = {
2239 REGULATOR_SUPPLY("v-esram34", "mcde"),
2240 REGULATOR_SUPPLY("esram34", "cm_control"),
1865}; 2241};
1866 2242
1867static struct regulator_init_data db8500_regulators[DB8500_NUM_REGULATORS] = { 2243static struct regulator_init_data db8500_regulators[DB8500_NUM_REGULATORS] = {
@@ -1923,6 +2299,8 @@ static struct regulator_init_data db8500_regulators[DB8500_NUM_REGULATORS] = {
1923 .name = "db8500-sva-mmdsp", 2299 .name = "db8500-sva-mmdsp",
1924 .valid_ops_mask = REGULATOR_CHANGE_STATUS, 2300 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
1925 }, 2301 },
2302 .consumer_supplies = db8500_svammdsp_consumers,
2303 .num_consumer_supplies = ARRAY_SIZE(db8500_svammdsp_consumers),
1926 }, 2304 },
1927 [DB8500_REGULATOR_SWITCH_SVAMMDSPRET] = { 2305 [DB8500_REGULATOR_SWITCH_SVAMMDSPRET] = {
1928 .constraints = { 2306 .constraints = {
@@ -1937,6 +2315,8 @@ static struct regulator_init_data db8500_regulators[DB8500_NUM_REGULATORS] = {
1937 .name = "db8500-sva-pipe", 2315 .name = "db8500-sva-pipe",
1938 .valid_ops_mask = REGULATOR_CHANGE_STATUS, 2316 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
1939 }, 2317 },
2318 .consumer_supplies = db8500_svapipe_consumers,
2319 .num_consumer_supplies = ARRAY_SIZE(db8500_svapipe_consumers),
1940 }, 2320 },
1941 [DB8500_REGULATOR_SWITCH_SIAMMDSP] = { 2321 [DB8500_REGULATOR_SWITCH_SIAMMDSP] = {
1942 .supply_regulator = "db8500-vape", 2322 .supply_regulator = "db8500-vape",
@@ -1944,6 +2324,8 @@ static struct regulator_init_data db8500_regulators[DB8500_NUM_REGULATORS] = {
1944 .name = "db8500-sia-mmdsp", 2324 .name = "db8500-sia-mmdsp",
1945 .valid_ops_mask = REGULATOR_CHANGE_STATUS, 2325 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
1946 }, 2326 },
2327 .consumer_supplies = db8500_siammdsp_consumers,
2328 .num_consumer_supplies = ARRAY_SIZE(db8500_siammdsp_consumers),
1947 }, 2329 },
1948 [DB8500_REGULATOR_SWITCH_SIAMMDSPRET] = { 2330 [DB8500_REGULATOR_SWITCH_SIAMMDSPRET] = {
1949 .constraints = { 2331 .constraints = {
@@ -1957,6 +2339,8 @@ static struct regulator_init_data db8500_regulators[DB8500_NUM_REGULATORS] = {
1957 .name = "db8500-sia-pipe", 2339 .name = "db8500-sia-pipe",
1958 .valid_ops_mask = REGULATOR_CHANGE_STATUS, 2340 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
1959 }, 2341 },
2342 .consumer_supplies = db8500_siapipe_consumers,
2343 .num_consumer_supplies = ARRAY_SIZE(db8500_siapipe_consumers),
1960 }, 2344 },
1961 [DB8500_REGULATOR_SWITCH_SGA] = { 2345 [DB8500_REGULATOR_SWITCH_SGA] = {
1962 .supply_regulator = "db8500-vape", 2346 .supply_regulator = "db8500-vape",
@@ -1964,6 +2348,9 @@ static struct regulator_init_data db8500_regulators[DB8500_NUM_REGULATORS] = {
1964 .name = "db8500-sga", 2348 .name = "db8500-sga",
1965 .valid_ops_mask = REGULATOR_CHANGE_STATUS, 2349 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
1966 }, 2350 },
2351 .consumer_supplies = db8500_sga_consumers,
2352 .num_consumer_supplies = ARRAY_SIZE(db8500_sga_consumers),
2353
1967 }, 2354 },
1968 [DB8500_REGULATOR_SWITCH_B2R2_MCDE] = { 2355 [DB8500_REGULATOR_SWITCH_B2R2_MCDE] = {
1969 .supply_regulator = "db8500-vape", 2356 .supply_regulator = "db8500-vape",
@@ -1980,6 +2367,8 @@ static struct regulator_init_data db8500_regulators[DB8500_NUM_REGULATORS] = {
1980 .name = "db8500-esram12", 2367 .name = "db8500-esram12",
1981 .valid_ops_mask = REGULATOR_CHANGE_STATUS, 2368 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
1982 }, 2369 },
2370 .consumer_supplies = db8500_esram12_consumers,
2371 .num_consumer_supplies = ARRAY_SIZE(db8500_esram12_consumers),
1983 }, 2372 },
1984 [DB8500_REGULATOR_SWITCH_ESRAM12RET] = { 2373 [DB8500_REGULATOR_SWITCH_ESRAM12RET] = {
1985 .constraints = { 2374 .constraints = {
@@ -1993,6 +2382,8 @@ static struct regulator_init_data db8500_regulators[DB8500_NUM_REGULATORS] = {
1993 .name = "db8500-esram34", 2382 .name = "db8500-esram34",
1994 .valid_ops_mask = REGULATOR_CHANGE_STATUS, 2383 .valid_ops_mask = REGULATOR_CHANGE_STATUS,
1995 }, 2384 },
2385 .consumer_supplies = db8500_esram34_consumers,
2386 .num_consumer_supplies = ARRAY_SIZE(db8500_esram34_consumers),
1996 }, 2387 },
1997 [DB8500_REGULATOR_SWITCH_ESRAM34RET] = { 2388 [DB8500_REGULATOR_SWITCH_ESRAM34RET] = {
1998 .constraints = { 2389 .constraints = {
@@ -2024,8 +2415,10 @@ static int __init db8500_prcmu_probe(struct platform_device *pdev)
2024 if (ux500_is_svp()) 2415 if (ux500_is_svp())
2025 return -ENODEV; 2416 return -ENODEV;
2026 2417
2418 db8500_prcmu_init_clkforce();
2419
2027 /* Clean up the mailbox interrupts after pre-kernel code. */ 2420 /* Clean up the mailbox interrupts after pre-kernel code. */
2028 writel(ALL_MBOX_BITS, (_PRCMU_BASE + PRCM_ARM_IT1_CLR)); 2421 writel(ALL_MBOX_BITS, PRCM_ARM_IT1_CLR);
2029 2422
2030 err = request_threaded_irq(IRQ_DB8500_PRCMU1, prcmu_irq_handler, 2423 err = request_threaded_irq(IRQ_DB8500_PRCMU1, prcmu_irq_handler,
2031 prcmu_irq_thread_fn, IRQF_NO_SUSPEND, "prcmu", NULL); 2424 prcmu_irq_thread_fn, IRQF_NO_SUSPEND, "prcmu", NULL);
diff --git a/drivers/mfd/db5500-prcmu-regs.h b/drivers/mfd/dbx500-prcmu-regs.h
index 9a8e9e4ddd33..ec22e9f15d32 100644
--- a/drivers/mfd/db5500-prcmu-regs.h
+++ b/drivers/mfd/dbx500-prcmu-regs.h
@@ -10,11 +10,49 @@
10 * PRCM Unit registers 10 * PRCM Unit registers
11 */ 11 */
12 12
13#ifndef __MACH_PRCMU_REGS_H 13#ifndef __DB8500_PRCMU_REGS_H
14#define __MACH_PRCMU_REGS_H 14#define __DB8500_PRCMU_REGS_H
15 15
16#include <mach/hardware.h> 16#include <mach/hardware.h>
17 17
18#define BITS(_start, _end) ((BIT(_end) - BIT(_start)) + BIT(_end))
19
20#define PRCM_SVACLK_MGT_OFF 0x008
21#define PRCM_SIACLK_MGT_OFF 0x00C
22#define PRCM_SGACLK_MGT_OFF 0x014
23#define PRCM_UARTCLK_MGT_OFF 0x018
24#define PRCM_MSP02CLK_MGT_OFF 0x01C
25#define PRCM_I2CCLK_MGT_OFF 0x020
26#define PRCM_SDMMCCLK_MGT_OFF 0x024
27#define PRCM_SLIMCLK_MGT_OFF 0x028
28#define PRCM_PER1CLK_MGT_OFF 0x02C
29#define PRCM_PER2CLK_MGT_OFF 0x030
30#define PRCM_PER3CLK_MGT_OFF 0x034
31#define PRCM_PER5CLK_MGT_OFF 0x038
32#define PRCM_PER6CLK_MGT_OFF 0x03C
33#define PRCM_PER7CLK_MGT_OFF 0x040
34#define PRCM_PWMCLK_MGT_OFF 0x044 /* for DB5500 */
35#define PRCM_IRDACLK_MGT_OFF 0x048 /* for DB5500 */
36#define PRCM_IRRCCLK_MGT_OFF 0x04C /* for DB5500 */
37#define PRCM_LCDCLK_MGT_OFF 0x044
38#define PRCM_BMLCLK_MGT_OFF 0x04C
39#define PRCM_HSITXCLK_MGT_OFF 0x050
40#define PRCM_HSIRXCLK_MGT_OFF 0x054
41#define PRCM_HDMICLK_MGT_OFF 0x058
42#define PRCM_APEATCLK_MGT_OFF 0x05C
43#define PRCM_APETRACECLK_MGT_OFF 0x060
44#define PRCM_MCDECLK_MGT_OFF 0x064
45#define PRCM_IPI2CCLK_MGT_OFF 0x068
46#define PRCM_DSIALTCLK_MGT_OFF 0x06C
47#define PRCM_DMACLK_MGT_OFF 0x074
48#define PRCM_B2R2CLK_MGT_OFF 0x078
49#define PRCM_TVCLK_MGT_OFF 0x07C
50#define PRCM_UNIPROCLK_MGT_OFF 0x278
51#define PRCM_SSPCLK_MGT_OFF 0x280
52#define PRCM_RNGCLK_MGT_OFF 0x284
53#define PRCM_UICCCLK_MGT_OFF 0x27C
54#define PRCM_MSP1CLK_MGT_OFF 0x288
55
18#define PRCM_ARM_PLLDIVPS (_PRCMU_BASE + 0x118) 56#define PRCM_ARM_PLLDIVPS (_PRCMU_BASE + 0x118)
19#define PRCM_ARM_PLLDIVPS_ARM_BRM_RATE 0x3f 57#define PRCM_ARM_PLLDIVPS_ARM_BRM_RATE 0x3f
20#define PRCM_ARM_PLLDIVPS_MAX_MASK 0xf 58#define PRCM_ARM_PLLDIVPS_MAX_MASK 0xf
@@ -30,11 +68,15 @@
30#define PRCM_PLLARM_ENABLE_PRCM_PLLARM_COUNTON 0x100 68#define PRCM_PLLARM_ENABLE_PRCM_PLLARM_COUNTON 0x100
31 69
32#define PRCM_ARMCLKFIX_MGT (_PRCMU_BASE + 0x0) 70#define PRCM_ARMCLKFIX_MGT (_PRCMU_BASE + 0x0)
71#define PRCM_A9PL_FORCE_CLKEN (_PRCMU_BASE + 0x19C)
33#define PRCM_A9_RESETN_CLR (_PRCMU_BASE + 0x1f4) 72#define PRCM_A9_RESETN_CLR (_PRCMU_BASE + 0x1f4)
34#define PRCM_A9_RESETN_SET (_PRCMU_BASE + 0x1f0) 73#define PRCM_A9_RESETN_SET (_PRCMU_BASE + 0x1f0)
35#define PRCM_ARM_LS_CLAMP (_PRCMU_BASE + 0x30c) 74#define PRCM_ARM_LS_CLAMP (_PRCMU_BASE + 0x30c)
36#define PRCM_SRAM_A9 (_PRCMU_BASE + 0x308) 75#define PRCM_SRAM_A9 (_PRCMU_BASE + 0x308)
37 76
77#define PRCM_A9PL_FORCE_CLKEN_PRCM_A9PL_FORCE_CLKEN BIT(0)
78#define PRCM_A9PL_FORCE_CLKEN_PRCM_A9AXI_FORCE_CLKEN BIT(1)
79
38/* ARM WFI Standby signal register */ 80/* ARM WFI Standby signal register */
39#define PRCM_ARM_WFI_STANDBY (_PRCMU_BASE + 0x130) 81#define PRCM_ARM_WFI_STANDBY (_PRCMU_BASE + 0x130)
40#define PRCM_IOCR (_PRCMU_BASE + 0x310) 82#define PRCM_IOCR (_PRCMU_BASE + 0x310)
@@ -61,12 +103,18 @@
61#define PRCM_ARMITVAL127TO96 (_PRCMU_BASE + 0x26C) 103#define PRCM_ARMITVAL127TO96 (_PRCMU_BASE + 0x26C)
62 104
63#define PRCM_HOSTACCESS_REQ (_PRCMU_BASE + 0x334) 105#define PRCM_HOSTACCESS_REQ (_PRCMU_BASE + 0x334)
106#define PRCM_HOSTACCESS_REQ_HOSTACCESS_REQ 0x1
64#define ARM_WAKEUP_MODEM 0x1 107#define ARM_WAKEUP_MODEM 0x1
65 108
66#define PRCM_ARM_IT1_CLEAR (_PRCMU_BASE + 0x48C) 109#define PRCM_ARM_IT1_CLR (_PRCMU_BASE + 0x48C)
67#define PRCM_ARM_IT1_VAL (_PRCMU_BASE + 0x494) 110#define PRCM_ARM_IT1_VAL (_PRCMU_BASE + 0x494)
68#define PRCM_HOLD_EVT (_PRCMU_BASE + 0x174) 111#define PRCM_HOLD_EVT (_PRCMU_BASE + 0x174)
69 112
113#define PRCM_MOD_AWAKE_STATUS (_PRCMU_BASE + 0x4A0)
114#define PRCM_MOD_AWAKE_STATUS_PRCM_MOD_COREPD_AWAKE BIT(0)
115#define PRCM_MOD_AWAKE_STATUS_PRCM_MOD_AAPD_AWAKE BIT(1)
116#define PRCM_MOD_AWAKE_STATUS_PRCM_MOD_VMODEM_OFF_ISO BIT(2)
117
70#define PRCM_ITSTATUS0 (_PRCMU_BASE + 0x148) 118#define PRCM_ITSTATUS0 (_PRCMU_BASE + 0x148)
71#define PRCM_ITSTATUS1 (_PRCMU_BASE + 0x150) 119#define PRCM_ITSTATUS1 (_PRCMU_BASE + 0x150)
72#define PRCM_ITSTATUS2 (_PRCMU_BASE + 0x158) 120#define PRCM_ITSTATUS2 (_PRCMU_BASE + 0x158)
@@ -87,16 +135,21 @@
87#define PRCM_PLLDSI_FREQ (_PRCMU_BASE + 0x500) 135#define PRCM_PLLDSI_FREQ (_PRCMU_BASE + 0x500)
88#define PRCM_PLLDSI_ENABLE (_PRCMU_BASE + 0x504) 136#define PRCM_PLLDSI_ENABLE (_PRCMU_BASE + 0x504)
89#define PRCM_PLLDSI_LOCKP (_PRCMU_BASE + 0x508) 137#define PRCM_PLLDSI_LOCKP (_PRCMU_BASE + 0x508)
90#define PRCM_LCDCLK_MGT (_PRCMU_BASE + 0x044) 138#define PRCM_LCDCLK_MGT (_PRCMU_BASE + PRCM_LCDCLK_MGT_OFF)
91#define PRCM_MCDECLK_MGT (_PRCMU_BASE + 0x064) 139#define PRCM_MCDECLK_MGT (_PRCMU_BASE + PRCM_MCDECLK_MGT_OFF)
92#define PRCM_HDMICLK_MGT (_PRCMU_BASE + 0x058) 140#define PRCM_HDMICLK_MGT (_PRCMU_BASE + PRCM_HDMICLK_MGT_OFF)
93#define PRCM_TVCLK_MGT (_PRCMU_BASE + 0x07c) 141#define PRCM_TVCLK_MGT (_PRCMU_BASE + PRCM_TVCLK_MGT_OFF)
94#define PRCM_DSI_PLLOUT_SEL (_PRCMU_BASE + 0x530) 142#define PRCM_DSI_PLLOUT_SEL (_PRCMU_BASE + 0x530)
95#define PRCM_DSITVCLK_DIV (_PRCMU_BASE + 0x52C) 143#define PRCM_DSITVCLK_DIV (_PRCMU_BASE + 0x52C)
96#define PRCM_PLLDSI_LOCKP (_PRCMU_BASE + 0x508) 144#define PRCM_PLLDSI_LOCKP (_PRCMU_BASE + 0x508)
97#define PRCM_APE_RESETN_SET (_PRCMU_BASE + 0x1E4) 145#define PRCM_APE_RESETN_SET (_PRCMU_BASE + 0x1E4)
98#define PRCM_APE_RESETN_CLR (_PRCMU_BASE + 0x1E8) 146#define PRCM_APE_RESETN_CLR (_PRCMU_BASE + 0x1E8)
147
99#define PRCM_CLKOCR (_PRCMU_BASE + 0x1CC) 148#define PRCM_CLKOCR (_PRCMU_BASE + 0x1CC)
149#define PRCM_CLKOCR_CLKOUT0_REF_CLK (1 << 0)
150#define PRCM_CLKOCR_CLKOUT0_MASK BITS(0, 13)
151#define PRCM_CLKOCR_CLKOUT1_REF_CLK (1 << 16)
152#define PRCM_CLKOCR_CLKOUT1_MASK BITS(16, 29)
100 153
101/* ePOD and memory power signal control registers */ 154/* ePOD and memory power signal control registers */
102#define PRCM_EPOD_C_SET (_PRCMU_BASE + 0x410) 155#define PRCM_EPOD_C_SET (_PRCMU_BASE + 0x410)
@@ -111,5 +164,41 @@
111#define PRCM_GPIOCR_DBG_STM_MOD_CMD1 0x800 164#define PRCM_GPIOCR_DBG_STM_MOD_CMD1 0x800
112#define PRCM_GPIOCR_DBG_UARTMOD_CMD0 0x1 165#define PRCM_GPIOCR_DBG_UARTMOD_CMD0 0x1
113 166
167/* PRCMU HW semaphore */
168#define PRCM_SEM (_PRCMU_BASE + 0x400)
169#define PRCM_SEM_PRCM_SEM BIT(0)
170
171#define PRCM_TCR (_PRCMU_BASE + 0x1C8)
172#define PRCM_TCR_TENSEL_MASK BITS(0, 7)
173#define PRCM_TCR_STOP_TIMERS BIT(16)
174#define PRCM_TCR_DOZE_MODE BIT(17)
175
176#define PRCM_CLKOCR_CLKODIV0_SHIFT 0
177#define PRCM_CLKOCR_CLKODIV0_MASK BITS(0, 5)
178#define PRCM_CLKOCR_CLKOSEL0_SHIFT 6
179#define PRCM_CLKOCR_CLKOSEL0_MASK BITS(6, 8)
180#define PRCM_CLKOCR_CLKODIV1_SHIFT 16
181#define PRCM_CLKOCR_CLKODIV1_MASK BITS(16, 21)
182#define PRCM_CLKOCR_CLKOSEL1_SHIFT 22
183#define PRCM_CLKOCR_CLKOSEL1_MASK BITS(22, 24)
184#define PRCM_CLKOCR_CLK1TYPE BIT(28)
185
186#define PRCM_CLK_MGT_CLKPLLDIV_MASK BITS(0, 4)
187#define PRCM_CLK_MGT_CLKPLLSW_MASK BITS(5, 7)
188#define PRCM_CLK_MGT_CLKEN BIT(8)
189
190/* GPIOCR register */
191#define PRCM_GPIOCR_SPI2_SELECT BIT(23)
192
193#define PRCM_DDR_SUBSYS_APE_MINBW (_PRCMU_BASE + 0x438)
194#define PRCM_CGATING_BYPASS (_PRCMU_BASE + 0x134)
195#define PRCM_CGATING_BYPASS_ICN2 BIT(6)
196
197/* Miscellaneous unit registers */
198#define PRCM_RESOUTN_SET (_PRCMU_BASE + 0x214)
199#define PRCM_RESOUTN_CLR (_PRCMU_BASE + 0x218)
200
201/* System reset register */
202#define PRCM_APE_SOFTRST (_PRCMU_BASE + 0x228)
114 203
115#endif /* __MACH_PRCMU__REGS_H */ 204#endif /* __DB8500_PRCMU_REGS_H */
diff --git a/drivers/mfd/dm355evm_msp.c b/drivers/mfd/dm355evm_msp.c
index 3d4a861976ca..8ad88da647b9 100644
--- a/drivers/mfd/dm355evm_msp.c
+++ b/drivers/mfd/dm355evm_msp.c
@@ -13,6 +13,7 @@
13#include <linux/mutex.h> 13#include <linux/mutex.h>
14#include <linux/platform_device.h> 14#include <linux/platform_device.h>
15#include <linux/clk.h> 15#include <linux/clk.h>
16#include <linux/module.h>
16#include <linux/err.h> 17#include <linux/err.h>
17#include <linux/gpio.h> 18#include <linux/gpio.h>
18#include <linux/leds.h> 19#include <linux/leds.h>
diff --git a/drivers/mfd/intel_msic.c b/drivers/mfd/intel_msic.c
new file mode 100644
index 000000000000..97c27762174f
--- /dev/null
+++ b/drivers/mfd/intel_msic.c
@@ -0,0 +1,502 @@
1/*
2 * Driver for Intel MSIC
3 *
4 * Copyright (C) 2011, Intel Corporation
5 * Author: Mika Westerberg <mika.westerberg@linux.intel.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/gpio.h>
13#include <linux/io.h>
14#include <linux/module.h>
15#include <linux/mfd/core.h>
16#include <linux/mfd/intel_msic.h>
17#include <linux/platform_device.h>
18#include <linux/slab.h>
19
20#include <asm/intel_scu_ipc.h>
21
22#define MSIC_VENDOR(id) ((id >> 6) & 3)
23#define MSIC_VERSION(id) (id & 0x3f)
24#define MSIC_MAJOR(id) ('A' + ((id >> 3) & 7))
25#define MSIC_MINOR(id) (id & 7)
26
27/*
28 * MSIC interrupt tree is readable from SRAM at INTEL_MSIC_IRQ_PHYS_BASE.
29 * Since IRQ block starts from address 0x002 we need to substract that from
30 * the actual IRQ status register address.
31 */
32#define MSIC_IRQ_STATUS(x) (INTEL_MSIC_IRQ_PHYS_BASE + ((x) - 2))
33#define MSIC_IRQ_STATUS_ACCDET MSIC_IRQ_STATUS(INTEL_MSIC_ACCDET)
34
35/*
36 * The SCU hardware has limitation of 16 bytes per read/write buffer on
37 * Medfield.
38 */
39#define SCU_IPC_RWBUF_LIMIT 16
40
41/**
42 * struct intel_msic - an MSIC MFD instance
43 * @pdev: pointer to the platform device
44 * @vendor: vendor ID
45 * @version: chip version
46 * @irq_base: base address of the mapped MSIC SRAM interrupt tree
47 */
48struct intel_msic {
49 struct platform_device *pdev;
50 unsigned vendor;
51 unsigned version;
52 void __iomem *irq_base;
53};
54
55static struct resource msic_touch_resources[] = {
56 {
57 .flags = IORESOURCE_IRQ,
58 },
59};
60
61static struct resource msic_adc_resources[] = {
62 {
63 .flags = IORESOURCE_IRQ,
64 },
65};
66
67static struct resource msic_battery_resources[] = {
68 {
69 .flags = IORESOURCE_IRQ,
70 },
71};
72
73static struct resource msic_gpio_resources[] = {
74 {
75 .flags = IORESOURCE_IRQ,
76 },
77};
78
79static struct resource msic_audio_resources[] = {
80 {
81 .name = "IRQ",
82 .flags = IORESOURCE_IRQ,
83 },
84 /*
85 * We will pass IRQ_BASE to the driver now but this can be removed
86 * when/if the driver starts to use intel_msic_irq_read().
87 */
88 {
89 .name = "IRQ_BASE",
90 .flags = IORESOURCE_MEM,
91 .start = MSIC_IRQ_STATUS_ACCDET,
92 .end = MSIC_IRQ_STATUS_ACCDET,
93 },
94};
95
96static struct resource msic_hdmi_resources[] = {
97 {
98 .flags = IORESOURCE_IRQ,
99 },
100};
101
102static struct resource msic_thermal_resources[] = {
103 {
104 .flags = IORESOURCE_IRQ,
105 },
106};
107
108static struct resource msic_power_btn_resources[] = {
109 {
110 .flags = IORESOURCE_IRQ,
111 },
112};
113
114static struct resource msic_ocd_resources[] = {
115 {
116 .flags = IORESOURCE_IRQ,
117 },
118};
119
120/*
121 * Devices that are part of the MSIC and are available via firmware
122 * populated SFI DEVS table.
123 */
124static struct mfd_cell msic_devs[] = {
125 [INTEL_MSIC_BLOCK_TOUCH] = {
126 .name = "msic_touch",
127 .num_resources = ARRAY_SIZE(msic_touch_resources),
128 .resources = msic_touch_resources,
129 },
130 [INTEL_MSIC_BLOCK_ADC] = {
131 .name = "msic_adc",
132 .num_resources = ARRAY_SIZE(msic_adc_resources),
133 .resources = msic_adc_resources,
134 },
135 [INTEL_MSIC_BLOCK_BATTERY] = {
136 .name = "msic_battery",
137 .num_resources = ARRAY_SIZE(msic_battery_resources),
138 .resources = msic_battery_resources,
139 },
140 [INTEL_MSIC_BLOCK_GPIO] = {
141 .name = "msic_gpio",
142 .num_resources = ARRAY_SIZE(msic_gpio_resources),
143 .resources = msic_gpio_resources,
144 },
145 [INTEL_MSIC_BLOCK_AUDIO] = {
146 .name = "msic_audio",
147 .num_resources = ARRAY_SIZE(msic_audio_resources),
148 .resources = msic_audio_resources,
149 },
150 [INTEL_MSIC_BLOCK_HDMI] = {
151 .name = "msic_hdmi",
152 .num_resources = ARRAY_SIZE(msic_hdmi_resources),
153 .resources = msic_hdmi_resources,
154 },
155 [INTEL_MSIC_BLOCK_THERMAL] = {
156 .name = "msic_thermal",
157 .num_resources = ARRAY_SIZE(msic_thermal_resources),
158 .resources = msic_thermal_resources,
159 },
160 [INTEL_MSIC_BLOCK_POWER_BTN] = {
161 .name = "msic_power_btn",
162 .num_resources = ARRAY_SIZE(msic_power_btn_resources),
163 .resources = msic_power_btn_resources,
164 },
165 [INTEL_MSIC_BLOCK_OCD] = {
166 .name = "msic_ocd",
167 .num_resources = ARRAY_SIZE(msic_ocd_resources),
168 .resources = msic_ocd_resources,
169 },
170};
171
172/*
173 * Other MSIC related devices which are not directly available via SFI DEVS
174 * table. These can be pseudo devices, regulators etc. which are needed for
175 * different purposes.
176 *
177 * These devices appear only after the MSIC driver itself is initialized so
178 * we can guarantee that the SCU IPC interface is ready.
179 */
180static struct mfd_cell msic_other_devs[] = {
181 /* Audio codec in the MSIC */
182 {
183 .id = -1,
184 .name = "sn95031",
185 },
186};
187
188/**
189 * intel_msic_reg_read - read a single MSIC register
190 * @reg: register to read
191 * @val: register value is placed here
192 *
193 * Read a single register from MSIC. Returns %0 on success and negative
194 * errno in case of failure.
195 *
196 * Function may sleep.
197 */
198int intel_msic_reg_read(unsigned short reg, u8 *val)
199{
200 return intel_scu_ipc_ioread8(reg, val);
201}
202EXPORT_SYMBOL_GPL(intel_msic_reg_read);
203
204/**
205 * intel_msic_reg_write - write a single MSIC register
206 * @reg: register to write
207 * @val: value to write to that register
208 *
209 * Write a single MSIC register. Returns 0 on success and negative
210 * errno in case of failure.
211 *
212 * Function may sleep.
213 */
214int intel_msic_reg_write(unsigned short reg, u8 val)
215{
216 return intel_scu_ipc_iowrite8(reg, val);
217}
218EXPORT_SYMBOL_GPL(intel_msic_reg_write);
219
220/**
221 * intel_msic_reg_update - update a single MSIC register
222 * @reg: register to update
223 * @val: value to write to the register
224 * @mask: specifies which of the bits are updated (%0 = don't update,
225 * %1 = update)
226 *
227 * Perform an update to a register @reg. @mask is used to specify which
228 * bits are updated. Returns %0 in case of success and negative errno in
229 * case of failure.
230 *
231 * Function may sleep.
232 */
233int intel_msic_reg_update(unsigned short reg, u8 val, u8 mask)
234{
235 return intel_scu_ipc_update_register(reg, val, mask);
236}
237EXPORT_SYMBOL_GPL(intel_msic_reg_update);
238
239/**
240 * intel_msic_bulk_read - read an array of registers
241 * @reg: array of register addresses to read
242 * @buf: array where the read values are placed
243 * @count: number of registers to read
244 *
245 * Function reads @count registers from the MSIC using addresses passed in
246 * @reg. Read values are placed in @buf. Reads are performed atomically
247 * wrt. MSIC.
248 *
249 * Returns %0 in case of success and negative errno in case of failure.
250 *
251 * Function may sleep.
252 */
253int intel_msic_bulk_read(unsigned short *reg, u8 *buf, size_t count)
254{
255 if (WARN_ON(count > SCU_IPC_RWBUF_LIMIT))
256 return -EINVAL;
257
258 return intel_scu_ipc_readv(reg, buf, count);
259}
260EXPORT_SYMBOL_GPL(intel_msic_bulk_read);
261
262/**
263 * intel_msic_bulk_write - write an array of values to the MSIC registers
264 * @reg: array of registers to write
265 * @buf: values to write to each register
266 * @count: number of registers to write
267 *
268 * Function writes @count registers in @buf to MSIC. Writes are performed
269 * atomically wrt MSIC. Returns %0 in case of success and negative errno in
270 * case of failure.
271 *
272 * Function may sleep.
273 */
274int intel_msic_bulk_write(unsigned short *reg, u8 *buf, size_t count)
275{
276 if (WARN_ON(count > SCU_IPC_RWBUF_LIMIT))
277 return -EINVAL;
278
279 return intel_scu_ipc_writev(reg, buf, count);
280}
281EXPORT_SYMBOL_GPL(intel_msic_bulk_write);
282
283/**
284 * intel_msic_irq_read - read a register from an MSIC interrupt tree
285 * @msic: MSIC instance
286 * @reg: interrupt register (between %INTEL_MSIC_IRQLVL1 and
287 * %INTEL_MSIC_RESETIRQ2)
288 * @val: value of the register is placed here
289 *
290 * This function can be used by an MSIC subdevice interrupt handler to read
291 * a register value from the MSIC interrupt tree. In this way subdevice
292 * drivers don't have to map in the interrupt tree themselves but can just
293 * call this function instead.
294 *
295 * Function doesn't sleep and is callable from interrupt context.
296 *
297 * Returns %-EINVAL if @reg is outside of the allowed register region.
298 */
299int intel_msic_irq_read(struct intel_msic *msic, unsigned short reg, u8 *val)
300{
301 if (WARN_ON(reg < INTEL_MSIC_IRQLVL1 || reg > INTEL_MSIC_RESETIRQ2))
302 return -EINVAL;
303
304 *val = readb(msic->irq_base + (reg - INTEL_MSIC_IRQLVL1));
305 return 0;
306}
307EXPORT_SYMBOL_GPL(intel_msic_irq_read);
308
309static int __devinit intel_msic_init_devices(struct intel_msic *msic)
310{
311 struct platform_device *pdev = msic->pdev;
312 struct intel_msic_platform_data *pdata = pdev->dev.platform_data;
313 int ret, i;
314
315 if (pdata->gpio) {
316 struct mfd_cell *cell = &msic_devs[INTEL_MSIC_BLOCK_GPIO];
317
318 cell->platform_data = pdata->gpio;
319 cell->pdata_size = sizeof(*pdata->gpio);
320 }
321
322 if (pdata->ocd) {
323 unsigned gpio = pdata->ocd->gpio;
324
325 ret = gpio_request_one(gpio, GPIOF_IN, "ocd_gpio");
326 if (ret) {
327 dev_err(&pdev->dev, "failed to register OCD GPIO\n");
328 return ret;
329 }
330
331 ret = gpio_to_irq(gpio);
332 if (ret < 0) {
333 dev_err(&pdev->dev, "no IRQ number for OCD GPIO\n");
334 gpio_free(gpio);
335 return ret;
336 }
337
338 /* Update the IRQ number for the OCD */
339 pdata->irq[INTEL_MSIC_BLOCK_OCD] = ret;
340 }
341
342 for (i = 0; i < ARRAY_SIZE(msic_devs); i++) {
343 if (!pdata->irq[i])
344 continue;
345
346 ret = mfd_add_devices(&pdev->dev, -1, &msic_devs[i], 1, NULL,
347 pdata->irq[i]);
348 if (ret)
349 goto fail;
350 }
351
352 ret = mfd_add_devices(&pdev->dev, 0, msic_other_devs,
353 ARRAY_SIZE(msic_other_devs), NULL, 0);
354 if (ret)
355 goto fail;
356
357 return 0;
358
359fail:
360 mfd_remove_devices(&pdev->dev);
361 if (pdata->ocd)
362 gpio_free(pdata->ocd->gpio);
363
364 return ret;
365}
366
367static void __devexit intel_msic_remove_devices(struct intel_msic *msic)
368{
369 struct platform_device *pdev = msic->pdev;
370 struct intel_msic_platform_data *pdata = pdev->dev.platform_data;
371
372 mfd_remove_devices(&pdev->dev);
373
374 if (pdata->ocd)
375 gpio_free(pdata->ocd->gpio);
376}
377
378static int __devinit intel_msic_probe(struct platform_device *pdev)
379{
380 struct intel_msic_platform_data *pdata = pdev->dev.platform_data;
381 struct intel_msic *msic;
382 struct resource *res;
383 u8 id0, id1;
384 int ret;
385
386 if (!pdata) {
387 dev_err(&pdev->dev, "no platform data passed\n");
388 return -EINVAL;
389 }
390
391 /* First validate that we have an MSIC in place */
392 ret = intel_scu_ipc_ioread8(INTEL_MSIC_ID0, &id0);
393 if (ret) {
394 dev_err(&pdev->dev, "failed to identify the MSIC chip (ID0)\n");
395 return -ENXIO;
396 }
397
398 ret = intel_scu_ipc_ioread8(INTEL_MSIC_ID1, &id1);
399 if (ret) {
400 dev_err(&pdev->dev, "failed to identify the MSIC chip (ID1)\n");
401 return -ENXIO;
402 }
403
404 if (MSIC_VENDOR(id0) != MSIC_VENDOR(id1)) {
405 dev_err(&pdev->dev, "invalid vendor ID: %x, %x\n", id0, id1);
406 return -ENXIO;
407 }
408
409 msic = kzalloc(sizeof(*msic), GFP_KERNEL);
410 if (!msic)
411 return -ENOMEM;
412
413 msic->vendor = MSIC_VENDOR(id0);
414 msic->version = MSIC_VERSION(id0);
415 msic->pdev = pdev;
416
417 /*
418 * Map in the MSIC interrupt tree area in SRAM. This is exposed to
419 * the clients via intel_msic_irq_read().
420 */
421 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
422 if (!res) {
423 dev_err(&pdev->dev, "failed to get SRAM iomem resource\n");
424 ret = -ENODEV;
425 goto fail_free_msic;
426 }
427
428 res = request_mem_region(res->start, resource_size(res), pdev->name);
429 if (!res) {
430 ret = -EBUSY;
431 goto fail_free_msic;
432 }
433
434 msic->irq_base = ioremap_nocache(res->start, resource_size(res));
435 if (!msic->irq_base) {
436 dev_err(&pdev->dev, "failed to map SRAM memory\n");
437 ret = -ENOMEM;
438 goto fail_release_region;
439 }
440
441 platform_set_drvdata(pdev, msic);
442
443 ret = intel_msic_init_devices(msic);
444 if (ret) {
445 dev_err(&pdev->dev, "failed to initialize MSIC devices\n");
446 goto fail_unmap_mem;
447 }
448
449 dev_info(&pdev->dev, "Intel MSIC version %c%d (vendor %#x)\n",
450 MSIC_MAJOR(msic->version), MSIC_MINOR(msic->version),
451 msic->vendor);
452
453 return 0;
454
455fail_unmap_mem:
456 iounmap(msic->irq_base);
457fail_release_region:
458 release_mem_region(res->start, resource_size(res));
459fail_free_msic:
460 kfree(msic);
461
462 return ret;
463}
464
465static int __devexit intel_msic_remove(struct platform_device *pdev)
466{
467 struct intel_msic *msic = platform_get_drvdata(pdev);
468 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
469
470 intel_msic_remove_devices(msic);
471 platform_set_drvdata(pdev, NULL);
472 iounmap(msic->irq_base);
473 release_mem_region(res->start, resource_size(res));
474 kfree(msic);
475
476 return 0;
477}
478
479static struct platform_driver intel_msic_driver = {
480 .probe = intel_msic_probe,
481 .remove = __devexit_p(intel_msic_remove),
482 .driver = {
483 .name = "intel_msic",
484 .owner = THIS_MODULE,
485 },
486};
487
488static int __init intel_msic_init(void)
489{
490 return platform_driver_register(&intel_msic_driver);
491}
492module_init(intel_msic_init);
493
494static void __exit intel_msic_exit(void)
495{
496 platform_driver_unregister(&intel_msic_driver);
497}
498module_exit(intel_msic_exit);
499
500MODULE_DESCRIPTION("Driver for Intel MSIC");
501MODULE_AUTHOR("Mika Westerberg <mika.westerberg@linux.intel.com>");
502MODULE_LICENSE("GPL");
diff --git a/drivers/mfd/jz4740-adc.c b/drivers/mfd/jz4740-adc.c
index 563654c9b19e..1e9ee533eacb 100644
--- a/drivers/mfd/jz4740-adc.c
+++ b/drivers/mfd/jz4740-adc.c
@@ -328,7 +328,7 @@ static int __devexit jz4740_adc_remove(struct platform_device *pdev)
328 return 0; 328 return 0;
329} 329}
330 330
331struct platform_driver jz4740_adc_driver = { 331static struct platform_driver jz4740_adc_driver = {
332 .probe = jz4740_adc_probe, 332 .probe = jz4740_adc_probe,
333 .remove = __devexit_p(jz4740_adc_remove), 333 .remove = __devexit_p(jz4740_adc_remove),
334 .driver = { 334 .driver = {
diff --git a/drivers/mfd/max8997.c b/drivers/mfd/max8997.c
index f83103b8970d..5be53ae9b61c 100644
--- a/drivers/mfd/max8997.c
+++ b/drivers/mfd/max8997.c
@@ -23,7 +23,9 @@
23 23
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/i2c.h> 25#include <linux/i2c.h>
26#include <linux/interrupt.h>
26#include <linux/pm_runtime.h> 27#include <linux/pm_runtime.h>
28#include <linux/module.h>
27#include <linux/mutex.h> 29#include <linux/mutex.h>
28#include <linux/mfd/core.h> 30#include <linux/mfd/core.h>
29#include <linux/mfd/max8997.h> 31#include <linux/mfd/max8997.h>
@@ -142,7 +144,6 @@ static int max8997_i2c_probe(struct i2c_client *i2c,
142 144
143 max8997->irq_base = pdata->irq_base; 145 max8997->irq_base = pdata->irq_base;
144 max8997->ono = pdata->ono; 146 max8997->ono = pdata->ono;
145 max8997->wakeup = pdata->wakeup;
146 147
147 mutex_init(&max8997->iolock); 148 mutex_init(&max8997->iolock);
148 149
@@ -169,6 +170,9 @@ static int max8997_i2c_probe(struct i2c_client *i2c,
169 if (ret < 0) 170 if (ret < 0)
170 goto err_mfd; 171 goto err_mfd;
171 172
173 /* MAX8997 has a power button input. */
174 device_init_wakeup(max8997->dev, pdata->wakeup);
175
172 return ret; 176 return ret;
173 177
174err_mfd: 178err_mfd:
@@ -398,7 +402,29 @@ static int max8997_restore(struct device *dev)
398 return 0; 402 return 0;
399} 403}
400 404
405static int max8997_suspend(struct device *dev)
406{
407 struct i2c_client *i2c = container_of(dev, struct i2c_client, dev);
408 struct max8997_dev *max8997 = i2c_get_clientdata(i2c);
409
410 if (device_may_wakeup(dev))
411 irq_set_irq_wake(max8997->irq, 1);
412 return 0;
413}
414
415static int max8997_resume(struct device *dev)
416{
417 struct i2c_client *i2c = container_of(dev, struct i2c_client, dev);
418 struct max8997_dev *max8997 = i2c_get_clientdata(i2c);
419
420 if (device_may_wakeup(dev))
421 irq_set_irq_wake(max8997->irq, 0);
422 return max8997_irq_resume(max8997);
423}
424
401const struct dev_pm_ops max8997_pm = { 425const struct dev_pm_ops max8997_pm = {
426 .suspend = max8997_suspend,
427 .resume = max8997_resume,
402 .freeze = max8997_freeze, 428 .freeze = max8997_freeze,
403 .restore = max8997_restore, 429 .restore = max8997_restore,
404}; 430};
diff --git a/drivers/mfd/mc13xxx-core.c b/drivers/mfd/mc13xxx-core.c
index 7e4d44bf92ab..e9619acc0237 100644
--- a/drivers/mfd/mc13xxx-core.c
+++ b/drivers/mfd/mc13xxx-core.c
@@ -26,20 +26,10 @@ struct mc13xxx {
26 26
27 irq_handler_t irqhandler[MC13XXX_NUM_IRQ]; 27 irq_handler_t irqhandler[MC13XXX_NUM_IRQ];
28 void *irqdata[MC13XXX_NUM_IRQ]; 28 void *irqdata[MC13XXX_NUM_IRQ];
29};
30
31struct mc13783 {
32 struct mc13xxx mc13xxx;
33 29
34 int adcflags; 30 int adcflags;
35}; 31};
36 32
37struct mc13xxx *mc13783_to_mc13xxx(struct mc13783 *mc13783)
38{
39 return &mc13783->mc13xxx;
40}
41EXPORT_SYMBOL(mc13783_to_mc13xxx);
42
43#define MC13XXX_IRQSTAT0 0 33#define MC13XXX_IRQSTAT0 0
44#define MC13XXX_IRQSTAT0_ADCDONEI (1 << 0) 34#define MC13XXX_IRQSTAT0_ADCDONEI (1 << 0)
45#define MC13XXX_IRQSTAT0_ADCBISDONEI (1 << 1) 35#define MC13XXX_IRQSTAT0_ADCBISDONEI (1 << 1)
@@ -136,14 +126,14 @@ EXPORT_SYMBOL(mc13783_to_mc13xxx);
136#define MC13XXX_REVISION_FAB (0x03 << 11) 126#define MC13XXX_REVISION_FAB (0x03 << 11)
137#define MC13XXX_REVISION_ICIDCODE (0x3f << 13) 127#define MC13XXX_REVISION_ICIDCODE (0x3f << 13)
138 128
139#define MC13783_ADC1 44 129#define MC13XXX_ADC1 44
140#define MC13783_ADC1_ADEN (1 << 0) 130#define MC13XXX_ADC1_ADEN (1 << 0)
141#define MC13783_ADC1_RAND (1 << 1) 131#define MC13XXX_ADC1_RAND (1 << 1)
142#define MC13783_ADC1_ADSEL (1 << 3) 132#define MC13XXX_ADC1_ADSEL (1 << 3)
143#define MC13783_ADC1_ASC (1 << 20) 133#define MC13XXX_ADC1_ASC (1 << 20)
144#define MC13783_ADC1_ADTRIGIGN (1 << 21) 134#define MC13XXX_ADC1_ADTRIGIGN (1 << 21)
145 135
146#define MC13783_ADC2 45 136#define MC13XXX_ADC2 45
147 137
148#define MC13XXX_NUMREGS 0x3f 138#define MC13XXX_NUMREGS 0x3f
149 139
@@ -487,7 +477,7 @@ enum mc13xxx_id {
487 MC13XXX_ID_INVALID, 477 MC13XXX_ID_INVALID,
488}; 478};
489 479
490const char *mc13xxx_chipname[] = { 480static const char *mc13xxx_chipname[] = {
491 [MC13XXX_ID_MC13783] = "mc13783", 481 [MC13XXX_ID_MC13783] = "mc13783",
492 [MC13XXX_ID_MC13892] = "mc13892", 482 [MC13XXX_ID_MC13892] = "mc13892",
493}; 483};
@@ -558,8 +548,6 @@ static const char *mc13xxx_get_chipname(struct mc13xxx *mc13xxx)
558 return mc13xxx_chipname[devid->driver_data]; 548 return mc13xxx_chipname[devid->driver_data];
559} 549}
560 550
561#include <linux/mfd/mc13783.h>
562
563int mc13xxx_get_flags(struct mc13xxx *mc13xxx) 551int mc13xxx_get_flags(struct mc13xxx *mc13xxx)
564{ 552{
565 struct mc13xxx_platform_data *pdata = 553 struct mc13xxx_platform_data *pdata =
@@ -569,15 +557,15 @@ int mc13xxx_get_flags(struct mc13xxx *mc13xxx)
569} 557}
570EXPORT_SYMBOL(mc13xxx_get_flags); 558EXPORT_SYMBOL(mc13xxx_get_flags);
571 559
572#define MC13783_ADC1_CHAN0_SHIFT 5 560#define MC13XXX_ADC1_CHAN0_SHIFT 5
573#define MC13783_ADC1_CHAN1_SHIFT 8 561#define MC13XXX_ADC1_CHAN1_SHIFT 8
574 562
575struct mc13xxx_adcdone_data { 563struct mc13xxx_adcdone_data {
576 struct mc13xxx *mc13xxx; 564 struct mc13xxx *mc13xxx;
577 struct completion done; 565 struct completion done;
578}; 566};
579 567
580static irqreturn_t mc13783_handler_adcdone(int irq, void *data) 568static irqreturn_t mc13xxx_handler_adcdone(int irq, void *data)
581{ 569{
582 struct mc13xxx_adcdone_data *adcdone_data = data; 570 struct mc13xxx_adcdone_data *adcdone_data = data;
583 571
@@ -588,12 +576,11 @@ static irqreturn_t mc13783_handler_adcdone(int irq, void *data)
588 return IRQ_HANDLED; 576 return IRQ_HANDLED;
589} 577}
590 578
591#define MC13783_ADC_WORKING (1 << 0) 579#define MC13XXX_ADC_WORKING (1 << 0)
592 580
593int mc13783_adc_do_conversion(struct mc13783 *mc13783, unsigned int mode, 581int mc13xxx_adc_do_conversion(struct mc13xxx *mc13xxx, unsigned int mode,
594 unsigned int channel, unsigned int *sample) 582 unsigned int channel, unsigned int *sample)
595{ 583{
596 struct mc13xxx *mc13xxx = &mc13783->mc13xxx;
597 u32 adc0, adc1, old_adc0; 584 u32 adc0, adc1, old_adc0;
598 int i, ret; 585 int i, ret;
599 struct mc13xxx_adcdone_data adcdone_data = { 586 struct mc13xxx_adcdone_data adcdone_data = {
@@ -605,51 +592,51 @@ int mc13783_adc_do_conversion(struct mc13783 *mc13783, unsigned int mode,
605 592
606 mc13xxx_lock(mc13xxx); 593 mc13xxx_lock(mc13xxx);
607 594
608 if (mc13783->adcflags & MC13783_ADC_WORKING) { 595 if (mc13xxx->adcflags & MC13XXX_ADC_WORKING) {
609 ret = -EBUSY; 596 ret = -EBUSY;
610 goto out; 597 goto out;
611 } 598 }
612 599
613 mc13783->adcflags |= MC13783_ADC_WORKING; 600 mc13xxx->adcflags |= MC13XXX_ADC_WORKING;
614 601
615 mc13xxx_reg_read(mc13xxx, MC13783_ADC0, &old_adc0); 602 mc13xxx_reg_read(mc13xxx, MC13XXX_ADC0, &old_adc0);
616 603
617 adc0 = MC13783_ADC0_ADINC1 | MC13783_ADC0_ADINC2; 604 adc0 = MC13XXX_ADC0_ADINC1 | MC13XXX_ADC0_ADINC2;
618 adc1 = MC13783_ADC1_ADEN | MC13783_ADC1_ADTRIGIGN | MC13783_ADC1_ASC; 605 adc1 = MC13XXX_ADC1_ADEN | MC13XXX_ADC1_ADTRIGIGN | MC13XXX_ADC1_ASC;
619 606
620 if (channel > 7) 607 if (channel > 7)
621 adc1 |= MC13783_ADC1_ADSEL; 608 adc1 |= MC13XXX_ADC1_ADSEL;
622 609
623 switch (mode) { 610 switch (mode) {
624 case MC13783_ADC_MODE_TS: 611 case MC13XXX_ADC_MODE_TS:
625 adc0 |= MC13783_ADC0_ADREFEN | MC13783_ADC0_TSMOD0 | 612 adc0 |= MC13XXX_ADC0_ADREFEN | MC13XXX_ADC0_TSMOD0 |
626 MC13783_ADC0_TSMOD1; 613 MC13XXX_ADC0_TSMOD1;
627 adc1 |= 4 << MC13783_ADC1_CHAN1_SHIFT; 614 adc1 |= 4 << MC13XXX_ADC1_CHAN1_SHIFT;
628 break; 615 break;
629 616
630 case MC13783_ADC_MODE_SINGLE_CHAN: 617 case MC13XXX_ADC_MODE_SINGLE_CHAN:
631 adc0 |= old_adc0 & MC13783_ADC0_TSMOD_MASK; 618 adc0 |= old_adc0 & MC13XXX_ADC0_TSMOD_MASK;
632 adc1 |= (channel & 0x7) << MC13783_ADC1_CHAN0_SHIFT; 619 adc1 |= (channel & 0x7) << MC13XXX_ADC1_CHAN0_SHIFT;
633 adc1 |= MC13783_ADC1_RAND; 620 adc1 |= MC13XXX_ADC1_RAND;
634 break; 621 break;
635 622
636 case MC13783_ADC_MODE_MULT_CHAN: 623 case MC13XXX_ADC_MODE_MULT_CHAN:
637 adc0 |= old_adc0 & MC13783_ADC0_TSMOD_MASK; 624 adc0 |= old_adc0 & MC13XXX_ADC0_TSMOD_MASK;
638 adc1 |= 4 << MC13783_ADC1_CHAN1_SHIFT; 625 adc1 |= 4 << MC13XXX_ADC1_CHAN1_SHIFT;
639 break; 626 break;
640 627
641 default: 628 default:
642 mc13783_unlock(mc13783); 629 mc13xxx_unlock(mc13xxx);
643 return -EINVAL; 630 return -EINVAL;
644 } 631 }
645 632
646 dev_dbg(&mc13783->mc13xxx.spidev->dev, "%s: request irq\n", __func__); 633 dev_dbg(&mc13xxx->spidev->dev, "%s: request irq\n", __func__);
647 mc13xxx_irq_request(mc13xxx, MC13783_IRQ_ADCDONE, 634 mc13xxx_irq_request(mc13xxx, MC13XXX_IRQ_ADCDONE,
648 mc13783_handler_adcdone, __func__, &adcdone_data); 635 mc13xxx_handler_adcdone, __func__, &adcdone_data);
649 mc13xxx_irq_ack(mc13xxx, MC13783_IRQ_ADCDONE); 636 mc13xxx_irq_ack(mc13xxx, MC13XXX_IRQ_ADCDONE);
650 637
651 mc13xxx_reg_write(mc13xxx, MC13783_ADC0, adc0); 638 mc13xxx_reg_write(mc13xxx, MC13XXX_ADC0, adc0);
652 mc13xxx_reg_write(mc13xxx, MC13783_ADC1, adc1); 639 mc13xxx_reg_write(mc13xxx, MC13XXX_ADC1, adc1);
653 640
654 mc13xxx_unlock(mc13xxx); 641 mc13xxx_unlock(mc13xxx);
655 642
@@ -660,27 +647,27 @@ int mc13783_adc_do_conversion(struct mc13783 *mc13783, unsigned int mode,
660 647
661 mc13xxx_lock(mc13xxx); 648 mc13xxx_lock(mc13xxx);
662 649
663 mc13xxx_irq_free(mc13xxx, MC13783_IRQ_ADCDONE, &adcdone_data); 650 mc13xxx_irq_free(mc13xxx, MC13XXX_IRQ_ADCDONE, &adcdone_data);
664 651
665 if (ret > 0) 652 if (ret > 0)
666 for (i = 0; i < 4; ++i) { 653 for (i = 0; i < 4; ++i) {
667 ret = mc13xxx_reg_read(mc13xxx, 654 ret = mc13xxx_reg_read(mc13xxx,
668 MC13783_ADC2, &sample[i]); 655 MC13XXX_ADC2, &sample[i]);
669 if (ret) 656 if (ret)
670 break; 657 break;
671 } 658 }
672 659
673 if (mode == MC13783_ADC_MODE_TS) 660 if (mode == MC13XXX_ADC_MODE_TS)
674 /* restore TSMOD */ 661 /* restore TSMOD */
675 mc13xxx_reg_write(mc13xxx, MC13783_ADC0, old_adc0); 662 mc13xxx_reg_write(mc13xxx, MC13XXX_ADC0, old_adc0);
676 663
677 mc13783->adcflags &= ~MC13783_ADC_WORKING; 664 mc13xxx->adcflags &= ~MC13XXX_ADC_WORKING;
678out: 665out:
679 mc13xxx_unlock(mc13xxx); 666 mc13xxx_unlock(mc13xxx);
680 667
681 return ret; 668 return ret;
682} 669}
683EXPORT_SYMBOL_GPL(mc13783_adc_do_conversion); 670EXPORT_SYMBOL_GPL(mc13xxx_adc_do_conversion);
684 671
685static int mc13xxx_add_subdevice_pdata(struct mc13xxx *mc13xxx, 672static int mc13xxx_add_subdevice_pdata(struct mc13xxx *mc13xxx,
686 const char *format, void *pdata, size_t pdata_size) 673 const char *format, void *pdata, size_t pdata_size)
@@ -716,6 +703,11 @@ static int mc13xxx_probe(struct spi_device *spi)
716 enum mc13xxx_id id; 703 enum mc13xxx_id id;
717 int ret; 704 int ret;
718 705
706 if (!pdata) {
707 dev_err(&spi->dev, "invalid platform data\n");
708 return -EINVAL;
709 }
710
719 mc13xxx = kzalloc(sizeof(*mc13xxx), GFP_KERNEL); 711 mc13xxx = kzalloc(sizeof(*mc13xxx), GFP_KERNEL);
720 if (!mc13xxx) 712 if (!mc13xxx)
721 return -ENOMEM; 713 return -ENOMEM;
@@ -763,10 +755,8 @@ err_revision:
763 if (pdata->flags & MC13XXX_USE_CODEC) 755 if (pdata->flags & MC13XXX_USE_CODEC)
764 mc13xxx_add_subdevice(mc13xxx, "%s-codec"); 756 mc13xxx_add_subdevice(mc13xxx, "%s-codec");
765 757
766 if (pdata->flags & MC13XXX_USE_REGULATOR) { 758 mc13xxx_add_subdevice_pdata(mc13xxx, "%s-regulator",
767 mc13xxx_add_subdevice_pdata(mc13xxx, "%s-regulator", 759 &pdata->regulators, sizeof(pdata->regulators));
768 &pdata->regulators, sizeof(pdata->regulators));
769 }
770 760
771 if (pdata->flags & MC13XXX_USE_RTC) 761 if (pdata->flags & MC13XXX_USE_RTC)
772 mc13xxx_add_subdevice(mc13xxx, "%s-rtc"); 762 mc13xxx_add_subdevice(mc13xxx, "%s-rtc");
@@ -774,10 +764,14 @@ err_revision:
774 if (pdata->flags & MC13XXX_USE_TOUCHSCREEN) 764 if (pdata->flags & MC13XXX_USE_TOUCHSCREEN)
775 mc13xxx_add_subdevice(mc13xxx, "%s-ts"); 765 mc13xxx_add_subdevice(mc13xxx, "%s-ts");
776 766
777 if (pdata->flags & MC13XXX_USE_LED) 767 if (pdata->leds)
778 mc13xxx_add_subdevice_pdata(mc13xxx, "%s-led", 768 mc13xxx_add_subdevice_pdata(mc13xxx, "%s-led",
779 pdata->leds, sizeof(*pdata->leds)); 769 pdata->leds, sizeof(*pdata->leds));
780 770
771 if (pdata->buttons)
772 mc13xxx_add_subdevice_pdata(mc13xxx, "%s-pwrbutton",
773 pdata->buttons, sizeof(*pdata->buttons));
774
781 return 0; 775 return 0;
782} 776}
783 777
diff --git a/drivers/mfd/menelaus.c b/drivers/mfd/menelaus.c
index af5d9d061371..cb4910ac4d12 100644
--- a/drivers/mfd/menelaus.c
+++ b/drivers/mfd/menelaus.c
@@ -1226,7 +1226,7 @@ static int menelaus_probe(struct i2c_client *client,
1226 menelaus_write_reg(MENELAUS_MCT_CTRL1, 0x73); 1226 menelaus_write_reg(MENELAUS_MCT_CTRL1, 0x73);
1227 1227
1228 if (client->irq > 0) { 1228 if (client->irq > 0) {
1229 err = request_irq(client->irq, menelaus_irq, IRQF_DISABLED, 1229 err = request_irq(client->irq, menelaus_irq, 0,
1230 DRIVER_NAME, menelaus); 1230 DRIVER_NAME, menelaus);
1231 if (err) { 1231 if (err) {
1232 dev_dbg(&client->dev, "can't get IRQ %d, err %d\n", 1232 dev_dbg(&client->dev, "can't get IRQ %d, err %d\n",
diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c
index 0902523af62d..0f5922812bff 100644
--- a/drivers/mfd/mfd-core.c
+++ b/drivers/mfd/mfd-core.c
@@ -17,6 +17,7 @@
17#include <linux/mfd/core.h> 17#include <linux/mfd/core.h>
18#include <linux/pm_runtime.h> 18#include <linux/pm_runtime.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/module.h>
20 21
21int mfd_cell_enable(struct platform_device *pdev) 22int mfd_cell_enable(struct platform_device *pdev)
22{ 23{
diff --git a/drivers/mfd/pcf50633-core.c b/drivers/mfd/pcf50633-core.c
index 57868416c760..ff1a7e741ecd 100644
--- a/drivers/mfd/pcf50633-core.c
+++ b/drivers/mfd/pcf50633-core.c
@@ -23,45 +23,22 @@
23#include <linux/i2c.h> 23#include <linux/i2c.h>
24#include <linux/pm.h> 24#include <linux/pm.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/regmap.h>
27#include <linux/err.h>
26 28
27#include <linux/mfd/pcf50633/core.h> 29#include <linux/mfd/pcf50633/core.h>
28 30
29static int __pcf50633_read(struct pcf50633 *pcf, u8 reg, int num, u8 *data)
30{
31 int ret;
32
33 ret = i2c_smbus_read_i2c_block_data(pcf->i2c_client, reg,
34 num, data);
35 if (ret < 0)
36 dev_err(pcf->dev, "Error reading %d regs at %d\n", num, reg);
37
38 return ret;
39}
40
41static int __pcf50633_write(struct pcf50633 *pcf, u8 reg, int num, u8 *data)
42{
43 int ret;
44
45 ret = i2c_smbus_write_i2c_block_data(pcf->i2c_client, reg,
46 num, data);
47 if (ret < 0)
48 dev_err(pcf->dev, "Error writing %d regs at %d\n", num, reg);
49
50 return ret;
51
52}
53
54/* Read a block of up to 32 regs */ 31/* Read a block of up to 32 regs */
55int pcf50633_read_block(struct pcf50633 *pcf, u8 reg, 32int pcf50633_read_block(struct pcf50633 *pcf, u8 reg,
56 int nr_regs, u8 *data) 33 int nr_regs, u8 *data)
57{ 34{
58 int ret; 35 int ret;
59 36
60 mutex_lock(&pcf->lock); 37 ret = regmap_raw_read(pcf->regmap, reg, data, nr_regs);
61 ret = __pcf50633_read(pcf, reg, nr_regs, data); 38 if (ret != 0)
62 mutex_unlock(&pcf->lock); 39 return ret;
63 40
64 return ret; 41 return nr_regs;
65} 42}
66EXPORT_SYMBOL_GPL(pcf50633_read_block); 43EXPORT_SYMBOL_GPL(pcf50633_read_block);
67 44
@@ -71,21 +48,22 @@ int pcf50633_write_block(struct pcf50633 *pcf , u8 reg,
71{ 48{
72 int ret; 49 int ret;
73 50
74 mutex_lock(&pcf->lock); 51 ret = regmap_raw_write(pcf->regmap, reg, data, nr_regs);
75 ret = __pcf50633_write(pcf, reg, nr_regs, data); 52 if (ret != 0)
76 mutex_unlock(&pcf->lock); 53 return ret;
77 54
78 return ret; 55 return nr_regs;
79} 56}
80EXPORT_SYMBOL_GPL(pcf50633_write_block); 57EXPORT_SYMBOL_GPL(pcf50633_write_block);
81 58
82u8 pcf50633_reg_read(struct pcf50633 *pcf, u8 reg) 59u8 pcf50633_reg_read(struct pcf50633 *pcf, u8 reg)
83{ 60{
84 u8 val; 61 unsigned int val;
62 int ret;
85 63
86 mutex_lock(&pcf->lock); 64 ret = regmap_read(pcf->regmap, reg, &val);
87 __pcf50633_read(pcf, reg, 1, &val); 65 if (ret < 0)
88 mutex_unlock(&pcf->lock); 66 return -1;
89 67
90 return val; 68 return val;
91} 69}
@@ -93,56 +71,19 @@ EXPORT_SYMBOL_GPL(pcf50633_reg_read);
93 71
94int pcf50633_reg_write(struct pcf50633 *pcf, u8 reg, u8 val) 72int pcf50633_reg_write(struct pcf50633 *pcf, u8 reg, u8 val)
95{ 73{
96 int ret; 74 return regmap_write(pcf->regmap, reg, val);
97
98 mutex_lock(&pcf->lock);
99 ret = __pcf50633_write(pcf, reg, 1, &val);
100 mutex_unlock(&pcf->lock);
101
102 return ret;
103} 75}
104EXPORT_SYMBOL_GPL(pcf50633_reg_write); 76EXPORT_SYMBOL_GPL(pcf50633_reg_write);
105 77
106int pcf50633_reg_set_bit_mask(struct pcf50633 *pcf, u8 reg, u8 mask, u8 val) 78int pcf50633_reg_set_bit_mask(struct pcf50633 *pcf, u8 reg, u8 mask, u8 val)
107{ 79{
108 int ret; 80 return regmap_update_bits(pcf->regmap, reg, mask, val);
109 u8 tmp;
110
111 val &= mask;
112
113 mutex_lock(&pcf->lock);
114 ret = __pcf50633_read(pcf, reg, 1, &tmp);
115 if (ret < 0)
116 goto out;
117
118 tmp &= ~mask;
119 tmp |= val;
120 ret = __pcf50633_write(pcf, reg, 1, &tmp);
121
122out:
123 mutex_unlock(&pcf->lock);
124
125 return ret;
126} 81}
127EXPORT_SYMBOL_GPL(pcf50633_reg_set_bit_mask); 82EXPORT_SYMBOL_GPL(pcf50633_reg_set_bit_mask);
128 83
129int pcf50633_reg_clear_bits(struct pcf50633 *pcf, u8 reg, u8 val) 84int pcf50633_reg_clear_bits(struct pcf50633 *pcf, u8 reg, u8 val)
130{ 85{
131 int ret; 86 return regmap_update_bits(pcf->regmap, reg, val, 0);
132 u8 tmp;
133
134 mutex_lock(&pcf->lock);
135 ret = __pcf50633_read(pcf, reg, 1, &tmp);
136 if (ret < 0)
137 goto out;
138
139 tmp &= ~val;
140 ret = __pcf50633_write(pcf, reg, 1, &tmp);
141
142out:
143 mutex_unlock(&pcf->lock);
144
145 return ret;
146} 87}
147EXPORT_SYMBOL_GPL(pcf50633_reg_clear_bits); 88EXPORT_SYMBOL_GPL(pcf50633_reg_clear_bits);
148 89
@@ -251,6 +192,11 @@ static int pcf50633_resume(struct device *dev)
251 192
252static SIMPLE_DEV_PM_OPS(pcf50633_pm, pcf50633_suspend, pcf50633_resume); 193static SIMPLE_DEV_PM_OPS(pcf50633_pm, pcf50633_suspend, pcf50633_resume);
253 194
195static struct regmap_config pcf50633_regmap_config = {
196 .reg_bits = 8,
197 .val_bits = 8,
198};
199
254static int __devinit pcf50633_probe(struct i2c_client *client, 200static int __devinit pcf50633_probe(struct i2c_client *client,
255 const struct i2c_device_id *ids) 201 const struct i2c_device_id *ids)
256{ 202{
@@ -272,16 +218,23 @@ static int __devinit pcf50633_probe(struct i2c_client *client,
272 218
273 mutex_init(&pcf->lock); 219 mutex_init(&pcf->lock);
274 220
221 pcf->regmap = regmap_init_i2c(client, &pcf50633_regmap_config);
222 if (IS_ERR(pcf->regmap)) {
223 ret = PTR_ERR(pcf->regmap);
224 dev_err(pcf->dev, "Failed to allocate register map: %d\n",
225 ret);
226 goto err_free;
227 }
228
275 i2c_set_clientdata(client, pcf); 229 i2c_set_clientdata(client, pcf);
276 pcf->dev = &client->dev; 230 pcf->dev = &client->dev;
277 pcf->i2c_client = client;
278 231
279 version = pcf50633_reg_read(pcf, 0); 232 version = pcf50633_reg_read(pcf, 0);
280 variant = pcf50633_reg_read(pcf, 1); 233 variant = pcf50633_reg_read(pcf, 1);
281 if (version < 0 || variant < 0) { 234 if (version < 0 || variant < 0) {
282 dev_err(pcf->dev, "Unable to probe pcf50633\n"); 235 dev_err(pcf->dev, "Unable to probe pcf50633\n");
283 ret = -ENODEV; 236 ret = -ENODEV;
284 goto err_free; 237 goto err_regmap;
285 } 238 }
286 239
287 dev_info(pcf->dev, "Probed device version %d variant %d\n", 240 dev_info(pcf->dev, "Probed device version %d variant %d\n",
@@ -328,6 +281,8 @@ static int __devinit pcf50633_probe(struct i2c_client *client,
328 281
329 return 0; 282 return 0;
330 283
284err_regmap:
285 regmap_exit(pcf->regmap);
331err_free: 286err_free:
332 kfree(pcf); 287 kfree(pcf);
333 288
@@ -351,6 +306,7 @@ static int __devexit pcf50633_remove(struct i2c_client *client)
351 for (i = 0; i < PCF50633_NUM_REGULATORS; i++) 306 for (i = 0; i < PCF50633_NUM_REGULATORS; i++)
352 platform_device_unregister(pcf->regulator_pdev[i]); 307 platform_device_unregister(pcf->regulator_pdev[i]);
353 308
309 regmap_exit(pcf->regmap);
354 kfree(pcf); 310 kfree(pcf);
355 311
356 return 0; 312 return 0;
diff --git a/drivers/mfd/pcf50633-irq.c b/drivers/mfd/pcf50633-irq.c
index 1b0192f1efff..048a3b903b01 100644
--- a/drivers/mfd/pcf50633-irq.c
+++ b/drivers/mfd/pcf50633-irq.c
@@ -15,6 +15,7 @@
15#include <linux/interrupt.h> 15#include <linux/interrupt.h>
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/mutex.h> 17#include <linux/mutex.h>
18#include <linux/export.h>
18#include <linux/slab.h> 19#include <linux/slab.h>
19 20
20#include <linux/mfd/pcf50633/core.h> 21#include <linux/mfd/pcf50633/core.h>
diff --git a/drivers/mfd/tc3589x.c b/drivers/mfd/tc3589x.c
index c27e515b0722..de979742c6fc 100644
--- a/drivers/mfd/tc3589x.c
+++ b/drivers/mfd/tc3589x.c
@@ -357,6 +357,7 @@ static int __devexit tc3589x_remove(struct i2c_client *client)
357 return 0; 357 return 0;
358} 358}
359 359
360#ifdef CONFIG_PM
360static int tc3589x_suspend(struct device *dev) 361static int tc3589x_suspend(struct device *dev)
361{ 362{
362 struct tc3589x *tc3589x = dev_get_drvdata(dev); 363 struct tc3589x *tc3589x = dev_get_drvdata(dev);
@@ -387,6 +388,7 @@ static int tc3589x_resume(struct device *dev)
387 388
388static const SIMPLE_DEV_PM_OPS(tc3589x_dev_pm_ops, tc3589x_suspend, 389static const SIMPLE_DEV_PM_OPS(tc3589x_dev_pm_ops, tc3589x_suspend,
389 tc3589x_resume); 390 tc3589x_resume);
391#endif
390 392
391static const struct i2c_device_id tc3589x_id[] = { 393static const struct i2c_device_id tc3589x_id[] = {
392 { "tc3589x", 24 }, 394 { "tc3589x", 24 },
diff --git a/drivers/mfd/timberdale.c b/drivers/mfd/timberdale.c
index 696879e2eef7..02d65692ceb4 100644
--- a/drivers/mfd/timberdale.c
+++ b/drivers/mfd/timberdale.c
@@ -697,7 +697,7 @@ static int __devinit timb_probe(struct pci_dev *dev,
697 dev_err(&dev->dev, "The driver supports an older " 697 dev_err(&dev->dev, "The driver supports an older "
698 "version of the FPGA, please update the driver to " 698 "version of the FPGA, please update the driver to "
699 "support %d.%d\n", priv->fw.major, priv->fw.minor); 699 "support %d.%d\n", priv->fw.major, priv->fw.minor);
700 goto err_ioremap; 700 goto err_config;
701 } 701 }
702 if (priv->fw.major < TIMB_SUPPORTED_MAJOR || 702 if (priv->fw.major < TIMB_SUPPORTED_MAJOR ||
703 priv->fw.minor < TIMB_REQUIRED_MINOR) { 703 priv->fw.minor < TIMB_REQUIRED_MINOR) {
@@ -705,13 +705,13 @@ static int __devinit timb_probe(struct pci_dev *dev,
705 "please upgrade the FPGA to at least: %d.%d\n", 705 "please upgrade the FPGA to at least: %d.%d\n",
706 priv->fw.major, priv->fw.minor, 706 priv->fw.major, priv->fw.minor,
707 TIMB_SUPPORTED_MAJOR, TIMB_REQUIRED_MINOR); 707 TIMB_SUPPORTED_MAJOR, TIMB_REQUIRED_MINOR);
708 goto err_ioremap; 708 goto err_config;
709 } 709 }
710 710
711 msix_entries = kzalloc(TIMBERDALE_NR_IRQS * sizeof(*msix_entries), 711 msix_entries = kzalloc(TIMBERDALE_NR_IRQS * sizeof(*msix_entries),
712 GFP_KERNEL); 712 GFP_KERNEL);
713 if (!msix_entries) 713 if (!msix_entries)
714 goto err_ioremap; 714 goto err_config;
715 715
716 for (i = 0; i < TIMBERDALE_NR_IRQS; i++) 716 for (i = 0; i < TIMBERDALE_NR_IRQS; i++)
717 msix_entries[i].entry = i; 717 msix_entries[i].entry = i;
@@ -825,6 +825,8 @@ err_mfd:
825err_create_file: 825err_create_file:
826 pci_disable_msix(dev); 826 pci_disable_msix(dev);
827err_msix: 827err_msix:
828 kfree(msix_entries);
829err_config:
828 iounmap(priv->ctl_membase); 830 iounmap(priv->ctl_membase);
829err_ioremap: 831err_ioremap:
830 release_mem_region(priv->ctl_mapbase, CHIPCTLSIZE); 832 release_mem_region(priv->ctl_mapbase, CHIPCTLSIZE);
@@ -833,7 +835,6 @@ err_request:
833err_start: 835err_start:
834 pci_disable_device(dev); 836 pci_disable_device(dev);
835err_enable: 837err_enable:
836 kfree(msix_entries);
837 kfree(priv); 838 kfree(priv);
838 pci_set_drvdata(dev, NULL); 839 pci_set_drvdata(dev, NULL);
839 return -ENODEV; 840 return -ENODEV;
diff --git a/drivers/mfd/tmio_core.c b/drivers/mfd/tmio_core.c
index eddc19ae464b..83af78c1b0eb 100644
--- a/drivers/mfd/tmio_core.c
+++ b/drivers/mfd/tmio_core.c
@@ -6,6 +6,7 @@
6 * published by the Free Software Foundation. 6 * published by the Free Software Foundation.
7 */ 7 */
8 8
9#include <linux/export.h>
9#include <linux/mfd/tmio.h> 10#include <linux/mfd/tmio.h>
10 11
11int tmio_core_mmc_enable(void __iomem *cnf, int shift, unsigned long base) 12int tmio_core_mmc_enable(void __iomem *cnf, int shift, unsigned long base)
diff --git a/drivers/mfd/tps65912-core.c b/drivers/mfd/tps65912-core.c
index 955bc00e4b20..5fec23a9ac03 100644
--- a/drivers/mfd/tps65912-core.c
+++ b/drivers/mfd/tps65912-core.c
@@ -131,9 +131,6 @@ int tps65912_device_init(struct tps65912 *tps65912)
131 if (init_data == NULL) 131 if (init_data == NULL)
132 return -ENOMEM; 132 return -ENOMEM;
133 133
134 init_data->irq = pmic_plat_data->irq;
135 init_data->irq_base = pmic_plat_data->irq;
136
137 mutex_init(&tps65912->io_mutex); 134 mutex_init(&tps65912->io_mutex);
138 dev_set_drvdata(tps65912->dev, tps65912); 135 dev_set_drvdata(tps65912->dev, tps65912);
139 136
@@ -153,10 +150,13 @@ int tps65912_device_init(struct tps65912 *tps65912)
153 if (ret < 0) 150 if (ret < 0)
154 goto err; 151 goto err;
155 152
153 init_data->irq = pmic_plat_data->irq;
154 init_data->irq_base = pmic_plat_data->irq;
156 ret = tps65912_irq_init(tps65912, init_data->irq, init_data); 155 ret = tps65912_irq_init(tps65912, init_data->irq, init_data);
157 if (ret < 0) 156 if (ret < 0)
158 goto err; 157 goto err;
159 158
159 kfree(init_data);
160 return ret; 160 return ret;
161 161
162err: 162err:
diff --git a/drivers/mfd/twl-core.c b/drivers/mfd/twl-core.c
index 01ecfeee6524..bfbd66021afd 100644
--- a/drivers/mfd/twl-core.c
+++ b/drivers/mfd/twl-core.c
@@ -30,6 +30,7 @@
30 30
31#include <linux/init.h> 31#include <linux/init.h>
32#include <linux/mutex.h> 32#include <linux/mutex.h>
33#include <linux/module.h>
33#include <linux/platform_device.h> 34#include <linux/platform_device.h>
34#include <linux/clk.h> 35#include <linux/clk.h>
35#include <linux/err.h> 36#include <linux/err.h>
@@ -109,7 +110,7 @@
109#define twl_has_watchdog() false 110#define twl_has_watchdog() false
110#endif 111#endif
111 112
112#if defined(CONFIG_TWL4030_CODEC) || defined(CONFIG_TWL4030_CODEC_MODULE) ||\ 113#if defined(CONFIG_MFD_TWL4030_AUDIO) || defined(CONFIG_MFD_TWL4030_AUDIO_MODULE) ||\
113 defined(CONFIG_TWL6040_CORE) || defined(CONFIG_TWL6040_CORE_MODULE) 114 defined(CONFIG_TWL6040_CORE) || defined(CONFIG_TWL6040_CORE_MODULE)
114#define twl_has_codec() true 115#define twl_has_codec() true
115#else 116#else
diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
index 8a7ee3139b86..f062c8cc6c38 100644
--- a/drivers/mfd/twl4030-irq.c
+++ b/drivers/mfd/twl4030-irq.c
@@ -30,7 +30,6 @@
30#include <linux/init.h> 30#include <linux/init.h>
31#include <linux/interrupt.h> 31#include <linux/interrupt.h>
32#include <linux/irq.h> 32#include <linux/irq.h>
33#include <linux/kthread.h>
34#include <linux/slab.h> 33#include <linux/slab.h>
35 34
36#include <linux/i2c/twl.h> 35#include <linux/i2c/twl.h>
@@ -278,59 +277,6 @@ static const struct sih sih_modules_twl5031[8] = {
278 277
279static unsigned twl4030_irq_base; 278static unsigned twl4030_irq_base;
280 279
281static struct completion irq_event;
282
283/*
284 * This thread processes interrupts reported by the Primary Interrupt Handler.
285 */
286static int twl4030_irq_thread(void *data)
287{
288 long irq = (long)data;
289 static unsigned i2c_errors;
290 static const unsigned max_i2c_errors = 100;
291
292
293 current->flags |= PF_NOFREEZE;
294
295 while (!kthread_should_stop()) {
296 int ret;
297 int module_irq;
298 u8 pih_isr;
299
300 /* Wait for IRQ, then read PIH irq status (also blocking) */
301 wait_for_completion_interruptible(&irq_event);
302
303 ret = twl_i2c_read_u8(TWL4030_MODULE_PIH, &pih_isr,
304 REG_PIH_ISR_P1);
305 if (ret) {
306 pr_warning("twl4030: I2C error %d reading PIH ISR\n",
307 ret);
308 if (++i2c_errors >= max_i2c_errors) {
309 printk(KERN_ERR "Maximum I2C error count"
310 " exceeded. Terminating %s.\n",
311 __func__);
312 break;
313 }
314 complete(&irq_event);
315 continue;
316 }
317
318 /* these handlers deal with the relevant SIH irq status */
319 local_irq_disable();
320 for (module_irq = twl4030_irq_base;
321 pih_isr;
322 pih_isr >>= 1, module_irq++) {
323 if (pih_isr & 0x1)
324 generic_handle_irq(module_irq);
325 }
326 local_irq_enable();
327
328 enable_irq(irq);
329 }
330
331 return 0;
332}
333
334/* 280/*
335 * handle_twl4030_pih() is the desc->handle method for the twl4030 interrupt. 281 * handle_twl4030_pih() is the desc->handle method for the twl4030 interrupt.
336 * This is a chained interrupt, so there is no desc->action method for it. 282 * This is a chained interrupt, so there is no desc->action method for it.
@@ -342,9 +288,25 @@ static int twl4030_irq_thread(void *data)
342 */ 288 */
343static irqreturn_t handle_twl4030_pih(int irq, void *devid) 289static irqreturn_t handle_twl4030_pih(int irq, void *devid)
344{ 290{
345 /* Acknowledge, clear *AND* mask the interrupt... */ 291 int module_irq;
346 disable_irq_nosync(irq); 292 irqreturn_t ret;
347 complete(devid); 293 u8 pih_isr;
294
295 ret = twl_i2c_read_u8(TWL4030_MODULE_PIH, &pih_isr,
296 REG_PIH_ISR_P1);
297 if (ret) {
298 pr_warning("twl4030: I2C error %d reading PIH ISR\n", ret);
299 return IRQ_NONE;
300 }
301
302 /* these handlers deal with the relevant SIH irq status */
303 for (module_irq = twl4030_irq_base;
304 pih_isr;
305 pih_isr >>= 1, module_irq++) {
306 if (pih_isr & 0x1)
307 handle_nested_irq(module_irq);
308 }
309
348 return IRQ_HANDLED; 310 return IRQ_HANDLED;
349} 311}
350/*----------------------------------------------------------------------*/ 312/*----------------------------------------------------------------------*/
@@ -460,113 +422,17 @@ static inline void activate_irq(int irq)
460 422
461/*----------------------------------------------------------------------*/ 423/*----------------------------------------------------------------------*/
462 424
463static DEFINE_SPINLOCK(sih_agent_lock);
464
465static struct workqueue_struct *wq;
466
467struct sih_agent { 425struct sih_agent {
468 int irq_base; 426 int irq_base;
469 const struct sih *sih; 427 const struct sih *sih;
470 428
471 u32 imr; 429 u32 imr;
472 bool imr_change_pending; 430 bool imr_change_pending;
473 struct work_struct mask_work;
474
475 u32 edge_change;
476 struct work_struct edge_work;
477};
478
479static void twl4030_sih_do_mask(struct work_struct *work)
480{
481 struct sih_agent *agent;
482 const struct sih *sih;
483 union {
484 u8 bytes[4];
485 u32 word;
486 } imr;
487 int status;
488 431
489 agent = container_of(work, struct sih_agent, mask_work);
490
491 /* see what work we have */
492 spin_lock_irq(&sih_agent_lock);
493 if (agent->imr_change_pending) {
494 sih = agent->sih;
495 /* byte[0] gets overwritten as we write ... */
496 imr.word = cpu_to_le32(agent->imr << 8);
497 agent->imr_change_pending = false;
498 } else
499 sih = NULL;
500 spin_unlock_irq(&sih_agent_lock);
501 if (!sih)
502 return;
503
504 /* write the whole mask ... simpler than subsetting it */
505 status = twl_i2c_write(sih->module, imr.bytes,
506 sih->mask[irq_line].imr_offset, sih->bytes_ixr);
507 if (status)
508 pr_err("twl4030: %s, %s --> %d\n", __func__,
509 "write", status);
510}
511
512static void twl4030_sih_do_edge(struct work_struct *work)
513{
514 struct sih_agent *agent;
515 const struct sih *sih;
516 u8 bytes[6];
517 u32 edge_change; 432 u32 edge_change;
518 int status;
519
520 agent = container_of(work, struct sih_agent, edge_work);
521
522 /* see what work we have */
523 spin_lock_irq(&sih_agent_lock);
524 edge_change = agent->edge_change;
525 agent->edge_change = 0;
526 sih = edge_change ? agent->sih : NULL;
527 spin_unlock_irq(&sih_agent_lock);
528 if (!sih)
529 return;
530
531 /* Read, reserving first byte for write scratch. Yes, this
532 * could be cached for some speedup ... but be careful about
533 * any processor on the other IRQ line, EDR registers are
534 * shared.
535 */
536 status = twl_i2c_read(sih->module, bytes + 1,
537 sih->edr_offset, sih->bytes_edr);
538 if (status) {
539 pr_err("twl4030: %s, %s --> %d\n", __func__,
540 "read", status);
541 return;
542 }
543
544 /* Modify only the bits we know must change */
545 while (edge_change) {
546 int i = fls(edge_change) - 1;
547 struct irq_data *idata = irq_get_irq_data(i + agent->irq_base);
548 int byte = 1 + (i >> 2);
549 int off = (i & 0x3) * 2;
550 unsigned int type;
551
552 bytes[byte] &= ~(0x03 << off);
553 433
554 type = irqd_get_trigger_type(idata); 434 struct mutex irq_lock;
555 if (type & IRQ_TYPE_EDGE_RISING) 435};
556 bytes[byte] |= BIT(off + 1);
557 if (type & IRQ_TYPE_EDGE_FALLING)
558 bytes[byte] |= BIT(off + 0);
559
560 edge_change &= ~BIT(i);
561 }
562
563 /* Write */
564 status = twl_i2c_write(sih->module, bytes,
565 sih->edr_offset, sih->bytes_edr);
566 if (status)
567 pr_err("twl4030: %s, %s --> %d\n", __func__,
568 "write", status);
569}
570 436
571/*----------------------------------------------------------------------*/ 437/*----------------------------------------------------------------------*/
572 438
@@ -579,50 +445,125 @@ static void twl4030_sih_do_edge(struct work_struct *work)
579 445
580static void twl4030_sih_mask(struct irq_data *data) 446static void twl4030_sih_mask(struct irq_data *data)
581{ 447{
582 struct sih_agent *sih = irq_data_get_irq_chip_data(data); 448 struct sih_agent *agent = irq_data_get_irq_chip_data(data);
583 unsigned long flags; 449
584 450 agent->imr |= BIT(data->irq - agent->irq_base);
585 spin_lock_irqsave(&sih_agent_lock, flags); 451 agent->imr_change_pending = true;
586 sih->imr |= BIT(data->irq - sih->irq_base);
587 sih->imr_change_pending = true;
588 queue_work(wq, &sih->mask_work);
589 spin_unlock_irqrestore(&sih_agent_lock, flags);
590} 452}
591 453
592static void twl4030_sih_unmask(struct irq_data *data) 454static void twl4030_sih_unmask(struct irq_data *data)
593{ 455{
594 struct sih_agent *sih = irq_data_get_irq_chip_data(data); 456 struct sih_agent *agent = irq_data_get_irq_chip_data(data);
595 unsigned long flags; 457
596 458 agent->imr &= ~BIT(data->irq - agent->irq_base);
597 spin_lock_irqsave(&sih_agent_lock, flags); 459 agent->imr_change_pending = true;
598 sih->imr &= ~BIT(data->irq - sih->irq_base);
599 sih->imr_change_pending = true;
600 queue_work(wq, &sih->mask_work);
601 spin_unlock_irqrestore(&sih_agent_lock, flags);
602} 460}
603 461
604static int twl4030_sih_set_type(struct irq_data *data, unsigned trigger) 462static int twl4030_sih_set_type(struct irq_data *data, unsigned trigger)
605{ 463{
606 struct sih_agent *sih = irq_data_get_irq_chip_data(data); 464 struct sih_agent *agent = irq_data_get_irq_chip_data(data);
607 unsigned long flags;
608 465
609 if (trigger & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)) 466 if (trigger & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
610 return -EINVAL; 467 return -EINVAL;
611 468
612 spin_lock_irqsave(&sih_agent_lock, flags); 469 if (irqd_get_trigger_type(data) != trigger)
613 if (irqd_get_trigger_type(data) != trigger) { 470 agent->edge_change |= BIT(data->irq - agent->irq_base);
614 sih->edge_change |= BIT(data->irq - sih->irq_base); 471
615 queue_work(wq, &sih->edge_work);
616 }
617 spin_unlock_irqrestore(&sih_agent_lock, flags);
618 return 0; 472 return 0;
619} 473}
620 474
475static void twl4030_sih_bus_lock(struct irq_data *data)
476{
477 struct sih_agent *agent = irq_data_get_irq_chip_data(data);
478
479 mutex_lock(&agent->irq_lock);
480}
481
482static void twl4030_sih_bus_sync_unlock(struct irq_data *data)
483{
484 struct sih_agent *agent = irq_data_get_irq_chip_data(data);
485 const struct sih *sih = agent->sih;
486 int status;
487
488 if (agent->imr_change_pending) {
489 union {
490 u32 word;
491 u8 bytes[4];
492 } imr;
493
494 /* byte[0] gets overwriten as we write ... */
495 imr.word = cpu_to_le32(agent->imr << 8);
496 agent->imr_change_pending = false;
497
498 /* write the whole mask ... simpler than subsetting it */
499 status = twl_i2c_write(sih->module, imr.bytes,
500 sih->mask[irq_line].imr_offset,
501 sih->bytes_ixr);
502 if (status)
503 pr_err("twl4030: %s, %s --> %d\n", __func__,
504 "write", status);
505 }
506
507 if (agent->edge_change) {
508 u32 edge_change;
509 u8 bytes[6];
510
511 edge_change = agent->edge_change;
512 agent->edge_change = 0;
513
514 /*
515 * Read, reserving first byte for write scratch. Yes, this
516 * could be cached for some speedup ... but be careful about
517 * any processor on the other IRQ line, EDR registers are
518 * shared.
519 */
520 status = twl_i2c_read(sih->module, bytes + 1,
521 sih->edr_offset, sih->bytes_edr);
522 if (status) {
523 pr_err("twl4030: %s, %s --> %d\n", __func__,
524 "read", status);
525 return;
526 }
527
528 /* Modify only the bits we know must change */
529 while (edge_change) {
530 int i = fls(edge_change) - 1;
531 struct irq_data *idata;
532 int byte = 1 + (i >> 2);
533 int off = (i & 0x3) * 2;
534 unsigned int type;
535
536 idata = irq_get_irq_data(i + agent->irq_base);
537
538 bytes[byte] &= ~(0x03 << off);
539
540 type = irqd_get_trigger_type(idata);
541 if (type & IRQ_TYPE_EDGE_RISING)
542 bytes[byte] |= BIT(off + 1);
543 if (type & IRQ_TYPE_EDGE_FALLING)
544 bytes[byte] |= BIT(off + 0);
545
546 edge_change &= ~BIT(i);
547 }
548
549 /* Write */
550 status = twl_i2c_write(sih->module, bytes,
551 sih->edr_offset, sih->bytes_edr);
552 if (status)
553 pr_err("twl4030: %s, %s --> %d\n", __func__,
554 "write", status);
555 }
556
557 mutex_unlock(&agent->irq_lock);
558}
559
621static struct irq_chip twl4030_sih_irq_chip = { 560static struct irq_chip twl4030_sih_irq_chip = {
622 .name = "twl4030", 561 .name = "twl4030",
623 .irq_mask = twl4030_sih_mask, 562 .irq_mask = twl4030_sih_mask,
624 .irq_unmask = twl4030_sih_unmask, 563 .irq_unmask = twl4030_sih_unmask,
625 .irq_set_type = twl4030_sih_set_type, 564 .irq_set_type = twl4030_sih_set_type,
565 .irq_bus_lock = twl4030_sih_bus_lock,
566 .irq_bus_sync_unlock = twl4030_sih_bus_sync_unlock,
626}; 567};
627 568
628/*----------------------------------------------------------------------*/ 569/*----------------------------------------------------------------------*/
@@ -655,9 +596,7 @@ static void handle_twl4030_sih(unsigned irq, struct irq_desc *desc)
655 int isr; 596 int isr;
656 597
657 /* reading ISR acks the IRQs, using clear-on-read mode */ 598 /* reading ISR acks the IRQs, using clear-on-read mode */
658 local_irq_enable();
659 isr = sih_read_isr(sih); 599 isr = sih_read_isr(sih);
660 local_irq_disable();
661 600
662 if (isr < 0) { 601 if (isr < 0) {
663 pr_err("twl4030: %s SIH, read ISR error %d\n", 602 pr_err("twl4030: %s SIH, read ISR error %d\n",
@@ -672,7 +611,7 @@ static void handle_twl4030_sih(unsigned irq, struct irq_desc *desc)
672 isr &= ~BIT(irq); 611 isr &= ~BIT(irq);
673 612
674 if (irq < sih->bits) 613 if (irq < sih->bits)
675 generic_handle_irq(agent->irq_base + irq); 614 handle_nested_irq(agent->irq_base + irq);
676 else 615 else
677 pr_err("twl4030: %s SIH, invalid ISR bit %d\n", 616 pr_err("twl4030: %s SIH, invalid ISR bit %d\n",
678 sih->name, irq); 617 sih->name, irq);
@@ -718,15 +657,14 @@ int twl4030_sih_setup(int module)
718 agent->irq_base = irq_base; 657 agent->irq_base = irq_base;
719 agent->sih = sih; 658 agent->sih = sih;
720 agent->imr = ~0; 659 agent->imr = ~0;
721 INIT_WORK(&agent->mask_work, twl4030_sih_do_mask); 660 mutex_init(&agent->irq_lock);
722 INIT_WORK(&agent->edge_work, twl4030_sih_do_edge);
723 661
724 for (i = 0; i < sih->bits; i++) { 662 for (i = 0; i < sih->bits; i++) {
725 irq = irq_base + i; 663 irq = irq_base + i;
726 664
665 irq_set_chip_data(irq, agent);
727 irq_set_chip_and_handler(irq, &twl4030_sih_irq_chip, 666 irq_set_chip_and_handler(irq, &twl4030_sih_irq_chip,
728 handle_edge_irq); 667 handle_edge_irq);
729 irq_set_chip_data(irq, agent);
730 activate_irq(irq); 668 activate_irq(irq);
731 } 669 }
732 670
@@ -758,7 +696,6 @@ int twl4030_init_irq(int irq_num, unsigned irq_base, unsigned irq_end)
758 696
759 int status; 697 int status;
760 int i; 698 int i;
761 struct task_struct *task;
762 699
763 /* 700 /*
764 * Mask and clear all TWL4030 interrupts since initially we do 701 * Mask and clear all TWL4030 interrupts since initially we do
@@ -768,12 +705,6 @@ int twl4030_init_irq(int irq_num, unsigned irq_base, unsigned irq_end)
768 if (status < 0) 705 if (status < 0)
769 return status; 706 return status;
770 707
771 wq = create_singlethread_workqueue("twl4030-irqchip");
772 if (!wq) {
773 pr_err("twl4030: workqueue FAIL\n");
774 return -ESRCH;
775 }
776
777 twl4030_irq_base = irq_base; 708 twl4030_irq_base = irq_base;
778 709
779 /* install an irq handler for each of the SIH modules; 710 /* install an irq handler for each of the SIH modules;
@@ -787,6 +718,7 @@ int twl4030_init_irq(int irq_num, unsigned irq_base, unsigned irq_end)
787 for (i = irq_base; i < irq_end; i++) { 718 for (i = irq_base; i < irq_end; i++) {
788 irq_set_chip_and_handler(i, &twl4030_irq_chip, 719 irq_set_chip_and_handler(i, &twl4030_irq_chip,
789 handle_simple_irq); 720 handle_simple_irq);
721 irq_set_nested_thread(i, 1);
790 activate_irq(i); 722 activate_irq(i);
791 } 723 }
792 twl4030_irq_next = i; 724 twl4030_irq_next = i;
@@ -801,34 +733,22 @@ int twl4030_init_irq(int irq_num, unsigned irq_base, unsigned irq_end)
801 } 733 }
802 734
803 /* install an irq handler to demultiplex the TWL4030 interrupt */ 735 /* install an irq handler to demultiplex the TWL4030 interrupt */
804 736 status = request_threaded_irq(irq_num, NULL, handle_twl4030_pih, 0,
805 737 "TWL4030-PIH", NULL);
806 init_completion(&irq_event);
807
808 status = request_irq(irq_num, handle_twl4030_pih, IRQF_DISABLED,
809 "TWL4030-PIH", &irq_event);
810 if (status < 0) { 738 if (status < 0) {
811 pr_err("twl4030: could not claim irq%d: %d\n", irq_num, status); 739 pr_err("twl4030: could not claim irq%d: %d\n", irq_num, status);
812 goto fail_rqirq; 740 goto fail_rqirq;
813 } 741 }
814 742
815 task = kthread_run(twl4030_irq_thread, (void *)(long)irq_num,
816 "twl4030-irq");
817 if (IS_ERR(task)) {
818 pr_err("twl4030: could not create irq %d thread!\n", irq_num);
819 status = PTR_ERR(task);
820 goto fail_kthread;
821 }
822 return status; 743 return status;
823fail_kthread:
824 free_irq(irq_num, &irq_event);
825fail_rqirq: 744fail_rqirq:
826 /* clean up twl4030_sih_setup */ 745 /* clean up twl4030_sih_setup */
827fail: 746fail:
828 for (i = irq_base; i < irq_end; i++) 747 for (i = irq_base; i < irq_end; i++) {
748 irq_set_nested_thread(i, 0);
829 irq_set_chip_and_handler(i, NULL, NULL); 749 irq_set_chip_and_handler(i, NULL, NULL);
830 destroy_workqueue(wq); 750 }
831 wq = NULL; 751
832 return status; 752 return status;
833} 753}
834 754
diff --git a/drivers/mfd/twl4030-madc.c b/drivers/mfd/twl4030-madc.c
index 7cbf2aa9e64f..834f824d3c11 100644
--- a/drivers/mfd/twl4030-madc.c
+++ b/drivers/mfd/twl4030-madc.c
@@ -740,6 +740,28 @@ static int __devinit twl4030_madc_probe(struct platform_device *pdev)
740 TWL4030_BCI_BCICTL1); 740 TWL4030_BCI_BCICTL1);
741 goto err_i2c; 741 goto err_i2c;
742 } 742 }
743
744 /* Check that MADC clock is on */
745 ret = twl_i2c_read_u8(TWL4030_MODULE_INTBR, &regval, TWL4030_REG_GPBR1);
746 if (ret) {
747 dev_err(&pdev->dev, "unable to read reg GPBR1 0x%X\n",
748 TWL4030_REG_GPBR1);
749 goto err_i2c;
750 }
751
752 /* If MADC clk is not on, turn it on */
753 if (!(regval & TWL4030_GPBR1_MADC_HFCLK_EN)) {
754 dev_info(&pdev->dev, "clk disabled, enabling\n");
755 regval |= TWL4030_GPBR1_MADC_HFCLK_EN;
756 ret = twl_i2c_write_u8(TWL4030_MODULE_INTBR, regval,
757 TWL4030_REG_GPBR1);
758 if (ret) {
759 dev_err(&pdev->dev, "unable to write reg GPBR1 0x%X\n",
760 TWL4030_REG_GPBR1);
761 goto err_i2c;
762 }
763 }
764
743 platform_set_drvdata(pdev, madc); 765 platform_set_drvdata(pdev, madc);
744 mutex_init(&madc->lock); 766 mutex_init(&madc->lock);
745 ret = request_threaded_irq(platform_get_irq(pdev, 0), NULL, 767 ret = request_threaded_irq(platform_get_irq(pdev, 0), NULL,
diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
index eb3b5f88e566..3eee45ffb096 100644
--- a/drivers/mfd/twl6030-irq.c
+++ b/drivers/mfd/twl6030-irq.c
@@ -32,11 +32,13 @@
32 */ 32 */
33 33
34#include <linux/init.h> 34#include <linux/init.h>
35#include <linux/export.h>
35#include <linux/interrupt.h> 36#include <linux/interrupt.h>
36#include <linux/irq.h> 37#include <linux/irq.h>
37#include <linux/kthread.h> 38#include <linux/kthread.h>
38#include <linux/i2c/twl.h> 39#include <linux/i2c/twl.h>
39#include <linux/platform_device.h> 40#include <linux/platform_device.h>
41#include <linux/suspend.h>
40 42
41#include "twl-core.h" 43#include "twl-core.h"
42 44
@@ -83,8 +85,48 @@ static int twl6030_interrupt_mapping[24] = {
83/*----------------------------------------------------------------------*/ 85/*----------------------------------------------------------------------*/
84 86
85static unsigned twl6030_irq_base; 87static unsigned twl6030_irq_base;
88static int twl_irq;
89static bool twl_irq_wake_enabled;
86 90
87static struct completion irq_event; 91static struct completion irq_event;
92static atomic_t twl6030_wakeirqs = ATOMIC_INIT(0);
93
94static int twl6030_irq_pm_notifier(struct notifier_block *notifier,
95 unsigned long pm_event, void *unused)
96{
97 int chained_wakeups;
98
99 switch (pm_event) {
100 case PM_SUSPEND_PREPARE:
101 chained_wakeups = atomic_read(&twl6030_wakeirqs);
102
103 if (chained_wakeups && !twl_irq_wake_enabled) {
104 if (enable_irq_wake(twl_irq))
105 pr_err("twl6030 IRQ wake enable failed\n");
106 else
107 twl_irq_wake_enabled = true;
108 } else if (!chained_wakeups && twl_irq_wake_enabled) {
109 disable_irq_wake(twl_irq);
110 twl_irq_wake_enabled = false;
111 }
112
113 disable_irq(twl_irq);
114 break;
115
116 case PM_POST_SUSPEND:
117 enable_irq(twl_irq);
118 break;
119
120 default:
121 break;
122 }
123
124 return NOTIFY_DONE;
125}
126
127static struct notifier_block twl6030_irq_pm_notifier_block = {
128 .notifier_call = twl6030_irq_pm_notifier,
129};
88 130
89/* 131/*
90 * This thread processes interrupts reported by the Primary Interrupt Handler. 132 * This thread processes interrupts reported by the Primary Interrupt Handler.
@@ -187,6 +229,16 @@ static inline void activate_irq(int irq)
187#endif 229#endif
188} 230}
189 231
232int twl6030_irq_set_wake(struct irq_data *d, unsigned int on)
233{
234 if (on)
235 atomic_inc(&twl6030_wakeirqs);
236 else
237 atomic_dec(&twl6030_wakeirqs);
238
239 return 0;
240}
241
190/*----------------------------------------------------------------------*/ 242/*----------------------------------------------------------------------*/
191 243
192static unsigned twl6030_irq_next; 244static unsigned twl6030_irq_next;
@@ -318,10 +370,12 @@ int twl6030_init_irq(int irq_num, unsigned irq_base, unsigned irq_end)
318 twl6030_irq_chip = dummy_irq_chip; 370 twl6030_irq_chip = dummy_irq_chip;
319 twl6030_irq_chip.name = "twl6030"; 371 twl6030_irq_chip.name = "twl6030";
320 twl6030_irq_chip.irq_set_type = NULL; 372 twl6030_irq_chip.irq_set_type = NULL;
373 twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
321 374
322 for (i = irq_base; i < irq_end; i++) { 375 for (i = irq_base; i < irq_end; i++) {
323 irq_set_chip_and_handler(i, &twl6030_irq_chip, 376 irq_set_chip_and_handler(i, &twl6030_irq_chip,
324 handle_simple_irq); 377 handle_simple_irq);
378 irq_set_chip_data(i, (void *)irq_num);
325 activate_irq(i); 379 activate_irq(i);
326 } 380 }
327 381
@@ -331,6 +385,14 @@ int twl6030_init_irq(int irq_num, unsigned irq_base, unsigned irq_end)
331 385
332 /* install an irq handler to demultiplex the TWL6030 interrupt */ 386 /* install an irq handler to demultiplex the TWL6030 interrupt */
333 init_completion(&irq_event); 387 init_completion(&irq_event);
388
389 status = request_irq(irq_num, handle_twl6030_pih, 0,
390 "TWL6030-PIH", &irq_event);
391 if (status < 0) {
392 pr_err("twl6030: could not claim irq%d: %d\n", irq_num, status);
393 goto fail_irq;
394 }
395
334 task = kthread_run(twl6030_irq_thread, (void *)irq_num, "twl6030-irq"); 396 task = kthread_run(twl6030_irq_thread, (void *)irq_num, "twl6030-irq");
335 if (IS_ERR(task)) { 397 if (IS_ERR(task)) {
336 pr_err("twl6030: could not create irq %d thread!\n", irq_num); 398 pr_err("twl6030: could not create irq %d thread!\n", irq_num);
@@ -338,17 +400,14 @@ int twl6030_init_irq(int irq_num, unsigned irq_base, unsigned irq_end)
338 goto fail_kthread; 400 goto fail_kthread;
339 } 401 }
340 402
341 status = request_irq(irq_num, handle_twl6030_pih, IRQF_DISABLED, 403 twl_irq = irq_num;
342 "TWL6030-PIH", &irq_event); 404 register_pm_notifier(&twl6030_irq_pm_notifier_block);
343 if (status < 0) {
344 pr_err("twl6030: could not claim irq%d: %d\n", irq_num, status);
345 goto fail_irq;
346 }
347 return status; 405 return status;
348fail_irq:
349 free_irq(irq_num, &irq_event);
350 406
351fail_kthread: 407fail_kthread:
408 free_irq(irq_num, &irq_event);
409
410fail_irq:
352 for (i = irq_base; i < irq_end; i++) 411 for (i = irq_base; i < irq_end; i++)
353 irq_set_chip_and_handler(i, NULL, NULL); 412 irq_set_chip_and_handler(i, NULL, NULL);
354 return status; 413 return status;
@@ -356,6 +415,7 @@ fail_kthread:
356 415
357int twl6030_exit_irq(void) 416int twl6030_exit_irq(void)
358{ 417{
418 unregister_pm_notifier(&twl6030_irq_pm_notifier_block);
359 419
360 if (twl6030_irq_base) { 420 if (twl6030_irq_base) {
361 pr_err("twl6030: can't yet clean up IRQs?\n"); 421 pr_err("twl6030: can't yet clean up IRQs?\n");
diff --git a/drivers/mfd/wl1273-core.c b/drivers/mfd/wl1273-core.c
index d97a86945174..f39b756df561 100644
--- a/drivers/mfd/wl1273-core.c
+++ b/drivers/mfd/wl1273-core.c
@@ -22,6 +22,7 @@
22 22
23#include <linux/mfd/wl1273-core.h> 23#include <linux/mfd/wl1273-core.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/module.h>
25 26
26#define DRIVER_DESC "WL1273 FM Radio Core" 27#define DRIVER_DESC "WL1273 FM Radio Core"
27 28
diff --git a/drivers/mfd/wm831x-irq.c b/drivers/mfd/wm831x-irq.c
index ada1835a5455..f4747a4a9a93 100644
--- a/drivers/mfd/wm831x-irq.c
+++ b/drivers/mfd/wm831x-irq.c
@@ -420,12 +420,19 @@ static int wm831x_irq_set_type(struct irq_data *data, unsigned int type)
420 switch (type) { 420 switch (type) {
421 case IRQ_TYPE_EDGE_BOTH: 421 case IRQ_TYPE_EDGE_BOTH:
422 wm831x->gpio_update[irq] = 0x10000 | WM831X_GPN_INT_MODE; 422 wm831x->gpio_update[irq] = 0x10000 | WM831X_GPN_INT_MODE;
423 wm831x->gpio_level[irq] = false;
423 break; 424 break;
424 case IRQ_TYPE_EDGE_RISING: 425 case IRQ_TYPE_EDGE_RISING:
425 wm831x->gpio_update[irq] = 0x10000 | WM831X_GPN_POL; 426 wm831x->gpio_update[irq] = 0x10000 | WM831X_GPN_POL;
427 wm831x->gpio_level[irq] = false;
426 break; 428 break;
427 case IRQ_TYPE_EDGE_FALLING: 429 case IRQ_TYPE_EDGE_FALLING:
428 wm831x->gpio_update[irq] = 0x10000; 430 wm831x->gpio_update[irq] = 0x10000;
431 wm831x->gpio_level[irq] = false;
432 break;
433 case IRQ_TYPE_LEVEL_HIGH:
434 wm831x->gpio_update[irq] = 0x10000 | WM831X_GPN_POL;
435 wm831x->gpio_level[irq] = true;
429 break; 436 break;
430 default: 437 default:
431 return -EINVAL; 438 return -EINVAL;
@@ -449,7 +456,7 @@ static irqreturn_t wm831x_irq_thread(int irq, void *data)
449{ 456{
450 struct wm831x *wm831x = data; 457 struct wm831x *wm831x = data;
451 unsigned int i; 458 unsigned int i;
452 int primary, status_addr; 459 int primary, status_addr, ret;
453 int status_regs[WM831X_NUM_IRQ_REGS] = { 0 }; 460 int status_regs[WM831X_NUM_IRQ_REGS] = { 0 };
454 int read[WM831X_NUM_IRQ_REGS] = { 0 }; 461 int read[WM831X_NUM_IRQ_REGS] = { 0 };
455 int *status; 462 int *status;
@@ -507,6 +514,19 @@ static irqreturn_t wm831x_irq_thread(int irq, void *data)
507 514
508 if (*status & wm831x_irqs[i].mask) 515 if (*status & wm831x_irqs[i].mask)
509 handle_nested_irq(wm831x->irq_base + i); 516 handle_nested_irq(wm831x->irq_base + i);
517
518 /* Simulate an edge triggered IRQ by polling the input
519 * status. This is sucky but improves interoperability.
520 */
521 if (primary == WM831X_GP_INT &&
522 wm831x->gpio_level[i - WM831X_IRQ_GPIO_1]) {
523 ret = wm831x_reg_read(wm831x, WM831X_GPIO_LEVEL);
524 while (ret & 1 << (i - WM831X_IRQ_GPIO_1)) {
525 handle_nested_irq(wm831x->irq_base + i);
526 ret = wm831x_reg_read(wm831x,
527 WM831X_GPIO_LEVEL);
528 }
529 }
510 } 530 }
511 531
512out: 532out:
@@ -596,8 +616,6 @@ int wm831x_irq_init(struct wm831x *wm831x, int irq)
596 "No interrupt specified - functionality limited\n"); 616 "No interrupt specified - functionality limited\n");
597 } 617 }
598 618
599
600
601 /* Enable top level interrupts, we mask at secondary level */ 619 /* Enable top level interrupts, we mask at secondary level */
602 wm831x_reg_write(wm831x, WM831X_SYSTEM_INTERRUPTS_MASK, 0); 620 wm831x_reg_write(wm831x, WM831X_SYSTEM_INTERRUPTS_MASK, 0);
603 621
diff --git a/drivers/mfd/wm8400-core.c b/drivers/mfd/wm8400-core.c
index e06ba9440cdb..62b4626f4561 100644
--- a/drivers/mfd/wm8400-core.c
+++ b/drivers/mfd/wm8400-core.c
@@ -12,6 +12,7 @@
12 * 12 *
13 */ 13 */
14 14
15#include <linux/module.h>
15#include <linux/bug.h> 16#include <linux/bug.h>
16#include <linux/err.h> 17#include <linux/err.h>
17#include <linux/i2c.h> 18#include <linux/i2c.h>
diff --git a/drivers/mfd/wm8994-core.c b/drivers/mfd/wm8994-core.c
index b03be1d4e0ca..5d6ba132837e 100644
--- a/drivers/mfd/wm8994-core.c
+++ b/drivers/mfd/wm8994-core.c
@@ -217,6 +217,47 @@ static int wm8994_suspend(struct device *dev)
217 return 0; 217 return 0;
218 } 218 }
219 219
220 ret = wm8994_reg_read(wm8994, WM8994_POWER_MANAGEMENT_4);
221 if (ret < 0) {
222 dev_err(dev, "Failed to read power status: %d\n", ret);
223 } else if (ret & (WM8994_AIF2ADCL_ENA | WM8994_AIF2ADCR_ENA |
224 WM8994_AIF1ADC2L_ENA | WM8994_AIF1ADC2R_ENA |
225 WM8994_AIF1ADC1L_ENA | WM8994_AIF1ADC1R_ENA)) {
226 dev_dbg(dev, "CODEC still active, ignoring suspend\n");
227 return 0;
228 }
229
230 ret = wm8994_reg_read(wm8994, WM8994_POWER_MANAGEMENT_5);
231 if (ret < 0) {
232 dev_err(dev, "Failed to read power status: %d\n", ret);
233 } else if (ret & (WM8994_AIF2DACL_ENA | WM8994_AIF2DACR_ENA |
234 WM8994_AIF1DAC2L_ENA | WM8994_AIF1DAC2R_ENA |
235 WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC1R_ENA)) {
236 dev_dbg(dev, "CODEC still active, ignoring suspend\n");
237 return 0;
238 }
239
240 switch (wm8994->type) {
241 case WM8958:
242 ret = wm8994_reg_read(wm8994, WM8958_MIC_DETECT_1);
243 if (ret < 0) {
244 dev_err(dev, "Failed to read power status: %d\n", ret);
245 } else if (ret & WM8958_MICD_ENA) {
246 dev_dbg(dev, "CODEC still active, ignoring suspend\n");
247 return 0;
248 }
249 break;
250 default:
251 break;
252 }
253
254 /* Disable LDO pulldowns while the device is suspended if we
255 * don't know that something will be driving them. */
256 if (!wm8994->ldo_ena_always_driven)
257 wm8994_set_bits(wm8994, WM8994_PULL_CONTROL_2,
258 WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD,
259 WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD);
260
220 /* GPIO configuration state is saved here since we may be configuring 261 /* GPIO configuration state is saved here since we may be configuring
221 * the GPIO alternate functions even if we're not using the gpiolib 262 * the GPIO alternate functions even if we're not using the gpiolib
222 * driver for them. 263 * driver for them.
@@ -286,6 +327,11 @@ static int wm8994_resume(struct device *dev)
286 if (ret < 0) 327 if (ret < 0)
287 dev_err(dev, "Failed to restore GPIO registers: %d\n", ret); 328 dev_err(dev, "Failed to restore GPIO registers: %d\n", ret);
288 329
330 /* Disable LDO pulldowns while the device is active */
331 wm8994_set_bits(wm8994, WM8994_PULL_CONTROL_2,
332 WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD,
333 0);
334
289 wm8994->suspended = false; 335 wm8994->suspended = false;
290 336
291 return 0; 337 return 0;
@@ -467,8 +513,15 @@ static int wm8994_device_init(struct wm8994 *wm8994, int irq)
467 pdata->gpio_defaults[i]); 513 pdata->gpio_defaults[i]);
468 } 514 }
469 } 515 }
516
517 wm8994->ldo_ena_always_driven = pdata->ldo_ena_always_driven;
470 } 518 }
471 519
520 /* Disable LDO pulldowns while the device is active */
521 wm8994_set_bits(wm8994, WM8994_PULL_CONTROL_2,
522 WM8994_LDO1ENA_PD | WM8994_LDO2ENA_PD,
523 0);
524
472 /* In some system designs where the regulators are not in use, 525 /* In some system designs where the regulators are not in use,
473 * we can achieve a small reduction in leakage currents by 526 * we can achieve a small reduction in leakage currents by
474 * floating LDO outputs. This bit makes no difference if the 527 * floating LDO outputs. This bit makes no difference if the
diff --git a/drivers/misc/ab8500-pwm.c b/drivers/misc/ab8500-pwm.c
index 35903154ca2e..2208a9d52622 100644
--- a/drivers/misc/ab8500-pwm.c
+++ b/drivers/misc/ab8500-pwm.c
@@ -10,6 +10,7 @@
10#include <linux/pwm.h> 10#include <linux/pwm.h>
11#include <linux/mfd/ab8500.h> 11#include <linux/mfd/ab8500.h>
12#include <linux/mfd/abx500.h> 12#include <linux/mfd/abx500.h>
13#include <linux/module.h>
13 14
14/* 15/*
15 * PWM Out generators 16 * PWM Out generators
diff --git a/drivers/misc/atmel-ssc.c b/drivers/misc/atmel-ssc.c
index 769a4e8e10dc..5bb187781074 100644
--- a/drivers/misc/atmel-ssc.c
+++ b/drivers/misc/atmel-ssc.c
@@ -16,6 +16,7 @@
16#include <linux/spinlock.h> 16#include <linux/spinlock.h>
17#include <linux/atmel-ssc.h> 17#include <linux/atmel-ssc.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/module.h>
19 20
20/* Serialize access to ssc_list and user count */ 21/* Serialize access to ssc_list and user count */
21static DEFINE_SPINLOCK(user_lock); 22static DEFINE_SPINLOCK(user_lock);
diff --git a/drivers/misc/atmel_tclib.c b/drivers/misc/atmel_tclib.c
index a844810b50f6..4bcfc3759734 100644
--- a/drivers/misc/atmel_tclib.c
+++ b/drivers/misc/atmel_tclib.c
@@ -7,6 +7,7 @@
7#include <linux/kernel.h> 7#include <linux/kernel.h>
8#include <linux/platform_device.h> 8#include <linux/platform_device.h>
9#include <linux/slab.h> 9#include <linux/slab.h>
10#include <linux/export.h>
10 11
11/* Number of bytes to reserve for the iomem resource */ 12/* Number of bytes to reserve for the iomem resource */
12#define ATMEL_TC_IOMEM_SIZE 256 13#define ATMEL_TC_IOMEM_SIZE 256
diff --git a/drivers/misc/bh1780gli.c b/drivers/misc/bh1780gli.c
index 82fe2d067827..bfeea9ba702e 100644
--- a/drivers/misc/bh1780gli.c
+++ b/drivers/misc/bh1780gli.c
@@ -22,6 +22,7 @@
22#include <linux/mutex.h> 22#include <linux/mutex.h>
23#include <linux/platform_device.h> 23#include <linux/platform_device.h>
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <linux/module.h>
25 26
26#define BH1780_REG_CONTROL 0x80 27#define BH1780_REG_CONTROL 0x80
27#define BH1780_REG_PARTID 0x8A 28#define BH1780_REG_PARTID 0x8A
diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
index 8cebec5e85ee..3f7ad83ed740 100644
--- a/drivers/misc/kgdbts.c
+++ b/drivers/misc/kgdbts.c
@@ -102,6 +102,7 @@
102#include <linux/nmi.h> 102#include <linux/nmi.h>
103#include <linux/delay.h> 103#include <linux/delay.h>
104#include <linux/kthread.h> 104#include <linux/kthread.h>
105#include <linux/module.h>
105 106
106#define v1printk(a...) do { \ 107#define v1printk(a...) do { \
107 if (verbose) \ 108 if (verbose) \
diff --git a/drivers/misc/sgi-gru/grukservices.c b/drivers/misc/sgi-gru/grukservices.c
index 9e9bddaa95ae..913de07e577c 100644
--- a/drivers/misc/sgi-gru/grukservices.c
+++ b/drivers/misc/sgi-gru/grukservices.c
@@ -31,6 +31,7 @@
31#include <linux/interrupt.h> 31#include <linux/interrupt.h>
32#include <linux/uaccess.h> 32#include <linux/uaccess.h>
33#include <linux/delay.h> 33#include <linux/delay.h>
34#include <linux/export.h>
34#include <asm/io_apic.h> 35#include <asm/io_apic.h>
35#include "gru.h" 36#include "gru.h"
36#include "grulib.h" 37#include "grulib.h"
diff --git a/drivers/misc/ti-st/st_kim.c b/drivers/misc/ti-st/st_kim.c
index 3a3580566dfc..43ef8d162f2d 100644
--- a/drivers/misc/ti-st/st_kim.c
+++ b/drivers/misc/ti-st/st_kim.c
@@ -35,6 +35,7 @@
35 35
36#include <linux/skbuff.h> 36#include <linux/skbuff.h>
37#include <linux/ti_wilink_st.h> 37#include <linux/ti_wilink_st.h>
38#include <linux/module.h>
38 39
39 40
40#define MAX_ST_DEVICES 3 /* Imagine 1 on each UART for now */ 41#define MAX_ST_DEVICES 3 /* Imagine 1 on each UART for now */
diff --git a/drivers/misc/tifm_7xx1.c b/drivers/misc/tifm_7xx1.c
index a6ef18259da0..ba2479022670 100644
--- a/drivers/misc/tifm_7xx1.c
+++ b/drivers/misc/tifm_7xx1.c
@@ -11,6 +11,7 @@
11 11
12#include <linux/tifm.h> 12#include <linux/tifm.h>
13#include <linux/dma-mapping.h> 13#include <linux/dma-mapping.h>
14#include <linux/module.h>
14 15
15#define DRIVER_NAME "tifm_7xx1" 16#define DRIVER_NAME "tifm_7xx1"
16#define DRIVER_VERSION "0.8" 17#define DRIVER_VERSION "0.8"
diff --git a/drivers/misc/tifm_core.c b/drivers/misc/tifm_core.c
index 44d4475a09dd..0bd5349b0422 100644
--- a/drivers/misc/tifm_core.c
+++ b/drivers/misc/tifm_core.c
@@ -13,6 +13,7 @@
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/idr.h> 15#include <linux/idr.h>
16#include <linux/module.h>
16 17
17#define DRIVER_NAME "tifm_core" 18#define DRIVER_NAME "tifm_core"
18#define DRIVER_VERSION "0.8" 19#define DRIVER_VERSION "0.8"
diff --git a/drivers/misc/vmw_balloon.c b/drivers/misc/vmw_balloon.c
index 053d36caf955..cd41d403c9df 100644
--- a/drivers/misc/vmw_balloon.c
+++ b/drivers/misc/vmw_balloon.c
@@ -151,7 +151,7 @@ MODULE_LICENSE("GPL");
151struct vmballoon_stats { 151struct vmballoon_stats {
152 unsigned int timer; 152 unsigned int timer;
153 153
154 /* allocation statustics */ 154 /* allocation statistics */
155 unsigned int alloc; 155 unsigned int alloc;
156 unsigned int alloc_fail; 156 unsigned int alloc_fail;
157 unsigned int sleep_alloc; 157 unsigned int sleep_alloc;
@@ -412,6 +412,7 @@ static int vmballoon_reserve_page(struct vmballoon *b, bool can_sleep)
412 gfp_t flags; 412 gfp_t flags;
413 unsigned int hv_status; 413 unsigned int hv_status;
414 bool locked = false; 414 bool locked = false;
415 flags = can_sleep ? VMW_PAGE_ALLOC_CANSLEEP : VMW_PAGE_ALLOC_NOSLEEP;
415 416
416 do { 417 do {
417 if (!can_sleep) 418 if (!can_sleep)
@@ -419,7 +420,6 @@ static int vmballoon_reserve_page(struct vmballoon *b, bool can_sleep)
419 else 420 else
420 STATS_INC(b->stats.sleep_alloc); 421 STATS_INC(b->stats.sleep_alloc);
421 422
422 flags = can_sleep ? VMW_PAGE_ALLOC_CANSLEEP : VMW_PAGE_ALLOC_NOSLEEP;
423 page = alloc_page(flags); 423 page = alloc_page(flags);
424 if (!page) { 424 if (!page) {
425 if (!can_sleep) 425 if (!can_sleep)
diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c
index 46b6e84d953e..6be49249895a 100644
--- a/drivers/mmc/core/bus.c
+++ b/drivers/mmc/core/bus.c
@@ -11,9 +11,11 @@
11 * MMC card bus driver model 11 * MMC card bus driver model
12 */ 12 */
13 13
14#include <linux/export.h>
14#include <linux/device.h> 15#include <linux/device.h>
15#include <linux/err.h> 16#include <linux/err.h>
16#include <linux/slab.h> 17#include <linux/slab.h>
18#include <linux/stat.h>
17#include <linux/pm_runtime.h> 19#include <linux/pm_runtime.h>
18 20
19#include <linux/mmc/card.h> 21#include <linux/mmc/card.h>
diff --git a/drivers/mmc/core/debugfs.c b/drivers/mmc/core/debugfs.c
index 6045ea469362..3923880118b6 100644
--- a/drivers/mmc/core/debugfs.c
+++ b/drivers/mmc/core/debugfs.c
@@ -8,6 +8,7 @@
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 */ 9 */
10#include <linux/moduleparam.h> 10#include <linux/moduleparam.h>
11#include <linux/export.h>
11#include <linux/debugfs.h> 12#include <linux/debugfs.h>
12#include <linux/fs.h> 13#include <linux/fs.h>
13#include <linux/seq_file.h> 14#include <linux/seq_file.h>
diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
index ca2e4f50f615..e8a5eb38748b 100644
--- a/drivers/mmc/core/host.c
+++ b/drivers/mmc/core/host.c
@@ -16,6 +16,7 @@
16#include <linux/err.h> 16#include <linux/err.h>
17#include <linux/idr.h> 17#include <linux/idr.h>
18#include <linux/pagemap.h> 18#include <linux/pagemap.h>
19#include <linux/export.h>
19#include <linux/leds.h> 20#include <linux/leds.h>
20#include <linux/slab.h> 21#include <linux/slab.h>
21#include <linux/suspend.h> 22#include <linux/suspend.h>
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 36270449dd9d..dbf421a6279c 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -12,6 +12,7 @@
12 12
13#include <linux/err.h> 13#include <linux/err.h>
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/stat.h>
15 16
16#include <linux/mmc/host.h> 17#include <linux/mmc/host.h>
17#include <linux/mmc/card.h> 18#include <linux/mmc/card.h>
diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
index 007863eea4fb..4d41fa984c93 100644
--- a/drivers/mmc/core/mmc_ops.c
+++ b/drivers/mmc/core/mmc_ops.c
@@ -10,6 +10,7 @@
10 */ 10 */
11 11
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/export.h>
13#include <linux/types.h> 14#include <linux/types.h>
14#include <linux/scatterlist.h> 15#include <linux/scatterlist.h>
15 16
diff --git a/drivers/mmc/core/quirks.c b/drivers/mmc/core/quirks.c
index 6c3cf98a62eb..06ee1aeaacec 100644
--- a/drivers/mmc/core/quirks.c
+++ b/drivers/mmc/core/quirks.c
@@ -11,6 +11,7 @@
11 11
12#include <linux/types.h> 12#include <linux/types.h>
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/export.h>
14#include <linux/mmc/card.h> 15#include <linux/mmc/card.h>
15 16
16#ifndef SDIO_VENDOR_ID_TI 17#ifndef SDIO_VENDOR_ID_TI
diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
index a230e7f9d77a..f2a05ea40f2a 100644
--- a/drivers/mmc/core/sd.c
+++ b/drivers/mmc/core/sd.c
@@ -12,6 +12,7 @@
12 12
13#include <linux/err.h> 13#include <linux/err.h>
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/stat.h>
15 16
16#include <linux/mmc/host.h> 17#include <linux/mmc/host.h>
17#include <linux/mmc/card.h> 18#include <linux/mmc/card.h>
diff --git a/drivers/mmc/core/sd_ops.c b/drivers/mmc/core/sd_ops.c
index 46a785419fab..274ef00b4463 100644
--- a/drivers/mmc/core/sd_ops.c
+++ b/drivers/mmc/core/sd_ops.c
@@ -11,6 +11,7 @@
11 11
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/types.h> 13#include <linux/types.h>
14#include <linux/export.h>
14#include <linux/scatterlist.h> 15#include <linux/scatterlist.h>
15 16
16#include <linux/mmc/host.h> 17#include <linux/mmc/host.h>
diff --git a/drivers/mmc/core/sdio_bus.c b/drivers/mmc/core/sdio_bus.c
index c643b2f78bf1..40989e6bb53a 100644
--- a/drivers/mmc/core/sdio_bus.c
+++ b/drivers/mmc/core/sdio_bus.c
@@ -13,6 +13,7 @@
13 13
14#include <linux/device.h> 14#include <linux/device.h>
15#include <linux/err.h> 15#include <linux/err.h>
16#include <linux/export.h>
16#include <linux/slab.h> 17#include <linux/slab.h>
17#include <linux/pm_runtime.h> 18#include <linux/pm_runtime.h>
18 19
diff --git a/drivers/mmc/core/sdio_io.c b/drivers/mmc/core/sdio_io.c
index 0f687cdeb064..b1f3168f791b 100644
--- a/drivers/mmc/core/sdio_io.c
+++ b/drivers/mmc/core/sdio_io.c
@@ -9,6 +9,7 @@
9 * your option) any later version. 9 * your option) any later version.
10 */ 10 */
11 11
12#include <linux/export.h>
12#include <linux/mmc/host.h> 13#include <linux/mmc/host.h>
13#include <linux/mmc/card.h> 14#include <linux/mmc/card.h>
14#include <linux/mmc/sdio.h> 15#include <linux/mmc/sdio.h>
diff --git a/drivers/mmc/core/sdio_irq.c b/drivers/mmc/core/sdio_irq.c
index b644dd59c16e..68f81b9ee0fb 100644
--- a/drivers/mmc/core/sdio_irq.c
+++ b/drivers/mmc/core/sdio_irq.c
@@ -16,6 +16,7 @@
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/sched.h> 17#include <linux/sched.h>
18#include <linux/kthread.h> 18#include <linux/kthread.h>
19#include <linux/export.h>
19#include <linux/wait.h> 20#include <linux/wait.h>
20#include <linux/delay.h> 21#include <linux/delay.h>
21 22
diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index 87d5067ba629..cf444b0ca2cc 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -263,7 +263,7 @@ config MMC_WBSD
263 263
264config MMC_AU1X 264config MMC_AU1X
265 tristate "Alchemy AU1XX0 MMC Card Interface support" 265 tristate "Alchemy AU1XX0 MMC Card Interface support"
266 depends on SOC_AU1200 266 depends on MIPS_ALCHEMY
267 help 267 help
268 This selects the AMD Alchemy(R) Multimedia card interface. 268 This selects the AMD Alchemy(R) Multimedia card interface.
269 If you have a Alchemy platform with a MMC slot, say Y or M here. 269 If you have a Alchemy platform with a MMC slot, say Y or M here.
diff --git a/drivers/mmc/host/au1xmmc.c b/drivers/mmc/host/au1xmmc.c
index 707bc7dddd22..5d3b9ae64523 100644
--- a/drivers/mmc/host/au1xmmc.c
+++ b/drivers/mmc/host/au1xmmc.c
@@ -64,11 +64,8 @@
64#define AU1XMMC_DESCRIPTOR_COUNT 1 64#define AU1XMMC_DESCRIPTOR_COUNT 1
65 65
66/* max DMA seg size: 64KB on Au1100, 4MB on Au1200 */ 66/* max DMA seg size: 64KB on Au1100, 4MB on Au1200 */
67#ifdef CONFIG_SOC_AU1100 67#define AU1100_MMC_DESCRIPTOR_SIZE 0x0000ffff
68#define AU1XMMC_DESCRIPTOR_SIZE 0x0000ffff 68#define AU1200_MMC_DESCRIPTOR_SIZE 0x003fffff
69#else /* Au1200 */
70#define AU1XMMC_DESCRIPTOR_SIZE 0x003fffff
71#endif
72 69
73#define AU1XMMC_OCR (MMC_VDD_27_28 | MMC_VDD_28_29 | MMC_VDD_29_30 | \ 70#define AU1XMMC_OCR (MMC_VDD_27_28 | MMC_VDD_28_29 | MMC_VDD_29_30 | \
74 MMC_VDD_30_31 | MMC_VDD_31_32 | MMC_VDD_32_33 | \ 71 MMC_VDD_30_31 | MMC_VDD_31_32 | MMC_VDD_32_33 | \
@@ -127,6 +124,7 @@ struct au1xmmc_host {
127#define HOST_F_XMIT 0x0001 124#define HOST_F_XMIT 0x0001
128#define HOST_F_RECV 0x0002 125#define HOST_F_RECV 0x0002
129#define HOST_F_DMA 0x0010 126#define HOST_F_DMA 0x0010
127#define HOST_F_DBDMA 0x0020
130#define HOST_F_ACTIVE 0x0100 128#define HOST_F_ACTIVE 0x0100
131#define HOST_F_STOP 0x1000 129#define HOST_F_STOP 0x1000
132 130
@@ -151,6 +149,16 @@ struct au1xmmc_host {
151#define DMA_CHANNEL(h) \ 149#define DMA_CHANNEL(h) \
152 (((h)->flags & HOST_F_XMIT) ? (h)->tx_chan : (h)->rx_chan) 150 (((h)->flags & HOST_F_XMIT) ? (h)->tx_chan : (h)->rx_chan)
153 151
152static inline int has_dbdma(void)
153{
154 switch (alchemy_get_cputype()) {
155 case ALCHEMY_CPU_AU1200:
156 return 1;
157 default:
158 return 0;
159 }
160}
161
154static inline void IRQ_ON(struct au1xmmc_host *host, u32 mask) 162static inline void IRQ_ON(struct au1xmmc_host *host, u32 mask)
155{ 163{
156 u32 val = au_readl(HOST_CONFIG(host)); 164 u32 val = au_readl(HOST_CONFIG(host));
@@ -353,14 +361,12 @@ static void au1xmmc_data_complete(struct au1xmmc_host *host, u32 status)
353 data->bytes_xfered = 0; 361 data->bytes_xfered = 0;
354 362
355 if (!data->error) { 363 if (!data->error) {
356 if (host->flags & HOST_F_DMA) { 364 if (host->flags & (HOST_F_DMA | HOST_F_DBDMA)) {
357#ifdef CONFIG_SOC_AU1200 /* DBDMA */
358 u32 chan = DMA_CHANNEL(host); 365 u32 chan = DMA_CHANNEL(host);
359 366
360 chan_tab_t *c = *((chan_tab_t **)chan); 367 chan_tab_t *c = *((chan_tab_t **)chan);
361 au1x_dma_chan_t *cp = c->chan_ptr; 368 au1x_dma_chan_t *cp = c->chan_ptr;
362 data->bytes_xfered = cp->ddma_bytecnt; 369 data->bytes_xfered = cp->ddma_bytecnt;
363#endif
364 } else 370 } else
365 data->bytes_xfered = 371 data->bytes_xfered =
366 (data->blocks * data->blksz) - host->pio.len; 372 (data->blocks * data->blksz) - host->pio.len;
@@ -570,11 +576,10 @@ static void au1xmmc_cmd_complete(struct au1xmmc_host *host, u32 status)
570 576
571 host->status = HOST_S_DATA; 577 host->status = HOST_S_DATA;
572 578
573 if (host->flags & HOST_F_DMA) { 579 if ((host->flags & (HOST_F_DMA | HOST_F_DBDMA))) {
574#ifdef CONFIG_SOC_AU1200 /* DBDMA */
575 u32 channel = DMA_CHANNEL(host); 580 u32 channel = DMA_CHANNEL(host);
576 581
577 /* Start the DMA as soon as the buffer gets something in it */ 582 /* Start the DBDMA as soon as the buffer gets something in it */
578 583
579 if (host->flags & HOST_F_RECV) { 584 if (host->flags & HOST_F_RECV) {
580 u32 mask = SD_STATUS_DB | SD_STATUS_NE; 585 u32 mask = SD_STATUS_DB | SD_STATUS_NE;
@@ -584,7 +589,6 @@ static void au1xmmc_cmd_complete(struct au1xmmc_host *host, u32 status)
584 } 589 }
585 590
586 au1xxx_dbdma_start(channel); 591 au1xxx_dbdma_start(channel);
587#endif
588 } 592 }
589} 593}
590 594
@@ -633,8 +637,7 @@ static int au1xmmc_prepare_data(struct au1xmmc_host *host,
633 637
634 au_writel(data->blksz - 1, HOST_BLKSIZE(host)); 638 au_writel(data->blksz - 1, HOST_BLKSIZE(host));
635 639
636 if (host->flags & HOST_F_DMA) { 640 if (host->flags & (HOST_F_DMA | HOST_F_DBDMA)) {
637#ifdef CONFIG_SOC_AU1200 /* DBDMA */
638 int i; 641 int i;
639 u32 channel = DMA_CHANNEL(host); 642 u32 channel = DMA_CHANNEL(host);
640 643
@@ -663,7 +666,6 @@ static int au1xmmc_prepare_data(struct au1xmmc_host *host,
663 666
664 datalen -= len; 667 datalen -= len;
665 } 668 }
666#endif
667 } else { 669 } else {
668 host->pio.index = 0; 670 host->pio.index = 0;
669 host->pio.offset = 0; 671 host->pio.offset = 0;
@@ -838,7 +840,6 @@ static irqreturn_t au1xmmc_irq(int irq, void *dev_id)
838 return IRQ_HANDLED; 840 return IRQ_HANDLED;
839} 841}
840 842
841#ifdef CONFIG_SOC_AU1200
842/* 8bit memory DMA device */ 843/* 8bit memory DMA device */
843static dbdev_tab_t au1xmmc_mem_dbdev = { 844static dbdev_tab_t au1xmmc_mem_dbdev = {
844 .dev_id = DSCR_CMD0_ALWAYS, 845 .dev_id = DSCR_CMD0_ALWAYS,
@@ -905,7 +906,7 @@ static int au1xmmc_dbdma_init(struct au1xmmc_host *host)
905 au1xxx_dbdma_ring_alloc(host->rx_chan, AU1XMMC_DESCRIPTOR_COUNT); 906 au1xxx_dbdma_ring_alloc(host->rx_chan, AU1XMMC_DESCRIPTOR_COUNT);
906 907
907 /* DBDMA is good to go */ 908 /* DBDMA is good to go */
908 host->flags |= HOST_F_DMA; 909 host->flags |= HOST_F_DMA | HOST_F_DBDMA;
909 910
910 return 0; 911 return 0;
911} 912}
@@ -918,7 +919,6 @@ static void au1xmmc_dbdma_shutdown(struct au1xmmc_host *host)
918 au1xxx_dbdma_chan_free(host->rx_chan); 919 au1xxx_dbdma_chan_free(host->rx_chan);
919 } 920 }
920} 921}
921#endif
922 922
923static void au1xmmc_enable_sdio_irq(struct mmc_host *mmc, int en) 923static void au1xmmc_enable_sdio_irq(struct mmc_host *mmc, int en)
924{ 924{
@@ -997,8 +997,16 @@ static int __devinit au1xmmc_probe(struct platform_device *pdev)
997 mmc->f_min = 450000; 997 mmc->f_min = 450000;
998 mmc->f_max = 24000000; 998 mmc->f_max = 24000000;
999 999
1000 mmc->max_seg_size = AU1XMMC_DESCRIPTOR_SIZE; 1000 switch (alchemy_get_cputype()) {
1001 mmc->max_segs = AU1XMMC_DESCRIPTOR_COUNT; 1001 case ALCHEMY_CPU_AU1100:
1002 mmc->max_seg_size = AU1100_MMC_DESCRIPTOR_SIZE;
1003 mmc->max_segs = AU1XMMC_DESCRIPTOR_COUNT;
1004 break;
1005 case ALCHEMY_CPU_AU1200:
1006 mmc->max_seg_size = AU1200_MMC_DESCRIPTOR_SIZE;
1007 mmc->max_segs = AU1XMMC_DESCRIPTOR_COUNT;
1008 break;
1009 }
1002 1010
1003 mmc->max_blk_size = 2048; 1011 mmc->max_blk_size = 2048;
1004 mmc->max_blk_count = 512; 1012 mmc->max_blk_count = 512;
@@ -1028,11 +1036,11 @@ static int __devinit au1xmmc_probe(struct platform_device *pdev)
1028 tasklet_init(&host->finish_task, au1xmmc_tasklet_finish, 1036 tasklet_init(&host->finish_task, au1xmmc_tasklet_finish,
1029 (unsigned long)host); 1037 (unsigned long)host);
1030 1038
1031#ifdef CONFIG_SOC_AU1200 1039 if (has_dbdma()) {
1032 ret = au1xmmc_dbdma_init(host); 1040 ret = au1xmmc_dbdma_init(host);
1033 if (ret) 1041 if (ret)
1034 pr_info(DRIVER_NAME ": DBDMA init failed; using PIO\n"); 1042 pr_info(DRIVER_NAME ": DBDMA init failed; using PIO\n");
1035#endif 1043 }
1036 1044
1037#ifdef CONFIG_LEDS_CLASS 1045#ifdef CONFIG_LEDS_CLASS
1038 if (host->platdata && host->platdata->led) { 1046 if (host->platdata && host->platdata->led) {
@@ -1073,9 +1081,8 @@ out5:
1073 au_writel(0, HOST_CONFIG2(host)); 1081 au_writel(0, HOST_CONFIG2(host));
1074 au_sync(); 1082 au_sync();
1075 1083
1076#ifdef CONFIG_SOC_AU1200 1084 if (host->flags & HOST_F_DBDMA)
1077 au1xmmc_dbdma_shutdown(host); 1085 au1xmmc_dbdma_shutdown(host);
1078#endif
1079 1086
1080 tasklet_kill(&host->data_task); 1087 tasklet_kill(&host->data_task);
1081 tasklet_kill(&host->finish_task); 1088 tasklet_kill(&host->finish_task);
@@ -1120,9 +1127,9 @@ static int __devexit au1xmmc_remove(struct platform_device *pdev)
1120 tasklet_kill(&host->data_task); 1127 tasklet_kill(&host->data_task);
1121 tasklet_kill(&host->finish_task); 1128 tasklet_kill(&host->finish_task);
1122 1129
1123#ifdef CONFIG_SOC_AU1200 1130 if (host->flags & HOST_F_DBDMA)
1124 au1xmmc_dbdma_shutdown(host); 1131 au1xmmc_dbdma_shutdown(host);
1125#endif 1132
1126 au1xmmc_set_power(host, 0); 1133 au1xmmc_set_power(host, 0);
1127 1134
1128 free_irq(host->irq, host); 1135 free_irq(host->irq, host);
@@ -1181,24 +1188,23 @@ static struct platform_driver au1xmmc_driver = {
1181 1188
1182static int __init au1xmmc_init(void) 1189static int __init au1xmmc_init(void)
1183{ 1190{
1184#ifdef CONFIG_SOC_AU1200 1191 if (has_dbdma()) {
1185 /* DSCR_CMD0_ALWAYS has a stride of 32 bits, we need a stride 1192 /* DSCR_CMD0_ALWAYS has a stride of 32 bits, we need a stride
1186 * of 8 bits. And since devices are shared, we need to create 1193 * of 8 bits. And since devices are shared, we need to create
1187 * our own to avoid freaking out other devices. 1194 * our own to avoid freaking out other devices.
1188 */ 1195 */
1189 memid = au1xxx_ddma_add_device(&au1xmmc_mem_dbdev); 1196 memid = au1xxx_ddma_add_device(&au1xmmc_mem_dbdev);
1190 if (!memid) 1197 if (!memid)
1191 pr_err("au1xmmc: cannot add memory dbdma dev\n"); 1198 pr_err("au1xmmc: cannot add memory dbdma\n");
1192#endif 1199 }
1193 return platform_driver_register(&au1xmmc_driver); 1200 return platform_driver_register(&au1xmmc_driver);
1194} 1201}
1195 1202
1196static void __exit au1xmmc_exit(void) 1203static void __exit au1xmmc_exit(void)
1197{ 1204{
1198#ifdef CONFIG_SOC_AU1200 1205 if (has_dbdma() && memid)
1199 if (memid)
1200 au1xxx_ddma_del_device(memid); 1206 au1xxx_ddma_del_device(memid);
1201#endif 1207
1202 platform_driver_unregister(&au1xmmc_driver); 1208 platform_driver_unregister(&au1xmmc_driver);
1203} 1209}
1204 1210
diff --git a/drivers/mmc/host/omap_hsmmc.c b/drivers/mmc/host/omap_hsmmc.c
index e8ff12396680..101cd31c8220 100644
--- a/drivers/mmc/host/omap_hsmmc.c
+++ b/drivers/mmc/host/omap_hsmmc.c
@@ -1270,7 +1270,7 @@ static void omap_hsmmc_protect_card(struct omap_hsmmc_host *host)
1270 } 1270 }
1271 } else { 1271 } else {
1272 if (!host->protect_card) { 1272 if (!host->protect_card) {
1273 pr_info"%s: cover is open, " 1273 pr_info("%s: cover is open, "
1274 "card is now inaccessible\n", 1274 "card is now inaccessible\n",
1275 mmc_hostname(host->mmc)); 1275 mmc_hostname(host->mmc));
1276 host->protect_card = 1; 1276 host->protect_card = 1;
diff --git a/drivers/mmc/host/s3cmci.c b/drivers/mmc/host/s3cmci.c
index d2856b6b2a62..720f99334a7f 100644
--- a/drivers/mmc/host/s3cmci.c
+++ b/drivers/mmc/host/s3cmci.c
@@ -913,9 +913,9 @@ request_done:
913} 913}
914 914
915static void s3cmci_dma_setup(struct s3cmci_host *host, 915static void s3cmci_dma_setup(struct s3cmci_host *host,
916 enum s3c2410_dmasrc source) 916 enum dma_data_direction source)
917{ 917{
918 static enum s3c2410_dmasrc last_source = -1; 918 static enum dma_data_direction last_source = -1;
919 static int setup_ok; 919 static int setup_ok;
920 920
921 if (last_source == source) 921 if (last_source == source)
@@ -1087,7 +1087,7 @@ static int s3cmci_prepare_dma(struct s3cmci_host *host, struct mmc_data *data)
1087 1087
1088 BUG_ON((data->flags & BOTH_DIR) == BOTH_DIR); 1088 BUG_ON((data->flags & BOTH_DIR) == BOTH_DIR);
1089 1089
1090 s3cmci_dma_setup(host, rw ? S3C2410_DMASRC_MEM : S3C2410_DMASRC_HW); 1090 s3cmci_dma_setup(host, rw ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
1091 s3c2410_dma_ctrl(host->dma, S3C2410_DMAOP_FLUSH); 1091 s3c2410_dma_ctrl(host->dma, S3C2410_DMAOP_FLUSH);
1092 1092
1093 dma_len = dma_map_sg(mmc_dev(host->mmc), data->sg, data->sg_len, 1093 dma_len = dma_map_sg(mmc_dev(host->mmc), data->sg, data->sg_len,
diff --git a/drivers/mmc/host/sdhci-tegra.c b/drivers/mmc/host/sdhci-tegra.c
index 067a4cded9cf..89699e861fc1 100644
--- a/drivers/mmc/host/sdhci-tegra.c
+++ b/drivers/mmc/host/sdhci-tegra.c
@@ -13,6 +13,7 @@
13 */ 13 */
14 14
15#include <linux/err.h> 15#include <linux/err.h>
16#include <linux/module.h>
16#include <linux/init.h> 17#include <linux/init.h>
17#include <linux/platform_device.h> 18#include <linux/platform_device.h>
18#include <linux/clk.h> 19#include <linux/clk.h>
diff --git a/drivers/mtd/ar7part.c b/drivers/mtd/ar7part.c
index 6697a1ec72d0..95949b97de6a 100644
--- a/drivers/mtd/ar7part.c
+++ b/drivers/mtd/ar7part.c
@@ -27,6 +27,7 @@
27#include <linux/mtd/partitions.h> 27#include <linux/mtd/partitions.h>
28#include <linux/bootmem.h> 28#include <linux/bootmem.h>
29#include <linux/magic.h> 29#include <linux/magic.h>
30#include <linux/module.h>
30 31
31#define AR7_PARTS 4 32#define AR7_PARTS 4
32#define ROOT_OFFSET 0xe0000 33#define ROOT_OFFSET 0xe0000
diff --git a/drivers/mtd/cmdlinepart.c b/drivers/mtd/cmdlinepart.c
index e790f38893b0..8cf667da2408 100644
--- a/drivers/mtd/cmdlinepart.c
+++ b/drivers/mtd/cmdlinepart.c
@@ -43,6 +43,7 @@
43#include <linux/mtd/mtd.h> 43#include <linux/mtd/mtd.h>
44#include <linux/mtd/partitions.h> 44#include <linux/mtd/partitions.h>
45#include <linux/bootmem.h> 45#include <linux/bootmem.h>
46#include <linux/module.h>
46 47
47/* error message prefix */ 48/* error message prefix */
48#define ERRP "mtd: " 49#define ERRP "mtd: "
diff --git a/drivers/mtd/lpddr/lpddr_cmds.c b/drivers/mtd/lpddr/lpddr_cmds.c
index 65655dd59e1f..1dca31d9a8b3 100644
--- a/drivers/mtd/lpddr/lpddr_cmds.c
+++ b/drivers/mtd/lpddr/lpddr_cmds.c
@@ -27,6 +27,7 @@
27#include <linux/mtd/pfow.h> 27#include <linux/mtd/pfow.h>
28#include <linux/mtd/qinfo.h> 28#include <linux/mtd/qinfo.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/module.h>
30 31
31static int lpddr_read(struct mtd_info *mtd, loff_t adr, size_t len, 32static int lpddr_read(struct mtd_info *mtd, loff_t adr, size_t len,
32 size_t *retlen, u_char *buf); 33 size_t *retlen, u_char *buf);
diff --git a/drivers/mtd/maps/lantiq-flash.c b/drivers/mtd/maps/lantiq-flash.c
index a90cabd7b84d..7e508969239e 100644
--- a/drivers/mtd/maps/lantiq-flash.c
+++ b/drivers/mtd/maps/lantiq-flash.c
@@ -182,7 +182,7 @@ ltq_mtd_probe(struct platform_device *pdev)
182 parts = ltq_mtd_data->parts; 182 parts = ltq_mtd_data->parts;
183 } 183 }
184 184
185 err = add_mtd_partitions(ltq_mtd->mtd, parts, nr_parts); 185 err = mtd_device_register(ltq_mtd->mtd, parts, nr_parts);
186 if (err) { 186 if (err) {
187 dev_err(&pdev->dev, "failed to add partitions\n"); 187 dev_err(&pdev->dev, "failed to add partitions\n");
188 goto err_destroy; 188 goto err_destroy;
@@ -208,7 +208,7 @@ ltq_mtd_remove(struct platform_device *pdev)
208 208
209 if (ltq_mtd) { 209 if (ltq_mtd) {
210 if (ltq_mtd->mtd) { 210 if (ltq_mtd->mtd) {
211 del_mtd_partitions(ltq_mtd->mtd); 211 mtd_device_unregister(ltq_mtd->mtd);
212 map_destroy(ltq_mtd->mtd); 212 map_destroy(ltq_mtd->mtd);
213 } 213 }
214 if (ltq_mtd->map->virt) 214 if (ltq_mtd->map->virt)
diff --git a/drivers/mtd/mtdblock_ro.c b/drivers/mtd/mtdblock_ro.c
index 795a8c0a05b8..0470a6e86309 100644
--- a/drivers/mtd/mtdblock_ro.c
+++ b/drivers/mtd/mtdblock_ro.c
@@ -23,6 +23,7 @@
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/mtd/mtd.h> 24#include <linux/mtd/mtd.h>
25#include <linux/mtd/blktrans.h> 25#include <linux/mtd/blktrans.h>
26#include <linux/module.h>
26 27
27static int mtdblock_readsect(struct mtd_blktrans_dev *dev, 28static int mtdblock_readsect(struct mtd_blktrans_dev *dev,
28 unsigned long block, char *buf) 29 unsigned long block, char *buf)
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index f1af2228a1b1..61086ea3cc6b 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -1144,7 +1144,7 @@ static void mtdchar_notify_remove(struct mtd_info *mtd)
1144 1144
1145 if (mtd_ino) { 1145 if (mtd_ino) {
1146 /* Destroy the inode if it exists */ 1146 /* Destroy the inode if it exists */
1147 mtd_ino->i_nlink = 0; 1147 clear_nlink(mtd_ino);
1148 iput(mtd_ino); 1148 iput(mtd_ino);
1149 } 1149 }
1150} 1150}
diff --git a/drivers/mtd/mtdsuper.c b/drivers/mtd/mtdsuper.c
index 16b02a1fc100..89f8e66448ab 100644
--- a/drivers/mtd/mtdsuper.c
+++ b/drivers/mtd/mtdsuper.c
@@ -14,6 +14,7 @@
14 14
15#include <linux/mtd/super.h> 15#include <linux/mtd/super.h>
16#include <linux/namei.h> 16#include <linux/namei.h>
17#include <linux/export.h>
17#include <linux/ctype.h> 18#include <linux/ctype.h>
18#include <linux/slab.h> 19#include <linux/slab.h>
19 20
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index 4c3425235adc..dbfa0f7fb464 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -138,7 +138,7 @@ config MTD_NAND_RICOH
138 138
139config MTD_NAND_AU1550 139config MTD_NAND_AU1550
140 tristate "Au1550/1200 NAND support" 140 tristate "Au1550/1200 NAND support"
141 depends on SOC_AU1200 || SOC_AU1550 141 depends on MIPS_ALCHEMY
142 help 142 help
143 This enables the driver for the NAND flash controller on the 143 This enables the driver for the NAND flash controller on the
144 AMD/Alchemy 1550 SOC. 144 AMD/Alchemy 1550 SOC.
diff --git a/drivers/mtd/nand/au1550nd.c b/drivers/mtd/nand/au1550nd.c
index e7767eef4505..fa5736b9286c 100644
--- a/drivers/mtd/nand/au1550nd.c
+++ b/drivers/mtd/nand/au1550nd.c
@@ -19,7 +19,11 @@
19#include <linux/mtd/partitions.h> 19#include <linux/mtd/partitions.h>
20#include <asm/io.h> 20#include <asm/io.h>
21 21
22#include <asm/mach-au1x00/au1xxx.h> 22#ifdef CONFIG_MIPS_PB1550
23#include <asm/mach-pb1x00/pb1550.h>
24#elif defined(CONFIG_MIPS_DB1550)
25#include <asm/mach-db1x00/db1x00.h>
26#endif
23#include <asm/mach-db1x00/bcsr.h> 27#include <asm/mach-db1x00/bcsr.h>
24 28
25/* 29/*
diff --git a/drivers/mtd/nand/cafe_nand.c b/drivers/mtd/nand/cafe_nand.c
index 87ebb4e5b0c3..7c8df837d3b8 100644
--- a/drivers/mtd/nand/cafe_nand.c
+++ b/drivers/mtd/nand/cafe_nand.c
@@ -21,6 +21,7 @@
21#include <linux/interrupt.h> 21#include <linux/interrupt.h>
22#include <linux/dma-mapping.h> 22#include <linux/dma-mapping.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/module.h>
24#include <asm/io.h> 25#include <asm/io.h>
25 26
26#define CAFE_NAND_CTRL1 0x00 27#define CAFE_NAND_CTRL1 0x00
diff --git a/drivers/mtd/nand/cmx270_nand.c b/drivers/mtd/nand/cmx270_nand.c
index 6fc043a30d1e..be33b0f4634d 100644
--- a/drivers/mtd/nand/cmx270_nand.c
+++ b/drivers/mtd/nand/cmx270_nand.c
@@ -22,6 +22,7 @@
22#include <linux/mtd/partitions.h> 22#include <linux/mtd/partitions.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/gpio.h> 24#include <linux/gpio.h>
25#include <linux/module.h>
25 26
26#include <asm/io.h> 27#include <asm/io.h>
27#include <asm/irq.h> 28#include <asm/irq.h>
diff --git a/drivers/mtd/nand/diskonchip.c b/drivers/mtd/nand/diskonchip.c
index 7837728d02ff..e1b84cb90f0d 100644
--- a/drivers/mtd/nand/diskonchip.c
+++ b/drivers/mtd/nand/diskonchip.c
@@ -31,6 +31,7 @@
31#include <linux/mtd/doc2000.h> 31#include <linux/mtd/doc2000.h>
32#include <linux/mtd/partitions.h> 32#include <linux/mtd/partitions.h>
33#include <linux/mtd/inftl.h> 33#include <linux/mtd/inftl.h>
34#include <linux/module.h>
34 35
35/* Where to look for the devices? */ 36/* Where to look for the devices? */
36#ifndef CONFIG_MTD_NAND_DISKONCHIP_PROBE_ADDRESS 37#ifndef CONFIG_MTD_NAND_DISKONCHIP_PROBE_ADDRESS
diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c
index ccbeaa1e4a8e..4165857752ca 100644
--- a/drivers/mtd/nand/nand_bbt.c
+++ b/drivers/mtd/nand/nand_bbt.c
@@ -67,6 +67,7 @@
67#include <linux/bitops.h> 67#include <linux/bitops.h>
68#include <linux/delay.h> 68#include <linux/delay.h>
69#include <linux/vmalloc.h> 69#include <linux/vmalloc.h>
70#include <linux/export.h>
70 71
71static int check_pattern_no_oob(uint8_t *buf, struct nand_bbt_descr *td) 72static int check_pattern_no_oob(uint8_t *buf, struct nand_bbt_descr *td)
72{ 73{
diff --git a/drivers/mtd/nand/omap2.c b/drivers/mtd/nand/omap2.c
index 0db2c0e7656a..ec22a5aab038 100644
--- a/drivers/mtd/nand/omap2.c
+++ b/drivers/mtd/nand/omap2.c
@@ -11,6 +11,7 @@
11#include <linux/platform_device.h> 11#include <linux/platform_device.h>
12#include <linux/dma-mapping.h> 12#include <linux/dma-mapping.h>
13#include <linux/delay.h> 13#include <linux/delay.h>
14#include <linux/module.h>
14#include <linux/interrupt.h> 15#include <linux/interrupt.h>
15#include <linux/jiffies.h> 16#include <linux/jiffies.h>
16#include <linux/sched.h> 17#include <linux/sched.h>
diff --git a/drivers/mtd/nand/sm_common.c b/drivers/mtd/nand/sm_common.c
index b6332e83b289..43469715b3fa 100644
--- a/drivers/mtd/nand/sm_common.c
+++ b/drivers/mtd/nand/sm_common.c
@@ -8,6 +8,7 @@
8 */ 8 */
9#include <linux/kernel.h> 9#include <linux/kernel.h>
10#include <linux/mtd/nand.h> 10#include <linux/mtd/nand.h>
11#include <linux/module.h>
11#include "sm_common.h" 12#include "sm_common.h"
12 13
13static struct nand_ecclayout nand_oob_sm = { 14static struct nand_ecclayout nand_oob_sm = {
diff --git a/drivers/mtd/onenand/onenand_bbt.c b/drivers/mtd/onenand/onenand_bbt.c
index fc2c16a0fd1c..b2d7fc5ea25d 100644
--- a/drivers/mtd/onenand/onenand_bbt.c
+++ b/drivers/mtd/onenand/onenand_bbt.c
@@ -15,6 +15,7 @@
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/export.h>
18 19
19/** 20/**
20 * check_short_pattern - [GENERIC] check if a pattern is in the buffer 21 * check_short_pattern - [GENERIC] check if a pattern is in the buffer
diff --git a/drivers/mtd/redboot.c b/drivers/mtd/redboot.c
index 7a87d07cd79f..84b4dda023f4 100644
--- a/drivers/mtd/redboot.c
+++ b/drivers/mtd/redboot.c
@@ -28,6 +28,7 @@
28 28
29#include <linux/mtd/mtd.h> 29#include <linux/mtd/mtd.h>
30#include <linux/mtd/partitions.h> 30#include <linux/mtd/partitions.h>
31#include <linux/module.h>
31 32
32struct fis_image_desc { 33struct fis_image_desc {
33 unsigned char name[16]; // Null terminated name 34 unsigned char name[16]; // Null terminated name
diff --git a/drivers/mtd/rfd_ftl.c b/drivers/mtd/rfd_ftl.c
index cc4d1805b864..73ae217a4252 100644
--- a/drivers/mtd/rfd_ftl.c
+++ b/drivers/mtd/rfd_ftl.c
@@ -18,6 +18,7 @@
18#include <linux/vmalloc.h> 18#include <linux/vmalloc.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/jiffies.h> 20#include <linux/jiffies.h>
21#include <linux/module.h>
21 22
22#include <asm/types.h> 23#include <asm/types.h>
23 24
diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c
index 97e093d19672..863835f4aefe 100644
--- a/drivers/mtd/ubi/vmt.c
+++ b/drivers/mtd/ubi/vmt.c
@@ -26,6 +26,7 @@
26#include <linux/err.h> 26#include <linux/err.h>
27#include <linux/math64.h> 27#include <linux/math64.h>
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/export.h>
29#include "ubi.h" 30#include "ubi.h"
30 31
31#ifdef CONFIG_MTD_UBI_DEBUG 32#ifdef CONFIG_MTD_UBI_DEBUG
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index c34cc1e7c6f6..b2b9109b6712 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -550,7 +550,7 @@ down:
550/* 550/*
551 * Get link speed and duplex from the slave's base driver 551 * Get link speed and duplex from the slave's base driver
552 * using ethtool. If for some reason the call fails or the 552 * using ethtool. If for some reason the call fails or the
553 * values are invalid, fake speed and duplex to 100/Full 553 * values are invalid, set speed and duplex to -1,
554 * and return error. 554 * and return error.
555 */ 555 */
556static int bond_update_speed_duplex(struct slave *slave) 556static int bond_update_speed_duplex(struct slave *slave)
@@ -560,9 +560,8 @@ static int bond_update_speed_duplex(struct slave *slave)
560 u32 slave_speed; 560 u32 slave_speed;
561 int res; 561 int res;
562 562
563 /* Fake speed and duplex */ 563 slave->speed = -1;
564 slave->speed = SPEED_100; 564 slave->duplex = -1;
565 slave->duplex = DUPLEX_FULL;
566 565
567 res = __ethtool_get_settings(slave_dev, &ecmd); 566 res = __ethtool_get_settings(slave_dev, &ecmd);
568 if (res < 0) 567 if (res < 0)
@@ -1751,16 +1750,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
1751 new_slave->link = BOND_LINK_DOWN; 1750 new_slave->link = BOND_LINK_DOWN;
1752 } 1751 }
1753 1752
1754 if (bond_update_speed_duplex(new_slave) && 1753 bond_update_speed_duplex(new_slave);
1755 (new_slave->link != BOND_LINK_DOWN)) {
1756 pr_warning("%s: Warning: failed to get speed and duplex from %s, assumed to be 100Mb/sec and Full.\n",
1757 bond_dev->name, new_slave->dev->name);
1758
1759 if (bond->params.mode == BOND_MODE_8023AD) {
1760 pr_warning("%s: Warning: Operation of 802.3ad mode requires ETHTOOL support in base driver for proper aggregator selection.\n",
1761 bond_dev->name);
1762 }
1763 }
1764 1754
1765 if (USES_PRIMARY(bond->params.mode) && bond->params.primary[0]) { 1755 if (USES_PRIMARY(bond->params.mode) && bond->params.primary[0]) {
1766 /* if there is a primary slave, remember it */ 1756 /* if there is a primary slave, remember it */
@@ -3220,6 +3210,7 @@ static int bond_slave_netdev_event(unsigned long event,
3220{ 3210{
3221 struct net_device *bond_dev = slave_dev->master; 3211 struct net_device *bond_dev = slave_dev->master;
3222 struct bonding *bond = netdev_priv(bond_dev); 3212 struct bonding *bond = netdev_priv(bond_dev);
3213 struct slave *slave = NULL;
3223 3214
3224 switch (event) { 3215 switch (event) {
3225 case NETDEV_UNREGISTER: 3216 case NETDEV_UNREGISTER:
@@ -3230,20 +3221,16 @@ static int bond_slave_netdev_event(unsigned long event,
3230 bond_release(bond_dev, slave_dev); 3221 bond_release(bond_dev, slave_dev);
3231 } 3222 }
3232 break; 3223 break;
3224 case NETDEV_UP:
3233 case NETDEV_CHANGE: 3225 case NETDEV_CHANGE:
3234 if (bond->params.mode == BOND_MODE_8023AD || bond_is_lb(bond)) { 3226 slave = bond_get_slave_by_dev(bond, slave_dev);
3235 struct slave *slave; 3227 if (slave) {
3228 u32 old_speed = slave->speed;
3229 u8 old_duplex = slave->duplex;
3236 3230
3237 slave = bond_get_slave_by_dev(bond, slave_dev); 3231 bond_update_speed_duplex(slave);
3238 if (slave) {
3239 u32 old_speed = slave->speed;
3240 u8 old_duplex = slave->duplex;
3241
3242 bond_update_speed_duplex(slave);
3243
3244 if (bond_is_lb(bond))
3245 break;
3246 3232
3233 if (bond->params.mode == BOND_MODE_8023AD) {
3247 if (old_speed != slave->speed) 3234 if (old_speed != slave->speed)
3248 bond_3ad_adapter_speed_changed(slave); 3235 bond_3ad_adapter_speed_changed(slave);
3249 if (old_duplex != slave->duplex) 3236 if (old_duplex != slave->duplex)
diff --git a/drivers/net/bonding/bond_procfs.c b/drivers/net/bonding/bond_procfs.c
index 95de93b90386..2acf0b080169 100644
--- a/drivers/net/bonding/bond_procfs.c
+++ b/drivers/net/bonding/bond_procfs.c
@@ -1,4 +1,5 @@
1#include <linux/proc_fs.h> 1#include <linux/proc_fs.h>
2#include <linux/export.h>
2#include <net/net_namespace.h> 3#include <net/net_namespace.h>
3#include <net/netns/generic.h> 4#include <net/netns/generic.h>
4#include "bonding.h" 5#include "bonding.h"
@@ -157,8 +158,16 @@ static void bond_info_show_slave(struct seq_file *seq,
157 seq_printf(seq, "\nSlave Interface: %s\n", slave->dev->name); 158 seq_printf(seq, "\nSlave Interface: %s\n", slave->dev->name);
158 seq_printf(seq, "MII Status: %s\n", 159 seq_printf(seq, "MII Status: %s\n",
159 (slave->link == BOND_LINK_UP) ? "up" : "down"); 160 (slave->link == BOND_LINK_UP) ? "up" : "down");
160 seq_printf(seq, "Speed: %d Mbps\n", slave->speed); 161 if (slave->speed == -1)
161 seq_printf(seq, "Duplex: %s\n", slave->duplex ? "full" : "half"); 162 seq_printf(seq, "Speed: %s\n", "Unknown");
163 else
164 seq_printf(seq, "Speed: %d Mbps\n", slave->speed);
165
166 if (slave->duplex == -1)
167 seq_printf(seq, "Duplex: %s\n", "Unknown");
168 else
169 seq_printf(seq, "Duplex: %s\n", slave->duplex ? "full" : "half");
170
162 seq_printf(seq, "Link Failure Count: %u\n", 171 seq_printf(seq, "Link Failure Count: %u\n",
163 slave->link_failure_count); 172 slave->link_failure_count);
164 173
diff --git a/drivers/net/ethernet/Kconfig b/drivers/net/ethernet/Kconfig
index 6dff5a0e733f..597f4d45c632 100644
--- a/drivers/net/ethernet/Kconfig
+++ b/drivers/net/ethernet/Kconfig
@@ -159,6 +159,7 @@ config S6GMAC
159 will be called s6gmac. 159 will be called s6gmac.
160 160
161source "drivers/net/ethernet/seeq/Kconfig" 161source "drivers/net/ethernet/seeq/Kconfig"
162source "drivers/net/ethernet/silan/Kconfig"
162source "drivers/net/ethernet/sis/Kconfig" 163source "drivers/net/ethernet/sis/Kconfig"
163source "drivers/net/ethernet/sfc/Kconfig" 164source "drivers/net/ethernet/sfc/Kconfig"
164source "drivers/net/ethernet/sgi/Kconfig" 165source "drivers/net/ethernet/sgi/Kconfig"
diff --git a/drivers/net/ethernet/Makefile b/drivers/net/ethernet/Makefile
index c53ad3afc991..be5dde040261 100644
--- a/drivers/net/ethernet/Makefile
+++ b/drivers/net/ethernet/Makefile
@@ -58,6 +58,7 @@ obj-$(CONFIG_SH_ETH) += renesas/
58obj-$(CONFIG_NET_VENDOR_RDC) += rdc/ 58obj-$(CONFIG_NET_VENDOR_RDC) += rdc/
59obj-$(CONFIG_S6GMAC) += s6gmac.o 59obj-$(CONFIG_S6GMAC) += s6gmac.o
60obj-$(CONFIG_NET_VENDOR_SEEQ) += seeq/ 60obj-$(CONFIG_NET_VENDOR_SEEQ) += seeq/
61obj-$(CONFIG_NET_VENDOR_SILAN) += silan/
61obj-$(CONFIG_NET_VENDOR_SIS) += sis/ 62obj-$(CONFIG_NET_VENDOR_SIS) += sis/
62obj-$(CONFIG_SFC) += sfc/ 63obj-$(CONFIG_SFC) += sfc/
63obj-$(CONFIG_NET_VENDOR_SGI) += sgi/ 64obj-$(CONFIG_NET_VENDOR_SGI) += sgi/
diff --git a/drivers/net/ethernet/amd/au1000_eth.c b/drivers/net/ethernet/amd/au1000_eth.c
index 82386677bb8c..4865ff14bebf 100644
--- a/drivers/net/ethernet/amd/au1000_eth.c
+++ b/drivers/net/ethernet/amd/au1000_eth.c
@@ -541,19 +541,17 @@ static void au1000_reset_mac(struct net_device *dev)
541 * these are not descriptors sitting in memory. 541 * these are not descriptors sitting in memory.
542 */ 542 */
543static void 543static void
544au1000_setup_hw_rings(struct au1000_private *aup, u32 rx_base, u32 tx_base) 544au1000_setup_hw_rings(struct au1000_private *aup, void __iomem *tx_base)
545{ 545{
546 int i; 546 int i;
547 547
548 for (i = 0; i < NUM_RX_DMA; i++) { 548 for (i = 0; i < NUM_RX_DMA; i++) {
549 aup->rx_dma_ring[i] = 549 aup->rx_dma_ring[i] = (struct rx_dma *)
550 (struct rx_dma *) 550 (tx_base + 0x100 + sizeof(struct rx_dma) * i);
551 (rx_base + sizeof(struct rx_dma)*i);
552 } 551 }
553 for (i = 0; i < NUM_TX_DMA; i++) { 552 for (i = 0; i < NUM_TX_DMA; i++) {
554 aup->tx_dma_ring[i] = 553 aup->tx_dma_ring[i] = (struct tx_dma *)
555 (struct tx_dma *) 554 (tx_base + sizeof(struct tx_dma) * i);
556 (tx_base + sizeof(struct tx_dma)*i);
557 } 555 }
558} 556}
559 557
@@ -1026,7 +1024,7 @@ static int __devinit au1000_probe(struct platform_device *pdev)
1026 struct net_device *dev = NULL; 1024 struct net_device *dev = NULL;
1027 struct db_dest *pDB, *pDBfree; 1025 struct db_dest *pDB, *pDBfree;
1028 int irq, i, err = 0; 1026 int irq, i, err = 0;
1029 struct resource *base, *macen; 1027 struct resource *base, *macen, *macdma;
1030 1028
1031 base = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1029 base = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1032 if (!base) { 1030 if (!base) {
@@ -1049,6 +1047,13 @@ static int __devinit au1000_probe(struct platform_device *pdev)
1049 goto out; 1047 goto out;
1050 } 1048 }
1051 1049
1050 macdma = platform_get_resource(pdev, IORESOURCE_MEM, 2);
1051 if (!macdma) {
1052 dev_err(&pdev->dev, "failed to retrieve MACDMA registers\n");
1053 err = -ENODEV;
1054 goto out;
1055 }
1056
1052 if (!request_mem_region(base->start, resource_size(base), 1057 if (!request_mem_region(base->start, resource_size(base),
1053 pdev->name)) { 1058 pdev->name)) {
1054 dev_err(&pdev->dev, "failed to request memory region for base registers\n"); 1059 dev_err(&pdev->dev, "failed to request memory region for base registers\n");
@@ -1063,6 +1068,13 @@ static int __devinit au1000_probe(struct platform_device *pdev)
1063 goto err_request; 1068 goto err_request;
1064 } 1069 }
1065 1070
1071 if (!request_mem_region(macdma->start, resource_size(macdma),
1072 pdev->name)) {
1073 dev_err(&pdev->dev, "failed to request MACDMA memory region\n");
1074 err = -ENXIO;
1075 goto err_macdma;
1076 }
1077
1066 dev = alloc_etherdev(sizeof(struct au1000_private)); 1078 dev = alloc_etherdev(sizeof(struct au1000_private));
1067 if (!dev) { 1079 if (!dev) {
1068 dev_err(&pdev->dev, "alloc_etherdev failed\n"); 1080 dev_err(&pdev->dev, "alloc_etherdev failed\n");
@@ -1109,10 +1121,14 @@ static int __devinit au1000_probe(struct platform_device *pdev)
1109 } 1121 }
1110 aup->mac_id = pdev->id; 1122 aup->mac_id = pdev->id;
1111 1123
1112 if (pdev->id == 0) 1124 aup->macdma = ioremap_nocache(macdma->start, resource_size(macdma));
1113 au1000_setup_hw_rings(aup, MAC0_RX_DMA_ADDR, MAC0_TX_DMA_ADDR); 1125 if (!aup->macdma) {
1114 else if (pdev->id == 1) 1126 dev_err(&pdev->dev, "failed to ioremap MACDMA registers\n");
1115 au1000_setup_hw_rings(aup, MAC1_RX_DMA_ADDR, MAC1_TX_DMA_ADDR); 1127 err = -ENXIO;
1128 goto err_remap3;
1129 }
1130
1131 au1000_setup_hw_rings(aup, aup->macdma);
1116 1132
1117 /* set a random MAC now in case platform_data doesn't provide one */ 1133 /* set a random MAC now in case platform_data doesn't provide one */
1118 random_ether_addr(dev->dev_addr); 1134 random_ether_addr(dev->dev_addr);
@@ -1252,6 +1268,8 @@ err_out:
1252err_mdiobus_reg: 1268err_mdiobus_reg:
1253 mdiobus_free(aup->mii_bus); 1269 mdiobus_free(aup->mii_bus);
1254err_mdiobus_alloc: 1270err_mdiobus_alloc:
1271 iounmap(aup->macdma);
1272err_remap3:
1255 iounmap(aup->enable); 1273 iounmap(aup->enable);
1256err_remap2: 1274err_remap2:
1257 iounmap(aup->mac); 1275 iounmap(aup->mac);
@@ -1261,6 +1279,8 @@ err_remap1:
1261err_vaddr: 1279err_vaddr:
1262 free_netdev(dev); 1280 free_netdev(dev);
1263err_alloc: 1281err_alloc:
1282 release_mem_region(macdma->start, resource_size(macdma));
1283err_macdma:
1264 release_mem_region(macen->start, resource_size(macen)); 1284 release_mem_region(macen->start, resource_size(macen));
1265err_request: 1285err_request:
1266 release_mem_region(base->start, resource_size(base)); 1286 release_mem_region(base->start, resource_size(base));
@@ -1293,9 +1313,13 @@ static int __devexit au1000_remove(struct platform_device *pdev)
1293 (NUM_TX_BUFFS + NUM_RX_BUFFS), 1313 (NUM_TX_BUFFS + NUM_RX_BUFFS),
1294 (void *)aup->vaddr, aup->dma_addr); 1314 (void *)aup->vaddr, aup->dma_addr);
1295 1315
1316 iounmap(aup->macdma);
1296 iounmap(aup->mac); 1317 iounmap(aup->mac);
1297 iounmap(aup->enable); 1318 iounmap(aup->enable);
1298 1319
1320 base = platform_get_resource(pdev, IORESOURCE_MEM, 2);
1321 release_mem_region(base->start, resource_size(base));
1322
1299 base = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1323 base = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1300 release_mem_region(base->start, resource_size(base)); 1324 release_mem_region(base->start, resource_size(base));
1301 1325
diff --git a/drivers/net/ethernet/amd/au1000_eth.h b/drivers/net/ethernet/amd/au1000_eth.h
index 6229c774552c..4b7f7ad62bb8 100644
--- a/drivers/net/ethernet/amd/au1000_eth.h
+++ b/drivers/net/ethernet/amd/au1000_eth.h
@@ -124,7 +124,7 @@ struct au1000_private {
124 */ 124 */
125 struct mac_reg *mac; /* mac registers */ 125 struct mac_reg *mac; /* mac registers */
126 u32 *enable; /* address of MAC Enable Register */ 126 u32 *enable; /* address of MAC Enable Register */
127 127 void __iomem *macdma; /* base of MAC DMA port */
128 u32 vaddr; /* virtual address of rx/tx buffers */ 128 u32 vaddr; /* virtual address of rx/tx buffers */
129 dma_addr_t dma_addr; /* dma address of rx/tx buffers */ 129 dma_addr_t dma_addr; /* dma address of rx/tx buffers */
130 130
diff --git a/drivers/net/ethernet/apple/Kconfig b/drivers/net/ethernet/apple/Kconfig
index a759d5483ab9..1375e2dc9468 100644
--- a/drivers/net/ethernet/apple/Kconfig
+++ b/drivers/net/ethernet/apple/Kconfig
@@ -52,18 +52,6 @@ config BMAC
52 To compile this driver as a module, choose M here: the module 52 To compile this driver as a module, choose M here: the module
53 will be called bmac. 53 will be called bmac.
54 54
55config MAC89x0
56 tristate "Macintosh CS89x0 based ethernet cards"
57 depends on MAC
58 ---help---
59 Support for CS89x0 chipset based Ethernet cards. If you have a
60 Nubus or LC-PDS network (Ethernet) card of this type, say Y and
61 read the Ethernet-HOWTO, available from
62 <http://www.tldp.org/docs.html#howto>.
63
64 To compile this driver as a module, choose M here. This module will
65 be called mac89x0.
66
67config MACMACE 55config MACMACE
68 bool "Macintosh (AV) onboard MACE ethernet" 56 bool "Macintosh (AV) onboard MACE ethernet"
69 depends on MAC 57 depends on MAC
diff --git a/drivers/net/ethernet/apple/Makefile b/drivers/net/ethernet/apple/Makefile
index 0d3a5919c95b..86eaa17af0f4 100644
--- a/drivers/net/ethernet/apple/Makefile
+++ b/drivers/net/ethernet/apple/Makefile
@@ -4,5 +4,4 @@
4 4
5obj-$(CONFIG_MACE) += mace.o 5obj-$(CONFIG_MACE) += mace.o
6obj-$(CONFIG_BMAC) += bmac.o 6obj-$(CONFIG_BMAC) += bmac.o
7obj-$(CONFIG_MAC89x0) += mac89x0.o
8obj-$(CONFIG_MACMACE) += macmace.o 7obj-$(CONFIG_MACMACE) += macmace.o
diff --git a/drivers/net/ethernet/brocade/bna/bnad.c b/drivers/net/ethernet/brocade/bna/bnad.c
index 5d7872ecff52..7f3091e7eb42 100644
--- a/drivers/net/ethernet/brocade/bna/bnad.c
+++ b/drivers/net/ethernet/brocade/bna/bnad.c
@@ -25,6 +25,7 @@
25#include <linux/if_ether.h> 25#include <linux/if_ether.h>
26#include <linux/ip.h> 26#include <linux/ip.h>
27#include <linux/prefetch.h> 27#include <linux/prefetch.h>
28#include <linux/module.h>
28 29
29#include "bnad.h" 30#include "bnad.h"
30#include "bna.h" 31#include "bna.h"
diff --git a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_offload.c b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_offload.c
index da5a5d9b8aff..90ff1318cc05 100644
--- a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_offload.c
+++ b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_offload.c
@@ -40,6 +40,7 @@
40#include <net/netevent.h> 40#include <net/netevent.h>
41#include <linux/highmem.h> 41#include <linux/highmem.h>
42#include <linux/vmalloc.h> 42#include <linux/vmalloc.h>
43#include <linux/export.h>
43 44
44#include "common.h" 45#include "common.h"
45#include "regs.h" 46#include "regs.h"
diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.c b/drivers/net/ethernet/chelsio/cxgb3/l2t.c
index 41540978a173..70fec8b1140f 100644
--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.c
+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.c
@@ -35,6 +35,7 @@
35#include <linux/if_vlan.h> 35#include <linux/if_vlan.h>
36#include <linux/jhash.h> 36#include <linux/jhash.h>
37#include <linux/slab.h> 37#include <linux/slab.h>
38#include <linux/export.h>
38#include <net/neighbour.h> 39#include <net/neighbour.h>
39#include "common.h" 40#include "common.h"
40#include "t3cdev.h" 41#include "t3cdev.h"
diff --git a/drivers/net/ethernet/chelsio/cxgb4/l2t.c b/drivers/net/ethernet/chelsio/cxgb4/l2t.c
index a2d323c473f8..6ac77a62f361 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/l2t.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/l2t.c
@@ -37,6 +37,9 @@
37#include <linux/if.h> 37#include <linux/if.h>
38#include <linux/if_vlan.h> 38#include <linux/if_vlan.h>
39#include <linux/jhash.h> 39#include <linux/jhash.h>
40#include <linux/module.h>
41#include <linux/debugfs.h>
42#include <linux/seq_file.h>
40#include <net/neighbour.h> 43#include <net/neighbour.h>
41#include "cxgb4.h" 44#include "cxgb4.h"
42#include "l2t.h" 45#include "l2t.h"
@@ -503,10 +506,6 @@ struct l2t_data *t4_init_l2t(void)
503 return d; 506 return d;
504} 507}
505 508
506#include <linux/module.h>
507#include <linux/debugfs.h>
508#include <linux/seq_file.h>
509
510static inline void *l2t_get_idx(struct seq_file *seq, loff_t pos) 509static inline void *l2t_get_idx(struct seq_file *seq, loff_t pos)
511{ 510{
512 struct l2t_entry *l2tab = seq->private; 511 struct l2t_entry *l2tab = seq->private;
diff --git a/drivers/net/ethernet/chelsio/cxgb4/sge.c b/drivers/net/ethernet/chelsio/cxgb4/sge.c
index ddc16985d0f6..140254c7cba9 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/sge.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/sge.c
@@ -40,6 +40,7 @@
40#include <linux/dma-mapping.h> 40#include <linux/dma-mapping.h>
41#include <linux/jiffies.h> 41#include <linux/jiffies.h>
42#include <linux/prefetch.h> 42#include <linux/prefetch.h>
43#include <linux/export.h>
43#include <net/ipv6.h> 44#include <net/ipv6.h>
44#include <net/tcp.h> 45#include <net/tcp.h>
45#include "cxgb4.h" 46#include "cxgb4.h"
diff --git a/drivers/net/ethernet/cirrus/Kconfig b/drivers/net/ethernet/cirrus/Kconfig
index 6cbb81ccc02e..1f8648f099c7 100644
--- a/drivers/net/ethernet/cirrus/Kconfig
+++ b/drivers/net/ethernet/cirrus/Kconfig
@@ -6,7 +6,7 @@ config NET_VENDOR_CIRRUS
6 bool "Cirrus devices" 6 bool "Cirrus devices"
7 default y 7 default y
8 depends on ISA || EISA || MACH_IXDP2351 || ARCH_IXDP2X01 \ 8 depends on ISA || EISA || MACH_IXDP2351 || ARCH_IXDP2X01 \
9 || MACH_MX31ADS || MACH_QQ2440 || (ARM && ARCH_EP93XX) 9 || MACH_MX31ADS || MACH_QQ2440 || (ARM && ARCH_EP93XX) || MAC
10 ---help--- 10 ---help---
11 If you have a network (Ethernet) card belonging to this class, say Y 11 If you have a network (Ethernet) card belonging to this class, say Y
12 and read the Ethernet-HOWTO, available from 12 and read the Ethernet-HOWTO, available from
@@ -47,4 +47,16 @@ config EP93XX_ETH
47 This is a driver for the ethernet hardware included in EP93xx CPUs. 47 This is a driver for the ethernet hardware included in EP93xx CPUs.
48 Say Y if you are building a kernel for EP93xx based devices. 48 Say Y if you are building a kernel for EP93xx based devices.
49 49
50config MAC89x0
51 tristate "Macintosh CS89x0 based ethernet cards"
52 depends on MAC
53 ---help---
54 Support for CS89x0 chipset based Ethernet cards. If you have a
55 Nubus or LC-PDS network (Ethernet) card of this type, say Y and
56 read the Ethernet-HOWTO, available from
57 <http://www.tldp.org/docs.html#howto>.
58
59 To compile this driver as a module, choose M here. This module will
60 be called mac89x0.
61
50endif # NET_VENDOR_CIRRUS 62endif # NET_VENDOR_CIRRUS
diff --git a/drivers/net/ethernet/cirrus/Makefile b/drivers/net/ethernet/cirrus/Makefile
index 14bd77e0cb57..ca245e2b5d98 100644
--- a/drivers/net/ethernet/cirrus/Makefile
+++ b/drivers/net/ethernet/cirrus/Makefile
@@ -4,3 +4,4 @@
4 4
5obj-$(CONFIG_CS89x0) += cs89x0.o 5obj-$(CONFIG_CS89x0) += cs89x0.o
6obj-$(CONFIG_EP93XX_ETH) += ep93xx_eth.o 6obj-$(CONFIG_EP93XX_ETH) += ep93xx_eth.o
7obj-$(CONFIG_MAC89x0) += mac89x0.o
diff --git a/drivers/net/ethernet/apple/mac89x0.c b/drivers/net/ethernet/cirrus/mac89x0.c
index 83781f316d1f..83781f316d1f 100644
--- a/drivers/net/ethernet/apple/mac89x0.c
+++ b/drivers/net/ethernet/cirrus/mac89x0.c
diff --git a/drivers/net/ethernet/emulex/benet/be_cmds.c b/drivers/net/ethernet/emulex/benet/be_cmds.c
index 824b8e6021f6..2c7b36673dfc 100644
--- a/drivers/net/ethernet/emulex/benet/be_cmds.c
+++ b/drivers/net/ethernet/emulex/benet/be_cmds.c
@@ -318,8 +318,7 @@ static int be_mbox_db_ready_wait(struct be_adapter *adapter, void __iomem *db)
318 318
319 if (msecs > 4000) { 319 if (msecs > 4000) {
320 dev_err(&adapter->pdev->dev, "mbox poll timed out\n"); 320 dev_err(&adapter->pdev->dev, "mbox poll timed out\n");
321 if (!lancer_chip(adapter)) 321 be_detect_dump_ue(adapter);
322 be_detect_dump_ue(adapter);
323 return -1; 322 return -1;
324 } 323 }
325 324
@@ -1540,7 +1539,14 @@ int be_cmd_rx_filter(struct be_adapter *adapter, u32 flags, u32 value)
1540 1539
1541 req->if_flags_mask = req->if_flags = 1540 req->if_flags_mask = req->if_flags =
1542 cpu_to_le32(BE_IF_FLAGS_MULTICAST); 1541 cpu_to_le32(BE_IF_FLAGS_MULTICAST);
1543 req->mcast_num = cpu_to_le16(netdev_mc_count(adapter->netdev)); 1542
1543 /* Reset mcast promisc mode if already set by setting mask
1544 * and not setting flags field
1545 */
1546 req->if_flags_mask |=
1547 cpu_to_le32(BE_IF_FLAGS_MCAST_PROMISCUOUS);
1548
1549 req->mcast_num = cpu_to_le32(netdev_mc_count(adapter->netdev));
1544 netdev_for_each_mc_addr(ha, adapter->netdev) 1550 netdev_for_each_mc_addr(ha, adapter->netdev)
1545 memcpy(req->mcast_mac[i++].byte, ha->addr, ETH_ALEN); 1551 memcpy(req->mcast_mac[i++].byte, ha->addr, ETH_ALEN);
1546 } 1552 }
diff --git a/drivers/net/ethernet/emulex/benet/be_hw.h b/drivers/net/ethernet/emulex/benet/be_hw.h
index fbc8a915519e..f2c89e3ccabd 100644
--- a/drivers/net/ethernet/emulex/benet/be_hw.h
+++ b/drivers/net/ethernet/emulex/benet/be_hw.h
@@ -48,6 +48,8 @@
48/* Lancer SLIPORT_CONTROL SLIPORT_STATUS registers */ 48/* Lancer SLIPORT_CONTROL SLIPORT_STATUS registers */
49#define SLIPORT_STATUS_OFFSET 0x404 49#define SLIPORT_STATUS_OFFSET 0x404
50#define SLIPORT_CONTROL_OFFSET 0x408 50#define SLIPORT_CONTROL_OFFSET 0x408
51#define SLIPORT_ERROR1_OFFSET 0x40C
52#define SLIPORT_ERROR2_OFFSET 0x410
51 53
52#define SLIPORT_STATUS_ERR_MASK 0x80000000 54#define SLIPORT_STATUS_ERR_MASK 0x80000000
53#define SLIPORT_STATUS_RN_MASK 0x01000000 55#define SLIPORT_STATUS_RN_MASK 0x01000000
diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
index 21804972fa2f..bf266a00c774 100644
--- a/drivers/net/ethernet/emulex/benet/be_main.c
+++ b/drivers/net/ethernet/emulex/benet/be_main.c
@@ -16,6 +16,7 @@
16 */ 16 */
17 17
18#include <linux/prefetch.h> 18#include <linux/prefetch.h>
19#include <linux/module.h>
19#include "be.h" 20#include "be.h"
20#include "be_cmds.h" 21#include "be_cmds.h"
21#include <asm/div64.h> 22#include <asm/div64.h>
@@ -1905,6 +1906,8 @@ loop_continue:
1905 be_rx_stats_update(rxo, rxcp); 1906 be_rx_stats_update(rxo, rxcp);
1906 } 1907 }
1907 1908
1909 be_cq_notify(adapter, rx_cq->id, false, work_done);
1910
1908 /* Refill the queue */ 1911 /* Refill the queue */
1909 if (work_done && atomic_read(&rxo->q.used) < RX_FRAGS_REFILL_WM) 1912 if (work_done && atomic_read(&rxo->q.used) < RX_FRAGS_REFILL_WM)
1910 be_post_rx_frags(rxo, GFP_ATOMIC); 1913 be_post_rx_frags(rxo, GFP_ATOMIC);
@@ -1912,10 +1915,8 @@ loop_continue:
1912 /* All consumed */ 1915 /* All consumed */
1913 if (work_done < budget) { 1916 if (work_done < budget) {
1914 napi_complete(napi); 1917 napi_complete(napi);
1915 be_cq_notify(adapter, rx_cq->id, true, work_done); 1918 /* Arm CQ */
1916 } else { 1919 be_cq_notify(adapter, rx_cq->id, true, 0);
1917 /* More to be consumed; continue with interrupts disabled */
1918 be_cq_notify(adapter, rx_cq->id, false, work_done);
1919 } 1920 }
1920 return work_done; 1921 return work_done;
1921} 1922}
@@ -1977,42 +1978,62 @@ static int be_poll_tx_mcc(struct napi_struct *napi, int budget)
1977 1978
1978void be_detect_dump_ue(struct be_adapter *adapter) 1979void be_detect_dump_ue(struct be_adapter *adapter)
1979{ 1980{
1980 u32 ue_status_lo, ue_status_hi, ue_status_lo_mask, ue_status_hi_mask; 1981 u32 ue_lo = 0, ue_hi = 0, ue_lo_mask = 0, ue_hi_mask = 0;
1982 u32 sliport_status = 0, sliport_err1 = 0, sliport_err2 = 0;
1981 u32 i; 1983 u32 i;
1982 1984
1983 pci_read_config_dword(adapter->pdev, 1985 if (lancer_chip(adapter)) {
1984 PCICFG_UE_STATUS_LOW, &ue_status_lo); 1986 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
1985 pci_read_config_dword(adapter->pdev, 1987 if (sliport_status & SLIPORT_STATUS_ERR_MASK) {
1986 PCICFG_UE_STATUS_HIGH, &ue_status_hi); 1988 sliport_err1 = ioread32(adapter->db +
1987 pci_read_config_dword(adapter->pdev, 1989 SLIPORT_ERROR1_OFFSET);
1988 PCICFG_UE_STATUS_LOW_MASK, &ue_status_lo_mask); 1990 sliport_err2 = ioread32(adapter->db +
1989 pci_read_config_dword(adapter->pdev, 1991 SLIPORT_ERROR2_OFFSET);
1990 PCICFG_UE_STATUS_HI_MASK, &ue_status_hi_mask); 1992 }
1993 } else {
1994 pci_read_config_dword(adapter->pdev,
1995 PCICFG_UE_STATUS_LOW, &ue_lo);
1996 pci_read_config_dword(adapter->pdev,
1997 PCICFG_UE_STATUS_HIGH, &ue_hi);
1998 pci_read_config_dword(adapter->pdev,
1999 PCICFG_UE_STATUS_LOW_MASK, &ue_lo_mask);
2000 pci_read_config_dword(adapter->pdev,
2001 PCICFG_UE_STATUS_HI_MASK, &ue_hi_mask);
1991 2002
1992 ue_status_lo = (ue_status_lo & (~ue_status_lo_mask)); 2003 ue_lo = (ue_lo & (~ue_lo_mask));
1993 ue_status_hi = (ue_status_hi & (~ue_status_hi_mask)); 2004 ue_hi = (ue_hi & (~ue_hi_mask));
2005 }
1994 2006
1995 if (ue_status_lo || ue_status_hi) { 2007 if (ue_lo || ue_hi ||
2008 sliport_status & SLIPORT_STATUS_ERR_MASK) {
1996 adapter->ue_detected = true; 2009 adapter->ue_detected = true;
1997 adapter->eeh_err = true; 2010 adapter->eeh_err = true;
1998 dev_err(&adapter->pdev->dev, "UE Detected!!\n"); 2011 dev_err(&adapter->pdev->dev, "UE Detected!!\n");
1999 } 2012 }
2000 2013
2001 if (ue_status_lo) { 2014 if (ue_lo) {
2002 for (i = 0; ue_status_lo; ue_status_lo >>= 1, i++) { 2015 for (i = 0; ue_lo; ue_lo >>= 1, i++) {
2003 if (ue_status_lo & 1) 2016 if (ue_lo & 1)
2004 dev_err(&adapter->pdev->dev, 2017 dev_err(&adapter->pdev->dev,
2005 "UE: %s bit set\n", ue_status_low_desc[i]); 2018 "UE: %s bit set\n", ue_status_low_desc[i]);
2006 } 2019 }
2007 } 2020 }
2008 if (ue_status_hi) { 2021 if (ue_hi) {
2009 for (i = 0; ue_status_hi; ue_status_hi >>= 1, i++) { 2022 for (i = 0; ue_hi; ue_hi >>= 1, i++) {
2010 if (ue_status_hi & 1) 2023 if (ue_hi & 1)
2011 dev_err(&adapter->pdev->dev, 2024 dev_err(&adapter->pdev->dev,
2012 "UE: %s bit set\n", ue_status_hi_desc[i]); 2025 "UE: %s bit set\n", ue_status_hi_desc[i]);
2013 } 2026 }
2014 } 2027 }
2015 2028
2029 if (sliport_status & SLIPORT_STATUS_ERR_MASK) {
2030 dev_err(&adapter->pdev->dev,
2031 "sliport status 0x%x\n", sliport_status);
2032 dev_err(&adapter->pdev->dev,
2033 "sliport error1 0x%x\n", sliport_err1);
2034 dev_err(&adapter->pdev->dev,
2035 "sliport error2 0x%x\n", sliport_err2);
2036 }
2016} 2037}
2017 2038
2018static void be_worker(struct work_struct *work) 2039static void be_worker(struct work_struct *work)
@@ -2022,7 +2043,7 @@ static void be_worker(struct work_struct *work)
2022 struct be_rx_obj *rxo; 2043 struct be_rx_obj *rxo;
2023 int i; 2044 int i;
2024 2045
2025 if (!adapter->ue_detected && !lancer_chip(adapter)) 2046 if (!adapter->ue_detected)
2026 be_detect_dump_ue(adapter); 2047 be_detect_dump_ue(adapter);
2027 2048
2028 /* when interrupts are not yet enabled, just reap any pending 2049 /* when interrupts are not yet enabled, just reap any pending
diff --git a/drivers/net/ethernet/ethoc.c b/drivers/net/ethernet/ethoc.c
index bdb348a5ccf6..251b635fe75a 100644
--- a/drivers/net/ethernet/ethoc.c
+++ b/drivers/net/ethernet/ethoc.c
@@ -22,6 +22,7 @@
22#include <linux/sched.h> 22#include <linux/sched.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/of.h> 24#include <linux/of.h>
25#include <linux/module.h>
25#include <net/ethoc.h> 26#include <net/ethoc.h>
26 27
27static int buffer_size = 0x8000; /* 32 KBytes */ 28static int buffer_size = 0x8000; /* 32 KBytes */
diff --git a/drivers/net/ethernet/freescale/ucc_geth.c b/drivers/net/ethernet/freescale/ucc_geth.c
index 46d690a92c0b..b5dc0273a1d1 100644
--- a/drivers/net/ethernet/freescale/ucc_geth.c
+++ b/drivers/net/ethernet/freescale/ucc_geth.c
@@ -17,6 +17,7 @@
17#include <linux/errno.h> 17#include <linux/errno.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/stddef.h> 19#include <linux/stddef.h>
20#include <linux/module.h>
20#include <linux/interrupt.h> 21#include <linux/interrupt.h>
21#include <linux/netdevice.h> 22#include <linux/netdevice.h>
22#include <linux/etherdevice.h> 23#include <linux/etherdevice.h>
diff --git a/drivers/net/ethernet/i825xx/3c505.c b/drivers/net/ethernet/i825xx/3c505.c
index 40e1a175fceb..ba82a266051d 100644
--- a/drivers/net/ethernet/i825xx/3c505.c
+++ b/drivers/net/ethernet/i825xx/3c505.c
@@ -126,15 +126,13 @@
126 * 126 *
127 *********************************************************/ 127 *********************************************************/
128 128
129#define filename __FILE__
130
131#define timeout_msg "*** timeout at %s:%s (line %d) ***\n" 129#define timeout_msg "*** timeout at %s:%s (line %d) ***\n"
132#define TIMEOUT_MSG(lineno) \ 130#define TIMEOUT_MSG(lineno) \
133 pr_notice(timeout_msg, filename, __func__, (lineno)) 131 pr_notice(timeout_msg, __FILE__, __func__, (lineno))
134 132
135#define invalid_pcb_msg "*** invalid pcb length %d at %s:%s (line %d) ***\n" 133#define invalid_pcb_msg "*** invalid pcb length %d at %s:%s (line %d) ***\n"
136#define INVALID_PCB_MSG(len) \ 134#define INVALID_PCB_MSG(len) \
137 pr_notice(invalid_pcb_msg, (len), filename, __func__, __LINE__) 135 pr_notice(invalid_pcb_msg, (len), __FILE__, __func__, __LINE__)
138 136
139#define search_msg "%s: Looking for 3c505 adapter at address %#x..." 137#define search_msg "%s: Looking for 3c505 adapter at address %#x..."
140 138
diff --git a/drivers/net/ethernet/intel/e100.c b/drivers/net/ethernet/intel/e100.c
index ae17cd1a907f..5a2fdf7a00c8 100644
--- a/drivers/net/ethernet/intel/e100.c
+++ b/drivers/net/ethernet/intel/e100.c
@@ -2810,6 +2810,10 @@ static int __devinit e100_probe(struct pci_dev *pdev,
2810 2810
2811 e100_get_defaults(nic); 2811 e100_get_defaults(nic);
2812 2812
2813 /* D100 MAC doesn't allow rx of vlan packets with normal MTU */
2814 if (nic->mac < mac_82558_D101_A4)
2815 netdev->features |= NETIF_F_VLAN_CHALLENGED;
2816
2813 /* locks must be initialized before calling hw_reset */ 2817 /* locks must be initialized before calling hw_reset */
2814 spin_lock_init(&nic->cb_lock); 2818 spin_lock_init(&nic->cb_lock);
2815 spin_lock_init(&nic->cmd_lock); 2819 spin_lock_init(&nic->cmd_lock);
diff --git a/drivers/net/ethernet/intel/e1000e/ich8lan.c b/drivers/net/ethernet/intel/e1000e/ich8lan.c
index 6a17c62cb86f..e2a80a283fd3 100644
--- a/drivers/net/ethernet/intel/e1000e/ich8lan.c
+++ b/drivers/net/ethernet/intel/e1000e/ich8lan.c
@@ -866,8 +866,7 @@ static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
866 866
867 if (test_and_set_bit(__E1000_ACCESS_SHARED_RESOURCE, 867 if (test_and_set_bit(__E1000_ACCESS_SHARED_RESOURCE,
868 &hw->adapter->state)) { 868 &hw->adapter->state)) {
869 WARN(1, "e1000e: %s: contention for Phy access\n", 869 e_dbg("contention for Phy access\n");
870 hw->adapter->netdev->name);
871 return -E1000_ERR_PHY; 870 return -E1000_ERR_PHY;
872 } 871 }
873 872
diff --git a/drivers/net/ethernet/intel/e1000e/param.c b/drivers/net/ethernet/intel/e1000e/param.c
index 4dd9b63273f6..20e93b08e7f3 100644
--- a/drivers/net/ethernet/intel/e1000e/param.c
+++ b/drivers/net/ethernet/intel/e1000e/param.c
@@ -27,6 +27,7 @@
27*******************************************************************************/ 27*******************************************************************************/
28 28
29#include <linux/netdevice.h> 29#include <linux/netdevice.h>
30#include <linux/module.h>
30#include <linux/pci.h> 31#include <linux/pci.h>
31 32
32#include "e1000.h" 33#include "e1000.h"
diff --git a/drivers/net/ethernet/intel/igb/e1000_phy.c b/drivers/net/ethernet/intel/igb/e1000_phy.c
index 7edf31efe756..b17d7c20f817 100644
--- a/drivers/net/ethernet/intel/igb/e1000_phy.c
+++ b/drivers/net/ethernet/intel/igb/e1000_phy.c
@@ -1687,7 +1687,7 @@ s32 igb_get_cable_length_m88_gen2(struct e1000_hw *hw)
1687 if (ret_val) 1687 if (ret_val)
1688 goto out; 1688 goto out;
1689 1689
1690 is_cm = !(phy_data & I347AT4_PCDC_CABLE_LENGTH_UNIT); 1690 is_cm = !(phy_data2 & I347AT4_PCDC_CABLE_LENGTH_UNIT);
1691 1691
1692 /* Populate the phy structure with cable length in meters */ 1692 /* Populate the phy structure with cable length in meters */
1693 phy->min_cable_length = phy_data / (is_cm ? 100 : 1); 1693 phy->min_cable_length = phy_data / (is_cm ? 100 : 1);
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_common.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_common.c
index 834f044be4c3..f1365fef4ed2 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_common.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_common.c
@@ -3344,7 +3344,7 @@ static u8 ixgbe_calculate_checksum(u8 *buffer, u32 length)
3344static s32 ixgbe_host_interface_command(struct ixgbe_hw *hw, u32 *buffer, 3344static s32 ixgbe_host_interface_command(struct ixgbe_hw *hw, u32 *buffer,
3345 u32 length) 3345 u32 length)
3346{ 3346{
3347 u32 hicr, i; 3347 u32 hicr, i, bi;
3348 u32 hdr_size = sizeof(struct ixgbe_hic_hdr); 3348 u32 hdr_size = sizeof(struct ixgbe_hic_hdr);
3349 u8 buf_len, dword_len; 3349 u8 buf_len, dword_len;
3350 3350
@@ -3398,9 +3398,9 @@ static s32 ixgbe_host_interface_command(struct ixgbe_hw *hw, u32 *buffer,
3398 dword_len = hdr_size >> 2; 3398 dword_len = hdr_size >> 2;
3399 3399
3400 /* first pull in the header so we know the buffer length */ 3400 /* first pull in the header so we know the buffer length */
3401 for (i = 0; i < dword_len; i++) { 3401 for (bi = 0; bi < dword_len; bi++) {
3402 buffer[i] = IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG, i); 3402 buffer[bi] = IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG, bi);
3403 le32_to_cpus(&buffer[i]); 3403 le32_to_cpus(&buffer[bi]);
3404 } 3404 }
3405 3405
3406 /* If there is any thing in data position pull it in */ 3406 /* If there is any thing in data position pull it in */
@@ -3414,12 +3414,14 @@ static s32 ixgbe_host_interface_command(struct ixgbe_hw *hw, u32 *buffer,
3414 goto out; 3414 goto out;
3415 } 3415 }
3416 3416
3417 /* Calculate length in DWORDs, add one for odd lengths */ 3417 /* Calculate length in DWORDs, add 3 for odd lengths */
3418 dword_len = (buf_len + 1) >> 2; 3418 dword_len = (buf_len + 3) >> 2;
3419 3419
3420 /* Pull in the rest of the buffer (i is where we left off)*/ 3420 /* Pull in the rest of the buffer (bi is where we left off)*/
3421 for (; i < buf_len; i++) 3421 for (; bi <= dword_len; bi++) {
3422 buffer[i] = IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG, i); 3422 buffer[bi] = IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG, bi);
3423 le32_to_cpus(&buffer[bi]);
3424 }
3423 3425
3424out: 3426out:
3425 return ret_val; 3427 return ret_val;
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_dcb_nl.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_dcb_nl.c
index 3631d639d86a..33b93ffb87cb 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_dcb_nl.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_dcb_nl.c
@@ -561,11 +561,12 @@ static int ixgbe_dcbnl_ieee_getets(struct net_device *dev,
561 struct ixgbe_adapter *adapter = netdev_priv(dev); 561 struct ixgbe_adapter *adapter = netdev_priv(dev);
562 struct ieee_ets *my_ets = adapter->ixgbe_ieee_ets; 562 struct ieee_ets *my_ets = adapter->ixgbe_ieee_ets;
563 563
564 ets->ets_cap = adapter->dcb_cfg.num_tcs.pg_tcs;
565
564 /* No IEEE PFC settings available */ 566 /* No IEEE PFC settings available */
565 if (!my_ets) 567 if (!my_ets)
566 return -EINVAL; 568 return 0;
567 569
568 ets->ets_cap = adapter->dcb_cfg.num_tcs.pg_tcs;
569 ets->cbs = my_ets->cbs; 570 ets->cbs = my_ets->cbs;
570 memcpy(ets->tc_tx_bw, my_ets->tc_tx_bw, sizeof(ets->tc_tx_bw)); 571 memcpy(ets->tc_tx_bw, my_ets->tc_tx_bw, sizeof(ets->tc_tx_bw));
571 memcpy(ets->tc_rx_bw, my_ets->tc_rx_bw, sizeof(ets->tc_rx_bw)); 572 memcpy(ets->tc_rx_bw, my_ets->tc_rx_bw, sizeof(ets->tc_rx_bw));
@@ -621,11 +622,12 @@ static int ixgbe_dcbnl_ieee_getpfc(struct net_device *dev,
621 struct ieee_pfc *my_pfc = adapter->ixgbe_ieee_pfc; 622 struct ieee_pfc *my_pfc = adapter->ixgbe_ieee_pfc;
622 int i; 623 int i;
623 624
625 pfc->pfc_cap = adapter->dcb_cfg.num_tcs.pfc_tcs;
626
624 /* No IEEE PFC settings available */ 627 /* No IEEE PFC settings available */
625 if (!my_pfc) 628 if (!my_pfc)
626 return -EINVAL; 629 return 0;
627 630
628 pfc->pfc_cap = adapter->dcb_cfg.num_tcs.pfc_tcs;
629 pfc->pfc_en = my_pfc->pfc_en; 631 pfc->pfc_en = my_pfc->pfc_en;
630 pfc->mbc = my_pfc->mbc; 632 pfc->mbc = my_pfc->mbc;
631 pfc->delay = my_pfc->delay; 633 pfc->delay = my_pfc->delay;
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
index 09b8e88b2999..8ef92d1a6aa1 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
@@ -3345,34 +3345,25 @@ static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3345 3345
3346 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true); 3346 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
3347 3347
3348 /* reconfigure the hardware */
3349 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
3350#ifdef IXGBE_FCOE 3348#ifdef IXGBE_FCOE
3351 if (adapter->netdev->features & NETIF_F_FCOE_MTU) 3349 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3352 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE); 3350 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3353#endif 3351#endif
3352
3353 /* reconfigure the hardware */
3354 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
3354 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, 3355 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3355 DCB_TX_CONFIG); 3356 DCB_TX_CONFIG);
3356 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame, 3357 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3357 DCB_RX_CONFIG); 3358 DCB_RX_CONFIG);
3358 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg); 3359 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
3359 } else { 3360 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
3360 struct net_device *dev = adapter->netdev; 3361 ixgbe_dcb_hw_ets(&adapter->hw,
3361 3362 adapter->ixgbe_ieee_ets,
3362 if (adapter->ixgbe_ieee_ets) { 3363 max_frame);
3363 struct ieee_ets *ets = adapter->ixgbe_ieee_ets; 3364 ixgbe_dcb_hw_pfc_config(&adapter->hw,
3364 int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN; 3365 adapter->ixgbe_ieee_pfc->pfc_en,
3365 3366 adapter->ixgbe_ieee_ets->prio_tc);
3366 ixgbe_dcb_hw_ets(&adapter->hw, ets, max_frame);
3367 }
3368
3369 if (adapter->ixgbe_ieee_pfc) {
3370 struct ieee_pfc *pfc = adapter->ixgbe_ieee_pfc;
3371 u8 *prio_tc = adapter->ixgbe_ieee_ets->prio_tc;
3372
3373 ixgbe_dcb_hw_pfc_config(&adapter->hw, pfc->pfc_en,
3374 prio_tc);
3375 }
3376 } 3367 }
3377 3368
3378 /* Enable RSS Hash per TC */ 3369 /* Enable RSS Hash per TC */
@@ -6125,7 +6116,6 @@ static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6125 autoneg = hw->phy.autoneg_advertised; 6116 autoneg = hw->phy.autoneg_advertised;
6126 if ((!autoneg) && (hw->mac.ops.get_link_capabilities)) 6117 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
6127 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation); 6118 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
6128 hw->mac.autotry_restart = false;
6129 if (hw->mac.ops.setup_link) 6119 if (hw->mac.ops.setup_link)
6130 hw->mac.ops.setup_link(hw, autoneg, negotiation, true); 6120 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
6131 6121
@@ -7589,13 +7579,6 @@ static int __devinit ixgbe_probe(struct pci_dev *pdev,
7589 goto err_eeprom; 7579 goto err_eeprom;
7590 } 7580 }
7591 7581
7592 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7593 if (hw->mac.ops.disable_tx_laser &&
7594 ((hw->phy.multispeed_fiber) ||
7595 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
7596 (hw->mac.type == ixgbe_mac_82599EB))))
7597 hw->mac.ops.disable_tx_laser(hw);
7598
7599 setup_timer(&adapter->service_timer, &ixgbe_service_timer, 7582 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
7600 (unsigned long) adapter); 7583 (unsigned long) adapter);
7601 7584
@@ -7693,6 +7676,13 @@ static int __devinit ixgbe_probe(struct pci_dev *pdev,
7693 if (err) 7676 if (err)
7694 goto err_register; 7677 goto err_register;
7695 7678
7679 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7680 if (hw->mac.ops.disable_tx_laser &&
7681 ((hw->phy.multispeed_fiber) ||
7682 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
7683 (hw->mac.type == ixgbe_mac_82599EB))))
7684 hw->mac.ops.disable_tx_laser(hw);
7685
7696 /* carrier off reporting is important to ethtool even BEFORE open */ 7686 /* carrier off reporting is important to ethtool even BEFORE open */
7697 netif_carrier_off(netdev); 7687 netif_carrier_off(netdev);
7698 7688
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.h
index 5a7e1eb33599..4a5d8897faab 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.h
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.h
@@ -42,10 +42,12 @@ int ixgbe_ndo_set_vf_spoofchk(struct net_device *netdev, int vf, bool setting);
42int ixgbe_ndo_get_vf_config(struct net_device *netdev, 42int ixgbe_ndo_get_vf_config(struct net_device *netdev,
43 int vf, struct ifla_vf_info *ivi); 43 int vf, struct ifla_vf_info *ivi);
44void ixgbe_check_vf_rate_limit(struct ixgbe_adapter *adapter); 44void ixgbe_check_vf_rate_limit(struct ixgbe_adapter *adapter);
45#ifdef CONFIG_PCI_IOV
45void ixgbe_disable_sriov(struct ixgbe_adapter *adapter); 46void ixgbe_disable_sriov(struct ixgbe_adapter *adapter);
46void ixgbe_enable_sriov(struct ixgbe_adapter *adapter, 47void ixgbe_enable_sriov(struct ixgbe_adapter *adapter,
47 const struct ixgbe_info *ii); 48 const struct ixgbe_info *ii);
48int ixgbe_check_vf_assignment(struct ixgbe_adapter *adapter); 49int ixgbe_check_vf_assignment(struct ixgbe_adapter *adapter);
50#endif
49 51
50 52
51#endif /* _IXGBE_SRIOV_H_ */ 53#endif /* _IXGBE_SRIOV_H_ */
diff --git a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
index 5e92cc2079bd..4c8e19951d57 100644
--- a/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
+++ b/drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c
@@ -54,7 +54,7 @@ char ixgbevf_driver_name[] = "ixgbevf";
54static const char ixgbevf_driver_string[] = 54static const char ixgbevf_driver_string[] =
55 "Intel(R) 10 Gigabit PCI Express Virtual Function Network Driver"; 55 "Intel(R) 10 Gigabit PCI Express Virtual Function Network Driver";
56 56
57#define DRV_VERSION "2.1.0-k" 57#define DRV_VERSION "2.2.0-k"
58const char ixgbevf_driver_version[] = DRV_VERSION; 58const char ixgbevf_driver_version[] = DRV_VERSION;
59static char ixgbevf_copyright[] = 59static char ixgbevf_copyright[] =
60 "Copyright (c) 2009 - 2010 Intel Corporation."; 60 "Copyright (c) 2009 - 2010 Intel Corporation.";
diff --git a/drivers/net/ethernet/mellanox/mlx4/alloc.c b/drivers/net/ethernet/mellanox/mlx4/alloc.c
index 116cae334dad..8be20e7ea3d1 100644
--- a/drivers/net/ethernet/mellanox/mlx4/alloc.c
+++ b/drivers/net/ethernet/mellanox/mlx4/alloc.c
@@ -34,6 +34,7 @@
34#include <linux/errno.h> 34#include <linux/errno.h>
35#include <linux/slab.h> 35#include <linux/slab.h>
36#include <linux/mm.h> 36#include <linux/mm.h>
37#include <linux/export.h>
37#include <linux/bitmap.h> 38#include <linux/bitmap.h>
38#include <linux/dma-mapping.h> 39#include <linux/dma-mapping.h>
39#include <linux/vmalloc.h> 40#include <linux/vmalloc.h>
diff --git a/drivers/net/ethernet/mellanox/mlx4/catas.c b/drivers/net/ethernet/mellanox/mlx4/catas.c
index 32f947154c33..45aea9c3ae2c 100644
--- a/drivers/net/ethernet/mellanox/mlx4/catas.c
+++ b/drivers/net/ethernet/mellanox/mlx4/catas.c
@@ -32,6 +32,7 @@
32 */ 32 */
33 33
34#include <linux/workqueue.h> 34#include <linux/workqueue.h>
35#include <linux/module.h>
35 36
36#include "mlx4.h" 37#include "mlx4.h"
37 38
diff --git a/drivers/net/ethernet/mellanox/mlx4/cmd.c b/drivers/net/ethernet/mellanox/mlx4/cmd.c
index 23cee7b6af91..78f5a1a0b8c8 100644
--- a/drivers/net/ethernet/mellanox/mlx4/cmd.c
+++ b/drivers/net/ethernet/mellanox/mlx4/cmd.c
@@ -34,6 +34,7 @@
34 34
35#include <linux/sched.h> 35#include <linux/sched.h>
36#include <linux/slab.h> 36#include <linux/slab.h>
37#include <linux/export.h>
37#include <linux/pci.h> 38#include <linux/pci.h>
38#include <linux/errno.h> 39#include <linux/errno.h>
39 40
diff --git a/drivers/net/ethernet/mellanox/mlx4/cq.c b/drivers/net/ethernet/mellanox/mlx4/cq.c
index bd8ef9f2fa71..499a5168892a 100644
--- a/drivers/net/ethernet/mellanox/mlx4/cq.c
+++ b/drivers/net/ethernet/mellanox/mlx4/cq.c
@@ -35,6 +35,7 @@
35 */ 35 */
36 36
37#include <linux/hardirq.h> 37#include <linux/hardirq.h>
38#include <linux/export.h>
38#include <linux/gfp.h> 39#include <linux/gfp.h>
39 40
40#include <linux/mlx4/cmd.h> 41#include <linux/mlx4/cmd.h>
diff --git a/drivers/net/ethernet/mellanox/mlx4/en_tx.c b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
index 90f2cd24faac..d901b4267537 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_tx.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_tx.c
@@ -39,6 +39,7 @@
39#include <linux/if_vlan.h> 39#include <linux/if_vlan.h>
40#include <linux/vmalloc.h> 40#include <linux/vmalloc.h>
41#include <linux/tcp.h> 41#include <linux/tcp.h>
42#include <linux/moduleparam.h>
42 43
43#include "mlx4_en.h" 44#include "mlx4_en.h"
44 45
diff --git a/drivers/net/ethernet/mellanox/mlx4/eq.c b/drivers/net/ethernet/mellanox/mlx4/eq.c
index 869a2c220a7b..24ee96775996 100644
--- a/drivers/net/ethernet/mellanox/mlx4/eq.c
+++ b/drivers/net/ethernet/mellanox/mlx4/eq.c
@@ -33,6 +33,7 @@
33 33
34#include <linux/interrupt.h> 34#include <linux/interrupt.h>
35#include <linux/slab.h> 35#include <linux/slab.h>
36#include <linux/export.h>
36#include <linux/mm.h> 37#include <linux/mm.h>
37#include <linux/dma-mapping.h> 38#include <linux/dma-mapping.h>
38 39
diff --git a/drivers/net/ethernet/mellanox/mlx4/fw.c b/drivers/net/ethernet/mellanox/mlx4/fw.c
index abdfbacab4a6..435ca6e49734 100644
--- a/drivers/net/ethernet/mellanox/mlx4/fw.c
+++ b/drivers/net/ethernet/mellanox/mlx4/fw.c
@@ -33,6 +33,7 @@
33 */ 33 */
34 34
35#include <linux/mlx4/cmd.h> 35#include <linux/mlx4/cmd.h>
36#include <linux/module.h>
36#include <linux/cache.h> 37#include <linux/cache.h>
37 38
38#include "fw.h" 39#include "fw.h"
diff --git a/drivers/net/ethernet/mellanox/mlx4/intf.c b/drivers/net/ethernet/mellanox/mlx4/intf.c
index 73c94fcdfddf..ca6feb55bd94 100644
--- a/drivers/net/ethernet/mellanox/mlx4/intf.c
+++ b/drivers/net/ethernet/mellanox/mlx4/intf.c
@@ -32,6 +32,7 @@
32 */ 32 */
33 33
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/export.h>
35 36
36#include "mlx4.h" 37#include "mlx4.h"
37 38
diff --git a/drivers/net/ethernet/mellanox/mlx4/mcg.c b/drivers/net/ethernet/mellanox/mlx4/mcg.c
index cd1784593a3c..978688c31046 100644
--- a/drivers/net/ethernet/mellanox/mlx4/mcg.c
+++ b/drivers/net/ethernet/mellanox/mlx4/mcg.c
@@ -35,6 +35,7 @@
35#include <linux/etherdevice.h> 35#include <linux/etherdevice.h>
36 36
37#include <linux/mlx4/cmd.h> 37#include <linux/mlx4/cmd.h>
38#include <linux/export.h>
38 39
39#include "mlx4.h" 40#include "mlx4.h"
40 41
diff --git a/drivers/net/ethernet/mellanox/mlx4/mr.c b/drivers/net/ethernet/mellanox/mlx4/mr.c
index ab639cfef78e..efa3e77355e4 100644
--- a/drivers/net/ethernet/mellanox/mlx4/mr.c
+++ b/drivers/net/ethernet/mellanox/mlx4/mr.c
@@ -33,6 +33,7 @@
33 */ 33 */
34 34
35#include <linux/errno.h> 35#include <linux/errno.h>
36#include <linux/export.h>
36#include <linux/slab.h> 37#include <linux/slab.h>
37 38
38#include <linux/mlx4/cmd.h> 39#include <linux/mlx4/cmd.h>
diff --git a/drivers/net/ethernet/mellanox/mlx4/pd.c b/drivers/net/ethernet/mellanox/mlx4/pd.c
index 3736163e30e9..260ed259ce9b 100644
--- a/drivers/net/ethernet/mellanox/mlx4/pd.c
+++ b/drivers/net/ethernet/mellanox/mlx4/pd.c
@@ -32,6 +32,7 @@
32 */ 32 */
33 33
34#include <linux/errno.h> 34#include <linux/errno.h>
35#include <linux/export.h>
35#include <linux/io-mapping.h> 36#include <linux/io-mapping.h>
36 37
37#include <asm/page.h> 38#include <asm/page.h>
diff --git a/drivers/net/ethernet/mellanox/mlx4/port.c b/drivers/net/ethernet/mellanox/mlx4/port.c
index a44f080fdfe5..d942aea4927b 100644
--- a/drivers/net/ethernet/mellanox/mlx4/port.c
+++ b/drivers/net/ethernet/mellanox/mlx4/port.c
@@ -32,6 +32,7 @@
32 32
33#include <linux/errno.h> 33#include <linux/errno.h>
34#include <linux/if_ether.h> 34#include <linux/if_ether.h>
35#include <linux/export.h>
35 36
36#include <linux/mlx4/cmd.h> 37#include <linux/mlx4/cmd.h>
37 38
diff --git a/drivers/net/ethernet/mellanox/mlx4/qp.c b/drivers/net/ethernet/mellanox/mlx4/qp.c
index 51c53898c35f..15f870cb2590 100644
--- a/drivers/net/ethernet/mellanox/mlx4/qp.c
+++ b/drivers/net/ethernet/mellanox/mlx4/qp.c
@@ -34,6 +34,7 @@
34 */ 34 */
35 35
36#include <linux/gfp.h> 36#include <linux/gfp.h>
37#include <linux/export.h>
37#include <linux/mlx4/cmd.h> 38#include <linux/mlx4/cmd.h>
38#include <linux/mlx4/qp.h> 39#include <linux/mlx4/qp.h>
39 40
diff --git a/drivers/net/ethernet/mellanox/mlx4/srq.c b/drivers/net/ethernet/mellanox/mlx4/srq.c
index a20b141dbb5c..9cbf3fce0145 100644
--- a/drivers/net/ethernet/mellanox/mlx4/srq.c
+++ b/drivers/net/ethernet/mellanox/mlx4/srq.c
@@ -32,6 +32,7 @@
32 */ 32 */
33 33
34#include <linux/mlx4/cmd.h> 34#include <linux/mlx4/cmd.h>
35#include <linux/export.h>
35#include <linux/gfp.h> 36#include <linux/gfp.h>
36 37
37#include "mlx4.h" 38#include "mlx4.h"
diff --git a/drivers/net/ethernet/neterion/vxge/vxge-main.c b/drivers/net/ethernet/neterion/vxge/vxge-main.c
index 671e166b5af1..a83197d757c1 100644
--- a/drivers/net/ethernet/neterion/vxge/vxge-main.c
+++ b/drivers/net/ethernet/neterion/vxge/vxge-main.c
@@ -55,6 +55,7 @@
55#include <linux/firmware.h> 55#include <linux/firmware.h>
56#include <linux/net_tstamp.h> 56#include <linux/net_tstamp.h>
57#include <linux/prefetch.h> 57#include <linux/prefetch.h>
58#include <linux/module.h>
58#include "vxge-main.h" 59#include "vxge-main.h"
59#include "vxge-reg.h" 60#include "vxge-reg.h"
60 61
diff --git a/drivers/net/ethernet/octeon/octeon_mgmt.c b/drivers/net/ethernet/octeon/octeon_mgmt.c
index bc1d946b7971..212f43b308a3 100644
--- a/drivers/net/ethernet/octeon/octeon_mgmt.c
+++ b/drivers/net/ethernet/octeon/octeon_mgmt.c
@@ -9,6 +9,7 @@
9#include <linux/capability.h> 9#include <linux/capability.h>
10#include <linux/dma-mapping.h> 10#include <linux/dma-mapping.h>
11#include <linux/init.h> 11#include <linux/init.h>
12#include <linux/module.h>
12#include <linux/interrupt.h> 13#include <linux/interrupt.h>
13#include <linux/platform_device.h> 14#include <linux/platform_device.h>
14#include <linux/netdevice.h> 15#include <linux/netdevice.h>
diff --git a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
index b89f3a684aec..48406ca382f1 100644
--- a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
+++ b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_main.c
@@ -20,6 +20,7 @@
20 20
21#include "pch_gbe.h" 21#include "pch_gbe.h"
22#include "pch_gbe_api.h" 22#include "pch_gbe_api.h"
23#include <linux/module.h>
23 24
24#define DRV_VERSION "1.00" 25#define DRV_VERSION "1.00"
25const char pch_driver_version[] = DRV_VERSION; 26const char pch_driver_version[] = DRV_VERSION;
diff --git a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_param.c b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_param.c
index 5b5d90a47e29..9c075ea2682e 100644
--- a/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_param.c
+++ b/drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe_param.c
@@ -18,6 +18,7 @@
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 20
21#include <linux/module.h> /* for __MODULE_STRING */
21#include "pch_gbe.h" 22#include "pch_gbe.h"
22 23
23#define OPTION_UNSET -1 24#define OPTION_UNSET -1
diff --git a/drivers/net/ethernet/realtek/Kconfig b/drivers/net/ethernet/realtek/Kconfig
index 84083ec6e612..0578859a3c73 100644
--- a/drivers/net/ethernet/realtek/Kconfig
+++ b/drivers/net/ethernet/realtek/Kconfig
@@ -115,16 +115,4 @@ config R8169
115 To compile this driver as a module, choose M here: the module 115 To compile this driver as a module, choose M here: the module
116 will be called r8169. This is recommended. 116 will be called r8169. This is recommended.
117 117
118config SC92031
119 tristate "Silan SC92031 PCI Fast Ethernet Adapter driver (EXPERIMENTAL)"
120 depends on PCI && EXPERIMENTAL
121 select CRC32
122 ---help---
123 This is a driver for the Fast Ethernet PCI network cards based on
124 the Silan SC92031 chip (sometimes also called Rsltek 8139D). If you
125 have one of these, say Y here.
126
127 To compile this driver as a module, choose M here: the module
128 will be called sc92031. This is recommended.
129
130endif # NET_VENDOR_REALTEK 118endif # NET_VENDOR_REALTEK
diff --git a/drivers/net/ethernet/realtek/Makefile b/drivers/net/ethernet/realtek/Makefile
index e48cfb6ac42d..71b1da30ecb5 100644
--- a/drivers/net/ethernet/realtek/Makefile
+++ b/drivers/net/ethernet/realtek/Makefile
@@ -6,4 +6,3 @@ obj-$(CONFIG_8139CP) += 8139cp.o
6obj-$(CONFIG_8139TOO) += 8139too.o 6obj-$(CONFIG_8139TOO) += 8139too.o
7obj-$(CONFIG_ATP) += atp.o 7obj-$(CONFIG_ATP) += atp.o
8obj-$(CONFIG_R8169) += r8169.o 8obj-$(CONFIG_R8169) += r8169.o
9obj-$(CONFIG_SC92031) += sc92031.o
diff --git a/drivers/net/ethernet/sfc/rx.c b/drivers/net/ethernet/sfc/rx.c
index adbda182f159..752d521c09b1 100644
--- a/drivers/net/ethernet/sfc/rx.c
+++ b/drivers/net/ethernet/sfc/rx.c
@@ -15,6 +15,7 @@
15#include <linux/tcp.h> 15#include <linux/tcp.h>
16#include <linux/udp.h> 16#include <linux/udp.h>
17#include <linux/prefetch.h> 17#include <linux/prefetch.h>
18#include <linux/moduleparam.h>
18#include <net/ip.h> 19#include <net/ip.h>
19#include <net/checksum.h> 20#include <net/checksum.h>
20#include "net_driver.h" 21#include "net_driver.h"
diff --git a/drivers/net/ethernet/silan/Kconfig b/drivers/net/ethernet/silan/Kconfig
new file mode 100644
index 000000000000..ae1ce170864d
--- /dev/null
+++ b/drivers/net/ethernet/silan/Kconfig
@@ -0,0 +1,33 @@
1#
2# Silan device configuration
3#
4
5config NET_VENDOR_SILAN
6 bool "Silan devices"
7 default y
8 depends on PCI && EXPERIMENTAL
9 ---help---
10 If you have a network (Ethernet) card belonging to this class, say Y
11 and read the Ethernet-HOWTO, available from
12 <http://www.tldp.org/docs.html#howto>.
13
14 Note that the answer to this question doesn't directly affect the
15 kernel: saying N will just cause the configurator to skip all
16 the questions about Silan devices. If you say Y, you will be asked for
17 your specific card in the following questions.
18
19if NET_VENDOR_SILAN
20
21config SC92031
22 tristate "Silan SC92031 PCI Fast Ethernet Adapter driver (EXPERIMENTAL)"
23 depends on PCI && EXPERIMENTAL
24 select CRC32
25 ---help---
26 This is a driver for the Fast Ethernet PCI network cards based on
27 the Silan SC92031 chip (sometimes also called Rsltek 8139D). If you
28 have one of these, say Y here.
29
30 To compile this driver as a module, choose M here: the module
31 will be called sc92031. This is recommended.
32
33endif # NET_VENDOR_SILAN
diff --git a/drivers/net/ethernet/silan/Makefile b/drivers/net/ethernet/silan/Makefile
new file mode 100644
index 000000000000..4ad3523dcb92
--- /dev/null
+++ b/drivers/net/ethernet/silan/Makefile
@@ -0,0 +1,5 @@
1#
2# Makefile for the Silan network device drivers.
3#
4
5obj-$(CONFIG_SC92031) += sc92031.o
diff --git a/drivers/net/ethernet/realtek/sc92031.c b/drivers/net/ethernet/silan/sc92031.c
index a284d6440538..a284d6440538 100644
--- a/drivers/net/ethernet/realtek/sc92031.c
+++ b/drivers/net/ethernet/silan/sc92031.c
diff --git a/drivers/net/ethernet/smsc/smsc9420.c b/drivers/net/ethernet/smsc/smsc9420.c
index 4f15680849ff..edb24b0e337b 100644
--- a/drivers/net/ethernet/smsc/smsc9420.c
+++ b/drivers/net/ethernet/smsc/smsc9420.c
@@ -28,6 +28,7 @@
28#include <linux/dma-mapping.h> 28#include <linux/dma-mapping.h>
29#include <linux/crc32.h> 29#include <linux/crc32.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/module.h>
31#include <asm/unaligned.h> 32#include <asm/unaligned.h>
32#include "smsc9420.h" 33#include "smsc9420.h"
33 34
diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig
index ac6f190743dd..22745d7bf530 100644
--- a/drivers/net/ethernet/stmicro/stmmac/Kconfig
+++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig
@@ -29,15 +29,6 @@ config STMMAC_DA
29 By default, the DMA arbitration scheme is based on Round-robin 29 By default, the DMA arbitration scheme is based on Round-robin
30 (rx:tx priority is 1:1). 30 (rx:tx priority is 1:1).
31 31
32config STMMAC_DUAL_MAC
33 bool "STMMAC: dual mac support (EXPERIMENTAL)"
34 default n
35 depends on EXPERIMENTAL && STMMAC_ETH && !STMMAC_TIMER
36 ---help---
37 Some ST SoCs (for example the stx7141 and stx7200c2) have two
38 Ethernet Controllers. This option turns on the second Ethernet
39 device on this kind of platforms.
40
41config STMMAC_TIMER 32config STMMAC_TIMER
42 bool "STMMAC Timer optimisation" 33 bool "STMMAC Timer optimisation"
43 default n 34 default n
diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
index ddb33cfd3543..7bf1e2015784 100644
--- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
+++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
@@ -1674,6 +1674,9 @@ static int __devinit ps3_gelic_driver_probe(struct ps3_system_bus_device *dev)
1674 int result; 1674 int result;
1675 1675
1676 pr_debug("%s: called\n", __func__); 1676 pr_debug("%s: called\n", __func__);
1677
1678 udbg_shutdown_ps3gelic();
1679
1677 result = ps3_open_hv_device(dev); 1680 result = ps3_open_hv_device(dev);
1678 1681
1679 if (result) { 1682 if (result) {
diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.h b/drivers/net/ethernet/toshiba/ps3_gelic_net.h
index d3fadfbc3bcc..a93df6ac1909 100644
--- a/drivers/net/ethernet/toshiba/ps3_gelic_net.h
+++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.h
@@ -359,6 +359,12 @@ static inline void *port_priv(struct gelic_port *port)
359 return port->priv; 359 return port->priv;
360} 360}
361 361
362#ifdef CONFIG_PPC_EARLY_DEBUG_PS3GELIC
363extern void udbg_shutdown_ps3gelic(void);
364#else
365static inline void udbg_shutdown_ps3gelic(void) {}
366#endif
367
362extern int gelic_card_set_irq_mask(struct gelic_card *card, u64 mask); 368extern int gelic_card_set_irq_mask(struct gelic_card *card, u64 mask);
363/* shared netdev ops */ 369/* shared netdev ops */
364extern void gelic_card_up(struct gelic_card *card); 370extern void gelic_card_up(struct gelic_card *card);
diff --git a/drivers/net/ethernet/xilinx/ll_temac_main.c b/drivers/net/ethernet/xilinx/ll_temac_main.c
index 4d1658e78dee..caf3659e173c 100644
--- a/drivers/net/ethernet/xilinx/ll_temac_main.c
+++ b/drivers/net/ethernet/xilinx/ll_temac_main.c
@@ -716,8 +716,8 @@ static int temac_start_xmit(struct sk_buff *skb, struct net_device *ndev)
716 cur_p = &lp->tx_bd_v[lp->tx_bd_tail]; 716 cur_p = &lp->tx_bd_v[lp->tx_bd_tail];
717 cur_p->phys = dma_map_single(ndev->dev.parent, 717 cur_p->phys = dma_map_single(ndev->dev.parent,
718 skb_frag_address(frag), 718 skb_frag_address(frag),
719 frag_size(frag), DMA_TO_DEVICE); 719 skb_frag_size(frag), DMA_TO_DEVICE);
720 cur_p->len = frag_size(frag); 720 cur_p->len = skb_frag_size(frag);
721 cur_p->app0 = 0; 721 cur_p->app0 = 0;
722 frag++; 722 frag++;
723 } 723 }
diff --git a/drivers/net/ethernet/xscale/ixp4xx_eth.c b/drivers/net/ethernet/xscale/ixp4xx_eth.c
index ec96d910e9a3..f45c85a84261 100644
--- a/drivers/net/ethernet/xscale/ixp4xx_eth.c
+++ b/drivers/net/ethernet/xscale/ixp4xx_eth.c
@@ -35,6 +35,7 @@
35#include <linux/platform_device.h> 35#include <linux/platform_device.h>
36#include <linux/ptp_classify.h> 36#include <linux/ptp_classify.h>
37#include <linux/slab.h> 37#include <linux/slab.h>
38#include <linux/module.h>
38#include <mach/ixp46x_ts.h> 39#include <mach/ixp46x_ts.h>
39#include <mach/npe.h> 40#include <mach/npe.h>
40#include <mach/qmgr.h> 41#include <mach/qmgr.h>
diff --git a/drivers/net/irda/Kconfig b/drivers/net/irda/Kconfig
index a40fab44b9ae..d423d18b4ad6 100644
--- a/drivers/net/irda/Kconfig
+++ b/drivers/net/irda/Kconfig
@@ -314,7 +314,7 @@ config TOSHIBA_FIR
314 314
315config AU1000_FIR 315config AU1000_FIR
316 tristate "Alchemy Au1000 SIR/FIR" 316 tristate "Alchemy Au1000 SIR/FIR"
317 depends on SOC_AU1000 && IRDA 317 depends on IRDA && MIPS_ALCHEMY
318 318
319config SMC_IRCC_FIR 319config SMC_IRCC_FIR
320 tristate "SMSC IrCC (EXPERIMENTAL)" 320 tristate "SMSC IrCC (EXPERIMENTAL)"
diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c
index a4eae750a414..f414ffb5b728 100644
--- a/drivers/net/phy/realtek.c
+++ b/drivers/net/phy/realtek.c
@@ -14,6 +14,7 @@
14 * 14 *
15 */ 15 */
16#include <linux/phy.h> 16#include <linux/phy.h>
17#include <linux/module.h>
17 18
18#define RTL821x_PHYSR 0x11 19#define RTL821x_PHYSR 0x11
19#define RTL821x_PHYSR_DUPLEX 0x2000 20#define RTL821x_PHYSR_DUPLEX 0x2000
diff --git a/drivers/net/rionet.c b/drivers/net/rionet.c
index 3bb131137033..7145714a5ec9 100644
--- a/drivers/net/rionet.c
+++ b/drivers/net/rionet.c
@@ -88,8 +88,8 @@ static struct rio_dev **rionet_active;
88#define dev_rionet_capable(dev) \ 88#define dev_rionet_capable(dev) \
89 is_rionet_capable(dev->src_ops, dev->dst_ops) 89 is_rionet_capable(dev->src_ops, dev->dst_ops)
90 90
91#define RIONET_MAC_MATCH(x) (*(u32 *)x == 0x00010001) 91#define RIONET_MAC_MATCH(x) (!memcmp((x), "\00\01\00\01", 4))
92#define RIONET_GET_DESTID(x) (*(u16 *)(x + 4)) 92#define RIONET_GET_DESTID(x) ((*((u8 *)x + 4) << 8) | *((u8 *)x + 5))
93 93
94static int rionet_rx_clean(struct net_device *ndev) 94static int rionet_rx_clean(struct net_device *ndev)
95{ 95{
diff --git a/drivers/net/usb/lg-vl600.c b/drivers/net/usb/lg-vl600.c
index 1e7221951056..d43db32f9478 100644
--- a/drivers/net/usb/lg-vl600.c
+++ b/drivers/net/usb/lg-vl600.c
@@ -27,6 +27,7 @@
27#include <linux/if_ether.h> 27#include <linux/if_ether.h>
28#include <linux/if_arp.h> 28#include <linux/if_arp.h>
29#include <linux/inetdevice.h> 29#include <linux/inetdevice.h>
30#include <linux/module.h>
30 31
31/* 32/*
32 * The device has a CDC ACM port for modem control (it claims to be 33 * The device has a CDC ACM port for modem control (it claims to be
diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index 5b23767ea817..ef883e97cee0 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -17,6 +17,7 @@
17#include <net/dst.h> 17#include <net/dst.h>
18#include <net/xfrm.h> 18#include <net/xfrm.h>
19#include <linux/veth.h> 19#include <linux/veth.h>
20#include <linux/module.h>
20 21
21#define DRV_NAME "veth" 22#define DRV_NAME "veth"
22#define DRV_VERSION "1.0" 23#define DRV_VERSION "1.0"
diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
index 91039ab16728..6ee8410443c4 100644
--- a/drivers/net/virtio_net.c
+++ b/drivers/net/virtio_net.c
@@ -925,12 +925,10 @@ static void virtnet_update_status(struct virtnet_info *vi)
925{ 925{
926 u16 v; 926 u16 v;
927 927
928 if (!virtio_has_feature(vi->vdev, VIRTIO_NET_F_STATUS)) 928 if (virtio_config_val(vi->vdev, VIRTIO_NET_F_STATUS,
929 return;
930
931 vi->vdev->config->get(vi->vdev,
932 offsetof(struct virtio_net_config, status), 929 offsetof(struct virtio_net_config, status),
933 &v, sizeof(v)); 930 &v) < 0)
931 return;
934 932
935 /* Ignore unknown (future) status bits */ 933 /* Ignore unknown (future) status bits */
936 v &= VIRTIO_NET_S_LINK_UP; 934 v &= VIRTIO_NET_S_LINK_UP;
@@ -1006,11 +1004,9 @@ static int virtnet_probe(struct virtio_device *vdev)
1006 } 1004 }
1007 1005
1008 /* Configuration may specify what MAC to use. Otherwise random. */ 1006 /* Configuration may specify what MAC to use. Otherwise random. */
1009 if (virtio_has_feature(vdev, VIRTIO_NET_F_MAC)) { 1007 if (virtio_config_val_len(vdev, VIRTIO_NET_F_MAC,
1010 vdev->config->get(vdev,
1011 offsetof(struct virtio_net_config, mac), 1008 offsetof(struct virtio_net_config, mac),
1012 dev->dev_addr, dev->addr_len); 1009 dev->dev_addr, dev->addr_len) < 0)
1013 } else
1014 random_ether_addr(dev->dev_addr); 1010 random_ether_addr(dev->dev_addr);
1015 1011
1016 /* Set up our device-specific information */ 1012 /* Set up our device-specific information */
diff --git a/drivers/net/vmxnet3/vmxnet3_drv.c b/drivers/net/vmxnet3/vmxnet3_drv.c
index b771ebac0f01..d96bfb1ac20b 100644
--- a/drivers/net/vmxnet3/vmxnet3_drv.c
+++ b/drivers/net/vmxnet3/vmxnet3_drv.c
@@ -24,6 +24,7 @@
24 * 24 *
25 */ 25 */
26 26
27#include <linux/module.h>
27#include <net/ip6_checksum.h> 28#include <net/ip6_checksum.h>
28 29
29#include "vmxnet3_int.h" 30#include "vmxnet3_int.h"
diff --git a/drivers/net/wimax/i2400m/control.c b/drivers/net/wimax/i2400m/control.c
index 727d728649b7..2fea02b35b2d 100644
--- a/drivers/net/wimax/i2400m/control.c
+++ b/drivers/net/wimax/i2400m/control.c
@@ -78,6 +78,8 @@
78#include <linux/kernel.h> 78#include <linux/kernel.h>
79#include <linux/slab.h> 79#include <linux/slab.h>
80#include <linux/wimax/i2400m.h> 80#include <linux/wimax/i2400m.h>
81#include <linux/export.h>
82#include <linux/moduleparam.h>
81 83
82 84
83#define D_SUBMODULE control 85#define D_SUBMODULE control
diff --git a/drivers/net/wimax/i2400m/debugfs.c b/drivers/net/wimax/i2400m/debugfs.c
index 9c70b5fa3f51..129ba36bd04d 100644
--- a/drivers/net/wimax/i2400m/debugfs.c
+++ b/drivers/net/wimax/i2400m/debugfs.c
@@ -26,6 +26,7 @@
26#include <linux/etherdevice.h> 26#include <linux/etherdevice.h>
27#include <linux/spinlock.h> 27#include <linux/spinlock.h>
28#include <linux/device.h> 28#include <linux/device.h>
29#include <linux/export.h>
29#include "i2400m.h" 30#include "i2400m.h"
30 31
31 32
diff --git a/drivers/net/wimax/i2400m/fw.c b/drivers/net/wimax/i2400m/fw.c
index 85dadd5bf4be..7cbd7d231e11 100644
--- a/drivers/net/wimax/i2400m/fw.c
+++ b/drivers/net/wimax/i2400m/fw.c
@@ -158,6 +158,7 @@
158#include <linux/sched.h> 158#include <linux/sched.h>
159#include <linux/slab.h> 159#include <linux/slab.h>
160#include <linux/usb.h> 160#include <linux/usb.h>
161#include <linux/export.h>
161#include "i2400m.h" 162#include "i2400m.h"
162 163
163 164
diff --git a/drivers/net/wimax/i2400m/netdev.c b/drivers/net/wimax/i2400m/netdev.c
index 2edd8fe1c1f3..64a110604ad3 100644
--- a/drivers/net/wimax/i2400m/netdev.c
+++ b/drivers/net/wimax/i2400m/netdev.c
@@ -76,6 +76,7 @@
76#include <linux/slab.h> 76#include <linux/slab.h>
77#include <linux/netdevice.h> 77#include <linux/netdevice.h>
78#include <linux/ethtool.h> 78#include <linux/ethtool.h>
79#include <linux/export.h>
79#include "i2400m.h" 80#include "i2400m.h"
80 81
81 82
diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
index 2f94a872101f..37becfcc98f2 100644
--- a/drivers/net/wimax/i2400m/rx.c
+++ b/drivers/net/wimax/i2400m/rx.c
@@ -149,6 +149,8 @@
149#include <linux/if_arp.h> 149#include <linux/if_arp.h>
150#include <linux/netdevice.h> 150#include <linux/netdevice.h>
151#include <linux/workqueue.h> 151#include <linux/workqueue.h>
152#include <linux/export.h>
153#include <linux/moduleparam.h>
152#include "i2400m.h" 154#include "i2400m.h"
153 155
154 156
diff --git a/drivers/net/wimax/i2400m/sdio.c b/drivers/net/wimax/i2400m/sdio.c
index be428cae28d8..21a9edd6e75d 100644
--- a/drivers/net/wimax/i2400m/sdio.c
+++ b/drivers/net/wimax/i2400m/sdio.c
@@ -55,6 +55,7 @@
55#include <linux/mmc/sdio_func.h> 55#include <linux/mmc/sdio_func.h>
56#include "i2400m-sdio.h" 56#include "i2400m-sdio.h"
57#include <linux/wimax/i2400m.h> 57#include <linux/wimax/i2400m.h>
58#include <linux/module.h>
58 59
59#define D_SUBMODULE main 60#define D_SUBMODULE main
60#include "sdio-debug-levels.h" 61#include "sdio-debug-levels.h"
diff --git a/drivers/net/wimax/i2400m/tx.c b/drivers/net/wimax/i2400m/tx.c
index 4b30ed11d785..4b9ecb20deec 100644
--- a/drivers/net/wimax/i2400m/tx.c
+++ b/drivers/net/wimax/i2400m/tx.c
@@ -245,6 +245,7 @@
245 */ 245 */
246#include <linux/netdevice.h> 246#include <linux/netdevice.h>
247#include <linux/slab.h> 247#include <linux/slab.h>
248#include <linux/export.h>
248#include "i2400m.h" 249#include "i2400m.h"
249 250
250 251
diff --git a/drivers/net/wimax/i2400m/usb.c b/drivers/net/wimax/i2400m/usb.c
index 9a644d052f1e..2c1b8b687646 100644
--- a/drivers/net/wimax/i2400m/usb.c
+++ b/drivers/net/wimax/i2400m/usb.c
@@ -67,6 +67,7 @@
67#include <linux/wimax/i2400m.h> 67#include <linux/wimax/i2400m.h>
68#include <linux/debugfs.h> 68#include <linux/debugfs.h>
69#include <linux/slab.h> 69#include <linux/slab.h>
70#include <linux/module.h>
70 71
71 72
72#define D_SUBMODULE usb 73#define D_SUBMODULE usb
diff --git a/drivers/net/wireless/adm8211.c b/drivers/net/wireless/adm8211.c
index 3b752d9fb3cd..f5ce5623da99 100644
--- a/drivers/net/wireless/adm8211.c
+++ b/drivers/net/wireless/adm8211.c
@@ -25,6 +25,7 @@
25#include <linux/delay.h> 25#include <linux/delay.h>
26#include <linux/crc32.h> 26#include <linux/crc32.h>
27#include <linux/eeprom_93cx6.h> 27#include <linux/eeprom_93cx6.h>
28#include <linux/module.h>
28#include <net/mac80211.h> 29#include <net/mac80211.h>
29 30
30#include "adm8211.h" 31#include "adm8211.h"
diff --git a/drivers/net/wireless/ath/Kconfig b/drivers/net/wireless/ath/Kconfig
index 073548836413..09602241901b 100644
--- a/drivers/net/wireless/ath/Kconfig
+++ b/drivers/net/wireless/ath/Kconfig
@@ -1,6 +1,6 @@
1menuconfig ATH_COMMON 1menuconfig ATH_COMMON
2 tristate "Atheros Wireless Cards" 2 tristate "Atheros Wireless Cards"
3 depends on CFG80211 3 depends on CFG80211 && (!UML || BROKEN)
4 ---help--- 4 ---help---
5 This will enable the support for the Atheros wireless drivers. 5 This will enable the support for the Atheros wireless drivers.
6 ath5k, ath9k, ath9k_htc and ar9170 drivers share some common code, this option 6 ath5k, ath9k, ath9k_htc and ar9170 drivers share some common code, this option
diff --git a/drivers/net/wireless/ath/ath5k/debug.c b/drivers/net/wireless/ath/ath5k/debug.c
index fce8c904eea9..8c5ce8b0c734 100644
--- a/drivers/net/wireless/ath/ath5k/debug.c
+++ b/drivers/net/wireless/ath/ath5k/debug.c
@@ -57,8 +57,9 @@
57 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 57 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
58 * THE POSSIBILITY OF SUCH DAMAGES. 58 * THE POSSIBILITY OF SUCH DAMAGES.
59 */ 59 */
60#include <linux/export.h>
61#include <linux/moduleparam.h>
60 62
61#include <linux/module.h>
62#include <linux/seq_file.h> 63#include <linux/seq_file.h>
63#include <linux/list.h> 64#include <linux/list.h>
64#include "debug.h" 65#include "debug.h"
diff --git a/drivers/net/wireless/ath/ath5k/pci.c b/drivers/net/wireless/ath/ath5k/pci.c
index c1dff2ced044..dfa48eb7d953 100644
--- a/drivers/net/wireless/ath/ath5k/pci.c
+++ b/drivers/net/wireless/ath/ath5k/pci.c
@@ -18,6 +18,7 @@
18#include <linux/pci.h> 18#include <linux/pci.h>
19#include <linux/pci-aspm.h> 19#include <linux/pci-aspm.h>
20#include <linux/etherdevice.h> 20#include <linux/etherdevice.h>
21#include <linux/module.h>
21#include "../ath.h" 22#include "../ath.h"
22#include "ath5k.h" 23#include "ath5k.h"
23#include "debug.h" 24#include "debug.h"
diff --git a/drivers/net/wireless/ath/ath6kl/cfg80211.c b/drivers/net/wireless/ath/ath6kl/cfg80211.c
index 3aff36bad5d3..f517eb8f7b44 100644
--- a/drivers/net/wireless/ath/ath6kl/cfg80211.c
+++ b/drivers/net/wireless/ath/ath6kl/cfg80211.c
@@ -14,6 +14,8 @@
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */ 15 */
16 16
17#include <linux/moduleparam.h>
18
17#include "core.h" 19#include "core.h"
18#include "cfg80211.h" 20#include "cfg80211.h"
19#include "debug.h" 21#include "debug.h"
diff --git a/drivers/net/wireless/ath/ath6kl/debug.c b/drivers/net/wireless/ath/ath6kl/debug.c
index ba3f23d71150..7879b5314285 100644
--- a/drivers/net/wireless/ath/ath6kl/debug.c
+++ b/drivers/net/wireless/ath/ath6kl/debug.c
@@ -19,6 +19,7 @@
19#include <linux/circ_buf.h> 19#include <linux/circ_buf.h>
20#include <linux/fs.h> 20#include <linux/fs.h>
21#include <linux/vmalloc.h> 21#include <linux/vmalloc.h>
22#include <linux/export.h>
22 23
23#include "debug.h" 24#include "debug.h"
24#include "target.h" 25#include "target.h"
diff --git a/drivers/net/wireless/ath/ath6kl/sdio.c b/drivers/net/wireless/ath/ath6kl/sdio.c
index f1dc311ee0c7..066d4f88807f 100644
--- a/drivers/net/wireless/ath/ath6kl/sdio.c
+++ b/drivers/net/wireless/ath/ath6kl/sdio.c
@@ -14,6 +14,7 @@
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */ 15 */
16 16
17#include <linux/module.h>
17#include <linux/mmc/card.h> 18#include <linux/mmc/card.h>
18#include <linux/mmc/mmc.h> 19#include <linux/mmc/mmc.h>
19#include <linux/mmc/host.h> 20#include <linux/mmc/host.h>
diff --git a/drivers/net/wireless/ath/ath9k/ahb.c b/drivers/net/wireless/ath/ath9k/ahb.c
index 85a54cd2b083..5e47ca6d16a8 100644
--- a/drivers/net/wireless/ath/ath9k/ahb.c
+++ b/drivers/net/wireless/ath/ath9k/ahb.c
@@ -19,6 +19,7 @@
19#include <linux/nl80211.h> 19#include <linux/nl80211.h>
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/ath9k_platform.h> 21#include <linux/ath9k_platform.h>
22#include <linux/module.h>
22#include "ath9k.h" 23#include "ath9k.h"
23 24
24static const struct platform_device_id ath9k_platform_id_table[] = { 25static const struct platform_device_id ath9k_platform_id_table[] = {
diff --git a/drivers/net/wireless/ath/ath9k/ani.c b/drivers/net/wireless/ath/ath9k/ani.c
index 2776c3c1f506..a639b94f7643 100644
--- a/drivers/net/wireless/ath/ath9k/ani.c
+++ b/drivers/net/wireless/ath/ath9k/ani.c
@@ -15,6 +15,7 @@
15 */ 15 */
16 16
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18#include <linux/export.h>
18#include "hw.h" 19#include "hw.h"
19#include "hw-ops.h" 20#include "hw-ops.h"
20 21
diff --git a/drivers/net/wireless/ath/ath9k/ar9002_hw.c b/drivers/net/wireless/ath/ath9k/ar9002_hw.c
index 626d547d2f06..11f192a1ceb7 100644
--- a/drivers/net/wireless/ath/ath9k/ar9002_hw.c
+++ b/drivers/net/wireless/ath/ath9k/ar9002_hw.c
@@ -14,6 +14,7 @@
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */ 15 */
16 16
17#include <linux/moduleparam.h>
17#include "hw.h" 18#include "hw.h"
18#include "ar5008_initvals.h" 19#include "ar5008_initvals.h"
19#include "ar9001_initvals.h" 20#include "ar9001_initvals.h"
diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
index f7d8e516a2a9..b5920168606d 100644
--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
@@ -15,6 +15,7 @@
15 */ 15 */
16 16
17#include "hw.h" 17#include "hw.h"
18#include <linux/export.h>
18 19
19#define AR_BufLen 0x00000fff 20#define AR_BufLen 0x00000fff
20 21
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
index b363cc06cfd9..ccde784a842f 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
@@ -13,6 +13,7 @@
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */ 15 */
16#include <linux/export.h>
16#include "hw.h" 17#include "hw.h"
17#include "ar9003_mac.h" 18#include "ar9003_mac.h"
18 19
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_paprd.c b/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
index 0c462c904cbe..a4450cba0653 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_paprd.c
@@ -14,6 +14,7 @@
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */ 15 */
16 16
17#include <linux/export.h>
17#include "hw.h" 18#include "hw.h"
18#include "ar9003_phy.h" 19#include "ar9003_phy.h"
19 20
diff --git a/drivers/net/wireless/ath/ath9k/ar9003_phy.c b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
index fe96997921d3..2330e7ede199 100644
--- a/drivers/net/wireless/ath/ath9k/ar9003_phy.c
+++ b/drivers/net/wireless/ath/ath9k/ar9003_phy.c
@@ -14,6 +14,7 @@
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */ 15 */
16 16
17#include <linux/export.h>
17#include "hw.h" 18#include "hw.h"
18#include "ar9003_phy.h" 19#include "ar9003_phy.h"
19 20
diff --git a/drivers/net/wireless/ath/ath9k/btcoex.c b/drivers/net/wireless/ath/ath9k/btcoex.c
index 6635c377dc00..012263968d64 100644
--- a/drivers/net/wireless/ath/ath9k/btcoex.c
+++ b/drivers/net/wireless/ath/ath9k/btcoex.c
@@ -14,6 +14,7 @@
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */ 15 */
16 16
17#include <linux/export.h>
17#include "hw.h" 18#include "hw.h"
18 19
19enum ath_bt_mode { 20enum ath_bt_mode {
diff --git a/drivers/net/wireless/ath/ath9k/calib.c b/drivers/net/wireless/ath/ath9k/calib.c
index ebaf304f464b..99538810a312 100644
--- a/drivers/net/wireless/ath/ath9k/calib.c
+++ b/drivers/net/wireless/ath/ath9k/calib.c
@@ -16,6 +16,7 @@
16 16
17#include "hw.h" 17#include "hw.h"
18#include "hw-ops.h" 18#include "hw-ops.h"
19#include <linux/export.h>
19 20
20/* Common calibration code */ 21/* Common calibration code */
21 22
diff --git a/drivers/net/wireless/ath/ath9k/debug.c b/drivers/net/wireless/ath/ath9k/debug.c
index 327aa28f6030..2741203e803f 100644
--- a/drivers/net/wireless/ath/ath9k/debug.c
+++ b/drivers/net/wireless/ath/ath9k/debug.c
@@ -16,6 +16,7 @@
16 16
17#include <linux/slab.h> 17#include <linux/slab.h>
18#include <linux/vmalloc.h> 18#include <linux/vmalloc.h>
19#include <linux/export.h>
19#include <asm/unaligned.h> 20#include <asm/unaligned.h>
20 21
21#include "ath9k.h" 22#include "ath9k.h"
diff --git a/drivers/net/wireless/ath/ath9k/hw.c b/drivers/net/wireless/ath/ath9k/hw.c
index f16d2033081f..4952ad8c4e8c 100644
--- a/drivers/net/wireless/ath/ath9k/hw.c
+++ b/drivers/net/wireless/ath/ath9k/hw.c
@@ -16,6 +16,7 @@
16 16
17#include <linux/io.h> 17#include <linux/io.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/module.h>
19#include <asm/unaligned.h> 20#include <asm/unaligned.h>
20 21
21#include "hw.h" 22#include "hw.h"
diff --git a/drivers/net/wireless/ath/ath9k/init.c b/drivers/net/wireless/ath/ath9k/init.c
index af1b32549531..d4c909f8e474 100644
--- a/drivers/net/wireless/ath/ath9k/init.c
+++ b/drivers/net/wireless/ath/ath9k/init.c
@@ -17,6 +17,7 @@
17#include <linux/dma-mapping.h> 17#include <linux/dma-mapping.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/ath9k_platform.h> 19#include <linux/ath9k_platform.h>
20#include <linux/module.h>
20 21
21#include "ath9k.h" 22#include "ath9k.h"
22 23
diff --git a/drivers/net/wireless/ath/ath9k/mac.c b/drivers/net/wireless/ath/ath9k/mac.c
index 6a8fdf33a527..ecdb6fd29079 100644
--- a/drivers/net/wireless/ath/ath9k/mac.c
+++ b/drivers/net/wireless/ath/ath9k/mac.c
@@ -16,6 +16,7 @@
16 16
17#include "hw.h" 17#include "hw.h"
18#include "hw-ops.h" 18#include "hw-ops.h"
19#include <linux/export.h>
19 20
20static void ath9k_hw_set_txq_interrupts(struct ath_hw *ah, 21static void ath9k_hw_set_txq_interrupts(struct ath_hw *ah,
21 struct ath9k_tx_queue_info *qi) 22 struct ath9k_tx_queue_info *qi)
diff --git a/drivers/net/wireless/ath/ath9k/pci.c b/drivers/net/wireless/ath/ath9k/pci.c
index edb0b4b3da3a..2dcdf63cb390 100644
--- a/drivers/net/wireless/ath/ath9k/pci.c
+++ b/drivers/net/wireless/ath/ath9k/pci.c
@@ -18,6 +18,7 @@
18#include <linux/pci.h> 18#include <linux/pci.h>
19#include <linux/pci-aspm.h> 19#include <linux/pci-aspm.h>
20#include <linux/ath9k_platform.h> 20#include <linux/ath9k_platform.h>
21#include <linux/module.h>
21#include "ath9k.h" 22#include "ath9k.h"
22 23
23static DEFINE_PCI_DEVICE_TABLE(ath_pci_id_table) = { 24static DEFINE_PCI_DEVICE_TABLE(ath_pci_id_table) = {
diff --git a/drivers/net/wireless/ath/ath9k/rc.c b/drivers/net/wireless/ath/ath9k/rc.c
index 8448281dd069..888abc2be3a5 100644
--- a/drivers/net/wireless/ath/ath9k/rc.c
+++ b/drivers/net/wireless/ath/ath9k/rc.c
@@ -16,6 +16,7 @@
16 */ 16 */
17 17
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/export.h>
19 20
20#include "ath9k.h" 21#include "ath9k.h"
21 22
diff --git a/drivers/net/wireless/ath/carl9170/fw.c b/drivers/net/wireless/ath/carl9170/fw.c
index f4cae1cccbff..cba9d0435dc4 100644
--- a/drivers/net/wireless/ath/carl9170/fw.c
+++ b/drivers/net/wireless/ath/carl9170/fw.c
@@ -23,6 +23,7 @@
23#include <linux/kernel.h> 23#include <linux/kernel.h>
24#include <linux/firmware.h> 24#include <linux/firmware.h>
25#include <linux/crc32.h> 25#include <linux/crc32.h>
26#include <linux/module.h>
26#include "carl9170.h" 27#include "carl9170.h"
27#include "fwcmd.h" 28#include "fwcmd.h"
28#include "version.h" 29#include "version.h"
diff --git a/drivers/net/wireless/ath/debug.c b/drivers/net/wireless/ath/debug.c
index 5367b1086e09..508eccf5d982 100644
--- a/drivers/net/wireless/ath/debug.c
+++ b/drivers/net/wireless/ath/debug.c
@@ -14,6 +14,7 @@
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */ 15 */
16 16
17#include <linux/export.h>
17#include "ath.h" 18#include "ath.h"
18 19
19const char *ath_opmode_to_string(enum nl80211_iftype opmode) 20const char *ath_opmode_to_string(enum nl80211_iftype opmode)
diff --git a/drivers/net/wireless/ath/hw.c b/drivers/net/wireless/ath/hw.c
index 3f508e59f146..19befb331073 100644
--- a/drivers/net/wireless/ath/hw.c
+++ b/drivers/net/wireless/ath/hw.c
@@ -14,6 +14,7 @@
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */ 15 */
16 16
17#include <linux/export.h>
17#include <asm/unaligned.h> 18#include <asm/unaligned.h>
18 19
19#include "ath.h" 20#include "ath.h"
diff --git a/drivers/net/wireless/ath/key.c b/drivers/net/wireless/ath/key.c
index 17b0efd86f9a..4cf7c5eb4813 100644
--- a/drivers/net/wireless/ath/key.c
+++ b/drivers/net/wireless/ath/key.c
@@ -15,6 +15,7 @@
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */ 16 */
17 17
18#include <linux/export.h>
18#include <asm/unaligned.h> 19#include <asm/unaligned.h>
19#include <net/mac80211.h> 20#include <net/mac80211.h>
20 21
diff --git a/drivers/net/wireless/ath/regd.c b/drivers/net/wireless/ath/regd.c
index 028310f263c8..85fa9cc73502 100644
--- a/drivers/net/wireless/ath/regd.c
+++ b/drivers/net/wireless/ath/regd.c
@@ -15,6 +15,7 @@
15 */ 15 */
16 16
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18#include <linux/export.h>
18#include <net/cfg80211.h> 19#include <net/cfg80211.h>
19#include <net/mac80211.h> 20#include <net/mac80211.h>
20#include "regd.h" 21#include "regd.h"
diff --git a/drivers/net/wireless/b43/main.c b/drivers/net/wireless/b43/main.c
index 7cf4125a1624..5634d9a9965b 100644
--- a/drivers/net/wireless/b43/main.c
+++ b/drivers/net/wireless/b43/main.c
@@ -34,7 +34,7 @@
34 34
35#include <linux/delay.h> 35#include <linux/delay.h>
36#include <linux/init.h> 36#include <linux/init.h>
37#include <linux/moduleparam.h> 37#include <linux/module.h>
38#include <linux/if_arp.h> 38#include <linux/if_arp.h>
39#include <linux/etherdevice.h> 39#include <linux/etherdevice.h>
40#include <linux/firmware.h> 40#include <linux/firmware.h>
diff --git a/drivers/net/wireless/b43/pcmcia.c b/drivers/net/wireless/b43/pcmcia.c
index 12b6b4067a39..714cad649c45 100644
--- a/drivers/net/wireless/b43/pcmcia.c
+++ b/drivers/net/wireless/b43/pcmcia.c
@@ -25,6 +25,7 @@
25 25
26#include <linux/ssb/ssb.h> 26#include <linux/ssb/ssb.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/module.h>
28 29
29#include <pcmcia/cistpl.h> 30#include <pcmcia/cistpl.h>
30#include <pcmcia/ciscode.h> 31#include <pcmcia/ciscode.h>
diff --git a/drivers/net/wireless/b43legacy/main.c b/drivers/net/wireless/b43legacy/main.c
index a3b72cd72c66..20f02437af8c 100644
--- a/drivers/net/wireless/b43legacy/main.c
+++ b/drivers/net/wireless/b43legacy/main.c
@@ -31,7 +31,7 @@
31 31
32#include <linux/delay.h> 32#include <linux/delay.h>
33#include <linux/init.h> 33#include <linux/init.h>
34#include <linux/moduleparam.h> 34#include <linux/module.h>
35#include <linux/if_arp.h> 35#include <linux/if_arp.h>
36#include <linux/etherdevice.h> 36#include <linux/etherdevice.h>
37#include <linux/firmware.h> 37#include <linux/firmware.h>
diff --git a/drivers/net/wireless/brcm80211/brcmfmac/bcmsdh.c b/drivers/net/wireless/brcm80211/brcmfmac/bcmsdh.c
index bff9dcd6fadc..89ff94da556a 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/bcmsdh.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/bcmsdh.c
@@ -17,6 +17,7 @@
17 17
18#include <linux/types.h> 18#include <linux/types.h>
19#include <linux/netdevice.h> 19#include <linux/netdevice.h>
20#include <linux/export.h>
20#include <linux/pci.h> 21#include <linux/pci.h>
21#include <linux/pci_ids.h> 22#include <linux/pci_ids.h>
22#include <linux/sched.h> 23#include <linux/sched.h>
diff --git a/drivers/net/wireless/brcm80211/brcmsmac/mac80211_if.c b/drivers/net/wireless/brcm80211/brcmsmac/mac80211_if.c
index ac8d02bd34f2..0d8a9cdf897a 100644
--- a/drivers/net/wireless/brcm80211/brcmsmac/mac80211_if.c
+++ b/drivers/net/wireless/brcm80211/brcmsmac/mac80211_if.c
@@ -21,6 +21,7 @@
21#include <linux/sched.h> 21#include <linux/sched.h>
22#include <linux/firmware.h> 22#include <linux/firmware.h>
23#include <linux/interrupt.h> 23#include <linux/interrupt.h>
24#include <linux/module.h>
24#include <net/mac80211.h> 25#include <net/mac80211.h>
25#include <defs.h> 26#include <defs.h>
26#include "nicpci.h" 27#include "nicpci.h"
diff --git a/drivers/net/wireless/hostap/hostap_80211_rx.c b/drivers/net/wireless/hostap/hostap_80211_rx.c
index e0b3e8d406b3..df7050abe717 100644
--- a/drivers/net/wireless/hostap/hostap_80211_rx.c
+++ b/drivers/net/wireless/hostap/hostap_80211_rx.c
@@ -1,5 +1,6 @@
1#include <linux/etherdevice.h> 1#include <linux/etherdevice.h>
2#include <linux/slab.h> 2#include <linux/slab.h>
3#include <linux/export.h>
3#include <net/lib80211.h> 4#include <net/lib80211.h>
4#include <linux/if_arp.h> 5#include <linux/if_arp.h>
5 6
diff --git a/drivers/net/wireless/hostap/hostap_80211_tx.c b/drivers/net/wireless/hostap/hostap_80211_tx.c
index c34a3b7f1292..344a981a052e 100644
--- a/drivers/net/wireless/hostap/hostap_80211_tx.c
+++ b/drivers/net/wireless/hostap/hostap_80211_tx.c
@@ -1,4 +1,5 @@
1#include <linux/slab.h> 1#include <linux/slab.h>
2#include <linux/export.h>
2 3
3#include "hostap_80211.h" 4#include "hostap_80211.h"
4#include "hostap_common.h" 5#include "hostap_common.h"
diff --git a/drivers/net/wireless/hostap/hostap_ap.c b/drivers/net/wireless/hostap/hostap_ap.c
index 3d05dc15c6b8..e1f410277242 100644
--- a/drivers/net/wireless/hostap/hostap_ap.c
+++ b/drivers/net/wireless/hostap/hostap_ap.c
@@ -21,6 +21,8 @@
21#include <linux/random.h> 21#include <linux/random.h>
22#include <linux/if_arp.h> 22#include <linux/if_arp.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/export.h>
25#include <linux/moduleparam.h>
24 26
25#include "hostap_wlan.h" 27#include "hostap_wlan.h"
26#include "hostap.h" 28#include "hostap.h"
diff --git a/drivers/net/wireless/hostap/hostap_info.c b/drivers/net/wireless/hostap/hostap_info.c
index d737091cf6ac..47932b28aac1 100644
--- a/drivers/net/wireless/hostap/hostap_info.c
+++ b/drivers/net/wireless/hostap/hostap_info.c
@@ -3,6 +3,7 @@
3#include <linux/if_arp.h> 3#include <linux/if_arp.h>
4#include <linux/sched.h> 4#include <linux/sched.h>
5#include <linux/slab.h> 5#include <linux/slab.h>
6#include <linux/export.h>
6#include "hostap_wlan.h" 7#include "hostap_wlan.h"
7#include "hostap.h" 8#include "hostap.h"
8#include "hostap_ap.h" 9#include "hostap_ap.h"
diff --git a/drivers/net/wireless/hostap/hostap_ioctl.c b/drivers/net/wireless/hostap/hostap_ioctl.c
index 12de46407c71..045a93645a3d 100644
--- a/drivers/net/wireless/hostap/hostap_ioctl.c
+++ b/drivers/net/wireless/hostap/hostap_ioctl.c
@@ -5,6 +5,7 @@
5#include <linux/sched.h> 5#include <linux/sched.h>
6#include <linux/ethtool.h> 6#include <linux/ethtool.h>
7#include <linux/if_arp.h> 7#include <linux/if_arp.h>
8#include <linux/module.h>
8#include <net/lib80211.h> 9#include <net/lib80211.h>
9 10
10#include "hostap_wlan.h" 11#include "hostap_wlan.h"
diff --git a/drivers/net/wireless/hostap/hostap_proc.c b/drivers/net/wireless/hostap/hostap_proc.c
index 005ff25a405f..75ef8f04aabe 100644
--- a/drivers/net/wireless/hostap/hostap_proc.c
+++ b/drivers/net/wireless/hostap/hostap_proc.c
@@ -2,6 +2,7 @@
2 2
3#include <linux/types.h> 3#include <linux/types.h>
4#include <linux/proc_fs.h> 4#include <linux/proc_fs.h>
5#include <linux/export.h>
5#include <net/lib80211.h> 6#include <net/lib80211.h>
6 7
7#include "hostap_wlan.h" 8#include "hostap_wlan.h"
diff --git a/drivers/net/wireless/iwlegacy/iwl-debugfs.c b/drivers/net/wireless/iwlegacy/iwl-debugfs.c
index 996996a71657..1407dca70def 100644
--- a/drivers/net/wireless/iwlegacy/iwl-debugfs.c
+++ b/drivers/net/wireless/iwlegacy/iwl-debugfs.c
@@ -26,6 +26,7 @@
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *****************************************************************************/ 27 *****************************************************************************/
28#include <linux/ieee80211.h> 28#include <linux/ieee80211.h>
29#include <linux/export.h>
29#include <net/mac80211.h> 30#include <net/mac80211.h>
30 31
31 32
diff --git a/drivers/net/wireless/iwlegacy/iwl-rx.c b/drivers/net/wireless/iwlegacy/iwl-rx.c
index 9b5d0abe8be9..f4d21ec22497 100644
--- a/drivers/net/wireless/iwlegacy/iwl-rx.c
+++ b/drivers/net/wireless/iwlegacy/iwl-rx.c
@@ -29,6 +29,7 @@
29 29
30#include <linux/etherdevice.h> 30#include <linux/etherdevice.h>
31#include <linux/slab.h> 31#include <linux/slab.h>
32#include <linux/export.h>
32#include <net/mac80211.h> 33#include <net/mac80211.h>
33#include <asm/unaligned.h> 34#include <asm/unaligned.h>
34#include "iwl-eeprom.h" 35#include "iwl-eeprom.h"
diff --git a/drivers/net/wireless/iwlegacy/iwl-scan.c b/drivers/net/wireless/iwlegacy/iwl-scan.c
index a6b5222fc59e..521b73b527d3 100644
--- a/drivers/net/wireless/iwlegacy/iwl-scan.c
+++ b/drivers/net/wireless/iwlegacy/iwl-scan.c
@@ -28,6 +28,7 @@
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/types.h> 29#include <linux/types.h>
30#include <linux/etherdevice.h> 30#include <linux/etherdevice.h>
31#include <linux/export.h>
31#include <net/mac80211.h> 32#include <net/mac80211.h>
32 33
33#include "iwl-eeprom.h" 34#include "iwl-eeprom.h"
diff --git a/drivers/net/wireless/iwlegacy/iwl-sta.c b/drivers/net/wireless/iwlegacy/iwl-sta.c
index 66f0fb2bbe00..f10df3e2813a 100644
--- a/drivers/net/wireless/iwlegacy/iwl-sta.c
+++ b/drivers/net/wireless/iwlegacy/iwl-sta.c
@@ -31,6 +31,7 @@
31#include <linux/etherdevice.h> 31#include <linux/etherdevice.h>
32#include <linux/sched.h> 32#include <linux/sched.h>
33#include <linux/lockdep.h> 33#include <linux/lockdep.h>
34#include <linux/export.h>
34 35
35#include "iwl-dev.h" 36#include "iwl-dev.h"
36#include "iwl-core.h" 37#include "iwl-core.h"
diff --git a/drivers/net/wireless/iwlegacy/iwl-tx.c b/drivers/net/wireless/iwlegacy/iwl-tx.c
index ef9e268bf8a0..c0dfb1a4e968 100644
--- a/drivers/net/wireless/iwlegacy/iwl-tx.c
+++ b/drivers/net/wireless/iwlegacy/iwl-tx.c
@@ -30,6 +30,7 @@
30#include <linux/etherdevice.h> 30#include <linux/etherdevice.h>
31#include <linux/sched.h> 31#include <linux/sched.h>
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/export.h>
33#include <net/mac80211.h> 34#include <net/mac80211.h>
34#include "iwl-eeprom.h" 35#include "iwl-eeprom.h"
35#include "iwl-dev.h" 36#include "iwl-dev.h"
diff --git a/drivers/net/wireless/iwlwifi/iwl-pci.c b/drivers/net/wireless/iwlwifi/iwl-pci.c
index 3b6cc66365e5..f0c623ade3ff 100644
--- a/drivers/net/wireless/iwlwifi/iwl-pci.c
+++ b/drivers/net/wireless/iwlwifi/iwl-pci.c
@@ -60,6 +60,7 @@
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 * 61 *
62 *****************************************************************************/ 62 *****************************************************************************/
63#include <linux/module.h>
63#include <linux/pci.h> 64#include <linux/pci.h>
64#include <linux/pci-aspm.h> 65#include <linux/pci-aspm.h>
65 66
diff --git a/drivers/net/wireless/iwmc3200wifi/commands.c b/drivers/net/wireless/iwmc3200wifi/commands.c
index 50dee6a0a5ca..bd75078c454b 100644
--- a/drivers/net/wireless/iwmc3200wifi/commands.c
+++ b/drivers/net/wireless/iwmc3200wifi/commands.c
@@ -42,6 +42,7 @@
42#include <linux/ieee80211.h> 42#include <linux/ieee80211.h>
43#include <linux/sched.h> 43#include <linux/sched.h>
44#include <linux/slab.h> 44#include <linux/slab.h>
45#include <linux/moduleparam.h>
45 46
46#include "iwm.h" 47#include "iwm.h"
47#include "bus.h" 48#include "bus.h"
diff --git a/drivers/net/wireless/iwmc3200wifi/debugfs.c b/drivers/net/wireless/iwmc3200wifi/debugfs.c
index 0a0cc9667cd6..87eef5773a02 100644
--- a/drivers/net/wireless/iwmc3200wifi/debugfs.c
+++ b/drivers/net/wireless/iwmc3200wifi/debugfs.c
@@ -25,6 +25,7 @@
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/bitops.h> 26#include <linux/bitops.h>
27#include <linux/debugfs.h> 27#include <linux/debugfs.h>
28#include <linux/export.h>
28 29
29#include "iwm.h" 30#include "iwm.h"
30#include "bus.h" 31#include "bus.h"
diff --git a/drivers/net/wireless/iwmc3200wifi/main.c b/drivers/net/wireless/iwmc3200wifi/main.c
index 362002735b12..98a179f98ea1 100644
--- a/drivers/net/wireless/iwmc3200wifi/main.c
+++ b/drivers/net/wireless/iwmc3200wifi/main.c
@@ -42,6 +42,7 @@
42#include <linux/ieee80211.h> 42#include <linux/ieee80211.h>
43#include <linux/wireless.h> 43#include <linux/wireless.h>
44#include <linux/slab.h> 44#include <linux/slab.h>
45#include <linux/moduleparam.h>
45 46
46#include "iwm.h" 47#include "iwm.h"
47#include "debug.h" 48#include "debug.h"
diff --git a/drivers/net/wireless/iwmc3200wifi/sdio.c b/drivers/net/wireless/iwmc3200wifi/sdio.c
index 56383e7be835..764b40dd24ad 100644
--- a/drivers/net/wireless/iwmc3200wifi/sdio.c
+++ b/drivers/net/wireless/iwmc3200wifi/sdio.c
@@ -63,6 +63,7 @@
63 */ 63 */
64 64
65#include <linux/kernel.h> 65#include <linux/kernel.h>
66#include <linux/module.h>
66#include <linux/slab.h> 67#include <linux/slab.h>
67#include <linux/netdevice.h> 68#include <linux/netdevice.h>
68#include <linux/debugfs.h> 69#include <linux/debugfs.h>
diff --git a/drivers/net/wireless/libertas/cmd.c b/drivers/net/wireless/libertas/cmd.c
index e08ab1de3d9d..d798bcc0d83a 100644
--- a/drivers/net/wireless/libertas/cmd.c
+++ b/drivers/net/wireless/libertas/cmd.c
@@ -8,6 +8,7 @@
8#include <linux/sched.h> 8#include <linux/sched.h>
9#include <linux/slab.h> 9#include <linux/slab.h>
10#include <linux/if_arp.h> 10#include <linux/if_arp.h>
11#include <linux/export.h>
11 12
12#include "decl.h" 13#include "decl.h"
13#include "cfg.h" 14#include "cfg.h"
diff --git a/drivers/net/wireless/libertas/debugfs.c b/drivers/net/wireless/libertas/debugfs.c
index 1af182778844..d8d8f0d0899f 100644
--- a/drivers/net/wireless/libertas/debugfs.c
+++ b/drivers/net/wireless/libertas/debugfs.c
@@ -5,6 +5,7 @@
5#include <linux/mm.h> 5#include <linux/mm.h>
6#include <linux/string.h> 6#include <linux/string.h>
7#include <linux/slab.h> 7#include <linux/slab.h>
8#include <linux/export.h>
8 9
9#include "decl.h" 10#include "decl.h"
10#include "cmd.h" 11#include "cmd.h"
diff --git a/drivers/net/wireless/libertas/if_sdio.c b/drivers/net/wireless/libertas/if_sdio.c
index c962e21762dc..9804ebc892d4 100644
--- a/drivers/net/wireless/libertas/if_sdio.c
+++ b/drivers/net/wireless/libertas/if_sdio.c
@@ -29,7 +29,7 @@
29#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 29#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30 30
31#include <linux/kernel.h> 31#include <linux/kernel.h>
32#include <linux/moduleparam.h> 32#include <linux/module.h>
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include <linux/firmware.h> 34#include <linux/firmware.h>
35#include <linux/netdevice.h> 35#include <linux/netdevice.h>
diff --git a/drivers/net/wireless/libertas/if_spi.c b/drivers/net/wireless/libertas/if_spi.c
index 622ae6de0d8b..11b69b300dc0 100644
--- a/drivers/net/wireless/libertas/if_spi.c
+++ b/drivers/net/wireless/libertas/if_spi.c
@@ -21,7 +21,7 @@
21 21
22#include <linux/hardirq.h> 22#include <linux/hardirq.h>
23#include <linux/interrupt.h> 23#include <linux/interrupt.h>
24#include <linux/moduleparam.h> 24#include <linux/module.h>
25#include <linux/firmware.h> 25#include <linux/firmware.h>
26#include <linux/jiffies.h> 26#include <linux/jiffies.h>
27#include <linux/list.h> 27#include <linux/list.h>
diff --git a/drivers/net/wireless/libertas/if_usb.c b/drivers/net/wireless/libertas/if_usb.c
index 8147f1e2a0b0..db879c364ebf 100644
--- a/drivers/net/wireless/libertas/if_usb.c
+++ b/drivers/net/wireless/libertas/if_usb.c
@@ -5,7 +5,7 @@
5#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 5#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
6 6
7#include <linux/delay.h> 7#include <linux/delay.h>
8#include <linux/moduleparam.h> 8#include <linux/module.h>
9#include <linux/firmware.h> 9#include <linux/firmware.h>
10#include <linux/netdevice.h> 10#include <linux/netdevice.h>
11#include <linux/slab.h> 11#include <linux/slab.h>
diff --git a/drivers/net/wireless/libertas/main.c b/drivers/net/wireless/libertas/main.c
index b03779bcd547..4ae99a40dbf7 100644
--- a/drivers/net/wireless/libertas/main.c
+++ b/drivers/net/wireless/libertas/main.c
@@ -6,7 +6,7 @@
6 6
7#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 7#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
8 8
9#include <linux/moduleparam.h> 9#include <linux/module.h>
10#include <linux/delay.h> 10#include <linux/delay.h>
11#include <linux/etherdevice.h> 11#include <linux/etherdevice.h>
12#include <linux/hardirq.h> 12#include <linux/hardirq.h>
diff --git a/drivers/net/wireless/libertas/rx.c b/drivers/net/wireless/libertas/rx.c
index 62e10eeadd7e..c7366b07b568 100644
--- a/drivers/net/wireless/libertas/rx.c
+++ b/drivers/net/wireless/libertas/rx.c
@@ -8,6 +8,7 @@
8#include <linux/hardirq.h> 8#include <linux/hardirq.h>
9#include <linux/slab.h> 9#include <linux/slab.h>
10#include <linux/types.h> 10#include <linux/types.h>
11#include <linux/export.h>
11#include <net/cfg80211.h> 12#include <net/cfg80211.h>
12 13
13#include "defs.h" 14#include "defs.h"
diff --git a/drivers/net/wireless/libertas/tx.c b/drivers/net/wireless/libertas/tx.c
index 8f127520d786..c025f9c18282 100644
--- a/drivers/net/wireless/libertas/tx.c
+++ b/drivers/net/wireless/libertas/tx.c
@@ -5,6 +5,7 @@
5#include <linux/netdevice.h> 5#include <linux/netdevice.h>
6#include <linux/etherdevice.h> 6#include <linux/etherdevice.h>
7#include <linux/sched.h> 7#include <linux/sched.h>
8#include <linux/export.h>
8#include <net/cfg80211.h> 9#include <net/cfg80211.h>
9 10
10#include "host.h" 11#include "host.h"
diff --git a/drivers/net/wireless/libertas_tf/cmd.c b/drivers/net/wireless/libertas_tf/cmd.c
index 13557fe0bf95..909ac3685010 100644
--- a/drivers/net/wireless/libertas_tf/cmd.c
+++ b/drivers/net/wireless/libertas_tf/cmd.c
@@ -11,6 +11,7 @@
11 11
12#include <linux/hardirq.h> 12#include <linux/hardirq.h>
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/export.h>
14 15
15#include "libertas_tf.h" 16#include "libertas_tf.h"
16 17
diff --git a/drivers/net/wireless/libertas_tf/if_usb.c b/drivers/net/wireless/libertas_tf/if_usb.c
index ba7d96584cb6..68202e63873a 100644
--- a/drivers/net/wireless/libertas_tf/if_usb.c
+++ b/drivers/net/wireless/libertas_tf/if_usb.c
@@ -15,7 +15,7 @@
15#include "if_usb.h" 15#include "if_usb.h"
16 16
17#include <linux/delay.h> 17#include <linux/delay.h>
18#include <linux/moduleparam.h> 18#include <linux/module.h>
19#include <linux/firmware.h> 19#include <linux/firmware.h>
20#include <linux/netdevice.h> 20#include <linux/netdevice.h>
21#include <linux/slab.h> 21#include <linux/slab.h>
diff --git a/drivers/net/wireless/libertas_tf/main.c b/drivers/net/wireless/libertas_tf/main.c
index acc461aa385e..ceb51b6e6702 100644
--- a/drivers/net/wireless/libertas_tf/main.c
+++ b/drivers/net/wireless/libertas_tf/main.c
@@ -13,6 +13,7 @@
13#include <linux/slab.h> 13#include <linux/slab.h>
14 14
15#include <linux/etherdevice.h> 15#include <linux/etherdevice.h>
16#include <linux/module.h>
16#include "libertas_tf.h" 17#include "libertas_tf.h"
17 18
18#define DRIVER_RELEASE_VERSION "004.p0" 19#define DRIVER_RELEASE_VERSION "004.p0"
diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
index 68455a2307cb..523ad55a2885 100644
--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -26,6 +26,7 @@
26#include <linux/rtnetlink.h> 26#include <linux/rtnetlink.h>
27#include <linux/etherdevice.h> 27#include <linux/etherdevice.h>
28#include <linux/debugfs.h> 28#include <linux/debugfs.h>
29#include <linux/module.h>
29#include <net/genetlink.h> 30#include <net/genetlink.h>
30#include "mac80211_hwsim.h" 31#include "mac80211_hwsim.h"
31 32
diff --git a/drivers/net/wireless/orinoco/fw.c b/drivers/net/wireless/orinoco/fw.c
index 527cf5333db5..4df8cf64b56c 100644
--- a/drivers/net/wireless/orinoco/fw.c
+++ b/drivers/net/wireless/orinoco/fw.c
@@ -6,6 +6,7 @@
6#include <linux/slab.h> 6#include <linux/slab.h>
7#include <linux/firmware.h> 7#include <linux/firmware.h>
8#include <linux/device.h> 8#include <linux/device.h>
9#include <linux/module.h>
9 10
10#include "hermes.h" 11#include "hermes.h"
11#include "hermes_dld.h" 12#include "hermes_dld.h"
diff --git a/drivers/net/wireless/p54/eeprom.c b/drivers/net/wireless/p54/eeprom.c
index 8b6f363b3f7d..fa8ce5104781 100644
--- a/drivers/net/wireless/p54/eeprom.c
+++ b/drivers/net/wireless/p54/eeprom.c
@@ -24,6 +24,7 @@
24 24
25#include <net/mac80211.h> 25#include <net/mac80211.h>
26#include <linux/crc-ccitt.h> 26#include <linux/crc-ccitt.h>
27#include <linux/export.h>
27 28
28#include "p54.h" 29#include "p54.h"
29#include "eeprom.h" 30#include "eeprom.h"
diff --git a/drivers/net/wireless/p54/fwio.c b/drivers/net/wireless/p54/fwio.c
index 53a3408931be..18e82b31afa6 100644
--- a/drivers/net/wireless/p54/fwio.c
+++ b/drivers/net/wireless/p54/fwio.c
@@ -20,6 +20,7 @@
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/firmware.h> 21#include <linux/firmware.h>
22#include <linux/etherdevice.h> 22#include <linux/etherdevice.h>
23#include <linux/export.h>
23 24
24#include <net/mac80211.h> 25#include <net/mac80211.h>
25 26
diff --git a/drivers/net/wireless/p54/main.c b/drivers/net/wireless/p54/main.c
index ad9ae04d07aa..db4d9a02f264 100644
--- a/drivers/net/wireless/p54/main.c
+++ b/drivers/net/wireless/p54/main.c
@@ -20,6 +20,7 @@
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/firmware.h> 21#include <linux/firmware.h>
22#include <linux/etherdevice.h> 22#include <linux/etherdevice.h>
23#include <linux/module.h>
23 24
24#include <net/mac80211.h> 25#include <net/mac80211.h>
25 26
diff --git a/drivers/net/wireless/p54/p54pci.c b/drivers/net/wireless/p54/p54pci.c
index 1b753173680f..b1f51a215792 100644
--- a/drivers/net/wireless/p54/p54pci.c
+++ b/drivers/net/wireless/p54/p54pci.c
@@ -20,6 +20,7 @@
20#include <linux/etherdevice.h> 20#include <linux/etherdevice.h>
21#include <linux/delay.h> 21#include <linux/delay.h>
22#include <linux/completion.h> 22#include <linux/completion.h>
23#include <linux/module.h>
23#include <net/mac80211.h> 24#include <net/mac80211.h>
24 25
25#include "p54.h" 26#include "p54.h"
diff --git a/drivers/net/wireless/p54/p54usb.c b/drivers/net/wireless/p54/p54usb.c
index a8f3bc740dfa..9b6096866427 100644
--- a/drivers/net/wireless/p54/p54usb.c
+++ b/drivers/net/wireless/p54/p54usb.c
@@ -20,6 +20,7 @@
20#include <linux/etherdevice.h> 20#include <linux/etherdevice.h>
21#include <linux/delay.h> 21#include <linux/delay.h>
22#include <linux/crc32.h> 22#include <linux/crc32.h>
23#include <linux/module.h>
23#include <net/mac80211.h> 24#include <net/mac80211.h>
24 25
25#include "p54.h" 26#include "p54.h"
diff --git a/drivers/net/wireless/p54/txrx.c b/drivers/net/wireless/p54/txrx.c
index f485784a60ae..6ed9c323e3cb 100644
--- a/drivers/net/wireless/p54/txrx.c
+++ b/drivers/net/wireless/p54/txrx.c
@@ -16,6 +16,7 @@
16 * published by the Free Software Foundation. 16 * published by the Free Software Foundation.
17 */ 17 */
18 18
19#include <linux/export.h>
19#include <linux/init.h> 20#include <linux/init.h>
20#include <linux/firmware.h> 21#include <linux/firmware.h>
21#include <linux/etherdevice.h> 22#include <linux/etherdevice.h>
diff --git a/drivers/net/wireless/rtl818x/rtl8180/dev.c b/drivers/net/wireless/rtl818x/rtl8180/dev.c
index 0082015ff664..2f14a5fb0cbb 100644
--- a/drivers/net/wireless/rtl818x/rtl8180/dev.c
+++ b/drivers/net/wireless/rtl818x/rtl8180/dev.c
@@ -22,6 +22,7 @@
22#include <linux/delay.h> 22#include <linux/delay.h>
23#include <linux/etherdevice.h> 23#include <linux/etherdevice.h>
24#include <linux/eeprom_93cx6.h> 24#include <linux/eeprom_93cx6.h>
25#include <linux/module.h>
25#include <net/mac80211.h> 26#include <net/mac80211.h>
26 27
27#include "rtl8180.h" 28#include "rtl8180.h"
diff --git a/drivers/net/wireless/rtl818x/rtl8187/dev.c b/drivers/net/wireless/rtl818x/rtl8187/dev.c
index 24873b55b55c..4a78f9e39dfa 100644
--- a/drivers/net/wireless/rtl818x/rtl8187/dev.c
+++ b/drivers/net/wireless/rtl818x/rtl8187/dev.c
@@ -26,6 +26,7 @@
26#include <linux/delay.h> 26#include <linux/delay.h>
27#include <linux/etherdevice.h> 27#include <linux/etherdevice.h>
28#include <linux/eeprom_93cx6.h> 28#include <linux/eeprom_93cx6.h>
29#include <linux/module.h>
29#include <net/mac80211.h> 30#include <net/mac80211.h>
30 31
31#include "rtl8187.h" 32#include "rtl8187.h"
diff --git a/drivers/net/wireless/rtlwifi/Kconfig b/drivers/net/wireless/rtlwifi/Kconfig
index 45e14760c16e..d6c42e69bdbd 100644
--- a/drivers/net/wireless/rtlwifi/Kconfig
+++ b/drivers/net/wireless/rtlwifi/Kconfig
@@ -12,7 +12,7 @@ config RTL8192CE
12 12
13config RTL8192SE 13config RTL8192SE
14 tristate "Realtek RTL8192SE/RTL8191SE PCIe Wireless Network Adapter" 14 tristate "Realtek RTL8192SE/RTL8191SE PCIe Wireless Network Adapter"
15 depends on MAC80211 && EXPERIMENTAL 15 depends on MAC80211 && EXPERIMENTAL && PCI
16 select FW_LOADER 16 select FW_LOADER
17 select RTLWIFI 17 select RTLWIFI
18 ---help--- 18 ---help---
@@ -23,7 +23,7 @@ config RTL8192SE
23 23
24config RTL8192DE 24config RTL8192DE
25 tristate "Realtek RTL8192DE/RTL8188DE PCIe Wireless Network Adapter" 25 tristate "Realtek RTL8192DE/RTL8188DE PCIe Wireless Network Adapter"
26 depends on MAC80211 && EXPERIMENTAL 26 depends on MAC80211 && EXPERIMENTAL && PCI
27 select FW_LOADER 27 select FW_LOADER
28 select RTLWIFI 28 select RTLWIFI
29 ---help--- 29 ---help---
diff --git a/drivers/net/wireless/rtlwifi/base.c b/drivers/net/wireless/rtlwifi/base.c
index d4fdd2a5a739..b4ce93436d2e 100644
--- a/drivers/net/wireless/rtlwifi/base.c
+++ b/drivers/net/wireless/rtlwifi/base.c
@@ -30,6 +30,7 @@
30#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 30#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31 31
32#include <linux/ip.h> 32#include <linux/ip.h>
33#include <linux/module.h>
33#include "wifi.h" 34#include "wifi.h"
34#include "rc.h" 35#include "rc.h"
35#include "base.h" 36#include "base.h"
diff --git a/drivers/net/wireless/rtlwifi/cam.c b/drivers/net/wireless/rtlwifi/cam.c
index 7babb6acd957..dc36d7461caa 100644
--- a/drivers/net/wireless/rtlwifi/cam.c
+++ b/drivers/net/wireless/rtlwifi/cam.c
@@ -29,6 +29,7 @@
29 29
30#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 30#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31 31
32#include <linux/export.h>
32#include "wifi.h" 33#include "wifi.h"
33#include "cam.h" 34#include "cam.h"
34 35
diff --git a/drivers/net/wireless/rtlwifi/efuse.c b/drivers/net/wireless/rtlwifi/efuse.c
index 3fc21f60bb04..ed1058b71587 100644
--- a/drivers/net/wireless/rtlwifi/efuse.c
+++ b/drivers/net/wireless/rtlwifi/efuse.c
@@ -27,6 +27,7 @@
27 * 27 *
28 *****************************************************************************/ 28 *****************************************************************************/
29 29
30#include <linux/export.h>
30#include "wifi.h" 31#include "wifi.h"
31#include "efuse.h" 32#include "efuse.h"
32 33
diff --git a/drivers/net/wireless/rtlwifi/pci.c b/drivers/net/wireless/rtlwifi/pci.c
index 177a8e669241..eb61061821e4 100644
--- a/drivers/net/wireless/rtlwifi/pci.c
+++ b/drivers/net/wireless/rtlwifi/pci.c
@@ -27,6 +27,7 @@
27 * 27 *
28 *****************************************************************************/ 28 *****************************************************************************/
29 29
30#include <linux/export.h>
30#include "core.h" 31#include "core.h"
31#include "wifi.h" 32#include "wifi.h"
32#include "pci.h" 33#include "pci.h"
diff --git a/drivers/net/wireless/rtlwifi/ps.c b/drivers/net/wireless/rtlwifi/ps.c
index a693feffbe72..db5262844543 100644
--- a/drivers/net/wireless/rtlwifi/ps.c
+++ b/drivers/net/wireless/rtlwifi/ps.c
@@ -27,6 +27,7 @@
27 * 27 *
28 *****************************************************************************/ 28 *****************************************************************************/
29 29
30#include <linux/export.h>
30#include "wifi.h" 31#include "wifi.h"
31#include "base.h" 32#include "base.h"
32#include "ps.h" 33#include "ps.h"
diff --git a/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c b/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c
index a00774e7090d..72a98cab6f69 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192c/dm_common.c
@@ -27,6 +27,7 @@
27 * 27 *
28 *****************************************************************************/ 28 *****************************************************************************/
29 29
30#include <linux/export.h>
30#include "dm_common.h" 31#include "dm_common.h"
31#include "phy_common.h" 32#include "phy_common.h"
32#include "../pci.h" 33#include "../pci.h"
diff --git a/drivers/net/wireless/rtlwifi/rtl8192c/fw_common.c b/drivers/net/wireless/rtlwifi/rtl8192c/fw_common.c
index 49a064bdbce6..950c65a15b8a 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192c/fw_common.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192c/fw_common.c
@@ -30,6 +30,7 @@
30#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 30#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31 31
32#include <linux/firmware.h> 32#include <linux/firmware.h>
33#include <linux/export.h>
33#include "../wifi.h" 34#include "../wifi.h"
34#include "../pci.h" 35#include "../pci.h"
35#include "../base.h" 36#include "../base.h"
diff --git a/drivers/net/wireless/rtlwifi/rtl8192c/main.c b/drivers/net/wireless/rtlwifi/rtl8192c/main.c
index 2f624fc27499..605ff191aeb7 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192c/main.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192c/main.c
@@ -27,6 +27,7 @@
27 * 27 *
28 *****************************************************************************/ 28 *****************************************************************************/
29 29
30#include <linux/module.h>
30#include "../wifi.h" 31#include "../wifi.h"
31 32
32 33
diff --git a/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c b/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c
index 3b11642d3f7d..1f07558debf2 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192c/phy_common.c
@@ -27,6 +27,7 @@
27 * 27 *
28 *****************************************************************************/ 28 *****************************************************************************/
29 29
30#include <linux/export.h>
30#include "../wifi.h" 31#include "../wifi.h"
31#include "../rtl8192ce/reg.h" 32#include "../rtl8192ce/reg.h"
32#include "../rtl8192ce/def.h" 33#include "../rtl8192ce/def.h"
diff --git a/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c b/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c
index a48404cc2b96..f2aa33dc4d78 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192ce/sw.c
@@ -28,6 +28,7 @@
28 *****************************************************************************/ 28 *****************************************************************************/
29 29
30#include <linux/vmalloc.h> 30#include <linux/vmalloc.h>
31#include <linux/module.h>
31 32
32#include "../wifi.h" 33#include "../wifi.h"
33#include "../core.h" 34#include "../core.h"
diff --git a/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c b/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c
index feed1ed8d9b6..c244f2f1b83f 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192cu/sw.c
@@ -42,6 +42,7 @@
42#include "led.h" 42#include "led.h"
43#include "hw.h" 43#include "hw.h"
44#include <linux/vmalloc.h> 44#include <linux/vmalloc.h>
45#include <linux/module.h>
45 46
46MODULE_AUTHOR("Georgia <georgia@realtek.com>"); 47MODULE_AUTHOR("Georgia <georgia@realtek.com>");
47MODULE_AUTHOR("Ziv Huang <ziv_huang@realtek.com>"); 48MODULE_AUTHOR("Ziv Huang <ziv_huang@realtek.com>");
diff --git a/drivers/net/wireless/rtlwifi/rtl8192de/sw.c b/drivers/net/wireless/rtlwifi/rtl8192de/sw.c
index 691f80092185..149493f4c25c 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192de/sw.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192de/sw.c
@@ -30,6 +30,7 @@
30#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 30#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31 31
32#include <linux/vmalloc.h> 32#include <linux/vmalloc.h>
33#include <linux/module.h>
33 34
34#include "../wifi.h" 35#include "../wifi.h"
35#include "../core.h" 36#include "../core.h"
diff --git a/drivers/net/wireless/rtlwifi/rtl8192se/sw.c b/drivers/net/wireless/rtlwifi/rtl8192se/sw.c
index 3ec9a0d41baf..92f49d522c56 100644
--- a/drivers/net/wireless/rtlwifi/rtl8192se/sw.c
+++ b/drivers/net/wireless/rtlwifi/rtl8192se/sw.c
@@ -30,6 +30,7 @@
30#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 30#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
31 31
32#include <linux/vmalloc.h> 32#include <linux/vmalloc.h>
33#include <linux/module.h>
33 34
34#include "../wifi.h" 35#include "../wifi.h"
35#include "../core.h" 36#include "../core.h"
diff --git a/drivers/net/wireless/rtlwifi/usb.c b/drivers/net/wireless/rtlwifi/usb.c
index b42c2e2b2055..54cb8a60514d 100644
--- a/drivers/net/wireless/rtlwifi/usb.c
+++ b/drivers/net/wireless/rtlwifi/usb.c
@@ -28,6 +28,7 @@
28#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 28#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
29 29
30#include <linux/usb.h> 30#include <linux/usb.h>
31#include <linux/export.h>
31#include "core.h" 32#include "core.h"
32#include "wifi.h" 33#include "wifi.h"
33#include "usb.h" 34#include "usb.h"
diff --git a/drivers/net/wireless/wl12xx/boot.c b/drivers/net/wireless/wl12xx/boot.c
index d4e628db76b0..681337914976 100644
--- a/drivers/net/wireless/wl12xx/boot.c
+++ b/drivers/net/wireless/wl12xx/boot.c
@@ -23,6 +23,7 @@
23 23
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/wl12xx.h> 25#include <linux/wl12xx.h>
26#include <linux/export.h>
26 27
27#include "acx.h" 28#include "acx.h"
28#include "reg.h" 29#include "reg.h"
diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
index cf0d69dd7be5..785bdbe38f2a 100644
--- a/drivers/net/wireless/zd1211rw/zd_usb.c
+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
@@ -28,6 +28,7 @@
28#include <linux/skbuff.h> 28#include <linux/skbuff.h>
29#include <linux/usb.h> 29#include <linux/usb.h>
30#include <linux/workqueue.h> 30#include <linux/workqueue.h>
31#include <linux/module.h>
31#include <net/mac80211.h> 32#include <net/mac80211.h>
32#include <asm/unaligned.h> 33#include <asm/unaligned.h>
33 34
diff --git a/drivers/net/xen-netback/common.h b/drivers/net/xen-netback/common.h
index 161f207786a4..94b79c3338c4 100644
--- a/drivers/net/xen-netback/common.h
+++ b/drivers/net/xen-netback/common.h
@@ -58,10 +58,6 @@ struct xenvif {
58 u8 fe_dev_addr[6]; 58 u8 fe_dev_addr[6];
59 59
60 /* Physical parameters of the comms window. */ 60 /* Physical parameters of the comms window. */
61 grant_handle_t tx_shmem_handle;
62 grant_ref_t tx_shmem_ref;
63 grant_handle_t rx_shmem_handle;
64 grant_ref_t rx_shmem_ref;
65 unsigned int irq; 61 unsigned int irq;
66 62
67 /* List of frontends to notify after a batch of frames sent. */ 63 /* List of frontends to notify after a batch of frames sent. */
@@ -70,8 +66,6 @@ struct xenvif {
70 /* The shared rings and indexes. */ 66 /* The shared rings and indexes. */
71 struct xen_netif_tx_back_ring tx; 67 struct xen_netif_tx_back_ring tx;
72 struct xen_netif_rx_back_ring rx; 68 struct xen_netif_rx_back_ring rx;
73 struct vm_struct *tx_comms_area;
74 struct vm_struct *rx_comms_area;
75 69
76 /* Frontend feature information. */ 70 /* Frontend feature information. */
77 u8 can_sg:1; 71 u8 can_sg:1;
@@ -106,6 +100,11 @@ struct xenvif {
106 wait_queue_head_t waiting_to_free; 100 wait_queue_head_t waiting_to_free;
107}; 101};
108 102
103static inline struct xenbus_device *xenvif_to_xenbus_device(struct xenvif *vif)
104{
105 return to_xenbus_device(vif->dev->dev.parent);
106}
107
109#define XEN_NETIF_TX_RING_SIZE __CONST_RING_SIZE(xen_netif_tx, PAGE_SIZE) 108#define XEN_NETIF_TX_RING_SIZE __CONST_RING_SIZE(xen_netif_tx, PAGE_SIZE)
110#define XEN_NETIF_RX_RING_SIZE __CONST_RING_SIZE(xen_netif_rx, PAGE_SIZE) 109#define XEN_NETIF_RX_RING_SIZE __CONST_RING_SIZE(xen_netif_rx, PAGE_SIZE)
111 110
diff --git a/drivers/net/xen-netback/netback.c b/drivers/net/xen-netback/netback.c
index d5508957200e..0cb594c86090 100644
--- a/drivers/net/xen-netback/netback.c
+++ b/drivers/net/xen-netback/netback.c
@@ -1589,88 +1589,42 @@ static int xen_netbk_kthread(void *data)
1589 1589
1590void xen_netbk_unmap_frontend_rings(struct xenvif *vif) 1590void xen_netbk_unmap_frontend_rings(struct xenvif *vif)
1591{ 1591{
1592 struct gnttab_unmap_grant_ref op; 1592 if (vif->tx.sring)
1593 1593 xenbus_unmap_ring_vfree(xenvif_to_xenbus_device(vif),
1594 if (vif->tx.sring) { 1594 vif->tx.sring);
1595 gnttab_set_unmap_op(&op, (unsigned long)vif->tx_comms_area->addr, 1595 if (vif->rx.sring)
1596 GNTMAP_host_map, vif->tx_shmem_handle); 1596 xenbus_unmap_ring_vfree(xenvif_to_xenbus_device(vif),
1597 1597 vif->rx.sring);
1598 if (HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1))
1599 BUG();
1600 }
1601
1602 if (vif->rx.sring) {
1603 gnttab_set_unmap_op(&op, (unsigned long)vif->rx_comms_area->addr,
1604 GNTMAP_host_map, vif->rx_shmem_handle);
1605
1606 if (HYPERVISOR_grant_table_op(GNTTABOP_unmap_grant_ref, &op, 1))
1607 BUG();
1608 }
1609 if (vif->rx_comms_area)
1610 free_vm_area(vif->rx_comms_area);
1611 if (vif->tx_comms_area)
1612 free_vm_area(vif->tx_comms_area);
1613} 1598}
1614 1599
1615int xen_netbk_map_frontend_rings(struct xenvif *vif, 1600int xen_netbk_map_frontend_rings(struct xenvif *vif,
1616 grant_ref_t tx_ring_ref, 1601 grant_ref_t tx_ring_ref,
1617 grant_ref_t rx_ring_ref) 1602 grant_ref_t rx_ring_ref)
1618{ 1603{
1619 struct gnttab_map_grant_ref op; 1604 void *addr;
1620 struct xen_netif_tx_sring *txs; 1605 struct xen_netif_tx_sring *txs;
1621 struct xen_netif_rx_sring *rxs; 1606 struct xen_netif_rx_sring *rxs;
1622 1607
1623 int err = -ENOMEM; 1608 int err = -ENOMEM;
1624 1609
1625 vif->tx_comms_area = alloc_vm_area(PAGE_SIZE); 1610 err = xenbus_map_ring_valloc(xenvif_to_xenbus_device(vif),
1626 if (vif->tx_comms_area == NULL) 1611 tx_ring_ref, &addr);
1612 if (err)
1627 goto err; 1613 goto err;
1628 1614
1629 vif->rx_comms_area = alloc_vm_area(PAGE_SIZE); 1615 txs = (struct xen_netif_tx_sring *)addr;
1630 if (vif->rx_comms_area == NULL)
1631 goto err;
1632
1633 gnttab_set_map_op(&op, (unsigned long)vif->tx_comms_area->addr,
1634 GNTMAP_host_map, tx_ring_ref, vif->domid);
1635
1636 if (HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1))
1637 BUG();
1638
1639 if (op.status) {
1640 netdev_warn(vif->dev,
1641 "failed to map tx ring. err=%d status=%d\n",
1642 err, op.status);
1643 err = op.status;
1644 goto err;
1645 }
1646
1647 vif->tx_shmem_ref = tx_ring_ref;
1648 vif->tx_shmem_handle = op.handle;
1649
1650 txs = (struct xen_netif_tx_sring *)vif->tx_comms_area->addr;
1651 BACK_RING_INIT(&vif->tx, txs, PAGE_SIZE); 1616 BACK_RING_INIT(&vif->tx, txs, PAGE_SIZE);
1652 1617
1653 gnttab_set_map_op(&op, (unsigned long)vif->rx_comms_area->addr, 1618 err = xenbus_map_ring_valloc(xenvif_to_xenbus_device(vif),
1654 GNTMAP_host_map, rx_ring_ref, vif->domid); 1619 rx_ring_ref, &addr);
1655 1620 if (err)
1656 if (HYPERVISOR_grant_table_op(GNTTABOP_map_grant_ref, &op, 1))
1657 BUG();
1658
1659 if (op.status) {
1660 netdev_warn(vif->dev,
1661 "failed to map rx ring. err=%d status=%d\n",
1662 err, op.status);
1663 err = op.status;
1664 goto err; 1621 goto err;
1665 }
1666
1667 vif->rx_shmem_ref = rx_ring_ref;
1668 vif->rx_shmem_handle = op.handle;
1669 vif->rx_req_cons_peek = 0;
1670 1622
1671 rxs = (struct xen_netif_rx_sring *)vif->rx_comms_area->addr; 1623 rxs = (struct xen_netif_rx_sring *)addr;
1672 BACK_RING_INIT(&vif->rx, rxs, PAGE_SIZE); 1624 BACK_RING_INIT(&vif->rx, rxs, PAGE_SIZE);
1673 1625
1626 vif->rx_req_cons_peek = 0;
1627
1674 return 0; 1628 return 0;
1675 1629
1676err: 1630err:
diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
index 5b0f1ff80361..06c3642e5bdb 100644
--- a/drivers/nfc/nfcwilink.c
+++ b/drivers/nfc/nfcwilink.c
@@ -27,6 +27,7 @@
27 * 27 *
28 */ 28 */
29#include <linux/platform_device.h> 29#include <linux/platform_device.h>
30#include <linux/module.h>
30#include <linux/nfc.h> 31#include <linux/nfc.h>
31#include <net/nfc/nci.h> 32#include <net/nfc/nci.h>
32#include <net/nfc/nci_core.h> 33#include <net/nfc/nci_core.h>
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index aeec35bc3789..fd85fa298e0f 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -681,9 +681,14 @@ int __init early_init_dt_scan_chosen(unsigned long node, const char *uname,
681 if (p != NULL && l > 0) 681 if (p != NULL && l > 0)
682 strlcpy(data, p, min((int)l, COMMAND_LINE_SIZE)); 682 strlcpy(data, p, min((int)l, COMMAND_LINE_SIZE));
683 683
684 /*
685 * CONFIG_CMDLINE is meant to be a default in case nothing else
686 * managed to set the command line, unless CONFIG_CMDLINE_FORCE
687 * is set in which case we override whatever was found earlier.
688 */
684#ifdef CONFIG_CMDLINE 689#ifdef CONFIG_CMDLINE
685#ifndef CONFIG_CMDLINE_FORCE 690#ifndef CONFIG_CMDLINE_FORCE
686 if (p == NULL || l == 0 || (l == 1 && (*p) == 0)) 691 if (!((char *)data)[0])
687#endif 692#endif
688 strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE); 693 strlcpy(data, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
689#endif /* CONFIG_CMDLINE */ 694#endif /* CONFIG_CMDLINE */
diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c
index bb184717588f..ffab033d207e 100644
--- a/drivers/of/of_net.c
+++ b/drivers/of/of_net.c
@@ -9,6 +9,7 @@
9#include <linux/kernel.h> 9#include <linux/kernel.h>
10#include <linux/of_net.h> 10#include <linux/of_net.h>
11#include <linux/phy.h> 11#include <linux/phy.h>
12#include <linux/export.h>
12 13
13/** 14/**
14 * It maps 'enum phy_interface_t' found in include/linux/phy.h 15 * It maps 'enum phy_interface_t' found in include/linux/phy.h
diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c
index 3701b62c1d5e..13e37e2d8ec1 100644
--- a/drivers/of/of_pci.c
+++ b/drivers/of/of_pci.c
@@ -1,4 +1,5 @@
1#include <linux/kernel.h> 1#include <linux/kernel.h>
2#include <linux/export.h>
2#include <linux/of.h> 3#include <linux/of.h>
3#include <linux/of_pci.h> 4#include <linux/of_pci.h>
4#include <asm/prom.h> 5#include <asm/prom.h>
diff --git a/drivers/of/of_pci_irq.c b/drivers/of/of_pci_irq.c
index ac1ec54e4fd5..93125163dea2 100644
--- a/drivers/of/of_pci_irq.c
+++ b/drivers/of/of_pci_irq.c
@@ -1,6 +1,7 @@
1#include <linux/kernel.h> 1#include <linux/kernel.h>
2#include <linux/of_pci.h> 2#include <linux/of_pci.h>
3#include <linux/of_irq.h> 3#include <linux/of_irq.h>
4#include <linux/export.h>
4#include <asm/prom.h> 5#include <asm/prom.h>
5 6
6/** 7/**
diff --git a/drivers/of/of_spi.c b/drivers/of/of_spi.c
index 1dbce58a58b0..6dbc074e4876 100644
--- a/drivers/of/of_spi.c
+++ b/drivers/of/of_spi.c
@@ -6,6 +6,7 @@
6 * tree. 6 * tree.
7 */ 7 */
8 8
9#include <linux/module.h>
9#include <linux/of.h> 10#include <linux/of.h>
10#include <linux/device.h> 11#include <linux/device.h>
11#include <linux/spi/spi.h> 12#include <linux/spi/spi.h>
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index ed5a6d3c26aa..cbd5d701c7e0 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -310,18 +310,21 @@ static const struct of_dev_auxdata *of_dev_lookup(const struct of_dev_auxdata *l
310 struct device_node *np) 310 struct device_node *np)
311{ 311{
312 struct resource res; 312 struct resource res;
313 if (lookup) { 313
314 for(; lookup->name != NULL; lookup++) { 314 if (!lookup)
315 if (!of_device_is_compatible(np, lookup->compatible)) 315 return NULL;
316 continue; 316
317 if (of_address_to_resource(np, 0, &res)) 317 for(; lookup->name != NULL; lookup++) {
318 continue; 318 if (!of_device_is_compatible(np, lookup->compatible))
319 if (res.start != lookup->phys_addr) 319 continue;
320 continue; 320 if (of_address_to_resource(np, 0, &res))
321 pr_debug("%s: devname=%s\n", np->full_name, lookup->name); 321 continue;
322 return lookup; 322 if (res.start != lookup->phys_addr)
323 } 323 continue;
324 pr_debug("%s: devname=%s\n", np->full_name, lookup->name);
325 return lookup;
324 } 326 }
327
325 return NULL; 328 return NULL;
326} 329}
327 330
@@ -329,8 +332,9 @@ static const struct of_dev_auxdata *of_dev_lookup(const struct of_dev_auxdata *l
329 * of_platform_bus_create() - Create a device for a node and its children. 332 * of_platform_bus_create() - Create a device for a node and its children.
330 * @bus: device node of the bus to instantiate 333 * @bus: device node of the bus to instantiate
331 * @matches: match table for bus nodes 334 * @matches: match table for bus nodes
332 * disallow recursive creation of child buses 335 * @lookup: auxdata table for matching id and platform_data with device nodes
333 * @parent: parent for new device, or NULL for top level. 336 * @parent: parent for new device, or NULL for top level.
337 * @strict: require compatible property
334 * 338 *
335 * Creates a platform_device for the provided device_node, and optionally 339 * Creates a platform_device for the provided device_node, and optionally
336 * recursively create devices for all the child nodes. 340 * recursively create devices for all the child nodes.
diff --git a/drivers/parisc/ccio-dma.c b/drivers/parisc/ccio-dma.c
index 75a80e46b391..8b490d77054f 100644
--- a/drivers/parisc/ccio-dma.c
+++ b/drivers/parisc/ccio-dma.c
@@ -44,6 +44,7 @@
44#include <linux/seq_file.h> 44#include <linux/seq_file.h>
45#include <linux/scatterlist.h> 45#include <linux/scatterlist.h>
46#include <linux/iommu-helper.h> 46#include <linux/iommu-helper.h>
47#include <linux/export.h>
47 48
48#include <asm/byteorder.h> 49#include <asm/byteorder.h>
49#include <asm/cache.h> /* for L1_CACHE_BYTES */ 50#include <asm/cache.h> /* for L1_CACHE_BYTES */
diff --git a/drivers/parisc/sba_iommu.c b/drivers/parisc/sba_iommu.c
index a6f762188bc3..8644d5372e7f 100644
--- a/drivers/parisc/sba_iommu.c
+++ b/drivers/parisc/sba_iommu.c
@@ -39,6 +39,7 @@
39 39
40#include <linux/proc_fs.h> 40#include <linux/proc_fs.h>
41#include <linux/seq_file.h> 41#include <linux/seq_file.h>
42#include <linux/module.h>
42 43
43#include <asm/ropes.h> 44#include <asm/ropes.h>
44#include <asm/mckinley.h> /* for proc_mckinley_root */ 45#include <asm/mckinley.h> /* for proc_mckinley_root */
diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
index cec66064ee4b..b6f9749b4fa7 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -51,17 +51,6 @@ config XEN_PCIDEV_FRONTEND
51 The PCI device frontend driver allows the kernel to import arbitrary 51 The PCI device frontend driver allows the kernel to import arbitrary
52 PCI devices from a PCI backend to support PCI driver domains. 52 PCI devices from a PCI backend to support PCI driver domains.
53 53
54config XEN_PCIDEV_FE_DEBUG
55 bool "Xen PCI Frontend debugging"
56 depends on XEN_PCIDEV_FRONTEND && PCI_DEBUG
57 help
58 Say Y here if you want the Xen PCI frontend to produce a bunch of debug
59 messages to the system log. Select this if you are having a
60 problem with Xen PCI frontend support and want to see more of what is
61 going on.
62
63 When in doubt, say N.
64
65config HT_IRQ 54config HT_IRQ
66 bool "Interrupts on hypertransport devices" 55 bool "Interrupts on hypertransport devices"
67 default y 56 default y
diff --git a/drivers/pci/ats.c b/drivers/pci/ats.c
index f727a09eb72f..7ec56fb0bd78 100644
--- a/drivers/pci/ats.c
+++ b/drivers/pci/ats.c
@@ -10,6 +10,7 @@
10 * PASID support added by Joerg Roedel <joerg.roedel@amd.com> 10 * PASID support added by Joerg Roedel <joerg.roedel@amd.com>
11 */ 11 */
12 12
13#include <linux/export.h>
13#include <linux/pci-ats.h> 14#include <linux/pci-ats.h>
14#include <linux/pci.h> 15#include <linux/pci.h>
15 16
diff --git a/drivers/pci/hotplug-pci.c b/drivers/pci/hotplug-pci.c
index 4d4a64478404..d3509cdeb554 100644
--- a/drivers/pci/hotplug-pci.c
+++ b/drivers/pci/hotplug-pci.c
@@ -1,6 +1,7 @@
1/* Core PCI functionality used only by PCI hotplug */ 1/* Core PCI functionality used only by PCI hotplug */
2 2
3#include <linux/pci.h> 3#include <linux/pci.h>
4#include <linux/export.h>
4#include "pci.h" 5#include "pci.h"
5 6
6 7
diff --git a/drivers/pci/hotplug/pciehp_acpi.c b/drivers/pci/hotplug/pciehp_acpi.c
index 5f7226223a62..376d70d17176 100644
--- a/drivers/pci/hotplug/pciehp_acpi.c
+++ b/drivers/pci/hotplug/pciehp_acpi.c
@@ -27,6 +27,7 @@
27#include <linux/pci.h> 27#include <linux/pci.h>
28#include <linux/pci_hotplug.h> 28#include <linux/pci_hotplug.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/module.h>
30#include "pciehp.h" 31#include "pciehp.h"
31 32
32#define PCIEHP_DETECT_PCIE (0) 33#define PCIEHP_DETECT_PCIE (0)
diff --git a/drivers/pci/hotplug/pcihp_slot.c b/drivers/pci/hotplug/pcihp_slot.c
index 3ffd9c1acc0a..8c05a18c9770 100644
--- a/drivers/pci/hotplug/pcihp_slot.c
+++ b/drivers/pci/hotplug/pcihp_slot.c
@@ -24,6 +24,7 @@
24 */ 24 */
25 25
26#include <linux/pci.h> 26#include <linux/pci.h>
27#include <linux/export.h>
27#include <linux/pci_hotplug.h> 28#include <linux/pci_hotplug.h>
28 29
29static struct hpp_type0 pci_default_type0 = { 30static struct hpp_type0 pci_default_type0 = {
diff --git a/drivers/pci/hotplug/rpadlpar_core.c b/drivers/pci/hotplug/rpadlpar_core.c
index 1d002b1c2bf4..c56a9413e1af 100644
--- a/drivers/pci/hotplug/rpadlpar_core.c
+++ b/drivers/pci/hotplug/rpadlpar_core.c
@@ -18,6 +18,7 @@
18#undef DEBUG 18#undef DEBUG
19 19
20#include <linux/init.h> 20#include <linux/init.h>
21#include <linux/module.h>
21#include <linux/pci.h> 22#include <linux/pci.h>
22#include <linux/string.h> 23#include <linux/string.h>
23#include <linux/vmalloc.h> 24#include <linux/vmalloc.h>
diff --git a/drivers/pci/htirq.c b/drivers/pci/htirq.c
index db057b6fe0c8..6e373ea57b32 100644
--- a/drivers/pci/htirq.c
+++ b/drivers/pci/htirq.c
@@ -9,6 +9,7 @@
9#include <linux/irq.h> 9#include <linux/irq.h>
10#include <linux/pci.h> 10#include <linux/pci.h>
11#include <linux/spinlock.h> 11#include <linux/spinlock.h>
12#include <linux/export.h>
12#include <linux/slab.h> 13#include <linux/slab.h>
13#include <linux/htirq.h> 14#include <linux/htirq.h>
14 15
diff --git a/drivers/pci/ioapic.c b/drivers/pci/ioapic.c
index 203508b227b7..5775638ac017 100644
--- a/drivers/pci/ioapic.c
+++ b/drivers/pci/ioapic.c
@@ -17,6 +17,7 @@
17 */ 17 */
18 18
19#include <linux/pci.h> 19#include <linux/pci.h>
20#include <linux/export.h>
20#include <linux/acpi.h> 21#include <linux/acpi.h>
21#include <linux/slab.h> 22#include <linux/slab.h>
22#include <acpi/acpi_bus.h> 23#include <acpi/acpi_bus.h>
diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index 9b4e88c636f8..b82c155d7b37 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -11,6 +11,7 @@
11#include <linux/pci.h> 11#include <linux/pci.h>
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/mutex.h> 13#include <linux/mutex.h>
14#include <linux/export.h>
14#include <linux/string.h> 15#include <linux/string.h>
15#include <linux/delay.h> 16#include <linux/delay.h>
16#include <linux/pci-ats.h> 17#include <linux/pci-ats.h>
diff --git a/drivers/pci/irq.c b/drivers/pci/irq.c
index de01174aff06..e5f69a43b1b1 100644
--- a/drivers/pci/irq.c
+++ b/drivers/pci/irq.c
@@ -7,6 +7,7 @@
7#include <linux/acpi.h> 7#include <linux/acpi.h>
8#include <linux/device.h> 8#include <linux/device.h>
9#include <linux/kernel.h> 9#include <linux/kernel.h>
10#include <linux/export.h>
10#include <linux/pci.h> 11#include <linux/pci.h>
11 12
12static void pci_note_irq_problem(struct pci_dev *pdev, const char *reason) 13static void pci_note_irq_problem(struct pci_dev *pdev, const char *reason)
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 2f10328bf661..0e6d04d7ba4f 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -11,6 +11,7 @@
11#include <linux/irq.h> 11#include <linux/irq.h>
12#include <linux/interrupt.h> 12#include <linux/interrupt.h>
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/export.h>
14#include <linux/ioport.h> 15#include <linux/ioport.h>
15#include <linux/pci.h> 16#include <linux/pci.h>
16#include <linux/proc_fs.h> 17#include <linux/proc_fs.h>
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 7bcf12adced7..106be0d08f81 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -19,6 +19,7 @@
19#include <linux/sched.h> 19#include <linux/sched.h>
20#include <linux/pci.h> 20#include <linux/pci.h>
21#include <linux/stat.h> 21#include <linux/stat.h>
22#include <linux/export.h>
22#include <linux/topology.h> 23#include <linux/topology.h>
23#include <linux/mm.h> 24#include <linux/mm.h>
24#include <linux/fs.h> 25#include <linux/fs.h>
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 7285145ac1c9..64765474676f 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -17,6 +17,7 @@
17 17
18#include <linux/types.h> 18#include <linux/types.h>
19#include <linux/kernel.h> 19#include <linux/kernel.h>
20#include <linux/export.h>
20#include <linux/pci.h> 21#include <linux/pci.h>
21#include <linux/init.h> 22#include <linux/init.h>
22#include <linux/delay.h> 23#include <linux/delay.h>
diff --git a/drivers/pci/rom.c b/drivers/pci/rom.c
index 36864a935d68..48ebdb237f3f 100644
--- a/drivers/pci/rom.c
+++ b/drivers/pci/rom.c
@@ -7,6 +7,7 @@
7 * PCI ROM access routines 7 * PCI ROM access routines
8 */ 8 */
9#include <linux/kernel.h> 9#include <linux/kernel.h>
10#include <linux/export.h>
10#include <linux/pci.h> 11#include <linux/pci.h>
11#include <linux/slab.h> 12#include <linux/slab.h>
12 13
diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
index 51a9095c7da4..5717509becbe 100644
--- a/drivers/pci/setup-res.c
+++ b/drivers/pci/setup-res.c
@@ -18,6 +18,7 @@
18 18
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/kernel.h> 20#include <linux/kernel.h>
21#include <linux/export.h>
21#include <linux/pci.h> 22#include <linux/pci.h>
22#include <linux/errno.h> 23#include <linux/errno.h>
23#include <linux/ioport.h> 24#include <linux/ioport.h>
diff --git a/drivers/pci/slot.c b/drivers/pci/slot.c
index 968cfea04f74..ac6412fb8d6f 100644
--- a/drivers/pci/slot.c
+++ b/drivers/pci/slot.c
@@ -7,6 +7,7 @@
7 7
8#include <linux/kobject.h> 8#include <linux/kobject.h>
9#include <linux/slab.h> 9#include <linux/slab.h>
10#include <linux/module.h>
10#include <linux/pci.h> 11#include <linux/pci.h>
11#include <linux/err.h> 12#include <linux/err.h>
12#include "pci.h" 13#include "pci.h"
diff --git a/drivers/pci/vpd.c b/drivers/pci/vpd.c
index a5a5ca17cfe6..39b79070335d 100644
--- a/drivers/pci/vpd.c
+++ b/drivers/pci/vpd.c
@@ -6,6 +6,7 @@
6 */ 6 */
7 7
8#include <linux/pci.h> 8#include <linux/pci.h>
9#include <linux/export.h>
9 10
10int pci_vpd_find_tag(const u8 *buf, unsigned int off, unsigned int len, u8 rdt) 11int pci_vpd_find_tag(const u8 *buf, unsigned int off, unsigned int len, u8 rdt)
11{ 12{
diff --git a/drivers/pcmcia/db1xxx_ss.c b/drivers/pcmcia/db1xxx_ss.c
index 01757f18a208..3e49df6d5e3b 100644
--- a/drivers/pcmcia/db1xxx_ss.c
+++ b/drivers/pcmcia/db1xxx_ss.c
@@ -24,6 +24,7 @@
24#include <linux/gpio.h> 24#include <linux/gpio.h>
25#include <linux/interrupt.h> 25#include <linux/interrupt.h>
26#include <linux/pm.h> 26#include <linux/pm.h>
27#include <linux/module.h>
27#include <linux/platform_device.h> 28#include <linux/platform_device.h>
28#include <linux/resource.h> 29#include <linux/resource.h>
29#include <linux/slab.h> 30#include <linux/slab.h>
diff --git a/drivers/pcmcia/pxa2xx_base.c b/drivers/pcmcia/pxa2xx_base.c
index 2c540542b5af..a87e2728b2c3 100644
--- a/drivers/pcmcia/pxa2xx_base.c
+++ b/drivers/pcmcia/pxa2xx_base.c
@@ -231,6 +231,7 @@ void pxa2xx_configure_sockets(struct device *dev)
231 231
232 __raw_writel(mecr, MECR); 232 __raw_writel(mecr, MECR);
233} 233}
234EXPORT_SYMBOL(pxa2xx_configure_sockets);
234 235
235static const char *skt_names[] = { 236static const char *skt_names[] = {
236 "PCMCIA socket 0", 237 "PCMCIA socket 0",
diff --git a/drivers/pcmcia/pxa2xx_cm_x255.c b/drivers/pcmcia/pxa2xx_cm_x255.c
index 63f4d5211ed2..0b4f946cf13a 100644
--- a/drivers/pcmcia/pxa2xx_cm_x255.c
+++ b/drivers/pcmcia/pxa2xx_cm_x255.c
@@ -14,6 +14,7 @@
14#include <linux/irq.h> 14#include <linux/irq.h>
15#include <linux/delay.h> 15#include <linux/delay.h>
16#include <linux/gpio.h> 16#include <linux/gpio.h>
17#include <linux/export.h>
17 18
18#include <asm/mach-types.h> 19#include <asm/mach-types.h>
19 20
diff --git a/drivers/pcmcia/pxa2xx_cm_x270.c b/drivers/pcmcia/pxa2xx_cm_x270.c
index 6ee42b4c3e68..923f315926ef 100644
--- a/drivers/pcmcia/pxa2xx_cm_x270.c
+++ b/drivers/pcmcia/pxa2xx_cm_x270.c
@@ -14,6 +14,7 @@
14#include <linux/irq.h> 14#include <linux/irq.h>
15#include <linux/delay.h> 15#include <linux/delay.h>
16#include <linux/gpio.h> 16#include <linux/gpio.h>
17#include <linux/export.h>
17 18
18#include <asm/mach-types.h> 19#include <asm/mach-types.h>
19 20
diff --git a/drivers/pcmcia/pxa2xx_cm_x2xx.c b/drivers/pcmcia/pxa2xx_cm_x2xx.c
index 4f09506ad8d4..6e7dcfd22ede 100644
--- a/drivers/pcmcia/pxa2xx_cm_x2xx.c
+++ b/drivers/pcmcia/pxa2xx_cm_x2xx.c
@@ -12,9 +12,8 @@
12 12
13#include <linux/module.h> 13#include <linux/module.h>
14 14
15#include <asm/system.h>
16#include <asm/mach-types.h> 15#include <asm/mach-types.h>
17#include <mach/system.h> 16#include <mach/hardware.h>
18 17
19int cmx255_pcmcia_init(void); 18int cmx255_pcmcia_init(void);
20int cmx270_pcmcia_init(void); 19int cmx270_pcmcia_init(void);
diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index 423522d87313..eadef9e191ea 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -12,6 +12,7 @@
12#define pr_fmt(fmt) "pinctrl core: " fmt 12#define pr_fmt(fmt) "pinctrl core: " fmt
13 13
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/export.h>
15#include <linux/init.h> 16#include <linux/init.h>
16#include <linux/device.h> 17#include <linux/device.h>
17#include <linux/slab.h> 18#include <linux/slab.h>
diff --git a/drivers/platform/x86/intel_scu_ipc.c b/drivers/platform/x86/intel_scu_ipc.c
index c86665369a22..48870e504231 100644
--- a/drivers/platform/x86/intel_scu_ipc.c
+++ b/drivers/platform/x86/intel_scu_ipc.c
@@ -24,6 +24,7 @@
24#include <linux/pci.h> 24#include <linux/pci.h>
25#include <linux/interrupt.h> 25#include <linux/interrupt.h>
26#include <linux/sfi.h> 26#include <linux/sfi.h>
27#include <linux/module.h>
27#include <asm/mrst.h> 28#include <asm/mrst.h>
28#include <asm/intel_scu_ipc.h> 29#include <asm/intel_scu_ipc.h>
29 30
diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
index 6f40bf202dc7..2264331bd48e 100644
--- a/drivers/platform/x86/msi-wmi.c
+++ b/drivers/platform/x86/msi-wmi.c
@@ -28,6 +28,7 @@
28#include <linux/acpi.h> 28#include <linux/acpi.h>
29#include <linux/backlight.h> 29#include <linux/backlight.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/module.h>
31 32
32MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>"); 33MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
33MODULE_DESCRIPTION("MSI laptop WMI hotkeys driver"); 34MODULE_DESCRIPTION("MSI laptop WMI hotkeys driver");
diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
index 9b88be42b6cd..a134c26870b0 100644
--- a/drivers/platform/x86/wmi.c
+++ b/drivers/platform/x86/wmi.c
@@ -36,6 +36,7 @@
36#include <linux/list.h> 36#include <linux/list.h>
37#include <linux/acpi.h> 37#include <linux/acpi.h>
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/module.h>
39#include <acpi/acpi_bus.h> 40#include <acpi/acpi_bus.h>
40#include <acpi/acpi_drivers.h> 41#include <acpi/acpi_drivers.h>
41 42
diff --git a/drivers/pnp/pnpacpi/core.c b/drivers/pnp/pnpacpi/core.c
index ca84d5099ce7..b00c17612a89 100644
--- a/drivers/pnp/pnpacpi/core.c
+++ b/drivers/pnp/pnpacpi/core.c
@@ -19,6 +19,7 @@
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */ 20 */
21 21
22#include <linux/export.h>
22#include <linux/acpi.h> 23#include <linux/acpi.h>
23#include <linux/pnp.h> 24#include <linux/pnp.h>
24#include <linux/slab.h> 25#include <linux/slab.h>
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index 57de051a74b3..9f88641e67f9 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -70,6 +70,7 @@ config BATTERY_DS2760
70 70
71config BATTERY_DS2780 71config BATTERY_DS2780
72 tristate "DS2780 battery driver" 72 tristate "DS2780 battery driver"
73 depends on HAS_IOMEM
73 select W1 74 select W1
74 select W1_SLAVE_DS2780 75 select W1_SLAVE_DS2780
75 help 76 help
diff --git a/drivers/power/ds2780_battery.c b/drivers/power/ds2780_battery.c
index 1fefe82e12e3..91a783d72360 100644
--- a/drivers/power/ds2780_battery.c
+++ b/drivers/power/ds2780_battery.c
@@ -39,6 +39,7 @@ struct ds2780_device_info {
39 struct device *dev; 39 struct device *dev;
40 struct power_supply bat; 40 struct power_supply bat;
41 struct device *w1_dev; 41 struct device *w1_dev;
42 struct task_struct *mutex_holder;
42}; 43};
43 44
44enum current_types { 45enum current_types {
@@ -49,8 +50,8 @@ enum current_types {
49static const char model[] = "DS2780"; 50static const char model[] = "DS2780";
50static const char manufacturer[] = "Maxim/Dallas"; 51static const char manufacturer[] = "Maxim/Dallas";
51 52
52static inline struct ds2780_device_info *to_ds2780_device_info( 53static inline struct ds2780_device_info *
53 struct power_supply *psy) 54to_ds2780_device_info(struct power_supply *psy)
54{ 55{
55 return container_of(psy, struct ds2780_device_info, bat); 56 return container_of(psy, struct ds2780_device_info, bat);
56} 57}
@@ -60,17 +61,28 @@ static inline struct power_supply *to_power_supply(struct device *dev)
60 return dev_get_drvdata(dev); 61 return dev_get_drvdata(dev);
61} 62}
62 63
63static inline int ds2780_read8(struct device *dev, u8 *val, int addr) 64static inline int ds2780_battery_io(struct ds2780_device_info *dev_info,
65 char *buf, int addr, size_t count, int io)
64{ 66{
65 return w1_ds2780_io(dev, val, addr, sizeof(u8), 0); 67 if (dev_info->mutex_holder == current)
68 return w1_ds2780_io_nolock(dev_info->w1_dev, buf, addr, count, io);
69 else
70 return w1_ds2780_io(dev_info->w1_dev, buf, addr, count, io);
71}
72
73static inline int ds2780_read8(struct ds2780_device_info *dev_info, u8 *val,
74 int addr)
75{
76 return ds2780_battery_io(dev_info, val, addr, sizeof(u8), 0);
66} 77}
67 78
68static int ds2780_read16(struct device *dev, s16 *val, int addr) 79static int ds2780_read16(struct ds2780_device_info *dev_info, s16 *val,
80 int addr)
69{ 81{
70 int ret; 82 int ret;
71 u8 raw[2]; 83 u8 raw[2];
72 84
73 ret = w1_ds2780_io(dev, raw, addr, sizeof(u8) * 2, 0); 85 ret = ds2780_battery_io(dev_info, raw, addr, sizeof(raw), 0);
74 if (ret < 0) 86 if (ret < 0)
75 return ret; 87 return ret;
76 88
@@ -79,16 +91,16 @@ static int ds2780_read16(struct device *dev, s16 *val, int addr)
79 return 0; 91 return 0;
80} 92}
81 93
82static inline int ds2780_read_block(struct device *dev, u8 *val, int addr, 94static inline int ds2780_read_block(struct ds2780_device_info *dev_info,
83 size_t count) 95 u8 *val, int addr, size_t count)
84{ 96{
85 return w1_ds2780_io(dev, val, addr, count, 0); 97 return ds2780_battery_io(dev_info, val, addr, count, 0);
86} 98}
87 99
88static inline int ds2780_write(struct device *dev, u8 *val, int addr, 100static inline int ds2780_write(struct ds2780_device_info *dev_info, u8 *val,
89 size_t count) 101 int addr, size_t count)
90{ 102{
91 return w1_ds2780_io(dev, val, addr, count, 1); 103 return ds2780_battery_io(dev_info, val, addr, count, 1);
92} 104}
93 105
94static inline int ds2780_store_eeprom(struct device *dev, int addr) 106static inline int ds2780_store_eeprom(struct device *dev, int addr)
@@ -122,7 +134,7 @@ static int ds2780_set_sense_register(struct ds2780_device_info *dev_info,
122{ 134{
123 int ret; 135 int ret;
124 136
125 ret = ds2780_write(dev_info->w1_dev, &conductance, 137 ret = ds2780_write(dev_info, &conductance,
126 DS2780_RSNSP_REG, sizeof(u8)); 138 DS2780_RSNSP_REG, sizeof(u8));
127 if (ret < 0) 139 if (ret < 0)
128 return ret; 140 return ret;
@@ -134,7 +146,7 @@ static int ds2780_set_sense_register(struct ds2780_device_info *dev_info,
134static int ds2780_get_rsgain_register(struct ds2780_device_info *dev_info, 146static int ds2780_get_rsgain_register(struct ds2780_device_info *dev_info,
135 u16 *rsgain) 147 u16 *rsgain)
136{ 148{
137 return ds2780_read16(dev_info->w1_dev, rsgain, DS2780_RSGAIN_MSB_REG); 149 return ds2780_read16(dev_info, rsgain, DS2780_RSGAIN_MSB_REG);
138} 150}
139 151
140/* Set RSGAIN value from 0 to 1.999 in steps of 0.001 */ 152/* Set RSGAIN value from 0 to 1.999 in steps of 0.001 */
@@ -144,8 +156,8 @@ static int ds2780_set_rsgain_register(struct ds2780_device_info *dev_info,
144 int ret; 156 int ret;
145 u8 raw[] = {rsgain >> 8, rsgain & 0xFF}; 157 u8 raw[] = {rsgain >> 8, rsgain & 0xFF};
146 158
147 ret = ds2780_write(dev_info->w1_dev, raw, 159 ret = ds2780_write(dev_info, raw,
148 DS2780_RSGAIN_MSB_REG, sizeof(u8) * 2); 160 DS2780_RSGAIN_MSB_REG, sizeof(raw));
149 if (ret < 0) 161 if (ret < 0)
150 return ret; 162 return ret;
151 163
@@ -167,7 +179,7 @@ static int ds2780_get_voltage(struct ds2780_device_info *dev_info,
167 * Bits 2 - 0 of the voltage value are in bits 7 - 5 of the 179 * Bits 2 - 0 of the voltage value are in bits 7 - 5 of the
168 * voltage LSB register 180 * voltage LSB register
169 */ 181 */
170 ret = ds2780_read16(dev_info->w1_dev, &voltage_raw, 182 ret = ds2780_read16(dev_info, &voltage_raw,
171 DS2780_VOLT_MSB_REG); 183 DS2780_VOLT_MSB_REG);
172 if (ret < 0) 184 if (ret < 0)
173 return ret; 185 return ret;
@@ -196,7 +208,7 @@ static int ds2780_get_temperature(struct ds2780_device_info *dev_info,
196 * Bits 2 - 0 of the temperature value are in bits 7 - 5 of the 208 * Bits 2 - 0 of the temperature value are in bits 7 - 5 of the
197 * temperature LSB register 209 * temperature LSB register
198 */ 210 */
199 ret = ds2780_read16(dev_info->w1_dev, &temperature_raw, 211 ret = ds2780_read16(dev_info, &temperature_raw,
200 DS2780_TEMP_MSB_REG); 212 DS2780_TEMP_MSB_REG);
201 if (ret < 0) 213 if (ret < 0)
202 return ret; 214 return ret;
@@ -222,13 +234,13 @@ static int ds2780_get_current(struct ds2780_device_info *dev_info,
222 * The units of measurement for current are dependent on the value of 234 * The units of measurement for current are dependent on the value of
223 * the sense resistor. 235 * the sense resistor.
224 */ 236 */
225 ret = ds2780_read8(dev_info->w1_dev, &sense_res_raw, DS2780_RSNSP_REG); 237 ret = ds2780_read8(dev_info, &sense_res_raw, DS2780_RSNSP_REG);
226 if (ret < 0) 238 if (ret < 0)
227 return ret; 239 return ret;
228 240
229 if (sense_res_raw == 0) { 241 if (sense_res_raw == 0) {
230 dev_err(dev_info->dev, "sense resistor value is 0\n"); 242 dev_err(dev_info->dev, "sense resistor value is 0\n");
231 return -ENXIO; 243 return -EINVAL;
232 } 244 }
233 sense_res = 1000 / sense_res_raw; 245 sense_res = 1000 / sense_res_raw;
234 246
@@ -248,7 +260,7 @@ static int ds2780_get_current(struct ds2780_device_info *dev_info,
248 * Bits 7 - 0 of the current value are in bits 7 - 0 of the current 260 * Bits 7 - 0 of the current value are in bits 7 - 0 of the current
249 * LSB register 261 * LSB register
250 */ 262 */
251 ret = ds2780_read16(dev_info->w1_dev, &current_raw, reg_msb); 263 ret = ds2780_read16(dev_info, &current_raw, reg_msb);
252 if (ret < 0) 264 if (ret < 0)
253 return ret; 265 return ret;
254 266
@@ -267,7 +279,7 @@ static int ds2780_get_accumulated_current(struct ds2780_device_info *dev_info,
267 * The units of measurement for accumulated current are dependent on 279 * The units of measurement for accumulated current are dependent on
268 * the value of the sense resistor. 280 * the value of the sense resistor.
269 */ 281 */
270 ret = ds2780_read8(dev_info->w1_dev, &sense_res_raw, DS2780_RSNSP_REG); 282 ret = ds2780_read8(dev_info, &sense_res_raw, DS2780_RSNSP_REG);
271 if (ret < 0) 283 if (ret < 0)
272 return ret; 284 return ret;
273 285
@@ -285,7 +297,7 @@ static int ds2780_get_accumulated_current(struct ds2780_device_info *dev_info,
285 * Bits 7 - 0 of the ACR value are in bits 7 - 0 of the ACR 297 * Bits 7 - 0 of the ACR value are in bits 7 - 0 of the ACR
286 * LSB register 298 * LSB register
287 */ 299 */
288 ret = ds2780_read16(dev_info->w1_dev, &current_raw, DS2780_ACR_MSB_REG); 300 ret = ds2780_read16(dev_info, &current_raw, DS2780_ACR_MSB_REG);
289 if (ret < 0) 301 if (ret < 0)
290 return ret; 302 return ret;
291 303
@@ -299,7 +311,7 @@ static int ds2780_get_capacity(struct ds2780_device_info *dev_info,
299 int ret; 311 int ret;
300 u8 raw; 312 u8 raw;
301 313
302 ret = ds2780_read8(dev_info->w1_dev, &raw, DS2780_RARC_REG); 314 ret = ds2780_read8(dev_info, &raw, DS2780_RARC_REG);
303 if (ret < 0) 315 if (ret < 0)
304 return ret; 316 return ret;
305 317
@@ -345,7 +357,7 @@ static int ds2780_get_charge_now(struct ds2780_device_info *dev_info,
345 * Bits 7 - 0 of the RAAC value are in bits 7 - 0 of the RAAC 357 * Bits 7 - 0 of the RAAC value are in bits 7 - 0 of the RAAC
346 * LSB register 358 * LSB register
347 */ 359 */
348 ret = ds2780_read16(dev_info->w1_dev, &charge_raw, DS2780_RAAC_MSB_REG); 360 ret = ds2780_read16(dev_info, &charge_raw, DS2780_RAAC_MSB_REG);
349 if (ret < 0) 361 if (ret < 0)
350 return ret; 362 return ret;
351 363
@@ -356,7 +368,7 @@ static int ds2780_get_charge_now(struct ds2780_device_info *dev_info,
356static int ds2780_get_control_register(struct ds2780_device_info *dev_info, 368static int ds2780_get_control_register(struct ds2780_device_info *dev_info,
357 u8 *control_reg) 369 u8 *control_reg)
358{ 370{
359 return ds2780_read8(dev_info->w1_dev, control_reg, DS2780_CONTROL_REG); 371 return ds2780_read8(dev_info, control_reg, DS2780_CONTROL_REG);
360} 372}
361 373
362static int ds2780_set_control_register(struct ds2780_device_info *dev_info, 374static int ds2780_set_control_register(struct ds2780_device_info *dev_info,
@@ -364,7 +376,7 @@ static int ds2780_set_control_register(struct ds2780_device_info *dev_info,
364{ 376{
365 int ret; 377 int ret;
366 378
367 ret = ds2780_write(dev_info->w1_dev, &control_reg, 379 ret = ds2780_write(dev_info, &control_reg,
368 DS2780_CONTROL_REG, sizeof(u8)); 380 DS2780_CONTROL_REG, sizeof(u8));
369 if (ret < 0) 381 if (ret < 0)
370 return ret; 382 return ret;
@@ -503,7 +515,7 @@ static ssize_t ds2780_get_sense_resistor_value(struct device *dev,
503 struct power_supply *psy = to_power_supply(dev); 515 struct power_supply *psy = to_power_supply(dev);
504 struct ds2780_device_info *dev_info = to_ds2780_device_info(psy); 516 struct ds2780_device_info *dev_info = to_ds2780_device_info(psy);
505 517
506 ret = ds2780_read8(dev_info->w1_dev, &sense_resistor, DS2780_RSNSP_REG); 518 ret = ds2780_read8(dev_info, &sense_resistor, DS2780_RSNSP_REG);
507 if (ret < 0) 519 if (ret < 0)
508 return ret; 520 return ret;
509 521
@@ -584,7 +596,7 @@ static ssize_t ds2780_get_pio_pin(struct device *dev,
584 struct power_supply *psy = to_power_supply(dev); 596 struct power_supply *psy = to_power_supply(dev);
585 struct ds2780_device_info *dev_info = to_ds2780_device_info(psy); 597 struct ds2780_device_info *dev_info = to_ds2780_device_info(psy);
586 598
587 ret = ds2780_read8(dev_info->w1_dev, &sfr, DS2780_SFR_REG); 599 ret = ds2780_read8(dev_info, &sfr, DS2780_SFR_REG);
588 if (ret < 0) 600 if (ret < 0)
589 return ret; 601 return ret;
590 602
@@ -611,7 +623,7 @@ static ssize_t ds2780_set_pio_pin(struct device *dev,
611 return -EINVAL; 623 return -EINVAL;
612 } 624 }
613 625
614 ret = ds2780_write(dev_info->w1_dev, &new_setting, 626 ret = ds2780_write(dev_info, &new_setting,
615 DS2780_SFR_REG, sizeof(u8)); 627 DS2780_SFR_REG, sizeof(u8));
616 if (ret < 0) 628 if (ret < 0)
617 return ret; 629 return ret;
@@ -632,7 +644,7 @@ static ssize_t ds2780_read_param_eeprom_bin(struct file *filp,
632 DS2780_EEPROM_BLOCK1_END - 644 DS2780_EEPROM_BLOCK1_END -
633 DS2780_EEPROM_BLOCK1_START + 1 - off); 645 DS2780_EEPROM_BLOCK1_START + 1 - off);
634 646
635 return ds2780_read_block(dev_info->w1_dev, buf, 647 return ds2780_read_block(dev_info, buf,
636 DS2780_EEPROM_BLOCK1_START + off, count); 648 DS2780_EEPROM_BLOCK1_START + off, count);
637} 649}
638 650
@@ -650,7 +662,7 @@ static ssize_t ds2780_write_param_eeprom_bin(struct file *filp,
650 DS2780_EEPROM_BLOCK1_END - 662 DS2780_EEPROM_BLOCK1_END -
651 DS2780_EEPROM_BLOCK1_START + 1 - off); 663 DS2780_EEPROM_BLOCK1_START + 1 - off);
652 664
653 ret = ds2780_write(dev_info->w1_dev, buf, 665 ret = ds2780_write(dev_info, buf,
654 DS2780_EEPROM_BLOCK1_START + off, count); 666 DS2780_EEPROM_BLOCK1_START + off, count);
655 if (ret < 0) 667 if (ret < 0)
656 return ret; 668 return ret;
@@ -685,9 +697,8 @@ static ssize_t ds2780_read_user_eeprom_bin(struct file *filp,
685 DS2780_EEPROM_BLOCK0_END - 697 DS2780_EEPROM_BLOCK0_END -
686 DS2780_EEPROM_BLOCK0_START + 1 - off); 698 DS2780_EEPROM_BLOCK0_START + 1 - off);
687 699
688 return ds2780_read_block(dev_info->w1_dev, buf, 700 return ds2780_read_block(dev_info, buf,
689 DS2780_EEPROM_BLOCK0_START + off, count); 701 DS2780_EEPROM_BLOCK0_START + off, count);
690
691} 702}
692 703
693static ssize_t ds2780_write_user_eeprom_bin(struct file *filp, 704static ssize_t ds2780_write_user_eeprom_bin(struct file *filp,
@@ -704,7 +715,7 @@ static ssize_t ds2780_write_user_eeprom_bin(struct file *filp,
704 DS2780_EEPROM_BLOCK0_END - 715 DS2780_EEPROM_BLOCK0_END -
705 DS2780_EEPROM_BLOCK0_START + 1 - off); 716 DS2780_EEPROM_BLOCK0_START + 1 - off);
706 717
707 ret = ds2780_write(dev_info->w1_dev, buf, 718 ret = ds2780_write(dev_info, buf,
708 DS2780_EEPROM_BLOCK0_START + off, count); 719 DS2780_EEPROM_BLOCK0_START + off, count);
709 if (ret < 0) 720 if (ret < 0)
710 return ret; 721 return ret;
@@ -768,6 +779,7 @@ static int __devinit ds2780_battery_probe(struct platform_device *pdev)
768 dev_info->bat.properties = ds2780_battery_props; 779 dev_info->bat.properties = ds2780_battery_props;
769 dev_info->bat.num_properties = ARRAY_SIZE(ds2780_battery_props); 780 dev_info->bat.num_properties = ARRAY_SIZE(ds2780_battery_props);
770 dev_info->bat.get_property = ds2780_battery_get_property; 781 dev_info->bat.get_property = ds2780_battery_get_property;
782 dev_info->mutex_holder = current;
771 783
772 ret = power_supply_register(&pdev->dev, &dev_info->bat); 784 ret = power_supply_register(&pdev->dev, &dev_info->bat);
773 if (ret) { 785 if (ret) {
@@ -797,6 +809,8 @@ static int __devinit ds2780_battery_probe(struct platform_device *pdev)
797 goto fail_remove_bin_file; 809 goto fail_remove_bin_file;
798 } 810 }
799 811
812 dev_info->mutex_holder = NULL;
813
800 return 0; 814 return 0;
801 815
802fail_remove_bin_file: 816fail_remove_bin_file:
@@ -816,6 +830,8 @@ static int __devexit ds2780_battery_remove(struct platform_device *pdev)
816{ 830{
817 struct ds2780_device_info *dev_info = platform_get_drvdata(pdev); 831 struct ds2780_device_info *dev_info = platform_get_drvdata(pdev);
818 832
833 dev_info->mutex_holder = current;
834
819 /* remove attributes */ 835 /* remove attributes */
820 sysfs_remove_group(&dev_info->bat.dev->kobj, &ds2780_attr_group); 836 sysfs_remove_group(&dev_info->bat.dev->kobj, &ds2780_attr_group);
821 837
diff --git a/drivers/power/max17042_battery.c b/drivers/power/max17042_battery.c
index 98bfab35b8e9..9f0183c73076 100644
--- a/drivers/power/max17042_battery.c
+++ b/drivers/power/max17042_battery.c
@@ -23,6 +23,7 @@
23 */ 23 */
24 24
25#include <linux/init.h> 25#include <linux/init.h>
26#include <linux/module.h>
26#include <linux/slab.h> 27#include <linux/slab.h>
27#include <linux/i2c.h> 28#include <linux/i2c.h>
28#include <linux/mod_devicetable.h> 29#include <linux/mod_devicetable.h>
diff --git a/drivers/power/max8903_charger.c b/drivers/power/max8903_charger.c
index a9b0209a2f55..2595145f3bff 100644
--- a/drivers/power/max8903_charger.c
+++ b/drivers/power/max8903_charger.c
@@ -22,6 +22,7 @@
22 22
23#include <linux/gpio.h> 23#include <linux/gpio.h>
24#include <linux/interrupt.h> 24#include <linux/interrupt.h>
25#include <linux/module.h>
25#include <linux/slab.h> 26#include <linux/slab.h>
26#include <linux/power_supply.h> 27#include <linux/power_supply.h>
27#include <linux/platform_device.h> 28#include <linux/platform_device.h>
diff --git a/drivers/power/max8997_charger.c b/drivers/power/max8997_charger.c
index ffc5033ea9c9..a23317d75c5a 100644
--- a/drivers/power/max8997_charger.c
+++ b/drivers/power/max8997_charger.c
@@ -19,6 +19,7 @@
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */ 20 */
21 21
22#include <linux/module.h>
22#include <linux/err.h> 23#include <linux/err.h>
23#include <linux/module.h> 24#include <linux/module.h>
24#include <linux/slab.h> 25#include <linux/slab.h>
diff --git a/drivers/power/max8998_charger.c b/drivers/power/max8998_charger.c
index ef8efadb58cb..93e3bb47a3a8 100644
--- a/drivers/power/max8998_charger.c
+++ b/drivers/power/max8998_charger.c
@@ -19,6 +19,7 @@
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */ 20 */
21 21
22#include <linux/module.h>
22#include <linux/err.h> 23#include <linux/err.h>
23#include <linux/module.h> 24#include <linux/module.h>
24#include <linux/slab.h> 25#include <linux/slab.h>
diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
index 605514afc29f..e15d4c9d3988 100644
--- a/drivers/power/power_supply_sysfs.c
+++ b/drivers/power/power_supply_sysfs.c
@@ -14,6 +14,7 @@
14#include <linux/ctype.h> 14#include <linux/ctype.h>
15#include <linux/power_supply.h> 15#include <linux/power_supply.h>
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <linux/stat.h>
17 18
18#include "power_supply.h" 19#include "power_supply.h"
19 20
diff --git a/drivers/pps/clients/Kconfig b/drivers/pps/clients/Kconfig
index 8520a7f4dd62..445197d4a8c4 100644
--- a/drivers/pps/clients/Kconfig
+++ b/drivers/pps/clients/Kconfig
@@ -29,4 +29,13 @@ config PPS_CLIENT_PARPORT
29 If you say yes here you get support for a PPS source connected 29 If you say yes here you get support for a PPS source connected
30 with the interrupt pin of your parallel port. 30 with the interrupt pin of your parallel port.
31 31
32config PPS_CLIENT_GPIO
33 tristate "PPS client using GPIO"
34 depends on PPS && GENERIC_HARDIRQS
35 help
36 If you say yes here you get support for a PPS source using
37 GPIO. To be useful you must also register a platform device
38 specifying the GPIO pin and other options, usually in your board
39 setup.
40
32endif 41endif
diff --git a/drivers/pps/clients/Makefile b/drivers/pps/clients/Makefile
index 4feb7e9e71ee..a461d15f4a2e 100644
--- a/drivers/pps/clients/Makefile
+++ b/drivers/pps/clients/Makefile
@@ -5,5 +5,6 @@
5obj-$(CONFIG_PPS_CLIENT_KTIMER) += pps-ktimer.o 5obj-$(CONFIG_PPS_CLIENT_KTIMER) += pps-ktimer.o
6obj-$(CONFIG_PPS_CLIENT_LDISC) += pps-ldisc.o 6obj-$(CONFIG_PPS_CLIENT_LDISC) += pps-ldisc.o
7obj-$(CONFIG_PPS_CLIENT_PARPORT) += pps_parport.o 7obj-$(CONFIG_PPS_CLIENT_PARPORT) += pps_parport.o
8obj-$(CONFIG_PPS_CLIENT_GPIO) += pps-gpio.o
8 9
9ccflags-$(CONFIG_PPS_DEBUG) := -DDEBUG 10ccflags-$(CONFIG_PPS_DEBUG) := -DDEBUG
diff --git a/drivers/pps/clients/pps-gpio.c b/drivers/pps/clients/pps-gpio.c
new file mode 100644
index 000000000000..655055545479
--- /dev/null
+++ b/drivers/pps/clients/pps-gpio.c
@@ -0,0 +1,227 @@
1/*
2 * pps-gpio.c -- PPS client driver using GPIO
3 *
4 *
5 * Copyright (C) 2010 Ricardo Martins <rasm@fe.up.pt>
6 * Copyright (C) 2011 James Nuss <jamesnuss@nanometrics.ca>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23#define PPS_GPIO_NAME "pps-gpio"
24#define pr_fmt(fmt) PPS_GPIO_NAME ": " fmt
25
26#include <linux/init.h>
27#include <linux/kernel.h>
28#include <linux/interrupt.h>
29#include <linux/module.h>
30#include <linux/platform_device.h>
31#include <linux/slab.h>
32#include <linux/pps_kernel.h>
33#include <linux/pps-gpio.h>
34#include <linux/gpio.h>
35#include <linux/list.h>
36
37/* Info for each registered platform device */
38struct pps_gpio_device_data {
39 int irq; /* IRQ used as PPS source */
40 struct pps_device *pps; /* PPS source device */
41 struct pps_source_info info; /* PPS source information */
42 const struct pps_gpio_platform_data *pdata;
43};
44
45/*
46 * Report the PPS event
47 */
48
49static irqreturn_t pps_gpio_irq_handler(int irq, void *data)
50{
51 const struct pps_gpio_device_data *info;
52 struct pps_event_time ts;
53 int rising_edge;
54
55 /* Get the time stamp first */
56 pps_get_ts(&ts);
57
58 info = data;
59
60 rising_edge = gpio_get_value(info->pdata->gpio_pin);
61 if ((rising_edge && !info->pdata->assert_falling_edge) ||
62 (!rising_edge && info->pdata->assert_falling_edge))
63 pps_event(info->pps, &ts, PPS_CAPTUREASSERT, NULL);
64 else if (info->pdata->capture_clear &&
65 ((rising_edge && info->pdata->assert_falling_edge) ||
66 (!rising_edge && !info->pdata->assert_falling_edge)))
67 pps_event(info->pps, &ts, PPS_CAPTURECLEAR, NULL);
68
69 return IRQ_HANDLED;
70}
71
72static int pps_gpio_setup(struct platform_device *pdev)
73{
74 int ret;
75 const struct pps_gpio_platform_data *pdata = pdev->dev.platform_data;
76
77 ret = gpio_request(pdata->gpio_pin, pdata->gpio_label);
78 if (ret) {
79 pr_warning("failed to request GPIO %u\n", pdata->gpio_pin);
80 return -EINVAL;
81 }
82
83 ret = gpio_direction_input(pdata->gpio_pin);
84 if (ret) {
85 pr_warning("failed to set pin direction\n");
86 gpio_free(pdata->gpio_pin);
87 return -EINVAL;
88 }
89
90 return 0;
91}
92
93static unsigned long
94get_irqf_trigger_flags(const struct pps_gpio_platform_data *pdata)
95{
96 unsigned long flags = pdata->assert_falling_edge ?
97 IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING;
98
99 if (pdata->capture_clear) {
100 flags |= ((flags & IRQF_TRIGGER_RISING) ?
101 IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING);
102 }
103
104 return flags;
105}
106
107static int pps_gpio_probe(struct platform_device *pdev)
108{
109 struct pps_gpio_device_data *data;
110 int irq;
111 int ret;
112 int err;
113 int pps_default_params;
114 const struct pps_gpio_platform_data *pdata = pdev->dev.platform_data;
115
116
117 /* GPIO setup */
118 ret = pps_gpio_setup(pdev);
119 if (ret)
120 return -EINVAL;
121
122 /* IRQ setup */
123 irq = gpio_to_irq(pdata->gpio_pin);
124 if (irq < 0) {
125 pr_err("failed to map GPIO to IRQ: %d\n", irq);
126 err = -EINVAL;
127 goto return_error;
128 }
129
130 /* allocate space for device info */
131 data = kzalloc(sizeof(struct pps_gpio_device_data), GFP_KERNEL);
132 if (data == NULL) {
133 err = -ENOMEM;
134 goto return_error;
135 }
136
137 /* initialize PPS specific parts of the bookkeeping data structure. */
138 data->info.mode = PPS_CAPTUREASSERT | PPS_OFFSETASSERT |
139 PPS_ECHOASSERT | PPS_CANWAIT | PPS_TSFMT_TSPEC;
140 if (pdata->capture_clear)
141 data->info.mode |= PPS_CAPTURECLEAR | PPS_OFFSETCLEAR |
142 PPS_ECHOCLEAR;
143 data->info.owner = THIS_MODULE;
144 snprintf(data->info.name, PPS_MAX_NAME_LEN - 1, "%s.%d",
145 pdev->name, pdev->id);
146
147 /* register PPS source */
148 pps_default_params = PPS_CAPTUREASSERT | PPS_OFFSETASSERT;
149 if (pdata->capture_clear)
150 pps_default_params |= PPS_CAPTURECLEAR | PPS_OFFSETCLEAR;
151 data->pps = pps_register_source(&data->info, pps_default_params);
152 if (data->pps == NULL) {
153 kfree(data);
154 pr_err("failed to register IRQ %d as PPS source\n", irq);
155 err = -EINVAL;
156 goto return_error;
157 }
158
159 data->irq = irq;
160 data->pdata = pdata;
161
162 /* register IRQ interrupt handler */
163 ret = request_irq(irq, pps_gpio_irq_handler,
164 get_irqf_trigger_flags(pdata), data->info.name, data);
165 if (ret) {
166 pps_unregister_source(data->pps);
167 kfree(data);
168 pr_err("failed to acquire IRQ %d\n", irq);
169 err = -EINVAL;
170 goto return_error;
171 }
172
173 platform_set_drvdata(pdev, data);
174 dev_info(data->pps->dev, "Registered IRQ %d as PPS source\n", irq);
175
176 return 0;
177
178return_error:
179 gpio_free(pdata->gpio_pin);
180 return err;
181}
182
183static int pps_gpio_remove(struct platform_device *pdev)
184{
185 struct pps_gpio_device_data *data = platform_get_drvdata(pdev);
186 const struct pps_gpio_platform_data *pdata = data->pdata;
187
188 platform_set_drvdata(pdev, NULL);
189 free_irq(data->irq, data);
190 gpio_free(pdata->gpio_pin);
191 pps_unregister_source(data->pps);
192 pr_info("removed IRQ %d as PPS source\n", data->irq);
193 kfree(data);
194 return 0;
195}
196
197static struct platform_driver pps_gpio_driver = {
198 .probe = pps_gpio_probe,
199 .remove = __devexit_p(pps_gpio_remove),
200 .driver = {
201 .name = PPS_GPIO_NAME,
202 .owner = THIS_MODULE
203 },
204};
205
206static int __init pps_gpio_init(void)
207{
208 int ret = platform_driver_register(&pps_gpio_driver);
209 if (ret < 0)
210 pr_err("failed to register platform driver\n");
211 return ret;
212}
213
214static void __exit pps_gpio_exit(void)
215{
216 platform_driver_unregister(&pps_gpio_driver);
217 pr_debug("unregistered platform driver\n");
218}
219
220module_init(pps_gpio_init);
221module_exit(pps_gpio_exit);
222
223MODULE_AUTHOR("Ricardo Martins <rasm@fe.up.pt>");
224MODULE_AUTHOR("James Nuss <jamesnuss@nanometrics.ca>");
225MODULE_DESCRIPTION("Use GPIO pin as PPS source");
226MODULE_LICENSE("GPL");
227MODULE_VERSION("1.0.0");
diff --git a/drivers/pps/clients/pps-ktimer.c b/drivers/pps/clients/pps-ktimer.c
index 82583b0ff82d..436b4e4e71a1 100644
--- a/drivers/pps/clients/pps-ktimer.c
+++ b/drivers/pps/clients/pps-ktimer.c
@@ -52,17 +52,6 @@ static void pps_ktimer_event(unsigned long ptr)
52} 52}
53 53
54/* 54/*
55 * The echo function
56 */
57
58static void pps_ktimer_echo(struct pps_device *pps, int event, void *data)
59{
60 dev_info(pps->dev, "echo %s %s\n",
61 event & PPS_CAPTUREASSERT ? "assert" : "",
62 event & PPS_CAPTURECLEAR ? "clear" : "");
63}
64
65/*
66 * The PPS info struct 55 * The PPS info struct
67 */ 56 */
68 57
@@ -72,7 +61,6 @@ static struct pps_source_info pps_ktimer_info = {
72 .mode = PPS_CAPTUREASSERT | PPS_OFFSETASSERT | 61 .mode = PPS_CAPTUREASSERT | PPS_OFFSETASSERT |
73 PPS_ECHOASSERT | 62 PPS_ECHOASSERT |
74 PPS_CANWAIT | PPS_TSFMT_TSPEC, 63 PPS_CANWAIT | PPS_TSFMT_TSPEC,
75 .echo = pps_ktimer_echo,
76 .owner = THIS_MODULE, 64 .owner = THIS_MODULE,
77}; 65};
78 66
diff --git a/drivers/pps/clients/pps_parport.c b/drivers/pps/clients/pps_parport.c
index c571d6dd8f61..e1b4705ae3ec 100644
--- a/drivers/pps/clients/pps_parport.c
+++ b/drivers/pps/clients/pps_parport.c
@@ -133,14 +133,6 @@ out_both:
133 return; 133 return;
134} 134}
135 135
136/* the PPS echo function */
137static void pps_echo(struct pps_device *pps, int event, void *data)
138{
139 dev_info(pps->dev, "echo %s %s\n",
140 event & PPS_CAPTUREASSERT ? "assert" : "",
141 event & PPS_CAPTURECLEAR ? "clear" : "");
142}
143
144static void parport_attach(struct parport *port) 136static void parport_attach(struct parport *port)
145{ 137{
146 struct pps_client_pp *device; 138 struct pps_client_pp *device;
@@ -151,7 +143,6 @@ static void parport_attach(struct parport *port)
151 PPS_OFFSETASSERT | PPS_OFFSETCLEAR | \ 143 PPS_OFFSETASSERT | PPS_OFFSETCLEAR | \
152 PPS_ECHOASSERT | PPS_ECHOCLEAR | \ 144 PPS_ECHOASSERT | PPS_ECHOCLEAR | \
153 PPS_CANWAIT | PPS_TSFMT_TSPEC, 145 PPS_CANWAIT | PPS_TSFMT_TSPEC,
154 .echo = pps_echo,
155 .owner = THIS_MODULE, 146 .owner = THIS_MODULE,
156 .dev = NULL 147 .dev = NULL
157 }; 148 };
diff --git a/drivers/pps/kapi.c b/drivers/pps/kapi.c
index a4e8eb9fece6..f197e8ea185c 100644
--- a/drivers/pps/kapi.c
+++ b/drivers/pps/kapi.c
@@ -52,6 +52,14 @@ static void pps_add_offset(struct pps_ktime *ts, struct pps_ktime *offset)
52 ts->sec += offset->sec; 52 ts->sec += offset->sec;
53} 53}
54 54
55static void pps_echo_client_default(struct pps_device *pps, int event,
56 void *data)
57{
58 dev_info(pps->dev, "echo %s %s\n",
59 event & PPS_CAPTUREASSERT ? "assert" : "",
60 event & PPS_CAPTURECLEAR ? "clear" : "");
61}
62
55/* 63/*
56 * Exported functions 64 * Exported functions
57 */ 65 */
@@ -80,13 +88,6 @@ struct pps_device *pps_register_source(struct pps_source_info *info,
80 err = -EINVAL; 88 err = -EINVAL;
81 goto pps_register_source_exit; 89 goto pps_register_source_exit;
82 } 90 }
83 if ((info->mode & (PPS_ECHOASSERT | PPS_ECHOCLEAR)) != 0 &&
84 info->echo == NULL) {
85 pr_err("%s: echo function is not defined\n",
86 info->name);
87 err = -EINVAL;
88 goto pps_register_source_exit;
89 }
90 if ((info->mode & (PPS_TSFMT_TSPEC | PPS_TSFMT_NTPFP)) == 0) { 91 if ((info->mode & (PPS_TSFMT_TSPEC | PPS_TSFMT_NTPFP)) == 0) {
91 pr_err("%s: unspecified time format\n", 92 pr_err("%s: unspecified time format\n",
92 info->name); 93 info->name);
@@ -108,6 +109,11 @@ struct pps_device *pps_register_source(struct pps_source_info *info,
108 pps->params.mode = default_params; 109 pps->params.mode = default_params;
109 pps->info = *info; 110 pps->info = *info;
110 111
112 /* check for default echo function */
113 if ((pps->info.mode & (PPS_ECHOASSERT | PPS_ECHOCLEAR)) &&
114 pps->info.echo == NULL)
115 pps->info.echo = pps_echo_client_default;
116
111 init_waitqueue_head(&pps->queue); 117 init_waitqueue_head(&pps->queue);
112 spin_lock_init(&pps->lock); 118 spin_lock_init(&pps->lock);
113 119
diff --git a/drivers/ps3/ps3stor_lib.c b/drivers/ps3/ps3stor_lib.c
index af0afa1db4a8..cc328dec946b 100644
--- a/drivers/ps3/ps3stor_lib.c
+++ b/drivers/ps3/ps3stor_lib.c
@@ -19,6 +19,7 @@
19 */ 19 */
20 20
21#include <linux/dma-mapping.h> 21#include <linux/dma-mapping.h>
22#include <linux/module.h>
22 23
23#include <asm/lv1call.h> 24#include <asm/lv1call.h>
24#include <asm/ps3stor.h> 25#include <asm/ps3stor.h>
diff --git a/drivers/ps3/sys-manager-core.c b/drivers/ps3/sys-manager-core.c
index 474225852b63..0e41737ea835 100644
--- a/drivers/ps3/sys-manager-core.c
+++ b/drivers/ps3/sys-manager-core.c
@@ -19,6 +19,7 @@
19 */ 19 */
20 20
21#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include <linux/export.h>
22#include <asm/lv1call.h> 23#include <asm/lv1call.h>
23#include <asm/ps3.h> 24#include <asm/ps3.h>
24 25
diff --git a/drivers/rapidio/Kconfig b/drivers/rapidio/Kconfig
index 070211a5955c..bc8719238793 100644
--- a/drivers/rapidio/Kconfig
+++ b/drivers/rapidio/Kconfig
@@ -1,6 +1,8 @@
1# 1#
2# RapidIO configuration 2# RapidIO configuration
3# 3#
4source "drivers/rapidio/devices/Kconfig"
5
4config RAPIDIO_DISC_TIMEOUT 6config RAPIDIO_DISC_TIMEOUT
5 int "Discovery timeout duration (seconds)" 7 int "Discovery timeout duration (seconds)"
6 depends on RAPIDIO 8 depends on RAPIDIO
@@ -20,8 +22,6 @@ config RAPIDIO_ENABLE_RX_TX_PORTS
20 ports for Input/Output direction to allow other traffic 22 ports for Input/Output direction to allow other traffic
21 than Maintenance transfers. 23 than Maintenance transfers.
22 24
23source "drivers/rapidio/switches/Kconfig"
24
25config RAPIDIO_DEBUG 25config RAPIDIO_DEBUG
26 bool "RapidIO subsystem debug messages" 26 bool "RapidIO subsystem debug messages"
27 depends on RAPIDIO 27 depends on RAPIDIO
@@ -32,3 +32,5 @@ config RAPIDIO_DEBUG
32 going on. 32 going on.
33 33
34 If you are unsure about this, say N here. 34 If you are unsure about this, say N here.
35
36source "drivers/rapidio/switches/Kconfig"
diff --git a/drivers/rapidio/Makefile b/drivers/rapidio/Makefile
index 89b8eca825b5..ec3fb8121004 100644
--- a/drivers/rapidio/Makefile
+++ b/drivers/rapidio/Makefile
@@ -4,5 +4,6 @@
4obj-y += rio.o rio-access.o rio-driver.o rio-scan.o rio-sysfs.o 4obj-y += rio.o rio-access.o rio-driver.o rio-scan.o rio-sysfs.o
5 5
6obj-$(CONFIG_RAPIDIO) += switches/ 6obj-$(CONFIG_RAPIDIO) += switches/
7obj-$(CONFIG_RAPIDIO) += devices/
7 8
8subdir-ccflags-$(CONFIG_RAPIDIO_DEBUG) := -DDEBUG 9subdir-ccflags-$(CONFIG_RAPIDIO_DEBUG) := -DDEBUG
diff --git a/drivers/rapidio/devices/Kconfig b/drivers/rapidio/devices/Kconfig
new file mode 100644
index 000000000000..12a9d7f7040b
--- /dev/null
+++ b/drivers/rapidio/devices/Kconfig
@@ -0,0 +1,10 @@
1#
2# RapidIO master port configuration
3#
4
5config RAPIDIO_TSI721
6 bool "IDT Tsi721 PCI Express SRIO Controller support"
7 depends on RAPIDIO && PCIEPORTBUS
8 default "n"
9 ---help---
10 Include support for IDT Tsi721 PCI Express Serial RapidIO controller.
diff --git a/drivers/rapidio/devices/Makefile b/drivers/rapidio/devices/Makefile
new file mode 100644
index 000000000000..3b7b4e2dff7c
--- /dev/null
+++ b/drivers/rapidio/devices/Makefile
@@ -0,0 +1,5 @@
1#
2# Makefile for RapidIO devices
3#
4
5obj-$(CONFIG_RAPIDIO_TSI721) += tsi721.o
diff --git a/drivers/rapidio/devices/tsi721.c b/drivers/rapidio/devices/tsi721.c
new file mode 100644
index 000000000000..5225930a10cd
--- /dev/null
+++ b/drivers/rapidio/devices/tsi721.c
@@ -0,0 +1,2360 @@
1/*
2 * RapidIO mport driver for Tsi721 PCIExpress-to-SRIO bridge
3 *
4 * Copyright 2011 Integrated Device Technology, Inc.
5 * Alexandre Bounine <alexandre.bounine@idt.com>
6 * Chul Kim <chul.kim@idt.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 as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * this program; if not, write to the Free Software Foundation, Inc., 59
20 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 */
22
23#include <linux/io.h>
24#include <linux/errno.h>
25#include <linux/init.h>
26#include <linux/ioport.h>
27#include <linux/kernel.h>
28#include <linux/module.h>
29#include <linux/pci.h>
30#include <linux/rio.h>
31#include <linux/rio_drv.h>
32#include <linux/dma-mapping.h>
33#include <linux/interrupt.h>
34#include <linux/kfifo.h>
35#include <linux/delay.h>
36
37#include "tsi721.h"
38
39#define DEBUG_PW /* Inbound Port-Write debugging */
40
41static void tsi721_omsg_handler(struct tsi721_device *priv, int ch);
42static void tsi721_imsg_handler(struct tsi721_device *priv, int ch);
43
44/**
45 * tsi721_lcread - read from local SREP config space
46 * @mport: RapidIO master port info
47 * @index: ID of RapdiIO interface
48 * @offset: Offset into configuration space
49 * @len: Length (in bytes) of the maintenance transaction
50 * @data: Value to be read into
51 *
52 * Generates a local SREP space read. Returns %0 on
53 * success or %-EINVAL on failure.
54 */
55static int tsi721_lcread(struct rio_mport *mport, int index, u32 offset,
56 int len, u32 *data)
57{
58 struct tsi721_device *priv = mport->priv;
59
60 if (len != sizeof(u32))
61 return -EINVAL; /* only 32-bit access is supported */
62
63 *data = ioread32(priv->regs + offset);
64
65 return 0;
66}
67
68/**
69 * tsi721_lcwrite - write into local SREP config space
70 * @mport: RapidIO master port info
71 * @index: ID of RapdiIO interface
72 * @offset: Offset into configuration space
73 * @len: Length (in bytes) of the maintenance transaction
74 * @data: Value to be written
75 *
76 * Generates a local write into SREP configuration space. Returns %0 on
77 * success or %-EINVAL on failure.
78 */
79static int tsi721_lcwrite(struct rio_mport *mport, int index, u32 offset,
80 int len, u32 data)
81{
82 struct tsi721_device *priv = mport->priv;
83
84 if (len != sizeof(u32))
85 return -EINVAL; /* only 32-bit access is supported */
86
87 iowrite32(data, priv->regs + offset);
88
89 return 0;
90}
91
92/**
93 * tsi721_maint_dma - Helper function to generate RapidIO maintenance
94 * transactions using designated Tsi721 DMA channel.
95 * @priv: pointer to tsi721 private data
96 * @sys_size: RapdiIO transport system size
97 * @destid: Destination ID of transaction
98 * @hopcount: Number of hops to target device
99 * @offset: Offset into configuration space
100 * @len: Length (in bytes) of the maintenance transaction
101 * @data: Location to be read from or write into
102 * @do_wr: Operation flag (1 == MAINT_WR)
103 *
104 * Generates a RapidIO maintenance transaction (Read or Write).
105 * Returns %0 on success and %-EINVAL or %-EFAULT on failure.
106 */
107static int tsi721_maint_dma(struct tsi721_device *priv, u32 sys_size,
108 u16 destid, u8 hopcount, u32 offset, int len,
109 u32 *data, int do_wr)
110{
111 struct tsi721_dma_desc *bd_ptr;
112 u32 rd_count, swr_ptr, ch_stat;
113 int i, err = 0;
114 u32 op = do_wr ? MAINT_WR : MAINT_RD;
115
116 if (offset > (RIO_MAINT_SPACE_SZ - len) || (len != sizeof(u32)))
117 return -EINVAL;
118
119 bd_ptr = priv->bdma[TSI721_DMACH_MAINT].bd_base;
120
121 rd_count = ioread32(
122 priv->regs + TSI721_DMAC_DRDCNT(TSI721_DMACH_MAINT));
123
124 /* Initialize DMA descriptor */
125 bd_ptr[0].type_id = cpu_to_le32((DTYPE2 << 29) | (op << 19) | destid);
126 bd_ptr[0].bcount = cpu_to_le32((sys_size << 26) | 0x04);
127 bd_ptr[0].raddr_lo = cpu_to_le32((hopcount << 24) | offset);
128 bd_ptr[0].raddr_hi = 0;
129 if (do_wr)
130 bd_ptr[0].data[0] = cpu_to_be32p(data);
131 else
132 bd_ptr[0].data[0] = 0xffffffff;
133
134 mb();
135
136 /* Start DMA operation */
137 iowrite32(rd_count + 2,
138 priv->regs + TSI721_DMAC_DWRCNT(TSI721_DMACH_MAINT));
139 ioread32(priv->regs + TSI721_DMAC_DWRCNT(TSI721_DMACH_MAINT));
140 i = 0;
141
142 /* Wait until DMA transfer is finished */
143 while ((ch_stat = ioread32(priv->regs +
144 TSI721_DMAC_STS(TSI721_DMACH_MAINT))) & TSI721_DMAC_STS_RUN) {
145 udelay(1);
146 if (++i >= 5000000) {
147 dev_dbg(&priv->pdev->dev,
148 "%s : DMA[%d] read timeout ch_status=%x\n",
149 __func__, TSI721_DMACH_MAINT, ch_stat);
150 if (!do_wr)
151 *data = 0xffffffff;
152 err = -EIO;
153 goto err_out;
154 }
155 }
156
157 if (ch_stat & TSI721_DMAC_STS_ABORT) {
158 /* If DMA operation aborted due to error,
159 * reinitialize DMA channel
160 */
161 dev_dbg(&priv->pdev->dev, "%s : DMA ABORT ch_stat=%x\n",
162 __func__, ch_stat);
163 dev_dbg(&priv->pdev->dev, "OP=%d : destid=%x hc=%x off=%x\n",
164 do_wr ? MAINT_WR : MAINT_RD, destid, hopcount, offset);
165 iowrite32(TSI721_DMAC_INT_ALL,
166 priv->regs + TSI721_DMAC_INT(TSI721_DMACH_MAINT));
167 iowrite32(TSI721_DMAC_CTL_INIT,
168 priv->regs + TSI721_DMAC_CTL(TSI721_DMACH_MAINT));
169 udelay(10);
170 iowrite32(0, priv->regs +
171 TSI721_DMAC_DWRCNT(TSI721_DMACH_MAINT));
172 udelay(1);
173 if (!do_wr)
174 *data = 0xffffffff;
175 err = -EIO;
176 goto err_out;
177 }
178
179 if (!do_wr)
180 *data = be32_to_cpu(bd_ptr[0].data[0]);
181
182 /*
183 * Update descriptor status FIFO RD pointer.
184 * NOTE: Skipping check and clear FIFO entries because we are waiting
185 * for transfer to be completed.
186 */
187 swr_ptr = ioread32(priv->regs + TSI721_DMAC_DSWP(TSI721_DMACH_MAINT));
188 iowrite32(swr_ptr, priv->regs + TSI721_DMAC_DSRP(TSI721_DMACH_MAINT));
189err_out:
190
191 return err;
192}
193
194/**
195 * tsi721_cread_dma - Generate a RapidIO maintenance read transaction
196 * using Tsi721 BDMA engine.
197 * @mport: RapidIO master port control structure
198 * @index: ID of RapdiIO interface
199 * @destid: Destination ID of transaction
200 * @hopcount: Number of hops to target device
201 * @offset: Offset into configuration space
202 * @len: Length (in bytes) of the maintenance transaction
203 * @val: Location to be read into
204 *
205 * Generates a RapidIO maintenance read transaction.
206 * Returns %0 on success and %-EINVAL or %-EFAULT on failure.
207 */
208static int tsi721_cread_dma(struct rio_mport *mport, int index, u16 destid,
209 u8 hopcount, u32 offset, int len, u32 *data)
210{
211 struct tsi721_device *priv = mport->priv;
212
213 return tsi721_maint_dma(priv, mport->sys_size, destid, hopcount,
214 offset, len, data, 0);
215}
216
217/**
218 * tsi721_cwrite_dma - Generate a RapidIO maintenance write transaction
219 * using Tsi721 BDMA engine
220 * @mport: RapidIO master port control structure
221 * @index: ID of RapdiIO interface
222 * @destid: Destination ID of transaction
223 * @hopcount: Number of hops to target device
224 * @offset: Offset into configuration space
225 * @len: Length (in bytes) of the maintenance transaction
226 * @val: Value to be written
227 *
228 * Generates a RapidIO maintenance write transaction.
229 * Returns %0 on success and %-EINVAL or %-EFAULT on failure.
230 */
231static int tsi721_cwrite_dma(struct rio_mport *mport, int index, u16 destid,
232 u8 hopcount, u32 offset, int len, u32 data)
233{
234 struct tsi721_device *priv = mport->priv;
235 u32 temp = data;
236
237 return tsi721_maint_dma(priv, mport->sys_size, destid, hopcount,
238 offset, len, &temp, 1);
239}
240
241/**
242 * tsi721_pw_handler - Tsi721 inbound port-write interrupt handler
243 * @mport: RapidIO master port structure
244 *
245 * Handles inbound port-write interrupts. Copies PW message from an internal
246 * buffer into PW message FIFO and schedules deferred routine to process
247 * queued messages.
248 */
249static int
250tsi721_pw_handler(struct rio_mport *mport)
251{
252 struct tsi721_device *priv = mport->priv;
253 u32 pw_stat;
254 u32 pw_buf[TSI721_RIO_PW_MSG_SIZE/sizeof(u32)];
255
256
257 pw_stat = ioread32(priv->regs + TSI721_RIO_PW_RX_STAT);
258
259 if (pw_stat & TSI721_RIO_PW_RX_STAT_PW_VAL) {
260 pw_buf[0] = ioread32(priv->regs + TSI721_RIO_PW_RX_CAPT(0));
261 pw_buf[1] = ioread32(priv->regs + TSI721_RIO_PW_RX_CAPT(1));
262 pw_buf[2] = ioread32(priv->regs + TSI721_RIO_PW_RX_CAPT(2));
263 pw_buf[3] = ioread32(priv->regs + TSI721_RIO_PW_RX_CAPT(3));
264
265 /* Queue PW message (if there is room in FIFO),
266 * otherwise discard it.
267 */
268 spin_lock(&priv->pw_fifo_lock);
269 if (kfifo_avail(&priv->pw_fifo) >= TSI721_RIO_PW_MSG_SIZE)
270 kfifo_in(&priv->pw_fifo, pw_buf,
271 TSI721_RIO_PW_MSG_SIZE);
272 else
273 priv->pw_discard_count++;
274 spin_unlock(&priv->pw_fifo_lock);
275 }
276
277 /* Clear pending PW interrupts */
278 iowrite32(TSI721_RIO_PW_RX_STAT_PW_DISC | TSI721_RIO_PW_RX_STAT_PW_VAL,
279 priv->regs + TSI721_RIO_PW_RX_STAT);
280
281 schedule_work(&priv->pw_work);
282
283 return 0;
284}
285
286static void tsi721_pw_dpc(struct work_struct *work)
287{
288 struct tsi721_device *priv = container_of(work, struct tsi721_device,
289 pw_work);
290 u32 msg_buffer[RIO_PW_MSG_SIZE/sizeof(u32)]; /* Use full size PW message
291 buffer for RIO layer */
292
293 /*
294 * Process port-write messages
295 */
296 while (kfifo_out_spinlocked(&priv->pw_fifo, (unsigned char *)msg_buffer,
297 TSI721_RIO_PW_MSG_SIZE, &priv->pw_fifo_lock)) {
298 /* Process one message */
299#ifdef DEBUG_PW
300 {
301 u32 i;
302 pr_debug("%s : Port-Write Message:", __func__);
303 for (i = 0; i < RIO_PW_MSG_SIZE/sizeof(u32); ) {
304 pr_debug("0x%02x: %08x %08x %08x %08x", i*4,
305 msg_buffer[i], msg_buffer[i + 1],
306 msg_buffer[i + 2], msg_buffer[i + 3]);
307 i += 4;
308 }
309 pr_debug("\n");
310 }
311#endif
312 /* Pass the port-write message to RIO core for processing */
313 rio_inb_pwrite_handler((union rio_pw_msg *)msg_buffer);
314 }
315}
316
317/**
318 * tsi721_pw_enable - enable/disable port-write interface init
319 * @mport: Master port implementing the port write unit
320 * @enable: 1=enable; 0=disable port-write message handling
321 */
322static int tsi721_pw_enable(struct rio_mport *mport, int enable)
323{
324 struct tsi721_device *priv = mport->priv;
325 u32 rval;
326
327 rval = ioread32(priv->regs + TSI721_RIO_EM_INT_ENABLE);
328
329 if (enable)
330 rval |= TSI721_RIO_EM_INT_ENABLE_PW_RX;
331 else
332 rval &= ~TSI721_RIO_EM_INT_ENABLE_PW_RX;
333
334 /* Clear pending PW interrupts */
335 iowrite32(TSI721_RIO_PW_RX_STAT_PW_DISC | TSI721_RIO_PW_RX_STAT_PW_VAL,
336 priv->regs + TSI721_RIO_PW_RX_STAT);
337 /* Update enable bits */
338 iowrite32(rval, priv->regs + TSI721_RIO_EM_INT_ENABLE);
339
340 return 0;
341}
342
343/**
344 * tsi721_dsend - Send a RapidIO doorbell
345 * @mport: RapidIO master port info
346 * @index: ID of RapidIO interface
347 * @destid: Destination ID of target device
348 * @data: 16-bit info field of RapidIO doorbell
349 *
350 * Sends a RapidIO doorbell message. Always returns %0.
351 */
352static int tsi721_dsend(struct rio_mport *mport, int index,
353 u16 destid, u16 data)
354{
355 struct tsi721_device *priv = mport->priv;
356 u32 offset;
357
358 offset = (((mport->sys_size) ? RIO_TT_CODE_16 : RIO_TT_CODE_8) << 18) |
359 (destid << 2);
360
361 dev_dbg(&priv->pdev->dev,
362 "Send Doorbell 0x%04x to destID 0x%x\n", data, destid);
363 iowrite16be(data, priv->odb_base + offset);
364
365 return 0;
366}
367
368/**
369 * tsi721_dbell_handler - Tsi721 doorbell interrupt handler
370 * @mport: RapidIO master port structure
371 *
372 * Handles inbound doorbell interrupts. Copies doorbell entry from an internal
373 * buffer into DB message FIFO and schedules deferred routine to process
374 * queued DBs.
375 */
376static int
377tsi721_dbell_handler(struct rio_mport *mport)
378{
379 struct tsi721_device *priv = mport->priv;
380 u32 regval;
381
382 /* Disable IDB interrupts */
383 regval = ioread32(priv->regs + TSI721_SR_CHINTE(IDB_QUEUE));
384 regval &= ~TSI721_SR_CHINT_IDBQRCV;
385 iowrite32(regval,
386 priv->regs + TSI721_SR_CHINTE(IDB_QUEUE));
387
388 schedule_work(&priv->idb_work);
389
390 return 0;
391}
392
393static void tsi721_db_dpc(struct work_struct *work)
394{
395 struct tsi721_device *priv = container_of(work, struct tsi721_device,
396 idb_work);
397 struct rio_mport *mport;
398 struct rio_dbell *dbell;
399 int found = 0;
400 u32 wr_ptr, rd_ptr;
401 u64 *idb_entry;
402 u32 regval;
403 union {
404 u64 msg;
405 u8 bytes[8];
406 } idb;
407
408 /*
409 * Process queued inbound doorbells
410 */
411 mport = priv->mport;
412
413 wr_ptr = ioread32(priv->regs + TSI721_IDQ_WP(IDB_QUEUE));
414 rd_ptr = ioread32(priv->regs + TSI721_IDQ_RP(IDB_QUEUE));
415
416 while (wr_ptr != rd_ptr) {
417 idb_entry = (u64 *)(priv->idb_base +
418 (TSI721_IDB_ENTRY_SIZE * rd_ptr));
419 rd_ptr++;
420 idb.msg = *idb_entry;
421 *idb_entry = 0;
422
423 /* Process one doorbell */
424 list_for_each_entry(dbell, &mport->dbells, node) {
425 if ((dbell->res->start <= DBELL_INF(idb.bytes)) &&
426 (dbell->res->end >= DBELL_INF(idb.bytes))) {
427 found = 1;
428 break;
429 }
430 }
431
432 if (found) {
433 dbell->dinb(mport, dbell->dev_id, DBELL_SID(idb.bytes),
434 DBELL_TID(idb.bytes), DBELL_INF(idb.bytes));
435 } else {
436 dev_dbg(&priv->pdev->dev,
437 "spurious inb doorbell, sid %2.2x tid %2.2x"
438 " info %4.4x\n", DBELL_SID(idb.bytes),
439 DBELL_TID(idb.bytes), DBELL_INF(idb.bytes));
440 }
441 }
442
443 iowrite32(rd_ptr & (IDB_QSIZE - 1),
444 priv->regs + TSI721_IDQ_RP(IDB_QUEUE));
445
446 /* Re-enable IDB interrupts */
447 regval = ioread32(priv->regs + TSI721_SR_CHINTE(IDB_QUEUE));
448 regval |= TSI721_SR_CHINT_IDBQRCV;
449 iowrite32(regval,
450 priv->regs + TSI721_SR_CHINTE(IDB_QUEUE));
451}
452
453/**
454 * tsi721_irqhandler - Tsi721 interrupt handler
455 * @irq: Linux interrupt number
456 * @ptr: Pointer to interrupt-specific data (mport structure)
457 *
458 * Handles Tsi721 interrupts signaled using MSI and INTA. Checks reported
459 * interrupt events and calls an event-specific handler(s).
460 */
461static irqreturn_t tsi721_irqhandler(int irq, void *ptr)
462{
463 struct rio_mport *mport = (struct rio_mport *)ptr;
464 struct tsi721_device *priv = mport->priv;
465 u32 dev_int;
466 u32 dev_ch_int;
467 u32 intval;
468 u32 ch_inte;
469
470 dev_int = ioread32(priv->regs + TSI721_DEV_INT);
471 if (!dev_int)
472 return IRQ_NONE;
473
474 dev_ch_int = ioread32(priv->regs + TSI721_DEV_CHAN_INT);
475
476 if (dev_int & TSI721_DEV_INT_SR2PC_CH) {
477 /* Service SR2PC Channel interrupts */
478 if (dev_ch_int & TSI721_INT_SR2PC_CHAN(IDB_QUEUE)) {
479 /* Service Inbound Doorbell interrupt */
480 intval = ioread32(priv->regs +
481 TSI721_SR_CHINT(IDB_QUEUE));
482 if (intval & TSI721_SR_CHINT_IDBQRCV)
483 tsi721_dbell_handler(mport);
484 else
485 dev_info(&priv->pdev->dev,
486 "Unsupported SR_CH_INT %x\n", intval);
487
488 /* Clear interrupts */
489 iowrite32(intval,
490 priv->regs + TSI721_SR_CHINT(IDB_QUEUE));
491 ioread32(priv->regs + TSI721_SR_CHINT(IDB_QUEUE));
492 }
493 }
494
495 if (dev_int & TSI721_DEV_INT_SMSG_CH) {
496 int ch;
497
498 /*
499 * Service channel interrupts from Messaging Engine
500 */
501
502 if (dev_ch_int & TSI721_INT_IMSG_CHAN_M) { /* Inbound Msg */
503 /* Disable signaled OB MSG Channel interrupts */
504 ch_inte = ioread32(priv->regs + TSI721_DEV_CHAN_INTE);
505 ch_inte &= ~(dev_ch_int & TSI721_INT_IMSG_CHAN_M);
506 iowrite32(ch_inte, priv->regs + TSI721_DEV_CHAN_INTE);
507
508 /*
509 * Process Inbound Message interrupt for each MBOX
510 */
511 for (ch = 4; ch < RIO_MAX_MBOX + 4; ch++) {
512 if (!(dev_ch_int & TSI721_INT_IMSG_CHAN(ch)))
513 continue;
514 tsi721_imsg_handler(priv, ch);
515 }
516 }
517
518 if (dev_ch_int & TSI721_INT_OMSG_CHAN_M) { /* Outbound Msg */
519 /* Disable signaled OB MSG Channel interrupts */
520 ch_inte = ioread32(priv->regs + TSI721_DEV_CHAN_INTE);
521 ch_inte &= ~(dev_ch_int & TSI721_INT_OMSG_CHAN_M);
522 iowrite32(ch_inte, priv->regs + TSI721_DEV_CHAN_INTE);
523
524 /*
525 * Process Outbound Message interrupts for each MBOX
526 */
527
528 for (ch = 0; ch < RIO_MAX_MBOX; ch++) {
529 if (!(dev_ch_int & TSI721_INT_OMSG_CHAN(ch)))
530 continue;
531 tsi721_omsg_handler(priv, ch);
532 }
533 }
534 }
535
536 if (dev_int & TSI721_DEV_INT_SRIO) {
537 /* Service SRIO MAC interrupts */
538 intval = ioread32(priv->regs + TSI721_RIO_EM_INT_STAT);
539 if (intval & TSI721_RIO_EM_INT_STAT_PW_RX)
540 tsi721_pw_handler(mport);
541 }
542
543 return IRQ_HANDLED;
544}
545
546static void tsi721_interrupts_init(struct tsi721_device *priv)
547{
548 u32 intr;
549
550 /* Enable IDB interrupts */
551 iowrite32(TSI721_SR_CHINT_ALL,
552 priv->regs + TSI721_SR_CHINT(IDB_QUEUE));
553 iowrite32(TSI721_SR_CHINT_IDBQRCV,
554 priv->regs + TSI721_SR_CHINTE(IDB_QUEUE));
555 iowrite32(TSI721_INT_SR2PC_CHAN(IDB_QUEUE),
556 priv->regs + TSI721_DEV_CHAN_INTE);
557
558 /* Enable SRIO MAC interrupts */
559 iowrite32(TSI721_RIO_EM_DEV_INT_EN_INT,
560 priv->regs + TSI721_RIO_EM_DEV_INT_EN);
561
562 if (priv->flags & TSI721_USING_MSIX)
563 intr = TSI721_DEV_INT_SRIO;
564 else
565 intr = TSI721_DEV_INT_SR2PC_CH | TSI721_DEV_INT_SRIO |
566 TSI721_DEV_INT_SMSG_CH;
567
568 iowrite32(intr, priv->regs + TSI721_DEV_INTE);
569 ioread32(priv->regs + TSI721_DEV_INTE);
570}
571
572#ifdef CONFIG_PCI_MSI
573/**
574 * tsi721_omsg_msix - MSI-X interrupt handler for outbound messaging
575 * @irq: Linux interrupt number
576 * @ptr: Pointer to interrupt-specific data (mport structure)
577 *
578 * Handles outbound messaging interrupts signaled using MSI-X.
579 */
580static irqreturn_t tsi721_omsg_msix(int irq, void *ptr)
581{
582 struct tsi721_device *priv = ((struct rio_mport *)ptr)->priv;
583 int mbox;
584
585 mbox = (irq - priv->msix[TSI721_VECT_OMB0_DONE].vector) % RIO_MAX_MBOX;
586 tsi721_omsg_handler(priv, mbox);
587 return IRQ_HANDLED;
588}
589
590/**
591 * tsi721_imsg_msix - MSI-X interrupt handler for inbound messaging
592 * @irq: Linux interrupt number
593 * @ptr: Pointer to interrupt-specific data (mport structure)
594 *
595 * Handles inbound messaging interrupts signaled using MSI-X.
596 */
597static irqreturn_t tsi721_imsg_msix(int irq, void *ptr)
598{
599 struct tsi721_device *priv = ((struct rio_mport *)ptr)->priv;
600 int mbox;
601
602 mbox = (irq - priv->msix[TSI721_VECT_IMB0_RCV].vector) % RIO_MAX_MBOX;
603 tsi721_imsg_handler(priv, mbox + 4);
604 return IRQ_HANDLED;
605}
606
607/**
608 * tsi721_srio_msix - Tsi721 MSI-X SRIO MAC interrupt handler
609 * @irq: Linux interrupt number
610 * @ptr: Pointer to interrupt-specific data (mport structure)
611 *
612 * Handles Tsi721 interrupts from SRIO MAC.
613 */
614static irqreturn_t tsi721_srio_msix(int irq, void *ptr)
615{
616 struct tsi721_device *priv = ((struct rio_mport *)ptr)->priv;
617 u32 srio_int;
618
619 /* Service SRIO MAC interrupts */
620 srio_int = ioread32(priv->regs + TSI721_RIO_EM_INT_STAT);
621 if (srio_int & TSI721_RIO_EM_INT_STAT_PW_RX)
622 tsi721_pw_handler((struct rio_mport *)ptr);
623
624 return IRQ_HANDLED;
625}
626
627/**
628 * tsi721_sr2pc_ch_msix - Tsi721 MSI-X SR2PC Channel interrupt handler
629 * @irq: Linux interrupt number
630 * @ptr: Pointer to interrupt-specific data (mport structure)
631 *
632 * Handles Tsi721 interrupts from SR2PC Channel.
633 * NOTE: At this moment services only one SR2PC channel associated with inbound
634 * doorbells.
635 */
636static irqreturn_t tsi721_sr2pc_ch_msix(int irq, void *ptr)
637{
638 struct tsi721_device *priv = ((struct rio_mport *)ptr)->priv;
639 u32 sr_ch_int;
640
641 /* Service Inbound DB interrupt from SR2PC channel */
642 sr_ch_int = ioread32(priv->regs + TSI721_SR_CHINT(IDB_QUEUE));
643 if (sr_ch_int & TSI721_SR_CHINT_IDBQRCV)
644 tsi721_dbell_handler((struct rio_mport *)ptr);
645
646 /* Clear interrupts */
647 iowrite32(sr_ch_int, priv->regs + TSI721_SR_CHINT(IDB_QUEUE));
648 /* Read back to ensure that interrupt was cleared */
649 sr_ch_int = ioread32(priv->regs + TSI721_SR_CHINT(IDB_QUEUE));
650
651 return IRQ_HANDLED;
652}
653
654/**
655 * tsi721_request_msix - register interrupt service for MSI-X mode.
656 * @mport: RapidIO master port structure
657 *
658 * Registers MSI-X interrupt service routines for interrupts that are active
659 * immediately after mport initialization. Messaging interrupt service routines
660 * should be registered during corresponding open requests.
661 */
662static int tsi721_request_msix(struct rio_mport *mport)
663{
664 struct tsi721_device *priv = mport->priv;
665 int err = 0;
666
667 err = request_irq(priv->msix[TSI721_VECT_IDB].vector,
668 tsi721_sr2pc_ch_msix, 0,
669 priv->msix[TSI721_VECT_IDB].irq_name, (void *)mport);
670 if (err)
671 goto out;
672
673 err = request_irq(priv->msix[TSI721_VECT_PWRX].vector,
674 tsi721_srio_msix, 0,
675 priv->msix[TSI721_VECT_PWRX].irq_name, (void *)mport);
676 if (err)
677 free_irq(
678 priv->msix[TSI721_VECT_IDB].vector,
679 (void *)mport);
680out:
681 return err;
682}
683
684/**
685 * tsi721_enable_msix - Attempts to enable MSI-X support for Tsi721.
686 * @priv: pointer to tsi721 private data
687 *
688 * Configures MSI-X support for Tsi721. Supports only an exact number
689 * of requested vectors.
690 */
691static int tsi721_enable_msix(struct tsi721_device *priv)
692{
693 struct msix_entry entries[TSI721_VECT_MAX];
694 int err;
695 int i;
696
697 entries[TSI721_VECT_IDB].entry = TSI721_MSIX_SR2PC_IDBQ_RCV(IDB_QUEUE);
698 entries[TSI721_VECT_PWRX].entry = TSI721_MSIX_SRIO_MAC_INT;
699
700 /*
701 * Initialize MSI-X entries for Messaging Engine:
702 * this driver supports four RIO mailboxes (inbound and outbound)
703 * NOTE: Inbound message MBOX 0...4 use IB channels 4...7. Therefore
704 * offset +4 is added to IB MBOX number.
705 */
706 for (i = 0; i < RIO_MAX_MBOX; i++) {
707 entries[TSI721_VECT_IMB0_RCV + i].entry =
708 TSI721_MSIX_IMSG_DQ_RCV(i + 4);
709 entries[TSI721_VECT_IMB0_INT + i].entry =
710 TSI721_MSIX_IMSG_INT(i + 4);
711 entries[TSI721_VECT_OMB0_DONE + i].entry =
712 TSI721_MSIX_OMSG_DONE(i);
713 entries[TSI721_VECT_OMB0_INT + i].entry =
714 TSI721_MSIX_OMSG_INT(i);
715 }
716
717 err = pci_enable_msix(priv->pdev, entries, ARRAY_SIZE(entries));
718 if (err) {
719 if (err > 0)
720 dev_info(&priv->pdev->dev,
721 "Only %d MSI-X vectors available, "
722 "not using MSI-X\n", err);
723 return err;
724 }
725
726 /*
727 * Copy MSI-X vector information into tsi721 private structure
728 */
729 priv->msix[TSI721_VECT_IDB].vector = entries[TSI721_VECT_IDB].vector;
730 snprintf(priv->msix[TSI721_VECT_IDB].irq_name, IRQ_DEVICE_NAME_MAX,
731 DRV_NAME "-idb@pci:%s", pci_name(priv->pdev));
732 priv->msix[TSI721_VECT_PWRX].vector = entries[TSI721_VECT_PWRX].vector;
733 snprintf(priv->msix[TSI721_VECT_PWRX].irq_name, IRQ_DEVICE_NAME_MAX,
734 DRV_NAME "-pwrx@pci:%s", pci_name(priv->pdev));
735
736 for (i = 0; i < RIO_MAX_MBOX; i++) {
737 priv->msix[TSI721_VECT_IMB0_RCV + i].vector =
738 entries[TSI721_VECT_IMB0_RCV + i].vector;
739 snprintf(priv->msix[TSI721_VECT_IMB0_RCV + i].irq_name,
740 IRQ_DEVICE_NAME_MAX, DRV_NAME "-imbr%d@pci:%s",
741 i, pci_name(priv->pdev));
742
743 priv->msix[TSI721_VECT_IMB0_INT + i].vector =
744 entries[TSI721_VECT_IMB0_INT + i].vector;
745 snprintf(priv->msix[TSI721_VECT_IMB0_INT + i].irq_name,
746 IRQ_DEVICE_NAME_MAX, DRV_NAME "-imbi%d@pci:%s",
747 i, pci_name(priv->pdev));
748
749 priv->msix[TSI721_VECT_OMB0_DONE + i].vector =
750 entries[TSI721_VECT_OMB0_DONE + i].vector;
751 snprintf(priv->msix[TSI721_VECT_OMB0_DONE + i].irq_name,
752 IRQ_DEVICE_NAME_MAX, DRV_NAME "-ombd%d@pci:%s",
753 i, pci_name(priv->pdev));
754
755 priv->msix[TSI721_VECT_OMB0_INT + i].vector =
756 entries[TSI721_VECT_OMB0_INT + i].vector;
757 snprintf(priv->msix[TSI721_VECT_OMB0_INT + i].irq_name,
758 IRQ_DEVICE_NAME_MAX, DRV_NAME "-ombi%d@pci:%s",
759 i, pci_name(priv->pdev));
760 }
761
762 return 0;
763}
764#endif /* CONFIG_PCI_MSI */
765
766static int tsi721_request_irq(struct rio_mport *mport)
767{
768 struct tsi721_device *priv = mport->priv;
769 int err;
770
771#ifdef CONFIG_PCI_MSI
772 if (priv->flags & TSI721_USING_MSIX)
773 err = tsi721_request_msix(mport);
774 else
775#endif
776 err = request_irq(priv->pdev->irq, tsi721_irqhandler,
777 (priv->flags & TSI721_USING_MSI) ? 0 : IRQF_SHARED,
778 DRV_NAME, (void *)mport);
779
780 if (err)
781 dev_err(&priv->pdev->dev,
782 "Unable to allocate interrupt, Error: %d\n", err);
783
784 return err;
785}
786
787/**
788 * tsi721_init_pc2sr_mapping - initializes outbound (PCIe->SRIO)
789 * translation regions.
790 * @priv: pointer to tsi721 private data
791 *
792 * Disables SREP translation regions.
793 */
794static void tsi721_init_pc2sr_mapping(struct tsi721_device *priv)
795{
796 int i;
797
798 /* Disable all PC2SR translation windows */
799 for (i = 0; i < TSI721_OBWIN_NUM; i++)
800 iowrite32(0, priv->regs + TSI721_OBWINLB(i));
801}
802
803/**
804 * tsi721_init_sr2pc_mapping - initializes inbound (SRIO->PCIe)
805 * translation regions.
806 * @priv: pointer to tsi721 private data
807 *
808 * Disables inbound windows.
809 */
810static void tsi721_init_sr2pc_mapping(struct tsi721_device *priv)
811{
812 int i;
813
814 /* Disable all SR2PC inbound windows */
815 for (i = 0; i < TSI721_IBWIN_NUM; i++)
816 iowrite32(0, priv->regs + TSI721_IBWINLB(i));
817}
818
819/**
820 * tsi721_port_write_init - Inbound port write interface init
821 * @priv: pointer to tsi721 private data
822 *
823 * Initializes inbound port write handler.
824 * Returns %0 on success or %-ENOMEM on failure.
825 */
826static int tsi721_port_write_init(struct tsi721_device *priv)
827{
828 priv->pw_discard_count = 0;
829 INIT_WORK(&priv->pw_work, tsi721_pw_dpc);
830 spin_lock_init(&priv->pw_fifo_lock);
831 if (kfifo_alloc(&priv->pw_fifo,
832 TSI721_RIO_PW_MSG_SIZE * 32, GFP_KERNEL)) {
833 dev_err(&priv->pdev->dev, "PW FIFO allocation failed\n");
834 return -ENOMEM;
835 }
836
837 /* Use reliable port-write capture mode */
838 iowrite32(TSI721_RIO_PW_CTL_PWC_REL, priv->regs + TSI721_RIO_PW_CTL);
839 return 0;
840}
841
842static int tsi721_doorbell_init(struct tsi721_device *priv)
843{
844 /* Outbound Doorbells do not require any setup.
845 * Tsi721 uses dedicated PCI BAR1 to generate doorbells.
846 * That BAR1 was mapped during the probe routine.
847 */
848
849 /* Initialize Inbound Doorbell processing DPC and queue */
850 priv->db_discard_count = 0;
851 INIT_WORK(&priv->idb_work, tsi721_db_dpc);
852
853 /* Allocate buffer for inbound doorbells queue */
854 priv->idb_base = dma_alloc_coherent(&priv->pdev->dev,
855 IDB_QSIZE * TSI721_IDB_ENTRY_SIZE,
856 &priv->idb_dma, GFP_KERNEL);
857 if (!priv->idb_base)
858 return -ENOMEM;
859
860 memset(priv->idb_base, 0, IDB_QSIZE * TSI721_IDB_ENTRY_SIZE);
861
862 dev_dbg(&priv->pdev->dev, "Allocated IDB buffer @ %p (phys = %llx)\n",
863 priv->idb_base, (unsigned long long)priv->idb_dma);
864
865 iowrite32(TSI721_IDQ_SIZE_VAL(IDB_QSIZE),
866 priv->regs + TSI721_IDQ_SIZE(IDB_QUEUE));
867 iowrite32(((u64)priv->idb_dma >> 32),
868 priv->regs + TSI721_IDQ_BASEU(IDB_QUEUE));
869 iowrite32(((u64)priv->idb_dma & TSI721_IDQ_BASEL_ADDR),
870 priv->regs + TSI721_IDQ_BASEL(IDB_QUEUE));
871 /* Enable accepting all inbound doorbells */
872 iowrite32(0, priv->regs + TSI721_IDQ_MASK(IDB_QUEUE));
873
874 iowrite32(TSI721_IDQ_INIT, priv->regs + TSI721_IDQ_CTL(IDB_QUEUE));
875
876 iowrite32(0, priv->regs + TSI721_IDQ_RP(IDB_QUEUE));
877
878 return 0;
879}
880
881static void tsi721_doorbell_free(struct tsi721_device *priv)
882{
883 if (priv->idb_base == NULL)
884 return;
885
886 /* Free buffer allocated for inbound doorbell queue */
887 dma_free_coherent(&priv->pdev->dev, IDB_QSIZE * TSI721_IDB_ENTRY_SIZE,
888 priv->idb_base, priv->idb_dma);
889 priv->idb_base = NULL;
890}
891
892static int tsi721_bdma_ch_init(struct tsi721_device *priv, int chnum)
893{
894 struct tsi721_dma_desc *bd_ptr;
895 u64 *sts_ptr;
896 dma_addr_t bd_phys, sts_phys;
897 int sts_size;
898 int bd_num = priv->bdma[chnum].bd_num;
899
900 dev_dbg(&priv->pdev->dev, "Init Block DMA Engine, CH%d\n", chnum);
901
902 /*
903 * Initialize DMA channel for maintenance requests
904 */
905
906 /* Allocate space for DMA descriptors */
907 bd_ptr = dma_alloc_coherent(&priv->pdev->dev,
908 bd_num * sizeof(struct tsi721_dma_desc),
909 &bd_phys, GFP_KERNEL);
910 if (!bd_ptr)
911 return -ENOMEM;
912
913 priv->bdma[chnum].bd_phys = bd_phys;
914 priv->bdma[chnum].bd_base = bd_ptr;
915
916 memset(bd_ptr, 0, bd_num * sizeof(struct tsi721_dma_desc));
917
918 dev_dbg(&priv->pdev->dev, "DMA descriptors @ %p (phys = %llx)\n",
919 bd_ptr, (unsigned long long)bd_phys);
920
921 /* Allocate space for descriptor status FIFO */
922 sts_size = (bd_num >= TSI721_DMA_MINSTSSZ) ?
923 bd_num : TSI721_DMA_MINSTSSZ;
924 sts_size = roundup_pow_of_two(sts_size);
925 sts_ptr = dma_alloc_coherent(&priv->pdev->dev,
926 sts_size * sizeof(struct tsi721_dma_sts),
927 &sts_phys, GFP_KERNEL);
928 if (!sts_ptr) {
929 /* Free space allocated for DMA descriptors */
930 dma_free_coherent(&priv->pdev->dev,
931 bd_num * sizeof(struct tsi721_dma_desc),
932 bd_ptr, bd_phys);
933 priv->bdma[chnum].bd_base = NULL;
934 return -ENOMEM;
935 }
936
937 priv->bdma[chnum].sts_phys = sts_phys;
938 priv->bdma[chnum].sts_base = sts_ptr;
939 priv->bdma[chnum].sts_size = sts_size;
940
941 memset(sts_ptr, 0, sts_size);
942
943 dev_dbg(&priv->pdev->dev,
944 "desc status FIFO @ %p (phys = %llx) size=0x%x\n",
945 sts_ptr, (unsigned long long)sts_phys, sts_size);
946
947 /* Initialize DMA descriptors ring */
948 bd_ptr[bd_num - 1].type_id = cpu_to_le32(DTYPE3 << 29);
949 bd_ptr[bd_num - 1].next_lo = cpu_to_le32((u64)bd_phys &
950 TSI721_DMAC_DPTRL_MASK);
951 bd_ptr[bd_num - 1].next_hi = cpu_to_le32((u64)bd_phys >> 32);
952
953 /* Setup DMA descriptor pointers */
954 iowrite32(((u64)bd_phys >> 32),
955 priv->regs + TSI721_DMAC_DPTRH(chnum));
956 iowrite32(((u64)bd_phys & TSI721_DMAC_DPTRL_MASK),
957 priv->regs + TSI721_DMAC_DPTRL(chnum));
958
959 /* Setup descriptor status FIFO */
960 iowrite32(((u64)sts_phys >> 32),
961 priv->regs + TSI721_DMAC_DSBH(chnum));
962 iowrite32(((u64)sts_phys & TSI721_DMAC_DSBL_MASK),
963 priv->regs + TSI721_DMAC_DSBL(chnum));
964 iowrite32(TSI721_DMAC_DSSZ_SIZE(sts_size),
965 priv->regs + TSI721_DMAC_DSSZ(chnum));
966
967 /* Clear interrupt bits */
968 iowrite32(TSI721_DMAC_INT_ALL,
969 priv->regs + TSI721_DMAC_INT(chnum));
970
971 ioread32(priv->regs + TSI721_DMAC_INT(chnum));
972
973 /* Toggle DMA channel initialization */
974 iowrite32(TSI721_DMAC_CTL_INIT, priv->regs + TSI721_DMAC_CTL(chnum));
975 ioread32(priv->regs + TSI721_DMAC_CTL(chnum));
976 udelay(10);
977
978 return 0;
979}
980
981static int tsi721_bdma_ch_free(struct tsi721_device *priv, int chnum)
982{
983 u32 ch_stat;
984
985 if (priv->bdma[chnum].bd_base == NULL)
986 return 0;
987
988 /* Check if DMA channel still running */
989 ch_stat = ioread32(priv->regs + TSI721_DMAC_STS(chnum));
990 if (ch_stat & TSI721_DMAC_STS_RUN)
991 return -EFAULT;
992
993 /* Put DMA channel into init state */
994 iowrite32(TSI721_DMAC_CTL_INIT,
995 priv->regs + TSI721_DMAC_CTL(chnum));
996
997 /* Free space allocated for DMA descriptors */
998 dma_free_coherent(&priv->pdev->dev,
999 priv->bdma[chnum].bd_num * sizeof(struct tsi721_dma_desc),
1000 priv->bdma[chnum].bd_base, priv->bdma[chnum].bd_phys);
1001 priv->bdma[chnum].bd_base = NULL;
1002
1003 /* Free space allocated for status FIFO */
1004 dma_free_coherent(&priv->pdev->dev,
1005 priv->bdma[chnum].sts_size * sizeof(struct tsi721_dma_sts),
1006 priv->bdma[chnum].sts_base, priv->bdma[chnum].sts_phys);
1007 priv->bdma[chnum].sts_base = NULL;
1008 return 0;
1009}
1010
1011static int tsi721_bdma_init(struct tsi721_device *priv)
1012{
1013 /* Initialize BDMA channel allocated for RapidIO maintenance read/write
1014 * request generation
1015 */
1016 priv->bdma[TSI721_DMACH_MAINT].bd_num = 2;
1017 if (tsi721_bdma_ch_init(priv, TSI721_DMACH_MAINT)) {
1018 dev_err(&priv->pdev->dev, "Unable to initialize maintenance DMA"
1019 " channel %d, aborting\n", TSI721_DMACH_MAINT);
1020 return -ENOMEM;
1021 }
1022
1023 return 0;
1024}
1025
1026static void tsi721_bdma_free(struct tsi721_device *priv)
1027{
1028 tsi721_bdma_ch_free(priv, TSI721_DMACH_MAINT);
1029}
1030
1031/* Enable Inbound Messaging Interrupts */
1032static void
1033tsi721_imsg_interrupt_enable(struct tsi721_device *priv, int ch,
1034 u32 inte_mask)
1035{
1036 u32 rval;
1037
1038 if (!inte_mask)
1039 return;
1040
1041 /* Clear pending Inbound Messaging interrupts */
1042 iowrite32(inte_mask, priv->regs + TSI721_IBDMAC_INT(ch));
1043
1044 /* Enable Inbound Messaging interrupts */
1045 rval = ioread32(priv->regs + TSI721_IBDMAC_INTE(ch));
1046 iowrite32(rval | inte_mask, priv->regs + TSI721_IBDMAC_INTE(ch));
1047
1048 if (priv->flags & TSI721_USING_MSIX)
1049 return; /* Finished if we are in MSI-X mode */
1050
1051 /*
1052 * For MSI and INTA interrupt signalling we need to enable next levels
1053 */
1054
1055 /* Enable Device Channel Interrupt */
1056 rval = ioread32(priv->regs + TSI721_DEV_CHAN_INTE);
1057 iowrite32(rval | TSI721_INT_IMSG_CHAN(ch),
1058 priv->regs + TSI721_DEV_CHAN_INTE);
1059}
1060
1061/* Disable Inbound Messaging Interrupts */
1062static void
1063tsi721_imsg_interrupt_disable(struct tsi721_device *priv, int ch,
1064 u32 inte_mask)
1065{
1066 u32 rval;
1067
1068 if (!inte_mask)
1069 return;
1070
1071 /* Clear pending Inbound Messaging interrupts */
1072 iowrite32(inte_mask, priv->regs + TSI721_IBDMAC_INT(ch));
1073
1074 /* Disable Inbound Messaging interrupts */
1075 rval = ioread32(priv->regs + TSI721_IBDMAC_INTE(ch));
1076 rval &= ~inte_mask;
1077 iowrite32(rval, priv->regs + TSI721_IBDMAC_INTE(ch));
1078
1079 if (priv->flags & TSI721_USING_MSIX)
1080 return; /* Finished if we are in MSI-X mode */
1081
1082 /*
1083 * For MSI and INTA interrupt signalling we need to disable next levels
1084 */
1085
1086 /* Disable Device Channel Interrupt */
1087 rval = ioread32(priv->regs + TSI721_DEV_CHAN_INTE);
1088 rval &= ~TSI721_INT_IMSG_CHAN(ch);
1089 iowrite32(rval, priv->regs + TSI721_DEV_CHAN_INTE);
1090}
1091
1092/* Enable Outbound Messaging interrupts */
1093static void
1094tsi721_omsg_interrupt_enable(struct tsi721_device *priv, int ch,
1095 u32 inte_mask)
1096{
1097 u32 rval;
1098
1099 if (!inte_mask)
1100 return;
1101
1102 /* Clear pending Outbound Messaging interrupts */
1103 iowrite32(inte_mask, priv->regs + TSI721_OBDMAC_INT(ch));
1104
1105 /* Enable Outbound Messaging channel interrupts */
1106 rval = ioread32(priv->regs + TSI721_OBDMAC_INTE(ch));
1107 iowrite32(rval | inte_mask, priv->regs + TSI721_OBDMAC_INTE(ch));
1108
1109 if (priv->flags & TSI721_USING_MSIX)
1110 return; /* Finished if we are in MSI-X mode */
1111
1112 /*
1113 * For MSI and INTA interrupt signalling we need to enable next levels
1114 */
1115
1116 /* Enable Device Channel Interrupt */
1117 rval = ioread32(priv->regs + TSI721_DEV_CHAN_INTE);
1118 iowrite32(rval | TSI721_INT_OMSG_CHAN(ch),
1119 priv->regs + TSI721_DEV_CHAN_INTE);
1120}
1121
1122/* Disable Outbound Messaging interrupts */
1123static void
1124tsi721_omsg_interrupt_disable(struct tsi721_device *priv, int ch,
1125 u32 inte_mask)
1126{
1127 u32 rval;
1128
1129 if (!inte_mask)
1130 return;
1131
1132 /* Clear pending Outbound Messaging interrupts */
1133 iowrite32(inte_mask, priv->regs + TSI721_OBDMAC_INT(ch));
1134
1135 /* Disable Outbound Messaging interrupts */
1136 rval = ioread32(priv->regs + TSI721_OBDMAC_INTE(ch));
1137 rval &= ~inte_mask;
1138 iowrite32(rval, priv->regs + TSI721_OBDMAC_INTE(ch));
1139
1140 if (priv->flags & TSI721_USING_MSIX)
1141 return; /* Finished if we are in MSI-X mode */
1142
1143 /*
1144 * For MSI and INTA interrupt signalling we need to disable next levels
1145 */
1146
1147 /* Disable Device Channel Interrupt */
1148 rval = ioread32(priv->regs + TSI721_DEV_CHAN_INTE);
1149 rval &= ~TSI721_INT_OMSG_CHAN(ch);
1150 iowrite32(rval, priv->regs + TSI721_DEV_CHAN_INTE);
1151}
1152
1153/**
1154 * tsi721_add_outb_message - Add message to the Tsi721 outbound message queue
1155 * @mport: Master port with outbound message queue
1156 * @rdev: Target of outbound message
1157 * @mbox: Outbound mailbox
1158 * @buffer: Message to add to outbound queue
1159 * @len: Length of message
1160 */
1161static int
1162tsi721_add_outb_message(struct rio_mport *mport, struct rio_dev *rdev, int mbox,
1163 void *buffer, size_t len)
1164{
1165 struct tsi721_device *priv = mport->priv;
1166 struct tsi721_omsg_desc *desc;
1167 u32 tx_slot;
1168
1169 if (!priv->omsg_init[mbox] ||
1170 len > TSI721_MSG_MAX_SIZE || len < 8)
1171 return -EINVAL;
1172
1173 tx_slot = priv->omsg_ring[mbox].tx_slot;
1174
1175 /* Copy copy message into transfer buffer */
1176 memcpy(priv->omsg_ring[mbox].omq_base[tx_slot], buffer, len);
1177
1178 if (len & 0x7)
1179 len += 8;
1180
1181 /* Build descriptor associated with buffer */
1182 desc = priv->omsg_ring[mbox].omd_base;
1183 desc[tx_slot].type_id = cpu_to_le32((DTYPE4 << 29) | rdev->destid);
1184 if (tx_slot % 4 == 0)
1185 desc[tx_slot].type_id |= cpu_to_le32(TSI721_OMD_IOF);
1186
1187 desc[tx_slot].msg_info =
1188 cpu_to_le32((mport->sys_size << 26) | (mbox << 22) |
1189 (0xe << 12) | (len & 0xff8));
1190 desc[tx_slot].bufptr_lo =
1191 cpu_to_le32((u64)priv->omsg_ring[mbox].omq_phys[tx_slot] &
1192 0xffffffff);
1193 desc[tx_slot].bufptr_hi =
1194 cpu_to_le32((u64)priv->omsg_ring[mbox].omq_phys[tx_slot] >> 32);
1195
1196 priv->omsg_ring[mbox].wr_count++;
1197
1198 /* Go to next descriptor */
1199 if (++priv->omsg_ring[mbox].tx_slot == priv->omsg_ring[mbox].size) {
1200 priv->omsg_ring[mbox].tx_slot = 0;
1201 /* Move through the ring link descriptor at the end */
1202 priv->omsg_ring[mbox].wr_count++;
1203 }
1204
1205 mb();
1206
1207 /* Set new write count value */
1208 iowrite32(priv->omsg_ring[mbox].wr_count,
1209 priv->regs + TSI721_OBDMAC_DWRCNT(mbox));
1210 ioread32(priv->regs + TSI721_OBDMAC_DWRCNT(mbox));
1211
1212 return 0;
1213}
1214
1215/**
1216 * tsi721_omsg_handler - Outbound Message Interrupt Handler
1217 * @priv: pointer to tsi721 private data
1218 * @ch: number of OB MSG channel to service
1219 *
1220 * Services channel interrupts from outbound messaging engine.
1221 */
1222static void tsi721_omsg_handler(struct tsi721_device *priv, int ch)
1223{
1224 u32 omsg_int;
1225
1226 spin_lock(&priv->omsg_ring[ch].lock);
1227
1228 omsg_int = ioread32(priv->regs + TSI721_OBDMAC_INT(ch));
1229
1230 if (omsg_int & TSI721_OBDMAC_INT_ST_FULL)
1231 dev_info(&priv->pdev->dev,
1232 "OB MBOX%d: Status FIFO is full\n", ch);
1233
1234 if (omsg_int & (TSI721_OBDMAC_INT_DONE | TSI721_OBDMAC_INT_IOF_DONE)) {
1235 u32 srd_ptr;
1236 u64 *sts_ptr, last_ptr = 0, prev_ptr = 0;
1237 int i, j;
1238 u32 tx_slot;
1239
1240 /*
1241 * Find last successfully processed descriptor
1242 */
1243
1244 /* Check and clear descriptor status FIFO entries */
1245 srd_ptr = priv->omsg_ring[ch].sts_rdptr;
1246 sts_ptr = priv->omsg_ring[ch].sts_base;
1247 j = srd_ptr * 8;
1248 while (sts_ptr[j]) {
1249 for (i = 0; i < 8 && sts_ptr[j]; i++, j++) {
1250 prev_ptr = last_ptr;
1251 last_ptr = le64_to_cpu(sts_ptr[j]);
1252 sts_ptr[j] = 0;
1253 }
1254
1255 ++srd_ptr;
1256 srd_ptr %= priv->omsg_ring[ch].sts_size;
1257 j = srd_ptr * 8;
1258 }
1259
1260 if (last_ptr == 0)
1261 goto no_sts_update;
1262
1263 priv->omsg_ring[ch].sts_rdptr = srd_ptr;
1264 iowrite32(srd_ptr, priv->regs + TSI721_OBDMAC_DSRP(ch));
1265
1266 if (!priv->mport->outb_msg[ch].mcback)
1267 goto no_sts_update;
1268
1269 /* Inform upper layer about transfer completion */
1270
1271 tx_slot = (last_ptr - (u64)priv->omsg_ring[ch].omd_phys)/
1272 sizeof(struct tsi721_omsg_desc);
1273
1274 /*
1275 * Check if this is a Link Descriptor (LD).
1276 * If yes, ignore LD and use descriptor processed
1277 * before LD.
1278 */
1279 if (tx_slot == priv->omsg_ring[ch].size) {
1280 if (prev_ptr)
1281 tx_slot = (prev_ptr -
1282 (u64)priv->omsg_ring[ch].omd_phys)/
1283 sizeof(struct tsi721_omsg_desc);
1284 else
1285 goto no_sts_update;
1286 }
1287
1288 /* Move slot index to the next message to be sent */
1289 ++tx_slot;
1290 if (tx_slot == priv->omsg_ring[ch].size)
1291 tx_slot = 0;
1292 BUG_ON(tx_slot >= priv->omsg_ring[ch].size);
1293 priv->mport->outb_msg[ch].mcback(priv->mport,
1294 priv->omsg_ring[ch].dev_id, ch,
1295 tx_slot);
1296 }
1297
1298no_sts_update:
1299
1300 if (omsg_int & TSI721_OBDMAC_INT_ERROR) {
1301 /*
1302 * Outbound message operation aborted due to error,
1303 * reinitialize OB MSG channel
1304 */
1305
1306 dev_dbg(&priv->pdev->dev, "OB MSG ABORT ch_stat=%x\n",
1307 ioread32(priv->regs + TSI721_OBDMAC_STS(ch)));
1308
1309 iowrite32(TSI721_OBDMAC_INT_ERROR,
1310 priv->regs + TSI721_OBDMAC_INT(ch));
1311 iowrite32(TSI721_OBDMAC_CTL_INIT,
1312 priv->regs + TSI721_OBDMAC_CTL(ch));
1313 ioread32(priv->regs + TSI721_OBDMAC_CTL(ch));
1314
1315 /* Inform upper level to clear all pending tx slots */
1316 if (priv->mport->outb_msg[ch].mcback)
1317 priv->mport->outb_msg[ch].mcback(priv->mport,
1318 priv->omsg_ring[ch].dev_id, ch,
1319 priv->omsg_ring[ch].tx_slot);
1320 /* Synch tx_slot tracking */
1321 iowrite32(priv->omsg_ring[ch].tx_slot,
1322 priv->regs + TSI721_OBDMAC_DRDCNT(ch));
1323 ioread32(priv->regs + TSI721_OBDMAC_DRDCNT(ch));
1324 priv->omsg_ring[ch].wr_count = priv->omsg_ring[ch].tx_slot;
1325 priv->omsg_ring[ch].sts_rdptr = 0;
1326 }
1327
1328 /* Clear channel interrupts */
1329 iowrite32(omsg_int, priv->regs + TSI721_OBDMAC_INT(ch));
1330
1331 if (!(priv->flags & TSI721_USING_MSIX)) {
1332 u32 ch_inte;
1333
1334 /* Re-enable channel interrupts */
1335 ch_inte = ioread32(priv->regs + TSI721_DEV_CHAN_INTE);
1336 ch_inte |= TSI721_INT_OMSG_CHAN(ch);
1337 iowrite32(ch_inte, priv->regs + TSI721_DEV_CHAN_INTE);
1338 }
1339
1340 spin_unlock(&priv->omsg_ring[ch].lock);
1341}
1342
1343/**
1344 * tsi721_open_outb_mbox - Initialize Tsi721 outbound mailbox
1345 * @mport: Master port implementing Outbound Messaging Engine
1346 * @dev_id: Device specific pointer to pass on event
1347 * @mbox: Mailbox to open
1348 * @entries: Number of entries in the outbound mailbox ring
1349 */
1350static int tsi721_open_outb_mbox(struct rio_mport *mport, void *dev_id,
1351 int mbox, int entries)
1352{
1353 struct tsi721_device *priv = mport->priv;
1354 struct tsi721_omsg_desc *bd_ptr;
1355 int i, rc = 0;
1356
1357 if ((entries < TSI721_OMSGD_MIN_RING_SIZE) ||
1358 (entries > (TSI721_OMSGD_RING_SIZE)) ||
1359 (!is_power_of_2(entries)) || mbox >= RIO_MAX_MBOX) {
1360 rc = -EINVAL;
1361 goto out;
1362 }
1363
1364 priv->omsg_ring[mbox].dev_id = dev_id;
1365 priv->omsg_ring[mbox].size = entries;
1366 priv->omsg_ring[mbox].sts_rdptr = 0;
1367 spin_lock_init(&priv->omsg_ring[mbox].lock);
1368
1369 /* Outbound Msg Buffer allocation based on
1370 the number of maximum descriptor entries */
1371 for (i = 0; i < entries; i++) {
1372 priv->omsg_ring[mbox].omq_base[i] =
1373 dma_alloc_coherent(
1374 &priv->pdev->dev, TSI721_MSG_BUFFER_SIZE,
1375 &priv->omsg_ring[mbox].omq_phys[i],
1376 GFP_KERNEL);
1377 if (priv->omsg_ring[mbox].omq_base[i] == NULL) {
1378 dev_dbg(&priv->pdev->dev,
1379 "Unable to allocate OB MSG data buffer for"
1380 " MBOX%d\n", mbox);
1381 rc = -ENOMEM;
1382 goto out_buf;
1383 }
1384 }
1385
1386 /* Outbound message descriptor allocation */
1387 priv->omsg_ring[mbox].omd_base = dma_alloc_coherent(
1388 &priv->pdev->dev,
1389 (entries + 1) * sizeof(struct tsi721_omsg_desc),
1390 &priv->omsg_ring[mbox].omd_phys, GFP_KERNEL);
1391 if (priv->omsg_ring[mbox].omd_base == NULL) {
1392 dev_dbg(&priv->pdev->dev,
1393 "Unable to allocate OB MSG descriptor memory "
1394 "for MBOX%d\n", mbox);
1395 rc = -ENOMEM;
1396 goto out_buf;
1397 }
1398
1399 priv->omsg_ring[mbox].tx_slot = 0;
1400
1401 /* Outbound message descriptor status FIFO allocation */
1402 priv->omsg_ring[mbox].sts_size = roundup_pow_of_two(entries + 1);
1403 priv->omsg_ring[mbox].sts_base = dma_alloc_coherent(&priv->pdev->dev,
1404 priv->omsg_ring[mbox].sts_size *
1405 sizeof(struct tsi721_dma_sts),
1406 &priv->omsg_ring[mbox].sts_phys, GFP_KERNEL);
1407 if (priv->omsg_ring[mbox].sts_base == NULL) {
1408 dev_dbg(&priv->pdev->dev,
1409 "Unable to allocate OB MSG descriptor status FIFO "
1410 "for MBOX%d\n", mbox);
1411 rc = -ENOMEM;
1412 goto out_desc;
1413 }
1414
1415 memset(priv->omsg_ring[mbox].sts_base, 0,
1416 entries * sizeof(struct tsi721_dma_sts));
1417
1418 /*
1419 * Configure Outbound Messaging Engine
1420 */
1421
1422 /* Setup Outbound Message descriptor pointer */
1423 iowrite32(((u64)priv->omsg_ring[mbox].omd_phys >> 32),
1424 priv->regs + TSI721_OBDMAC_DPTRH(mbox));
1425 iowrite32(((u64)priv->omsg_ring[mbox].omd_phys &
1426 TSI721_OBDMAC_DPTRL_MASK),
1427 priv->regs + TSI721_OBDMAC_DPTRL(mbox));
1428
1429 /* Setup Outbound Message descriptor status FIFO */
1430 iowrite32(((u64)priv->omsg_ring[mbox].sts_phys >> 32),
1431 priv->regs + TSI721_OBDMAC_DSBH(mbox));
1432 iowrite32(((u64)priv->omsg_ring[mbox].sts_phys &
1433 TSI721_OBDMAC_DSBL_MASK),
1434 priv->regs + TSI721_OBDMAC_DSBL(mbox));
1435 iowrite32(TSI721_DMAC_DSSZ_SIZE(priv->omsg_ring[mbox].sts_size),
1436 priv->regs + (u32)TSI721_OBDMAC_DSSZ(mbox));
1437
1438 /* Enable interrupts */
1439
1440#ifdef CONFIG_PCI_MSI
1441 if (priv->flags & TSI721_USING_MSIX) {
1442 /* Request interrupt service if we are in MSI-X mode */
1443 rc = request_irq(
1444 priv->msix[TSI721_VECT_OMB0_DONE + mbox].vector,
1445 tsi721_omsg_msix, 0,
1446 priv->msix[TSI721_VECT_OMB0_DONE + mbox].irq_name,
1447 (void *)mport);
1448
1449 if (rc) {
1450 dev_dbg(&priv->pdev->dev,
1451 "Unable to allocate MSI-X interrupt for "
1452 "OBOX%d-DONE\n", mbox);
1453 goto out_stat;
1454 }
1455
1456 rc = request_irq(priv->msix[TSI721_VECT_OMB0_INT + mbox].vector,
1457 tsi721_omsg_msix, 0,
1458 priv->msix[TSI721_VECT_OMB0_INT + mbox].irq_name,
1459 (void *)mport);
1460
1461 if (rc) {
1462 dev_dbg(&priv->pdev->dev,
1463 "Unable to allocate MSI-X interrupt for "
1464 "MBOX%d-INT\n", mbox);
1465 free_irq(
1466 priv->msix[TSI721_VECT_OMB0_DONE + mbox].vector,
1467 (void *)mport);
1468 goto out_stat;
1469 }
1470 }
1471#endif /* CONFIG_PCI_MSI */
1472
1473 tsi721_omsg_interrupt_enable(priv, mbox, TSI721_OBDMAC_INT_ALL);
1474
1475 /* Initialize Outbound Message descriptors ring */
1476 bd_ptr = priv->omsg_ring[mbox].omd_base;
1477 bd_ptr[entries].type_id = cpu_to_le32(DTYPE5 << 29);
1478 bd_ptr[entries].msg_info = 0;
1479 bd_ptr[entries].next_lo =
1480 cpu_to_le32((u64)priv->omsg_ring[mbox].omd_phys &
1481 TSI721_OBDMAC_DPTRL_MASK);
1482 bd_ptr[entries].next_hi =
1483 cpu_to_le32((u64)priv->omsg_ring[mbox].omd_phys >> 32);
1484 priv->omsg_ring[mbox].wr_count = 0;
1485 mb();
1486
1487 /* Initialize Outbound Message engine */
1488 iowrite32(TSI721_OBDMAC_CTL_INIT, priv->regs + TSI721_OBDMAC_CTL(mbox));
1489 ioread32(priv->regs + TSI721_OBDMAC_DWRCNT(mbox));
1490 udelay(10);
1491
1492 priv->omsg_init[mbox] = 1;
1493
1494 return 0;
1495
1496#ifdef CONFIG_PCI_MSI
1497out_stat:
1498 dma_free_coherent(&priv->pdev->dev,
1499 priv->omsg_ring[mbox].sts_size * sizeof(struct tsi721_dma_sts),
1500 priv->omsg_ring[mbox].sts_base,
1501 priv->omsg_ring[mbox].sts_phys);
1502
1503 priv->omsg_ring[mbox].sts_base = NULL;
1504#endif /* CONFIG_PCI_MSI */
1505
1506out_desc:
1507 dma_free_coherent(&priv->pdev->dev,
1508 (entries + 1) * sizeof(struct tsi721_omsg_desc),
1509 priv->omsg_ring[mbox].omd_base,
1510 priv->omsg_ring[mbox].omd_phys);
1511
1512 priv->omsg_ring[mbox].omd_base = NULL;
1513
1514out_buf:
1515 for (i = 0; i < priv->omsg_ring[mbox].size; i++) {
1516 if (priv->omsg_ring[mbox].omq_base[i]) {
1517 dma_free_coherent(&priv->pdev->dev,
1518 TSI721_MSG_BUFFER_SIZE,
1519 priv->omsg_ring[mbox].omq_base[i],
1520 priv->omsg_ring[mbox].omq_phys[i]);
1521
1522 priv->omsg_ring[mbox].omq_base[i] = NULL;
1523 }
1524 }
1525
1526out:
1527 return rc;
1528}
1529
1530/**
1531 * tsi721_close_outb_mbox - Close Tsi721 outbound mailbox
1532 * @mport: Master port implementing the outbound message unit
1533 * @mbox: Mailbox to close
1534 */
1535static void tsi721_close_outb_mbox(struct rio_mport *mport, int mbox)
1536{
1537 struct tsi721_device *priv = mport->priv;
1538 u32 i;
1539
1540 if (!priv->omsg_init[mbox])
1541 return;
1542 priv->omsg_init[mbox] = 0;
1543
1544 /* Disable Interrupts */
1545
1546 tsi721_omsg_interrupt_disable(priv, mbox, TSI721_OBDMAC_INT_ALL);
1547
1548#ifdef CONFIG_PCI_MSI
1549 if (priv->flags & TSI721_USING_MSIX) {
1550 free_irq(priv->msix[TSI721_VECT_OMB0_DONE + mbox].vector,
1551 (void *)mport);
1552 free_irq(priv->msix[TSI721_VECT_OMB0_INT + mbox].vector,
1553 (void *)mport);
1554 }
1555#endif /* CONFIG_PCI_MSI */
1556
1557 /* Free OMSG Descriptor Status FIFO */
1558 dma_free_coherent(&priv->pdev->dev,
1559 priv->omsg_ring[mbox].sts_size * sizeof(struct tsi721_dma_sts),
1560 priv->omsg_ring[mbox].sts_base,
1561 priv->omsg_ring[mbox].sts_phys);
1562
1563 priv->omsg_ring[mbox].sts_base = NULL;
1564
1565 /* Free OMSG descriptors */
1566 dma_free_coherent(&priv->pdev->dev,
1567 (priv->omsg_ring[mbox].size + 1) *
1568 sizeof(struct tsi721_omsg_desc),
1569 priv->omsg_ring[mbox].omd_base,
1570 priv->omsg_ring[mbox].omd_phys);
1571
1572 priv->omsg_ring[mbox].omd_base = NULL;
1573
1574 /* Free message buffers */
1575 for (i = 0; i < priv->omsg_ring[mbox].size; i++) {
1576 if (priv->omsg_ring[mbox].omq_base[i]) {
1577 dma_free_coherent(&priv->pdev->dev,
1578 TSI721_MSG_BUFFER_SIZE,
1579 priv->omsg_ring[mbox].omq_base[i],
1580 priv->omsg_ring[mbox].omq_phys[i]);
1581
1582 priv->omsg_ring[mbox].omq_base[i] = NULL;
1583 }
1584 }
1585}
1586
1587/**
1588 * tsi721_imsg_handler - Inbound Message Interrupt Handler
1589 * @priv: pointer to tsi721 private data
1590 * @ch: inbound message channel number to service
1591 *
1592 * Services channel interrupts from inbound messaging engine.
1593 */
1594static void tsi721_imsg_handler(struct tsi721_device *priv, int ch)
1595{
1596 u32 mbox = ch - 4;
1597 u32 imsg_int;
1598
1599 spin_lock(&priv->imsg_ring[mbox].lock);
1600
1601 imsg_int = ioread32(priv->regs + TSI721_IBDMAC_INT(ch));
1602
1603 if (imsg_int & TSI721_IBDMAC_INT_SRTO)
1604 dev_info(&priv->pdev->dev, "IB MBOX%d SRIO timeout\n",
1605 mbox);
1606
1607 if (imsg_int & TSI721_IBDMAC_INT_PC_ERROR)
1608 dev_info(&priv->pdev->dev, "IB MBOX%d PCIe error\n",
1609 mbox);
1610
1611 if (imsg_int & TSI721_IBDMAC_INT_FQ_LOW)
1612 dev_info(&priv->pdev->dev,
1613 "IB MBOX%d IB free queue low\n", mbox);
1614
1615 /* Clear IB channel interrupts */
1616 iowrite32(imsg_int, priv->regs + TSI721_IBDMAC_INT(ch));
1617
1618 /* If an IB Msg is received notify the upper layer */
1619 if (imsg_int & TSI721_IBDMAC_INT_DQ_RCV &&
1620 priv->mport->inb_msg[mbox].mcback)
1621 priv->mport->inb_msg[mbox].mcback(priv->mport,
1622 priv->imsg_ring[mbox].dev_id, mbox, -1);
1623
1624 if (!(priv->flags & TSI721_USING_MSIX)) {
1625 u32 ch_inte;
1626
1627 /* Re-enable channel interrupts */
1628 ch_inte = ioread32(priv->regs + TSI721_DEV_CHAN_INTE);
1629 ch_inte |= TSI721_INT_IMSG_CHAN(ch);
1630 iowrite32(ch_inte, priv->regs + TSI721_DEV_CHAN_INTE);
1631 }
1632
1633 spin_unlock(&priv->imsg_ring[mbox].lock);
1634}
1635
1636/**
1637 * tsi721_open_inb_mbox - Initialize Tsi721 inbound mailbox
1638 * @mport: Master port implementing the Inbound Messaging Engine
1639 * @dev_id: Device specific pointer to pass on event
1640 * @mbox: Mailbox to open
1641 * @entries: Number of entries in the inbound mailbox ring
1642 */
1643static int tsi721_open_inb_mbox(struct rio_mport *mport, void *dev_id,
1644 int mbox, int entries)
1645{
1646 struct tsi721_device *priv = mport->priv;
1647 int ch = mbox + 4;
1648 int i;
1649 u64 *free_ptr;
1650 int rc = 0;
1651
1652 if ((entries < TSI721_IMSGD_MIN_RING_SIZE) ||
1653 (entries > TSI721_IMSGD_RING_SIZE) ||
1654 (!is_power_of_2(entries)) || mbox >= RIO_MAX_MBOX) {
1655 rc = -EINVAL;
1656 goto out;
1657 }
1658
1659 /* Initialize IB Messaging Ring */
1660 priv->imsg_ring[mbox].dev_id = dev_id;
1661 priv->imsg_ring[mbox].size = entries;
1662 priv->imsg_ring[mbox].rx_slot = 0;
1663 priv->imsg_ring[mbox].desc_rdptr = 0;
1664 priv->imsg_ring[mbox].fq_wrptr = 0;
1665 for (i = 0; i < priv->imsg_ring[mbox].size; i++)
1666 priv->imsg_ring[mbox].imq_base[i] = NULL;
1667 spin_lock_init(&priv->imsg_ring[mbox].lock);
1668
1669 /* Allocate buffers for incoming messages */
1670 priv->imsg_ring[mbox].buf_base =
1671 dma_alloc_coherent(&priv->pdev->dev,
1672 entries * TSI721_MSG_BUFFER_SIZE,
1673 &priv->imsg_ring[mbox].buf_phys,
1674 GFP_KERNEL);
1675
1676 if (priv->imsg_ring[mbox].buf_base == NULL) {
1677 dev_err(&priv->pdev->dev,
1678 "Failed to allocate buffers for IB MBOX%d\n", mbox);
1679 rc = -ENOMEM;
1680 goto out;
1681 }
1682
1683 /* Allocate memory for circular free list */
1684 priv->imsg_ring[mbox].imfq_base =
1685 dma_alloc_coherent(&priv->pdev->dev,
1686 entries * 8,
1687 &priv->imsg_ring[mbox].imfq_phys,
1688 GFP_KERNEL);
1689
1690 if (priv->imsg_ring[mbox].imfq_base == NULL) {
1691 dev_err(&priv->pdev->dev,
1692 "Failed to allocate free queue for IB MBOX%d\n", mbox);
1693 rc = -ENOMEM;
1694 goto out_buf;
1695 }
1696
1697 /* Allocate memory for Inbound message descriptors */
1698 priv->imsg_ring[mbox].imd_base =
1699 dma_alloc_coherent(&priv->pdev->dev,
1700 entries * sizeof(struct tsi721_imsg_desc),
1701 &priv->imsg_ring[mbox].imd_phys, GFP_KERNEL);
1702
1703 if (priv->imsg_ring[mbox].imd_base == NULL) {
1704 dev_err(&priv->pdev->dev,
1705 "Failed to allocate descriptor memory for IB MBOX%d\n",
1706 mbox);
1707 rc = -ENOMEM;
1708 goto out_dma;
1709 }
1710
1711 /* Fill free buffer pointer list */
1712 free_ptr = priv->imsg_ring[mbox].imfq_base;
1713 for (i = 0; i < entries; i++)
1714 free_ptr[i] = cpu_to_le64(
1715 (u64)(priv->imsg_ring[mbox].buf_phys) +
1716 i * 0x1000);
1717
1718 mb();
1719
1720 /*
1721 * For mapping of inbound SRIO Messages into appropriate queues we need
1722 * to set Inbound Device ID register in the messaging engine. We do it
1723 * once when first inbound mailbox is requested.
1724 */
1725 if (!(priv->flags & TSI721_IMSGID_SET)) {
1726 iowrite32((u32)priv->mport->host_deviceid,
1727 priv->regs + TSI721_IB_DEVID);
1728 priv->flags |= TSI721_IMSGID_SET;
1729 }
1730
1731 /*
1732 * Configure Inbound Messaging channel (ch = mbox + 4)
1733 */
1734
1735 /* Setup Inbound Message free queue */
1736 iowrite32(((u64)priv->imsg_ring[mbox].imfq_phys >> 32),
1737 priv->regs + TSI721_IBDMAC_FQBH(ch));
1738 iowrite32(((u64)priv->imsg_ring[mbox].imfq_phys &
1739 TSI721_IBDMAC_FQBL_MASK),
1740 priv->regs+TSI721_IBDMAC_FQBL(ch));
1741 iowrite32(TSI721_DMAC_DSSZ_SIZE(entries),
1742 priv->regs + TSI721_IBDMAC_FQSZ(ch));
1743
1744 /* Setup Inbound Message descriptor queue */
1745 iowrite32(((u64)priv->imsg_ring[mbox].imd_phys >> 32),
1746 priv->regs + TSI721_IBDMAC_DQBH(ch));
1747 iowrite32(((u32)priv->imsg_ring[mbox].imd_phys &
1748 (u32)TSI721_IBDMAC_DQBL_MASK),
1749 priv->regs+TSI721_IBDMAC_DQBL(ch));
1750 iowrite32(TSI721_DMAC_DSSZ_SIZE(entries),
1751 priv->regs + TSI721_IBDMAC_DQSZ(ch));
1752
1753 /* Enable interrupts */
1754
1755#ifdef CONFIG_PCI_MSI
1756 if (priv->flags & TSI721_USING_MSIX) {
1757 /* Request interrupt service if we are in MSI-X mode */
1758 rc = request_irq(priv->msix[TSI721_VECT_IMB0_RCV + mbox].vector,
1759 tsi721_imsg_msix, 0,
1760 priv->msix[TSI721_VECT_IMB0_RCV + mbox].irq_name,
1761 (void *)mport);
1762
1763 if (rc) {
1764 dev_dbg(&priv->pdev->dev,
1765 "Unable to allocate MSI-X interrupt for "
1766 "IBOX%d-DONE\n", mbox);
1767 goto out_desc;
1768 }
1769
1770 rc = request_irq(priv->msix[TSI721_VECT_IMB0_INT + mbox].vector,
1771 tsi721_imsg_msix, 0,
1772 priv->msix[TSI721_VECT_IMB0_INT + mbox].irq_name,
1773 (void *)mport);
1774
1775 if (rc) {
1776 dev_dbg(&priv->pdev->dev,
1777 "Unable to allocate MSI-X interrupt for "
1778 "IBOX%d-INT\n", mbox);
1779 free_irq(
1780 priv->msix[TSI721_VECT_IMB0_RCV + mbox].vector,
1781 (void *)mport);
1782 goto out_desc;
1783 }
1784 }
1785#endif /* CONFIG_PCI_MSI */
1786
1787 tsi721_imsg_interrupt_enable(priv, ch, TSI721_IBDMAC_INT_ALL);
1788
1789 /* Initialize Inbound Message Engine */
1790 iowrite32(TSI721_IBDMAC_CTL_INIT, priv->regs + TSI721_IBDMAC_CTL(ch));
1791 ioread32(priv->regs + TSI721_IBDMAC_CTL(ch));
1792 udelay(10);
1793 priv->imsg_ring[mbox].fq_wrptr = entries - 1;
1794 iowrite32(entries - 1, priv->regs + TSI721_IBDMAC_FQWP(ch));
1795
1796 priv->imsg_init[mbox] = 1;
1797 return 0;
1798
1799#ifdef CONFIG_PCI_MSI
1800out_desc:
1801 dma_free_coherent(&priv->pdev->dev,
1802 priv->imsg_ring[mbox].size * sizeof(struct tsi721_imsg_desc),
1803 priv->imsg_ring[mbox].imd_base,
1804 priv->imsg_ring[mbox].imd_phys);
1805
1806 priv->imsg_ring[mbox].imd_base = NULL;
1807#endif /* CONFIG_PCI_MSI */
1808
1809out_dma:
1810 dma_free_coherent(&priv->pdev->dev,
1811 priv->imsg_ring[mbox].size * 8,
1812 priv->imsg_ring[mbox].imfq_base,
1813 priv->imsg_ring[mbox].imfq_phys);
1814
1815 priv->imsg_ring[mbox].imfq_base = NULL;
1816
1817out_buf:
1818 dma_free_coherent(&priv->pdev->dev,
1819 priv->imsg_ring[mbox].size * TSI721_MSG_BUFFER_SIZE,
1820 priv->imsg_ring[mbox].buf_base,
1821 priv->imsg_ring[mbox].buf_phys);
1822
1823 priv->imsg_ring[mbox].buf_base = NULL;
1824
1825out:
1826 return rc;
1827}
1828
1829/**
1830 * tsi721_close_inb_mbox - Shut down Tsi721 inbound mailbox
1831 * @mport: Master port implementing the Inbound Messaging Engine
1832 * @mbox: Mailbox to close
1833 */
1834static void tsi721_close_inb_mbox(struct rio_mport *mport, int mbox)
1835{
1836 struct tsi721_device *priv = mport->priv;
1837 u32 rx_slot;
1838 int ch = mbox + 4;
1839
1840 if (!priv->imsg_init[mbox]) /* mbox isn't initialized yet */
1841 return;
1842 priv->imsg_init[mbox] = 0;
1843
1844 /* Disable Inbound Messaging Engine */
1845
1846 /* Disable Interrupts */
1847 tsi721_imsg_interrupt_disable(priv, ch, TSI721_OBDMAC_INT_MASK);
1848
1849#ifdef CONFIG_PCI_MSI
1850 if (priv->flags & TSI721_USING_MSIX) {
1851 free_irq(priv->msix[TSI721_VECT_IMB0_RCV + mbox].vector,
1852 (void *)mport);
1853 free_irq(priv->msix[TSI721_VECT_IMB0_INT + mbox].vector,
1854 (void *)mport);
1855 }
1856#endif /* CONFIG_PCI_MSI */
1857
1858 /* Clear Inbound Buffer Queue */
1859 for (rx_slot = 0; rx_slot < priv->imsg_ring[mbox].size; rx_slot++)
1860 priv->imsg_ring[mbox].imq_base[rx_slot] = NULL;
1861
1862 /* Free memory allocated for message buffers */
1863 dma_free_coherent(&priv->pdev->dev,
1864 priv->imsg_ring[mbox].size * TSI721_MSG_BUFFER_SIZE,
1865 priv->imsg_ring[mbox].buf_base,
1866 priv->imsg_ring[mbox].buf_phys);
1867
1868 priv->imsg_ring[mbox].buf_base = NULL;
1869
1870 /* Free memory allocated for free pointr list */
1871 dma_free_coherent(&priv->pdev->dev,
1872 priv->imsg_ring[mbox].size * 8,
1873 priv->imsg_ring[mbox].imfq_base,
1874 priv->imsg_ring[mbox].imfq_phys);
1875
1876 priv->imsg_ring[mbox].imfq_base = NULL;
1877
1878 /* Free memory allocated for RX descriptors */
1879 dma_free_coherent(&priv->pdev->dev,
1880 priv->imsg_ring[mbox].size * sizeof(struct tsi721_imsg_desc),
1881 priv->imsg_ring[mbox].imd_base,
1882 priv->imsg_ring[mbox].imd_phys);
1883
1884 priv->imsg_ring[mbox].imd_base = NULL;
1885}
1886
1887/**
1888 * tsi721_add_inb_buffer - Add buffer to the Tsi721 inbound message queue
1889 * @mport: Master port implementing the Inbound Messaging Engine
1890 * @mbox: Inbound mailbox number
1891 * @buf: Buffer to add to inbound queue
1892 */
1893static int tsi721_add_inb_buffer(struct rio_mport *mport, int mbox, void *buf)
1894{
1895 struct tsi721_device *priv = mport->priv;
1896 u32 rx_slot;
1897 int rc = 0;
1898
1899 rx_slot = priv->imsg_ring[mbox].rx_slot;
1900 if (priv->imsg_ring[mbox].imq_base[rx_slot]) {
1901 dev_err(&priv->pdev->dev,
1902 "Error adding inbound buffer %d, buffer exists\n",
1903 rx_slot);
1904 rc = -EINVAL;
1905 goto out;
1906 }
1907
1908 priv->imsg_ring[mbox].imq_base[rx_slot] = buf;
1909
1910 if (++priv->imsg_ring[mbox].rx_slot == priv->imsg_ring[mbox].size)
1911 priv->imsg_ring[mbox].rx_slot = 0;
1912
1913out:
1914 return rc;
1915}
1916
1917/**
1918 * tsi721_get_inb_message - Fetch inbound message from the Tsi721 MSG Queue
1919 * @mport: Master port implementing the Inbound Messaging Engine
1920 * @mbox: Inbound mailbox number
1921 *
1922 * Returns pointer to the message on success or NULL on failure.
1923 */
1924static void *tsi721_get_inb_message(struct rio_mport *mport, int mbox)
1925{
1926 struct tsi721_device *priv = mport->priv;
1927 struct tsi721_imsg_desc *desc;
1928 u32 rx_slot;
1929 void *rx_virt = NULL;
1930 u64 rx_phys;
1931 void *buf = NULL;
1932 u64 *free_ptr;
1933 int ch = mbox + 4;
1934 int msg_size;
1935
1936 if (!priv->imsg_init[mbox])
1937 return NULL;
1938
1939 desc = priv->imsg_ring[mbox].imd_base;
1940 desc += priv->imsg_ring[mbox].desc_rdptr;
1941
1942 if (!(le32_to_cpu(desc->msg_info) & TSI721_IMD_HO))
1943 goto out;
1944
1945 rx_slot = priv->imsg_ring[mbox].rx_slot;
1946 while (priv->imsg_ring[mbox].imq_base[rx_slot] == NULL) {
1947 if (++rx_slot == priv->imsg_ring[mbox].size)
1948 rx_slot = 0;
1949 }
1950
1951 rx_phys = ((u64)le32_to_cpu(desc->bufptr_hi) << 32) |
1952 le32_to_cpu(desc->bufptr_lo);
1953
1954 rx_virt = priv->imsg_ring[mbox].buf_base +
1955 (rx_phys - (u64)priv->imsg_ring[mbox].buf_phys);
1956
1957 buf = priv->imsg_ring[mbox].imq_base[rx_slot];
1958 msg_size = le32_to_cpu(desc->msg_info) & TSI721_IMD_BCOUNT;
1959 if (msg_size == 0)
1960 msg_size = RIO_MAX_MSG_SIZE;
1961
1962 memcpy(buf, rx_virt, msg_size);
1963 priv->imsg_ring[mbox].imq_base[rx_slot] = NULL;
1964
1965 desc->msg_info &= cpu_to_le32(~TSI721_IMD_HO);
1966 if (++priv->imsg_ring[mbox].desc_rdptr == priv->imsg_ring[mbox].size)
1967 priv->imsg_ring[mbox].desc_rdptr = 0;
1968
1969 iowrite32(priv->imsg_ring[mbox].desc_rdptr,
1970 priv->regs + TSI721_IBDMAC_DQRP(ch));
1971
1972 /* Return free buffer into the pointer list */
1973 free_ptr = priv->imsg_ring[mbox].imfq_base;
1974 free_ptr[priv->imsg_ring[mbox].fq_wrptr] = cpu_to_le64(rx_phys);
1975
1976 if (++priv->imsg_ring[mbox].fq_wrptr == priv->imsg_ring[mbox].size)
1977 priv->imsg_ring[mbox].fq_wrptr = 0;
1978
1979 iowrite32(priv->imsg_ring[mbox].fq_wrptr,
1980 priv->regs + TSI721_IBDMAC_FQWP(ch));
1981out:
1982 return buf;
1983}
1984
1985/**
1986 * tsi721_messages_init - Initialization of Messaging Engine
1987 * @priv: pointer to tsi721 private data
1988 *
1989 * Configures Tsi721 messaging engine.
1990 */
1991static int tsi721_messages_init(struct tsi721_device *priv)
1992{
1993 int ch;
1994
1995 iowrite32(0, priv->regs + TSI721_SMSG_ECC_LOG);
1996 iowrite32(0, priv->regs + TSI721_RETRY_GEN_CNT);
1997 iowrite32(0, priv->regs + TSI721_RETRY_RX_CNT);
1998
1999 /* Set SRIO Message Request/Response Timeout */
2000 iowrite32(TSI721_RQRPTO_VAL, priv->regs + TSI721_RQRPTO);
2001
2002 /* Initialize Inbound Messaging Engine Registers */
2003 for (ch = 0; ch < TSI721_IMSG_CHNUM; ch++) {
2004 /* Clear interrupt bits */
2005 iowrite32(TSI721_IBDMAC_INT_MASK,
2006 priv->regs + TSI721_IBDMAC_INT(ch));
2007 /* Clear Status */
2008 iowrite32(0, priv->regs + TSI721_IBDMAC_STS(ch));
2009
2010 iowrite32(TSI721_SMSG_ECC_COR_LOG_MASK,
2011 priv->regs + TSI721_SMSG_ECC_COR_LOG(ch));
2012 iowrite32(TSI721_SMSG_ECC_NCOR_MASK,
2013 priv->regs + TSI721_SMSG_ECC_NCOR(ch));
2014 }
2015
2016 return 0;
2017}
2018
2019/**
2020 * tsi721_disable_ints - disables all device interrupts
2021 * @priv: pointer to tsi721 private data
2022 */
2023static void tsi721_disable_ints(struct tsi721_device *priv)
2024{
2025 int ch;
2026
2027 /* Disable all device level interrupts */
2028 iowrite32(0, priv->regs + TSI721_DEV_INTE);
2029
2030 /* Disable all Device Channel interrupts */
2031 iowrite32(0, priv->regs + TSI721_DEV_CHAN_INTE);
2032
2033 /* Disable all Inbound Msg Channel interrupts */
2034 for (ch = 0; ch < TSI721_IMSG_CHNUM; ch++)
2035 iowrite32(0, priv->regs + TSI721_IBDMAC_INTE(ch));
2036
2037 /* Disable all Outbound Msg Channel interrupts */
2038 for (ch = 0; ch < TSI721_OMSG_CHNUM; ch++)
2039 iowrite32(0, priv->regs + TSI721_OBDMAC_INTE(ch));
2040
2041 /* Disable all general messaging interrupts */
2042 iowrite32(0, priv->regs + TSI721_SMSG_INTE);
2043
2044 /* Disable all BDMA Channel interrupts */
2045 for (ch = 0; ch < TSI721_DMA_MAXCH; ch++)
2046 iowrite32(0, priv->regs + TSI721_DMAC_INTE(ch));
2047
2048 /* Disable all general BDMA interrupts */
2049 iowrite32(0, priv->regs + TSI721_BDMA_INTE);
2050
2051 /* Disable all SRIO Channel interrupts */
2052 for (ch = 0; ch < TSI721_SRIO_MAXCH; ch++)
2053 iowrite32(0, priv->regs + TSI721_SR_CHINTE(ch));
2054
2055 /* Disable all general SR2PC interrupts */
2056 iowrite32(0, priv->regs + TSI721_SR2PC_GEN_INTE);
2057
2058 /* Disable all PC2SR interrupts */
2059 iowrite32(0, priv->regs + TSI721_PC2SR_INTE);
2060
2061 /* Disable all I2C interrupts */
2062 iowrite32(0, priv->regs + TSI721_I2C_INT_ENABLE);
2063
2064 /* Disable SRIO MAC interrupts */
2065 iowrite32(0, priv->regs + TSI721_RIO_EM_INT_ENABLE);
2066 iowrite32(0, priv->regs + TSI721_RIO_EM_DEV_INT_EN);
2067}
2068
2069/**
2070 * tsi721_setup_mport - Setup Tsi721 as RapidIO subsystem master port
2071 * @priv: pointer to tsi721 private data
2072 *
2073 * Configures Tsi721 as RapidIO master port.
2074 */
2075static int __devinit tsi721_setup_mport(struct tsi721_device *priv)
2076{
2077 struct pci_dev *pdev = priv->pdev;
2078 int err = 0;
2079 struct rio_ops *ops;
2080
2081 struct rio_mport *mport;
2082
2083 ops = kzalloc(sizeof(struct rio_ops), GFP_KERNEL);
2084 if (!ops) {
2085 dev_dbg(&pdev->dev, "Unable to allocate memory for rio_ops\n");
2086 return -ENOMEM;
2087 }
2088
2089 ops->lcread = tsi721_lcread;
2090 ops->lcwrite = tsi721_lcwrite;
2091 ops->cread = tsi721_cread_dma;
2092 ops->cwrite = tsi721_cwrite_dma;
2093 ops->dsend = tsi721_dsend;
2094 ops->open_inb_mbox = tsi721_open_inb_mbox;
2095 ops->close_inb_mbox = tsi721_close_inb_mbox;
2096 ops->open_outb_mbox = tsi721_open_outb_mbox;
2097 ops->close_outb_mbox = tsi721_close_outb_mbox;
2098 ops->add_outb_message = tsi721_add_outb_message;
2099 ops->add_inb_buffer = tsi721_add_inb_buffer;
2100 ops->get_inb_message = tsi721_get_inb_message;
2101
2102 mport = kzalloc(sizeof(struct rio_mport), GFP_KERNEL);
2103 if (!mport) {
2104 kfree(ops);
2105 dev_dbg(&pdev->dev, "Unable to allocate memory for mport\n");
2106 return -ENOMEM;
2107 }
2108
2109 mport->ops = ops;
2110 mport->index = 0;
2111 mport->sys_size = 0; /* small system */
2112 mport->phy_type = RIO_PHY_SERIAL;
2113 mport->priv = (void *)priv;
2114 mport->phys_efptr = 0x100;
2115
2116 INIT_LIST_HEAD(&mport->dbells);
2117
2118 rio_init_dbell_res(&mport->riores[RIO_DOORBELL_RESOURCE], 0, 0xffff);
2119 rio_init_mbox_res(&mport->riores[RIO_INB_MBOX_RESOURCE], 0, 0);
2120 rio_init_mbox_res(&mport->riores[RIO_OUTB_MBOX_RESOURCE], 0, 0);
2121 strcpy(mport->name, "Tsi721 mport");
2122
2123 /* Hook up interrupt handler */
2124
2125#ifdef CONFIG_PCI_MSI
2126 if (!tsi721_enable_msix(priv))
2127 priv->flags |= TSI721_USING_MSIX;
2128 else if (!pci_enable_msi(pdev))
2129 priv->flags |= TSI721_USING_MSI;
2130 else
2131 dev_info(&pdev->dev,
2132 "MSI/MSI-X is not available. Using legacy INTx.\n");
2133#endif /* CONFIG_PCI_MSI */
2134
2135 err = tsi721_request_irq(mport);
2136
2137 if (!err) {
2138 tsi721_interrupts_init(priv);
2139 ops->pwenable = tsi721_pw_enable;
2140 } else
2141 dev_err(&pdev->dev, "Unable to get assigned PCI IRQ "
2142 "vector %02X err=0x%x\n", pdev->irq, err);
2143
2144 /* Enable SRIO link */
2145 iowrite32(ioread32(priv->regs + TSI721_DEVCTL) |
2146 TSI721_DEVCTL_SRBOOT_CMPL,
2147 priv->regs + TSI721_DEVCTL);
2148
2149 rio_register_mport(mport);
2150 priv->mport = mport;
2151
2152 if (mport->host_deviceid >= 0)
2153 iowrite32(RIO_PORT_GEN_HOST | RIO_PORT_GEN_MASTER |
2154 RIO_PORT_GEN_DISCOVERED,
2155 priv->regs + (0x100 + RIO_PORT_GEN_CTL_CSR));
2156 else
2157 iowrite32(0, priv->regs + (0x100 + RIO_PORT_GEN_CTL_CSR));
2158
2159 return 0;
2160}
2161
2162static int __devinit tsi721_probe(struct pci_dev *pdev,
2163 const struct pci_device_id *id)
2164{
2165 struct tsi721_device *priv;
2166 int i;
2167 int err;
2168 u32 regval;
2169
2170 priv = kzalloc(sizeof(struct tsi721_device), GFP_KERNEL);
2171 if (priv == NULL) {
2172 dev_err(&pdev->dev, "Failed to allocate memory for device\n");
2173 err = -ENOMEM;
2174 goto err_exit;
2175 }
2176
2177 err = pci_enable_device(pdev);
2178 if (err) {
2179 dev_err(&pdev->dev, "Failed to enable PCI device\n");
2180 goto err_clean;
2181 }
2182
2183 priv->pdev = pdev;
2184
2185#ifdef DEBUG
2186 for (i = 0; i <= PCI_STD_RESOURCE_END; i++) {
2187 dev_dbg(&pdev->dev, "res[%d] @ 0x%llx (0x%lx, 0x%lx)\n",
2188 i, (unsigned long long)pci_resource_start(pdev, i),
2189 (unsigned long)pci_resource_len(pdev, i),
2190 pci_resource_flags(pdev, i));
2191 }
2192#endif
2193 /*
2194 * Verify BAR configuration
2195 */
2196
2197 /* BAR_0 (registers) must be 512KB+ in 32-bit address space */
2198 if (!(pci_resource_flags(pdev, BAR_0) & IORESOURCE_MEM) ||
2199 pci_resource_flags(pdev, BAR_0) & IORESOURCE_MEM_64 ||
2200 pci_resource_len(pdev, BAR_0) < TSI721_REG_SPACE_SIZE) {
2201 dev_err(&pdev->dev,
2202 "Missing or misconfigured CSR BAR0, aborting.\n");
2203 err = -ENODEV;
2204 goto err_disable_pdev;
2205 }
2206
2207 /* BAR_1 (outbound doorbells) must be 16MB+ in 32-bit address space */
2208 if (!(pci_resource_flags(pdev, BAR_1) & IORESOURCE_MEM) ||
2209 pci_resource_flags(pdev, BAR_1) & IORESOURCE_MEM_64 ||
2210 pci_resource_len(pdev, BAR_1) < TSI721_DB_WIN_SIZE) {
2211 dev_err(&pdev->dev,
2212 "Missing or misconfigured Doorbell BAR1, aborting.\n");
2213 err = -ENODEV;
2214 goto err_disable_pdev;
2215 }
2216
2217 /*
2218 * BAR_2 and BAR_4 (outbound translation) must be in 64-bit PCIe address
2219 * space.
2220 * NOTE: BAR_2 and BAR_4 are not used by this version of driver.
2221 * It may be a good idea to keep them disabled using HW configuration
2222 * to save PCI memory space.
2223 */
2224 if ((pci_resource_flags(pdev, BAR_2) & IORESOURCE_MEM) &&
2225 (pci_resource_flags(pdev, BAR_2) & IORESOURCE_MEM_64)) {
2226 dev_info(&pdev->dev, "Outbound BAR2 is not used but enabled.\n");
2227 }
2228
2229 if ((pci_resource_flags(pdev, BAR_4) & IORESOURCE_MEM) &&
2230 (pci_resource_flags(pdev, BAR_4) & IORESOURCE_MEM_64)) {
2231 dev_info(&pdev->dev, "Outbound BAR4 is not used but enabled.\n");
2232 }
2233
2234 err = pci_request_regions(pdev, DRV_NAME);
2235 if (err) {
2236 dev_err(&pdev->dev, "Cannot obtain PCI resources, "
2237 "aborting.\n");
2238 goto err_disable_pdev;
2239 }
2240
2241 pci_set_master(pdev);
2242
2243 priv->regs = pci_ioremap_bar(pdev, BAR_0);
2244 if (!priv->regs) {
2245 dev_err(&pdev->dev,
2246 "Unable to map device registers space, aborting\n");
2247 err = -ENOMEM;
2248 goto err_free_res;
2249 }
2250
2251 priv->odb_base = pci_ioremap_bar(pdev, BAR_1);
2252 if (!priv->odb_base) {
2253 dev_err(&pdev->dev,
2254 "Unable to map outbound doorbells space, aborting\n");
2255 err = -ENOMEM;
2256 goto err_unmap_bars;
2257 }
2258
2259 /* Configure DMA attributes. */
2260 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
2261 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
2262 dev_info(&pdev->dev, "Unable to set DMA mask\n");
2263 goto err_unmap_bars;
2264 }
2265
2266 if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)))
2267 dev_info(&pdev->dev, "Unable to set consistent DMA mask\n");
2268 } else {
2269 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
2270 if (err)
2271 dev_info(&pdev->dev, "Unable to set consistent DMA mask\n");
2272 }
2273
2274 /* Clear "no snoop" and "relaxed ordering" bits. */
2275 pci_read_config_dword(pdev, 0x40 + PCI_EXP_DEVCTL, &regval);
2276 regval &= ~(PCI_EXP_DEVCTL_RELAX_EN | PCI_EXP_DEVCTL_NOSNOOP_EN);
2277 pci_write_config_dword(pdev, 0x40 + PCI_EXP_DEVCTL, regval);
2278
2279 /*
2280 * FIXUP: correct offsets of MSI-X tables in the MSI-X Capability Block
2281 */
2282 pci_write_config_dword(pdev, TSI721_PCIECFG_EPCTL, 0x01);
2283 pci_write_config_dword(pdev, TSI721_PCIECFG_MSIXTBL,
2284 TSI721_MSIXTBL_OFFSET);
2285 pci_write_config_dword(pdev, TSI721_PCIECFG_MSIXPBA,
2286 TSI721_MSIXPBA_OFFSET);
2287 pci_write_config_dword(pdev, TSI721_PCIECFG_EPCTL, 0);
2288 /* End of FIXUP */
2289
2290 tsi721_disable_ints(priv);
2291
2292 tsi721_init_pc2sr_mapping(priv);
2293 tsi721_init_sr2pc_mapping(priv);
2294
2295 if (tsi721_bdma_init(priv)) {
2296 dev_err(&pdev->dev, "BDMA initialization failed, aborting\n");
2297 err = -ENOMEM;
2298 goto err_unmap_bars;
2299 }
2300
2301 err = tsi721_doorbell_init(priv);
2302 if (err)
2303 goto err_free_bdma;
2304
2305 tsi721_port_write_init(priv);
2306
2307 err = tsi721_messages_init(priv);
2308 if (err)
2309 goto err_free_consistent;
2310
2311 err = tsi721_setup_mport(priv);
2312 if (err)
2313 goto err_free_consistent;
2314
2315 return 0;
2316
2317err_free_consistent:
2318 tsi721_doorbell_free(priv);
2319err_free_bdma:
2320 tsi721_bdma_free(priv);
2321err_unmap_bars:
2322 if (priv->regs)
2323 iounmap(priv->regs);
2324 if (priv->odb_base)
2325 iounmap(priv->odb_base);
2326err_free_res:
2327 pci_release_regions(pdev);
2328 pci_clear_master(pdev);
2329err_disable_pdev:
2330 pci_disable_device(pdev);
2331err_clean:
2332 kfree(priv);
2333err_exit:
2334 return err;
2335}
2336
2337static DEFINE_PCI_DEVICE_TABLE(tsi721_pci_tbl) = {
2338 { PCI_DEVICE(PCI_VENDOR_ID_IDT, PCI_DEVICE_ID_TSI721) },
2339 { 0, } /* terminate list */
2340};
2341
2342MODULE_DEVICE_TABLE(pci, tsi721_pci_tbl);
2343
2344static struct pci_driver tsi721_driver = {
2345 .name = "tsi721",
2346 .id_table = tsi721_pci_tbl,
2347 .probe = tsi721_probe,
2348};
2349
2350static int __init tsi721_init(void)
2351{
2352 return pci_register_driver(&tsi721_driver);
2353}
2354
2355static void __exit tsi721_exit(void)
2356{
2357 pci_unregister_driver(&tsi721_driver);
2358}
2359
2360device_initcall(tsi721_init);
diff --git a/drivers/rapidio/devices/tsi721.h b/drivers/rapidio/devices/tsi721.h
new file mode 100644
index 000000000000..58be4deb1402
--- /dev/null
+++ b/drivers/rapidio/devices/tsi721.h
@@ -0,0 +1,766 @@
1/*
2 * Tsi721 PCIExpress-to-SRIO bridge definitions
3 *
4 * Copyright 2011, Integrated Device Technology, Inc.
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 Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc., 59
18 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21#ifndef __TSI721_H
22#define __TSI721_H
23
24#define DRV_NAME "tsi721"
25
26#define DEFAULT_HOPCOUNT 0xff
27#define DEFAULT_DESTID 0xff
28
29/* PCI device ID */
30#define PCI_DEVICE_ID_TSI721 0x80ab
31
32#define BAR_0 0
33#define BAR_1 1
34#define BAR_2 2
35#define BAR_4 4
36
37#define TSI721_PC2SR_BARS 2
38#define TSI721_PC2SR_WINS 8
39#define TSI721_PC2SR_ZONES 8
40#define TSI721_MAINT_WIN 0 /* Window for outbound maintenance requests */
41#define IDB_QUEUE 0 /* Inbound Doorbell Queue to use */
42#define IDB_QSIZE 512 /* Inbound Doorbell Queue size */
43
44/* Memory space sizes */
45#define TSI721_REG_SPACE_SIZE (512 * 1024) /* 512K */
46#define TSI721_DB_WIN_SIZE (16 * 1024 * 1024) /* 16MB */
47
48#define RIO_TT_CODE_8 0x00000000
49#define RIO_TT_CODE_16 0x00000001
50
51#define TSI721_DMA_MAXCH 8
52#define TSI721_DMA_MINSTSSZ 32
53#define TSI721_DMA_STSBLKSZ 8
54
55#define TSI721_SRIO_MAXCH 8
56
57#define DBELL_SID(buf) (((u8)buf[2] << 8) | (u8)buf[3])
58#define DBELL_TID(buf) (((u8)buf[4] << 8) | (u8)buf[5])
59#define DBELL_INF(buf) (((u8)buf[0] << 8) | (u8)buf[1])
60
61#define TSI721_RIO_PW_MSG_SIZE 16 /* Tsi721 saves only 16 bytes of PW msg */
62
63/* Register definitions */
64
65/*
66 * Registers in PCIe configuration space
67 */
68
69#define TSI721_PCIECFG_MSIXTBL 0x0a4
70#define TSI721_MSIXTBL_OFFSET 0x2c000
71#define TSI721_PCIECFG_MSIXPBA 0x0a8
72#define TSI721_MSIXPBA_OFFSET 0x2a000
73#define TSI721_PCIECFG_EPCTL 0x400
74
75/*
76 * Event Management Registers
77 */
78
79#define TSI721_RIO_EM_INT_STAT 0x10910
80#define TSI721_RIO_EM_INT_STAT_PW_RX 0x00010000
81
82#define TSI721_RIO_EM_INT_ENABLE 0x10914
83#define TSI721_RIO_EM_INT_ENABLE_PW_RX 0x00010000
84
85#define TSI721_RIO_EM_DEV_INT_EN 0x10930
86#define TSI721_RIO_EM_DEV_INT_EN_INT 0x00000001
87
88/*
89 * Port-Write Block Registers
90 */
91
92#define TSI721_RIO_PW_CTL 0x10a04
93#define TSI721_RIO_PW_CTL_PW_TIMER 0xf0000000
94#define TSI721_RIO_PW_CTL_PWT_DIS (0 << 28)
95#define TSI721_RIO_PW_CTL_PWT_103 (1 << 28)
96#define TSI721_RIO_PW_CTL_PWT_205 (1 << 29)
97#define TSI721_RIO_PW_CTL_PWT_410 (1 << 30)
98#define TSI721_RIO_PW_CTL_PWT_820 (1 << 31)
99#define TSI721_RIO_PW_CTL_PWC_MODE 0x01000000
100#define TSI721_RIO_PW_CTL_PWC_CONT 0x00000000
101#define TSI721_RIO_PW_CTL_PWC_REL 0x01000000
102
103#define TSI721_RIO_PW_RX_STAT 0x10a10
104#define TSI721_RIO_PW_RX_STAT_WR_SIZE 0x0000f000
105#define TSI_RIO_PW_RX_STAT_WDPTR 0x00000100
106#define TSI721_RIO_PW_RX_STAT_PW_SHORT 0x00000008
107#define TSI721_RIO_PW_RX_STAT_PW_TRUNC 0x00000004
108#define TSI721_RIO_PW_RX_STAT_PW_DISC 0x00000002
109#define TSI721_RIO_PW_RX_STAT_PW_VAL 0x00000001
110
111#define TSI721_RIO_PW_RX_CAPT(x) (0x10a20 + (x)*4)
112
113/*
114 * Inbound Doorbells
115 */
116
117#define TSI721_IDB_ENTRY_SIZE 64
118
119#define TSI721_IDQ_CTL(x) (0x20000 + (x) * 1000)
120#define TSI721_IDQ_SUSPEND 0x00000002
121#define TSI721_IDQ_INIT 0x00000001
122
123#define TSI721_IDQ_STS(x) (0x20004 + (x) * 1000)
124#define TSI721_IDQ_RUN 0x00200000
125
126#define TSI721_IDQ_MASK(x) (0x20008 + (x) * 1000)
127#define TSI721_IDQ_MASK_MASK 0xffff0000
128#define TSI721_IDQ_MASK_PATT 0x0000ffff
129
130#define TSI721_IDQ_RP(x) (0x2000c + (x) * 1000)
131#define TSI721_IDQ_RP_PTR 0x0007ffff
132
133#define TSI721_IDQ_WP(x) (0x20010 + (x) * 1000)
134#define TSI721_IDQ_WP_PTR 0x0007ffff
135
136#define TSI721_IDQ_BASEL(x) (0x20014 + (x) * 1000)
137#define TSI721_IDQ_BASEL_ADDR 0xffffffc0
138#define TSI721_IDQ_BASEU(x) (0x20018 + (x) * 1000)
139#define TSI721_IDQ_SIZE(x) (0x2001c + (x) * 1000)
140#define TSI721_IDQ_SIZE_VAL(size) (__fls(size) - 4)
141#define TSI721_IDQ_SIZE_MIN 512
142#define TSI721_IDQ_SIZE_MAX (512 * 1024)
143
144#define TSI721_SR_CHINT(x) (0x20040 + (x) * 1000)
145#define TSI721_SR_CHINTE(x) (0x20044 + (x) * 1000)
146#define TSI721_SR_CHINTSET(x) (0x20048 + (x) * 1000)
147#define TSI721_SR_CHINT_ODBOK 0x00000020
148#define TSI721_SR_CHINT_IDBQRCV 0x00000010
149#define TSI721_SR_CHINT_SUSP 0x00000008
150#define TSI721_SR_CHINT_ODBTO 0x00000004
151#define TSI721_SR_CHINT_ODBRTRY 0x00000002
152#define TSI721_SR_CHINT_ODBERR 0x00000001
153#define TSI721_SR_CHINT_ALL 0x0000003f
154
155#define TSI721_IBWIN_NUM 8
156
157#define TSI721_IBWINLB(x) (0x29000 + (x) * 20)
158#define TSI721_IBWINLB_BA 0xfffff000
159#define TSI721_IBWINLB_WEN 0x00000001
160
161#define TSI721_SR2PC_GEN_INTE 0x29800
162#define TSI721_SR2PC_PWE 0x29804
163#define TSI721_SR2PC_GEN_INT 0x29808
164
165#define TSI721_DEV_INTE 0x29840
166#define TSI721_DEV_INT 0x29844
167#define TSI721_DEV_INTSET 0x29848
168#define TSI721_DEV_INT_SMSG_CH 0x00000800
169#define TSI721_DEV_INT_SMSG_NCH 0x00000400
170#define TSI721_DEV_INT_SR2PC_CH 0x00000200
171#define TSI721_DEV_INT_SRIO 0x00000020
172
173#define TSI721_DEV_CHAN_INTE 0x2984c
174#define TSI721_DEV_CHAN_INT 0x29850
175
176#define TSI721_INT_SR2PC_CHAN_M 0xff000000
177#define TSI721_INT_SR2PC_CHAN(x) (1 << (24 + (x)))
178#define TSI721_INT_IMSG_CHAN_M 0x00ff0000
179#define TSI721_INT_IMSG_CHAN(x) (1 << (16 + (x)))
180#define TSI721_INT_OMSG_CHAN_M 0x0000ff00
181#define TSI721_INT_OMSG_CHAN(x) (1 << (8 + (x)))
182
183/*
184 * PC2SR block registers
185 */
186#define TSI721_OBWIN_NUM TSI721_PC2SR_WINS
187
188#define TSI721_OBWINLB(x) (0x40000 + (x) * 20)
189#define TSI721_OBWINLB_BA 0xffff8000
190#define TSI721_OBWINLB_WEN 0x00000001
191
192#define TSI721_OBWINUB(x) (0x40004 + (x) * 20)
193
194#define TSI721_OBWINSZ(x) (0x40008 + (x) * 20)
195#define TSI721_OBWINSZ_SIZE 0x00001f00
196#define TSI721_OBWIN_SIZE(size) (__fls(size) - 15)
197
198#define TSI721_ZONE_SEL 0x41300
199#define TSI721_ZONE_SEL_RD_WRB 0x00020000
200#define TSI721_ZONE_SEL_GO 0x00010000
201#define TSI721_ZONE_SEL_WIN 0x00000038
202#define TSI721_ZONE_SEL_ZONE 0x00000007
203
204#define TSI721_LUT_DATA0 0x41304
205#define TSI721_LUT_DATA0_ADD 0xfffff000
206#define TSI721_LUT_DATA0_RDTYPE 0x00000f00
207#define TSI721_LUT_DATA0_NREAD 0x00000100
208#define TSI721_LUT_DATA0_MNTRD 0x00000200
209#define TSI721_LUT_DATA0_RDCRF 0x00000020
210#define TSI721_LUT_DATA0_WRCRF 0x00000010
211#define TSI721_LUT_DATA0_WRTYPE 0x0000000f
212#define TSI721_LUT_DATA0_NWR 0x00000001
213#define TSI721_LUT_DATA0_MNTWR 0x00000002
214#define TSI721_LUT_DATA0_NWR_R 0x00000004
215
216#define TSI721_LUT_DATA1 0x41308
217
218#define TSI721_LUT_DATA2 0x4130c
219#define TSI721_LUT_DATA2_HC 0xff000000
220#define TSI721_LUT_DATA2_ADD65 0x000c0000
221#define TSI721_LUT_DATA2_TT 0x00030000
222#define TSI721_LUT_DATA2_DSTID 0x0000ffff
223
224#define TSI721_PC2SR_INTE 0x41310
225
226#define TSI721_DEVCTL 0x48004
227#define TSI721_DEVCTL_SRBOOT_CMPL 0x00000004
228
229#define TSI721_I2C_INT_ENABLE 0x49120
230
231/*
232 * Block DMA Engine Registers
233 * x = 0..7
234 */
235
236#define TSI721_DMAC_DWRCNT(x) (0x51000 + (x) * 0x1000)
237#define TSI721_DMAC_DRDCNT(x) (0x51004 + (x) * 0x1000)
238
239#define TSI721_DMAC_CTL(x) (0x51008 + (x) * 0x1000)
240#define TSI721_DMAC_CTL_SUSP 0x00000002
241#define TSI721_DMAC_CTL_INIT 0x00000001
242
243#define TSI721_DMAC_INT(x) (0x5100c + (x) * 0x1000)
244#define TSI721_DMAC_INT_STFULL 0x00000010
245#define TSI721_DMAC_INT_DONE 0x00000008
246#define TSI721_DMAC_INT_SUSP 0x00000004
247#define TSI721_DMAC_INT_ERR 0x00000002
248#define TSI721_DMAC_INT_IOFDONE 0x00000001
249#define TSI721_DMAC_INT_ALL 0x0000001f
250
251#define TSI721_DMAC_INTSET(x) (0x51010 + (x) * 0x1000)
252
253#define TSI721_DMAC_STS(x) (0x51014 + (x) * 0x1000)
254#define TSI721_DMAC_STS_ABORT 0x00400000
255#define TSI721_DMAC_STS_RUN 0x00200000
256#define TSI721_DMAC_STS_CS 0x001f0000
257
258#define TSI721_DMAC_INTE(x) (0x51018 + (x) * 0x1000)
259
260#define TSI721_DMAC_DPTRL(x) (0x51024 + (x) * 0x1000)
261#define TSI721_DMAC_DPTRL_MASK 0xffffffe0
262
263#define TSI721_DMAC_DPTRH(x) (0x51028 + (x) * 0x1000)
264
265#define TSI721_DMAC_DSBL(x) (0x5102c + (x) * 0x1000)
266#define TSI721_DMAC_DSBL_MASK 0xffffffc0
267
268#define TSI721_DMAC_DSBH(x) (0x51030 + (x) * 0x1000)
269
270#define TSI721_DMAC_DSSZ(x) (0x51034 + (x) * 0x1000)
271#define TSI721_DMAC_DSSZ_SIZE_M 0x0000000f
272#define TSI721_DMAC_DSSZ_SIZE(size) (__fls(size) - 4)
273
274
275#define TSI721_DMAC_DSRP(x) (0x51038 + (x) * 0x1000)
276#define TSI721_DMAC_DSRP_MASK 0x0007ffff
277
278#define TSI721_DMAC_DSWP(x) (0x5103c + (x) * 0x1000)
279#define TSI721_DMAC_DSWP_MASK 0x0007ffff
280
281#define TSI721_BDMA_INTE 0x5f000
282
283/*
284 * Messaging definitions
285 */
286#define TSI721_MSG_BUFFER_SIZE RIO_MAX_MSG_SIZE
287#define TSI721_MSG_MAX_SIZE RIO_MAX_MSG_SIZE
288#define TSI721_IMSG_MAXCH 8
289#define TSI721_IMSG_CHNUM TSI721_IMSG_MAXCH
290#define TSI721_IMSGD_MIN_RING_SIZE 32
291#define TSI721_IMSGD_RING_SIZE 512
292
293#define TSI721_OMSG_CHNUM 4 /* One channel per MBOX */
294#define TSI721_OMSGD_MIN_RING_SIZE 32
295#define TSI721_OMSGD_RING_SIZE 512
296
297/*
298 * Outbound Messaging Engine Registers
299 * x = 0..7
300 */
301
302#define TSI721_OBDMAC_DWRCNT(x) (0x61000 + (x) * 0x1000)
303
304#define TSI721_OBDMAC_DRDCNT(x) (0x61004 + (x) * 0x1000)
305
306#define TSI721_OBDMAC_CTL(x) (0x61008 + (x) * 0x1000)
307#define TSI721_OBDMAC_CTL_MASK 0x00000007
308#define TSI721_OBDMAC_CTL_RETRY_THR 0x00000004
309#define TSI721_OBDMAC_CTL_SUSPEND 0x00000002
310#define TSI721_OBDMAC_CTL_INIT 0x00000001
311
312#define TSI721_OBDMAC_INT(x) (0x6100c + (x) * 0x1000)
313#define TSI721_OBDMAC_INTSET(x) (0x61010 + (x) * 0x1000)
314#define TSI721_OBDMAC_INTE(x) (0x61018 + (x) * 0x1000)
315#define TSI721_OBDMAC_INT_MASK 0x0000001F
316#define TSI721_OBDMAC_INT_ST_FULL 0x00000010
317#define TSI721_OBDMAC_INT_DONE 0x00000008
318#define TSI721_OBDMAC_INT_SUSPENDED 0x00000004
319#define TSI721_OBDMAC_INT_ERROR 0x00000002
320#define TSI721_OBDMAC_INT_IOF_DONE 0x00000001
321#define TSI721_OBDMAC_INT_ALL TSI721_OBDMAC_INT_MASK
322
323#define TSI721_OBDMAC_STS(x) (0x61014 + (x) * 0x1000)
324#define TSI721_OBDMAC_STS_MASK 0x007f0000
325#define TSI721_OBDMAC_STS_ABORT 0x00400000
326#define TSI721_OBDMAC_STS_RUN 0x00200000
327#define TSI721_OBDMAC_STS_CS 0x001f0000
328
329#define TSI721_OBDMAC_PWE(x) (0x6101c + (x) * 0x1000)
330#define TSI721_OBDMAC_PWE_MASK 0x00000002
331#define TSI721_OBDMAC_PWE_ERROR_EN 0x00000002
332
333#define TSI721_OBDMAC_DPTRL(x) (0x61020 + (x) * 0x1000)
334#define TSI721_OBDMAC_DPTRL_MASK 0xfffffff0
335
336#define TSI721_OBDMAC_DPTRH(x) (0x61024 + (x) * 0x1000)
337#define TSI721_OBDMAC_DPTRH_MASK 0xffffffff
338
339#define TSI721_OBDMAC_DSBL(x) (0x61040 + (x) * 0x1000)
340#define TSI721_OBDMAC_DSBL_MASK 0xffffffc0
341
342#define TSI721_OBDMAC_DSBH(x) (0x61044 + (x) * 0x1000)
343#define TSI721_OBDMAC_DSBH_MASK 0xffffffff
344
345#define TSI721_OBDMAC_DSSZ(x) (0x61048 + (x) * 0x1000)
346#define TSI721_OBDMAC_DSSZ_MASK 0x0000000f
347
348#define TSI721_OBDMAC_DSRP(x) (0x6104c + (x) * 0x1000)
349#define TSI721_OBDMAC_DSRP_MASK 0x0007ffff
350
351#define TSI721_OBDMAC_DSWP(x) (0x61050 + (x) * 0x1000)
352#define TSI721_OBDMAC_DSWP_MASK 0x0007ffff
353
354#define TSI721_RQRPTO 0x60010
355#define TSI721_RQRPTO_MASK 0x00ffffff
356#define TSI721_RQRPTO_VAL 400 /* Response TO value */
357
358/*
359 * Inbound Messaging Engine Registers
360 * x = 0..7
361 */
362
363#define TSI721_IB_DEVID_GLOBAL 0xffff
364#define TSI721_IBDMAC_FQBL(x) (0x61200 + (x) * 0x1000)
365#define TSI721_IBDMAC_FQBL_MASK 0xffffffc0
366
367#define TSI721_IBDMAC_FQBH(x) (0x61204 + (x) * 0x1000)
368#define TSI721_IBDMAC_FQBH_MASK 0xffffffff
369
370#define TSI721_IBDMAC_FQSZ_ENTRY_INX TSI721_IMSGD_RING_SIZE
371#define TSI721_IBDMAC_FQSZ(x) (0x61208 + (x) * 0x1000)
372#define TSI721_IBDMAC_FQSZ_MASK 0x0000000f
373
374#define TSI721_IBDMAC_FQRP(x) (0x6120c + (x) * 0x1000)
375#define TSI721_IBDMAC_FQRP_MASK 0x0007ffff
376
377#define TSI721_IBDMAC_FQWP(x) (0x61210 + (x) * 0x1000)
378#define TSI721_IBDMAC_FQWP_MASK 0x0007ffff
379
380#define TSI721_IBDMAC_FQTH(x) (0x61214 + (x) * 0x1000)
381#define TSI721_IBDMAC_FQTH_MASK 0x0007ffff
382
383#define TSI721_IB_DEVID 0x60020
384#define TSI721_IB_DEVID_MASK 0x0000ffff
385
386#define TSI721_IBDMAC_CTL(x) (0x61240 + (x) * 0x1000)
387#define TSI721_IBDMAC_CTL_MASK 0x00000003
388#define TSI721_IBDMAC_CTL_SUSPEND 0x00000002
389#define TSI721_IBDMAC_CTL_INIT 0x00000001
390
391#define TSI721_IBDMAC_STS(x) (0x61244 + (x) * 0x1000)
392#define TSI721_IBDMAC_STS_MASK 0x007f0000
393#define TSI721_IBSMAC_STS_ABORT 0x00400000
394#define TSI721_IBSMAC_STS_RUN 0x00200000
395#define TSI721_IBSMAC_STS_CS 0x001f0000
396
397#define TSI721_IBDMAC_INT(x) (0x61248 + (x) * 0x1000)
398#define TSI721_IBDMAC_INTSET(x) (0x6124c + (x) * 0x1000)
399#define TSI721_IBDMAC_INTE(x) (0x61250 + (x) * 0x1000)
400#define TSI721_IBDMAC_INT_MASK 0x0000100f
401#define TSI721_IBDMAC_INT_SRTO 0x00001000
402#define TSI721_IBDMAC_INT_SUSPENDED 0x00000008
403#define TSI721_IBDMAC_INT_PC_ERROR 0x00000004
404#define TSI721_IBDMAC_INT_FQ_LOW 0x00000002
405#define TSI721_IBDMAC_INT_DQ_RCV 0x00000001
406#define TSI721_IBDMAC_INT_ALL TSI721_IBDMAC_INT_MASK
407
408#define TSI721_IBDMAC_PWE(x) (0x61254 + (x) * 0x1000)
409#define TSI721_IBDMAC_PWE_MASK 0x00001700
410#define TSI721_IBDMAC_PWE_SRTO 0x00001000
411#define TSI721_IBDMAC_PWE_ILL_FMT 0x00000400
412#define TSI721_IBDMAC_PWE_ILL_DEC 0x00000200
413#define TSI721_IBDMAC_PWE_IMP_SP 0x00000100
414
415#define TSI721_IBDMAC_DQBL(x) (0x61300 + (x) * 0x1000)
416#define TSI721_IBDMAC_DQBL_MASK 0xffffffc0
417#define TSI721_IBDMAC_DQBL_ADDR 0xffffffc0
418
419#define TSI721_IBDMAC_DQBH(x) (0x61304 + (x) * 0x1000)
420#define TSI721_IBDMAC_DQBH_MASK 0xffffffff
421
422#define TSI721_IBDMAC_DQRP(x) (0x61308 + (x) * 0x1000)
423#define TSI721_IBDMAC_DQRP_MASK 0x0007ffff
424
425#define TSI721_IBDMAC_DQWR(x) (0x6130c + (x) * 0x1000)
426#define TSI721_IBDMAC_DQWR_MASK 0x0007ffff
427
428#define TSI721_IBDMAC_DQSZ(x) (0x61314 + (x) * 0x1000)
429#define TSI721_IBDMAC_DQSZ_MASK 0x0000000f
430
431/*
432 * Messaging Engine Interrupts
433 */
434
435#define TSI721_SMSG_PWE 0x6a004
436
437#define TSI721_SMSG_INTE 0x6a000
438#define TSI721_SMSG_INT 0x6a008
439#define TSI721_SMSG_INTSET 0x6a010
440#define TSI721_SMSG_INT_MASK 0x0086ffff
441#define TSI721_SMSG_INT_UNS_RSP 0x00800000
442#define TSI721_SMSG_INT_ECC_NCOR 0x00040000
443#define TSI721_SMSG_INT_ECC_COR 0x00020000
444#define TSI721_SMSG_INT_ECC_NCOR_CH 0x0000ff00
445#define TSI721_SMSG_INT_ECC_COR_CH 0x000000ff
446
447#define TSI721_SMSG_ECC_LOG 0x6a014
448#define TSI721_SMSG_ECC_LOG_MASK 0x00070007
449#define TSI721_SMSG_ECC_LOG_ECC_NCOR_M 0x00070000
450#define TSI721_SMSG_ECC_LOG_ECC_COR_M 0x00000007
451
452#define TSI721_RETRY_GEN_CNT 0x6a100
453#define TSI721_RETRY_GEN_CNT_MASK 0xffffffff
454
455#define TSI721_RETRY_RX_CNT 0x6a104
456#define TSI721_RETRY_RX_CNT_MASK 0xffffffff
457
458#define TSI721_SMSG_ECC_COR_LOG(x) (0x6a300 + (x) * 4)
459#define TSI721_SMSG_ECC_COR_LOG_MASK 0x000000ff
460
461#define TSI721_SMSG_ECC_NCOR(x) (0x6a340 + (x) * 4)
462#define TSI721_SMSG_ECC_NCOR_MASK 0x000000ff
463
464/*
465 * Block DMA Descriptors
466 */
467
468struct tsi721_dma_desc {
469 __le32 type_id;
470
471#define TSI721_DMAD_DEVID 0x0000ffff
472#define TSI721_DMAD_CRF 0x00010000
473#define TSI721_DMAD_PRIO 0x00060000
474#define TSI721_DMAD_RTYPE 0x00780000
475#define TSI721_DMAD_IOF 0x08000000
476#define TSI721_DMAD_DTYPE 0xe0000000
477
478 __le32 bcount;
479
480#define TSI721_DMAD_BCOUNT1 0x03ffffff /* if DTYPE == 1 */
481#define TSI721_DMAD_BCOUNT2 0x0000000f /* if DTYPE == 2 */
482#define TSI721_DMAD_TT 0x0c000000
483#define TSI721_DMAD_RADDR0 0xc0000000
484
485 union {
486 __le32 raddr_lo; /* if DTYPE == (1 || 2) */
487 __le32 next_lo; /* if DTYPE == 3 */
488 };
489
490#define TSI721_DMAD_CFGOFF 0x00ffffff
491#define TSI721_DMAD_HOPCNT 0xff000000
492
493 union {
494 __le32 raddr_hi; /* if DTYPE == (1 || 2) */
495 __le32 next_hi; /* if DTYPE == 3 */
496 };
497
498 union {
499 struct { /* if DTYPE == 1 */
500 __le32 bufptr_lo;
501 __le32 bufptr_hi;
502 __le32 s_dist;
503 __le32 s_size;
504 } t1;
505 __le32 data[4]; /* if DTYPE == 2 */
506 u32 reserved[4]; /* if DTYPE == 3 */
507 };
508} __aligned(32);
509
510/*
511 * Inbound Messaging Descriptor
512 */
513struct tsi721_imsg_desc {
514 __le32 type_id;
515
516#define TSI721_IMD_DEVID 0x0000ffff
517#define TSI721_IMD_CRF 0x00010000
518#define TSI721_IMD_PRIO 0x00060000
519#define TSI721_IMD_TT 0x00180000
520#define TSI721_IMD_DTYPE 0xe0000000
521
522 __le32 msg_info;
523
524#define TSI721_IMD_BCOUNT 0x00000ff8
525#define TSI721_IMD_SSIZE 0x0000f000
526#define TSI721_IMD_LETER 0x00030000
527#define TSI721_IMD_XMBOX 0x003c0000
528#define TSI721_IMD_MBOX 0x00c00000
529#define TSI721_IMD_CS 0x78000000
530#define TSI721_IMD_HO 0x80000000
531
532 __le32 bufptr_lo;
533 __le32 bufptr_hi;
534 u32 reserved[12];
535
536} __aligned(64);
537
538/*
539 * Outbound Messaging Descriptor
540 */
541struct tsi721_omsg_desc {
542 __le32 type_id;
543
544#define TSI721_OMD_DEVID 0x0000ffff
545#define TSI721_OMD_CRF 0x00010000
546#define TSI721_OMD_PRIO 0x00060000
547#define TSI721_OMD_IOF 0x08000000
548#define TSI721_OMD_DTYPE 0xe0000000
549#define TSI721_OMD_RSRVD 0x17f80000
550
551 __le32 msg_info;
552
553#define TSI721_OMD_BCOUNT 0x00000ff8
554#define TSI721_OMD_SSIZE 0x0000f000
555#define TSI721_OMD_LETER 0x00030000
556#define TSI721_OMD_XMBOX 0x003c0000
557#define TSI721_OMD_MBOX 0x00c00000
558#define TSI721_OMD_TT 0x0c000000
559
560 union {
561 __le32 bufptr_lo; /* if DTYPE == 4 */
562 __le32 next_lo; /* if DTYPE == 5 */
563 };
564
565 union {
566 __le32 bufptr_hi; /* if DTYPE == 4 */
567 __le32 next_hi; /* if DTYPE == 5 */
568 };
569
570} __aligned(16);
571
572struct tsi721_dma_sts {
573 __le64 desc_sts[8];
574} __aligned(64);
575
576struct tsi721_desc_sts_fifo {
577 union {
578 __le64 da64;
579 struct {
580 __le32 lo;
581 __le32 hi;
582 } da32;
583 } stat[8];
584} __aligned(64);
585
586/* Descriptor types for BDMA and Messaging blocks */
587enum dma_dtype {
588 DTYPE1 = 1, /* Data Transfer DMA Descriptor */
589 DTYPE2 = 2, /* Immediate Data Transfer DMA Descriptor */
590 DTYPE3 = 3, /* Block Pointer DMA Descriptor */
591 DTYPE4 = 4, /* Outbound Msg DMA Descriptor */
592 DTYPE5 = 5, /* OB Messaging Block Pointer Descriptor */
593 DTYPE6 = 6 /* Inbound Messaging Descriptor */
594};
595
596enum dma_rtype {
597 NREAD = 0,
598 LAST_NWRITE_R = 1,
599 ALL_NWRITE = 2,
600 ALL_NWRITE_R = 3,
601 MAINT_RD = 4,
602 MAINT_WR = 5
603};
604
605/*
606 * mport Driver Definitions
607 */
608#define TSI721_DMA_CHNUM TSI721_DMA_MAXCH
609
610#define TSI721_DMACH_MAINT 0 /* DMA channel for maint requests */
611#define TSI721_DMACH_MAINT_NBD 32 /* Number of BDs for maint requests */
612
613#define MSG_DMA_ENTRY_INX_TO_SIZE(x) ((0x10 << (x)) & 0xFFFF0)
614
615enum tsi721_smsg_int_flag {
616 SMSG_INT_NONE = 0x00000000,
617 SMSG_INT_ECC_COR_CH = 0x000000ff,
618 SMSG_INT_ECC_NCOR_CH = 0x0000ff00,
619 SMSG_INT_ECC_COR = 0x00020000,
620 SMSG_INT_ECC_NCOR = 0x00040000,
621 SMSG_INT_UNS_RSP = 0x00800000,
622 SMSG_INT_ALL = 0x0006ffff
623};
624
625/* Structures */
626
627struct tsi721_bdma_chan {
628 int bd_num; /* number of buffer descriptors */
629 void *bd_base; /* start of DMA descriptors */
630 dma_addr_t bd_phys;
631 void *sts_base; /* start of DMA BD status FIFO */
632 dma_addr_t sts_phys;
633 int sts_size;
634};
635
636struct tsi721_imsg_ring {
637 u32 size;
638 /* VA/PA of data buffers for incoming messages */
639 void *buf_base;
640 dma_addr_t buf_phys;
641 /* VA/PA of circular free buffer list */
642 void *imfq_base;
643 dma_addr_t imfq_phys;
644 /* VA/PA of Inbound message descriptors */
645 void *imd_base;
646 dma_addr_t imd_phys;
647 /* Inbound Queue buffer pointers */
648 void *imq_base[TSI721_IMSGD_RING_SIZE];
649
650 u32 rx_slot;
651 void *dev_id;
652 u32 fq_wrptr;
653 u32 desc_rdptr;
654 spinlock_t lock;
655};
656
657struct tsi721_omsg_ring {
658 u32 size;
659 /* VA/PA of OB Msg descriptors */
660 void *omd_base;
661 dma_addr_t omd_phys;
662 /* VA/PA of OB Msg data buffers */
663 void *omq_base[TSI721_OMSGD_RING_SIZE];
664 dma_addr_t omq_phys[TSI721_OMSGD_RING_SIZE];
665 /* VA/PA of OB Msg descriptor status FIFO */
666 void *sts_base;
667 dma_addr_t sts_phys;
668 u32 sts_size; /* # of allocated status entries */
669 u32 sts_rdptr;
670
671 u32 tx_slot;
672 void *dev_id;
673 u32 wr_count;
674 spinlock_t lock;
675};
676
677enum tsi721_flags {
678 TSI721_USING_MSI = (1 << 0),
679 TSI721_USING_MSIX = (1 << 1),
680 TSI721_IMSGID_SET = (1 << 2),
681};
682
683#ifdef CONFIG_PCI_MSI
684/*
685 * MSI-X Table Entries (0 ... 69)
686 */
687#define TSI721_MSIX_DMACH_DONE(x) (0 + (x))
688#define TSI721_MSIX_DMACH_INT(x) (8 + (x))
689#define TSI721_MSIX_BDMA_INT 16
690#define TSI721_MSIX_OMSG_DONE(x) (17 + (x))
691#define TSI721_MSIX_OMSG_INT(x) (25 + (x))
692#define TSI721_MSIX_IMSG_DQ_RCV(x) (33 + (x))
693#define TSI721_MSIX_IMSG_INT(x) (41 + (x))
694#define TSI721_MSIX_MSG_INT 49
695#define TSI721_MSIX_SR2PC_IDBQ_RCV(x) (50 + (x))
696#define TSI721_MSIX_SR2PC_CH_INT(x) (58 + (x))
697#define TSI721_MSIX_SR2PC_INT 66
698#define TSI721_MSIX_PC2SR_INT 67
699#define TSI721_MSIX_SRIO_MAC_INT 68
700#define TSI721_MSIX_I2C_INT 69
701
702/* MSI-X vector and init table entry indexes */
703enum tsi721_msix_vect {
704 TSI721_VECT_IDB,
705 TSI721_VECT_PWRX, /* PW_RX is part of SRIO MAC Interrupt reporting */
706 TSI721_VECT_OMB0_DONE,
707 TSI721_VECT_OMB1_DONE,
708 TSI721_VECT_OMB2_DONE,
709 TSI721_VECT_OMB3_DONE,
710 TSI721_VECT_OMB0_INT,
711 TSI721_VECT_OMB1_INT,
712 TSI721_VECT_OMB2_INT,
713 TSI721_VECT_OMB3_INT,
714 TSI721_VECT_IMB0_RCV,
715 TSI721_VECT_IMB1_RCV,
716 TSI721_VECT_IMB2_RCV,
717 TSI721_VECT_IMB3_RCV,
718 TSI721_VECT_IMB0_INT,
719 TSI721_VECT_IMB1_INT,
720 TSI721_VECT_IMB2_INT,
721 TSI721_VECT_IMB3_INT,
722 TSI721_VECT_MAX
723};
724
725#define IRQ_DEVICE_NAME_MAX 64
726
727struct msix_irq {
728 u16 vector;
729 char irq_name[IRQ_DEVICE_NAME_MAX];
730};
731#endif /* CONFIG_PCI_MSI */
732
733struct tsi721_device {
734 struct pci_dev *pdev;
735 struct rio_mport *mport;
736 u32 flags;
737 void __iomem *regs;
738#ifdef CONFIG_PCI_MSI
739 struct msix_irq msix[TSI721_VECT_MAX];
740#endif
741 /* Doorbells */
742 void __iomem *odb_base;
743 void *idb_base;
744 dma_addr_t idb_dma;
745 struct work_struct idb_work;
746 u32 db_discard_count;
747
748 /* Inbound Port-Write */
749 struct work_struct pw_work;
750 struct kfifo pw_fifo;
751 spinlock_t pw_fifo_lock;
752 u32 pw_discard_count;
753
754 /* BDMA Engine */
755 struct tsi721_bdma_chan bdma[TSI721_DMA_CHNUM];
756
757 /* Inbound Messaging */
758 int imsg_init[TSI721_IMSG_CHNUM];
759 struct tsi721_imsg_ring imsg_ring[TSI721_IMSG_CHNUM];
760
761 /* Outbound Messaging */
762 int omsg_init[TSI721_OMSG_CHNUM];
763 struct tsi721_omsg_ring omsg_ring[TSI721_OMSG_CHNUM];
764};
765
766#endif
diff --git a/drivers/rapidio/rio-scan.c b/drivers/rapidio/rio-scan.c
index ebe77dd87daf..2bebd791a092 100644
--- a/drivers/rapidio/rio-scan.c
+++ b/drivers/rapidio/rio-scan.c
@@ -516,7 +516,7 @@ static struct rio_dev __devinit *rio_setup_device(struct rio_net *net,
516 return rdev; 516 return rdev;
517 517
518cleanup: 518cleanup:
519 if (rio_is_switch(rdev)) 519 if (rswitch)
520 kfree(rswitch->route_table); 520 kfree(rswitch->route_table);
521 521
522 kfree(rdev); 522 kfree(rdev);
@@ -923,7 +923,7 @@ static int __devinit rio_enum_peer(struct rio_net *net, struct rio_mport *port,
923 * rio_enum_complete- Tests if enumeration of a network is complete 923 * rio_enum_complete- Tests if enumeration of a network is complete
924 * @port: Master port to send transaction 924 * @port: Master port to send transaction
925 * 925 *
926 * Tests the Component Tag CSR for non-zero value (enumeration 926 * Tests the PGCCSR discovered bit for non-zero value (enumeration
927 * complete flag). Return %1 if enumeration is complete or %0 if 927 * complete flag). Return %1 if enumeration is complete or %0 if
928 * enumeration is incomplete. 928 * enumeration is incomplete.
929 */ 929 */
@@ -933,7 +933,7 @@ static int rio_enum_complete(struct rio_mport *port)
933 933
934 rio_local_read_config_32(port, port->phys_efptr + RIO_PORT_GEN_CTL_CSR, 934 rio_local_read_config_32(port, port->phys_efptr + RIO_PORT_GEN_CTL_CSR,
935 &regval); 935 &regval);
936 return (regval & RIO_PORT_GEN_MASTER) ? 1 : 0; 936 return (regval & RIO_PORT_GEN_DISCOVERED) ? 1 : 0;
937} 937}
938 938
939/** 939/**
diff --git a/drivers/rapidio/switches/idt_gen2.c b/drivers/rapidio/switches/idt_gen2.c
index 043ee3136e40..809b7a3336ba 100644
--- a/drivers/rapidio/switches/idt_gen2.c
+++ b/drivers/rapidio/switches/idt_gen2.c
@@ -10,6 +10,7 @@
10 * option) any later version. 10 * option) any later version.
11 */ 11 */
12 12
13#include <linux/stat.h>
13#include <linux/rio.h> 14#include <linux/rio.h>
14#include <linux/rio_drv.h> 15#include <linux/rio_drv.h>
15#include <linux/rio_ids.h> 16#include <linux/rio_ids.h>
diff --git a/drivers/regulator/88pm8607.c b/drivers/regulator/88pm8607.c
index e821b2159b4b..ca0d608f8248 100644
--- a/drivers/regulator/88pm8607.c
+++ b/drivers/regulator/88pm8607.c
@@ -16,6 +16,7 @@
16#include <linux/regulator/driver.h> 16#include <linux/regulator/driver.h>
17#include <linux/regulator/machine.h> 17#include <linux/regulator/machine.h>
18#include <linux/mfd/88pm860x.h> 18#include <linux/mfd/88pm860x.h>
19#include <linux/module.h>
19 20
20struct pm8607_regulator_info { 21struct pm8607_regulator_info {
21 struct regulator_desc desc; 22 struct regulator_desc desc;
diff --git a/drivers/regulator/ab8500.c b/drivers/regulator/ab8500.c
index 02f3c2333c83..6e1ae69646b3 100644
--- a/drivers/regulator/ab8500.c
+++ b/drivers/regulator/ab8500.c
@@ -13,6 +13,7 @@
13 */ 13 */
14#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/module.h>
16#include <linux/err.h> 17#include <linux/err.h>
17#include <linux/platform_device.h> 18#include <linux/platform_device.h>
18#include <linux/mfd/ab8500.h> 19#include <linux/mfd/ab8500.h>
diff --git a/drivers/regulator/bq24022.c b/drivers/regulator/bq24022.c
index 068d488a4f71..e24d1b7d97a8 100644
--- a/drivers/regulator/bq24022.c
+++ b/drivers/regulator/bq24022.c
@@ -14,6 +14,7 @@
14#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/platform_device.h> 15#include <linux/platform_device.h>
16#include <linux/err.h> 16#include <linux/err.h>
17#include <linux/module.h>
17#include <linux/gpio.h> 18#include <linux/gpio.h>
18#include <linux/regulator/bq24022.h> 19#include <linux/regulator/bq24022.h>
19#include <linux/regulator/driver.h> 20#include <linux/regulator/driver.h>
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 67fa2a3297ad..669d02160221 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -28,6 +28,7 @@
28#include <linux/regulator/consumer.h> 28#include <linux/regulator/consumer.h>
29#include <linux/regulator/driver.h> 29#include <linux/regulator/driver.h>
30#include <linux/regulator/machine.h> 30#include <linux/regulator/machine.h>
31#include <linux/module.h>
31 32
32#define CREATE_TRACE_POINTS 33#define CREATE_TRACE_POINTS
33#include <trace/events/regulator.h> 34#include <trace/events/regulator.h>
diff --git a/drivers/regulator/da903x.c b/drivers/regulator/da903x.c
index 362e08221085..e23ddfa8b2c6 100644
--- a/drivers/regulator/da903x.c
+++ b/drivers/regulator/da903x.c
@@ -12,6 +12,7 @@
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/err.h> 14#include <linux/err.h>
15#include <linux/module.h>
15#include <linux/platform_device.h> 16#include <linux/platform_device.h>
16#include <linux/regulator/driver.h> 17#include <linux/regulator/driver.h>
17#include <linux/regulator/machine.h> 18#include <linux/regulator/machine.h>
diff --git a/drivers/regulator/db8500-prcmu.c b/drivers/regulator/db8500-prcmu.c
index 2bb8f451cc06..78329751af54 100644
--- a/drivers/regulator/db8500-prcmu.c
+++ b/drivers/regulator/db8500-prcmu.c
@@ -13,10 +13,11 @@
13#include <linux/err.h> 13#include <linux/err.h>
14#include <linux/spinlock.h> 14#include <linux/spinlock.h>
15#include <linux/platform_device.h> 15#include <linux/platform_device.h>
16#include <linux/mfd/db8500-prcmu.h> 16#include <linux/mfd/dbx500-prcmu.h>
17#include <linux/regulator/driver.h> 17#include <linux/regulator/driver.h>
18#include <linux/regulator/machine.h> 18#include <linux/regulator/machine.h>
19#include <linux/regulator/db8500-prcmu.h> 19#include <linux/regulator/db8500-prcmu.h>
20#include <linux/module.h>
20 21
21/* 22/*
22 * power state reference count 23 * power state reference count
diff --git a/drivers/regulator/dummy.c b/drivers/regulator/dummy.c
index f6ef6694ab98..b8f520513ce7 100644
--- a/drivers/regulator/dummy.c
+++ b/drivers/regulator/dummy.c
@@ -16,6 +16,7 @@
16 */ 16 */
17 17
18#include <linux/err.h> 18#include <linux/err.h>
19#include <linux/export.h>
19#include <linux/platform_device.h> 20#include <linux/platform_device.h>
20#include <linux/regulator/driver.h> 21#include <linux/regulator/driver.h>
21#include <linux/regulator/machine.h> 22#include <linux/regulator/machine.h>
diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c
index 2fe9d99c9f23..21ecf212a522 100644
--- a/drivers/regulator/fixed.c
+++ b/drivers/regulator/fixed.c
@@ -20,6 +20,7 @@
20 20
21#include <linux/err.h> 21#include <linux/err.h>
22#include <linux/mutex.h> 22#include <linux/mutex.h>
23#include <linux/module.h>
23#include <linux/platform_device.h> 24#include <linux/platform_device.h>
24#include <linux/regulator/driver.h> 25#include <linux/regulator/driver.h>
25#include <linux/regulator/fixed.h> 26#include <linux/regulator/fixed.h>
diff --git a/drivers/regulator/lp3971.c b/drivers/regulator/lp3971.c
index 0f22ef12601c..72b16b5f3db6 100644
--- a/drivers/regulator/lp3971.c
+++ b/drivers/regulator/lp3971.c
@@ -16,6 +16,7 @@
16#include <linux/err.h> 16#include <linux/err.h>
17#include <linux/i2c.h> 17#include <linux/i2c.h>
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/module.h>
19#include <linux/regulator/driver.h> 20#include <linux/regulator/driver.h>
20#include <linux/regulator/lp3971.h> 21#include <linux/regulator/lp3971.h>
21#include <linux/slab.h> 22#include <linux/slab.h>
diff --git a/drivers/regulator/lp3972.c b/drivers/regulator/lp3972.c
index 6aa1b506fb5d..fbc5e3741bef 100644
--- a/drivers/regulator/lp3972.c
+++ b/drivers/regulator/lp3972.c
@@ -12,6 +12,7 @@
12#include <linux/bug.h> 12#include <linux/bug.h>
13#include <linux/err.h> 13#include <linux/err.h>
14#include <linux/i2c.h> 14#include <linux/i2c.h>
15#include <linux/module.h>
15#include <linux/kernel.h> 16#include <linux/kernel.h>
16#include <linux/regulator/driver.h> 17#include <linux/regulator/driver.h>
17#include <linux/regulator/lp3972.h> 18#include <linux/regulator/lp3972.h>
diff --git a/drivers/regulator/max8925-regulator.c b/drivers/regulator/max8925-regulator.c
index e4dbd667c043..cc9ec0e03271 100644
--- a/drivers/regulator/max8925-regulator.c
+++ b/drivers/regulator/max8925-regulator.c
@@ -9,6 +9,7 @@
9 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
10 */ 10 */
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/module.h>
12#include <linux/init.h> 13#include <linux/init.h>
13#include <linux/err.h> 14#include <linux/err.h>
14#include <linux/i2c.h> 15#include <linux/i2c.h>
diff --git a/drivers/regulator/max8997.c b/drivers/regulator/max8997.c
index ad6628ca94f4..6176129a27e5 100644
--- a/drivers/regulator/max8997.c
+++ b/drivers/regulator/max8997.c
@@ -26,6 +26,7 @@
26#include <linux/err.h> 26#include <linux/err.h>
27#include <linux/gpio.h> 27#include <linux/gpio.h>
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/module.h>
29#include <linux/platform_device.h> 30#include <linux/platform_device.h>
30#include <linux/regulator/driver.h> 31#include <linux/regulator/driver.h>
31#include <linux/regulator/machine.h> 32#include <linux/regulator/machine.h>
diff --git a/drivers/regulator/mc13783-regulator.c b/drivers/regulator/mc13783-regulator.c
index 730f43ad415b..8479082e1aea 100644
--- a/drivers/regulator/mc13783-regulator.c
+++ b/drivers/regulator/mc13783-regulator.c
@@ -18,6 +18,7 @@
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/err.h> 20#include <linux/err.h>
21#include <linux/module.h>
21#include "mc13xxx.h" 22#include "mc13xxx.h"
22 23
23#define MC13783_REG_SWITCHERS5 29 24#define MC13783_REG_SWITCHERS5 29
@@ -336,9 +337,9 @@ static int __devinit mc13783_regulator_probe(struct platform_device *pdev)
336{ 337{
337 struct mc13xxx_regulator_priv *priv; 338 struct mc13xxx_regulator_priv *priv;
338 struct mc13xxx *mc13783 = dev_get_drvdata(pdev->dev.parent); 339 struct mc13xxx *mc13783 = dev_get_drvdata(pdev->dev.parent);
339 struct mc13783_regulator_platform_data *pdata = 340 struct mc13xxx_regulator_platform_data *pdata =
340 dev_get_platdata(&pdev->dev); 341 dev_get_platdata(&pdev->dev);
341 struct mc13783_regulator_init_data *init_data; 342 struct mc13xxx_regulator_init_data *init_data;
342 int i, ret; 343 int i, ret;
343 344
344 dev_dbg(&pdev->dev, "%s id %d\n", __func__, pdev->id); 345 dev_dbg(&pdev->dev, "%s id %d\n", __func__, pdev->id);
@@ -381,7 +382,7 @@ err:
381static int __devexit mc13783_regulator_remove(struct platform_device *pdev) 382static int __devexit mc13783_regulator_remove(struct platform_device *pdev)
382{ 383{
383 struct mc13xxx_regulator_priv *priv = platform_get_drvdata(pdev); 384 struct mc13xxx_regulator_priv *priv = platform_get_drvdata(pdev);
384 struct mc13783_regulator_platform_data *pdata = 385 struct mc13xxx_regulator_platform_data *pdata =
385 dev_get_platdata(&pdev->dev); 386 dev_get_platdata(&pdev->dev);
386 int i; 387 int i;
387 388
diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
index 3285d41842f2..023d17d022cf 100644
--- a/drivers/regulator/mc13892-regulator.c
+++ b/drivers/regulator/mc13892-regulator.c
@@ -18,6 +18,7 @@
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/err.h> 20#include <linux/err.h>
21#include <linux/module.h>
21#include "mc13xxx.h" 22#include "mc13xxx.h"
22 23
23#define MC13892_REVISION 7 24#define MC13892_REVISION 7
diff --git a/drivers/regulator/mc13xxx-regulator-core.c b/drivers/regulator/mc13xxx-regulator-core.c
index bc27ab136378..6532853a6ef5 100644
--- a/drivers/regulator/mc13xxx-regulator-core.c
+++ b/drivers/regulator/mc13xxx-regulator-core.c
@@ -23,6 +23,7 @@
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/err.h> 25#include <linux/err.h>
26#include <linux/module.h>
26#include "mc13xxx.h" 27#include "mc13xxx.h"
27 28
28static int mc13xxx_regulator_enable(struct regulator_dev *rdev) 29static int mc13xxx_regulator_enable(struct regulator_dev *rdev)
diff --git a/drivers/regulator/tps6586x-regulator.c b/drivers/regulator/tps6586x-regulator.c
index dbcf09d5080c..14b9389dd52a 100644
--- a/drivers/regulator/tps6586x-regulator.c
+++ b/drivers/regulator/tps6586x-regulator.c
@@ -14,6 +14,7 @@
14 */ 14 */
15 15
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/module.h>
17#include <linux/init.h> 18#include <linux/init.h>
18#include <linux/err.h> 19#include <linux/err.h>
19#include <linux/slab.h> 20#include <linux/slab.h>
diff --git a/drivers/regulator/userspace-consumer.c b/drivers/regulator/userspace-consumer.c
index 9d5ba9357597..fc6655146999 100644
--- a/drivers/regulator/userspace-consumer.c
+++ b/drivers/regulator/userspace-consumer.c
@@ -18,6 +18,7 @@
18 18
19#include <linux/err.h> 19#include <linux/err.h>
20#include <linux/mutex.h> 20#include <linux/mutex.h>
21#include <linux/module.h>
21#include <linux/platform_device.h> 22#include <linux/platform_device.h>
22#include <linux/regulator/consumer.h> 23#include <linux/regulator/consumer.h>
23#include <linux/regulator/userspace-consumer.h> 24#include <linux/regulator/userspace-consumer.h>
diff --git a/drivers/regulator/virtual.c b/drivers/regulator/virtual.c
index 69e550f57638..858c1f861ba5 100644
--- a/drivers/regulator/virtual.c
+++ b/drivers/regulator/virtual.c
@@ -16,6 +16,7 @@
16#include <linux/platform_device.h> 16#include <linux/platform_device.h>
17#include <linux/regulator/consumer.h> 17#include <linux/regulator/consumer.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/module.h>
19 20
20struct virtual_consumer_data { 21struct virtual_consumer_data {
21 struct mutex lock; 22 struct mutex lock;
diff --git a/drivers/regulator/wm8400-regulator.c b/drivers/regulator/wm8400-regulator.c
index 0f12c70bebc9..71632ddc3781 100644
--- a/drivers/regulator/wm8400-regulator.c
+++ b/drivers/regulator/wm8400-regulator.c
@@ -15,6 +15,7 @@
15#include <linux/bug.h> 15#include <linux/bug.h>
16#include <linux/err.h> 16#include <linux/err.h>
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18#include <linux/module.h>
18#include <linux/regulator/driver.h> 19#include <linux/regulator/driver.h>
19#include <linux/mfd/wm8400-private.h> 20#include <linux/mfd/wm8400-private.h>
20 21
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 5a538fc1cc85..53eb4e55b289 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -8,7 +8,7 @@ config RTC_LIB
8menuconfig RTC_CLASS 8menuconfig RTC_CLASS
9 bool "Real Time Clock" 9 bool "Real Time Clock"
10 default n 10 default n
11 depends on !S390 11 depends on !S390 && !UML
12 select RTC_LIB 12 select RTC_LIB
13 help 13 help
14 Generic RTC class support. If you say yes here, you will 14 Generic RTC class support. If you say yes here, you will
diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index 01a7df5317c1..e8326f26fa2f 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -21,16 +21,13 @@
21#include "rtc-core.h" 21#include "rtc-core.h"
22 22
23 23
24static DEFINE_IDR(rtc_idr); 24static DEFINE_IDA(rtc_ida);
25static DEFINE_MUTEX(idr_lock);
26struct class *rtc_class; 25struct class *rtc_class;
27 26
28static void rtc_device_release(struct device *dev) 27static void rtc_device_release(struct device *dev)
29{ 28{
30 struct rtc_device *rtc = to_rtc_device(dev); 29 struct rtc_device *rtc = to_rtc_device(dev);
31 mutex_lock(&idr_lock); 30 ida_simple_remove(&rtc_ida, rtc->id);
32 idr_remove(&rtc_idr, rtc->id);
33 mutex_unlock(&idr_lock);
34 kfree(rtc); 31 kfree(rtc);
35} 32}
36 33
@@ -146,25 +143,16 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev,
146 struct rtc_wkalrm alrm; 143 struct rtc_wkalrm alrm;
147 int id, err; 144 int id, err;
148 145
149 if (idr_pre_get(&rtc_idr, GFP_KERNEL) == 0) { 146 id = ida_simple_get(&rtc_ida, 0, 0, GFP_KERNEL);
150 err = -ENOMEM; 147 if (id < 0) {
148 err = id;
151 goto exit; 149 goto exit;
152 } 150 }
153 151
154
155 mutex_lock(&idr_lock);
156 err = idr_get_new(&rtc_idr, NULL, &id);
157 mutex_unlock(&idr_lock);
158
159 if (err < 0)
160 goto exit;
161
162 id = id & MAX_ID_MASK;
163
164 rtc = kzalloc(sizeof(struct rtc_device), GFP_KERNEL); 152 rtc = kzalloc(sizeof(struct rtc_device), GFP_KERNEL);
165 if (rtc == NULL) { 153 if (rtc == NULL) {
166 err = -ENOMEM; 154 err = -ENOMEM;
167 goto exit_idr; 155 goto exit_ida;
168 } 156 }
169 157
170 rtc->id = id; 158 rtc->id = id;
@@ -222,10 +210,8 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev,
222exit_kfree: 210exit_kfree:
223 kfree(rtc); 211 kfree(rtc);
224 212
225exit_idr: 213exit_ida:
226 mutex_lock(&idr_lock); 214 ida_simple_remove(&rtc_ida, id);
227 idr_remove(&rtc_idr, id);
228 mutex_unlock(&idr_lock);
229 215
230exit: 216exit:
231 dev_err(dev, "rtc core: unable to register %s, err = %d\n", 217 dev_err(dev, "rtc core: unable to register %s, err = %d\n",
@@ -276,7 +262,7 @@ static void __exit rtc_exit(void)
276{ 262{
277 rtc_dev_exit(); 263 rtc_dev_exit();
278 class_destroy(rtc_class); 264 class_destroy(rtc_class);
279 idr_destroy(&rtc_idr); 265 ida_destroy(&rtc_ida);
280} 266}
281 267
282subsys_initcall(rtc_init); 268subsys_initcall(rtc_init);
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 44e91e598f8d..8e286259a007 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -13,6 +13,7 @@
13 13
14#include <linux/rtc.h> 14#include <linux/rtc.h>
15#include <linux/sched.h> 15#include <linux/sched.h>
16#include <linux/module.h>
16#include <linux/log2.h> 17#include <linux/log2.h>
17#include <linux/workqueue.h> 18#include <linux/workqueue.h>
18 19
diff --git a/drivers/rtc/rtc-dm355evm.c b/drivers/rtc/rtc-dm355evm.c
index 58d4e18530da..2322c43af201 100644
--- a/drivers/rtc/rtc-dm355evm.c
+++ b/drivers/rtc/rtc-dm355evm.c
@@ -14,6 +14,7 @@
14#include <linux/platform_device.h> 14#include <linux/platform_device.h>
15 15
16#include <linux/i2c/dm355evm_msp.h> 16#include <linux/i2c/dm355evm_msp.h>
17#include <linux/module.h>
17 18
18 19
19/* 20/*
diff --git a/drivers/rtc/rtc-ds1305.c b/drivers/rtc/rtc-ds1305.c
index 57fbcc149ba7..3a33b1fdbe0f 100644
--- a/drivers/rtc/rtc-ds1305.c
+++ b/drivers/rtc/rtc-ds1305.c
@@ -17,6 +17,7 @@
17 17
18#include <linux/spi/spi.h> 18#include <linux/spi/spi.h>
19#include <linux/spi/ds1305.h> 19#include <linux/spi/ds1305.h>
20#include <linux/module.h>
20 21
21 22
22/* 23/*
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index b2005b44e4f7..62b0763b7b9a 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -34,6 +34,7 @@ enum ds_type {
34 ds_1388, 34 ds_1388,
35 ds_3231, 35 ds_3231,
36 m41t00, 36 m41t00,
37 mcp7941x,
37 rx_8025, 38 rx_8025,
38 // rs5c372 too? different address... 39 // rs5c372 too? different address...
39}; 40};
@@ -43,6 +44,7 @@ enum ds_type {
43#define DS1307_REG_SECS 0x00 /* 00-59 */ 44#define DS1307_REG_SECS 0x00 /* 00-59 */
44# define DS1307_BIT_CH 0x80 45# define DS1307_BIT_CH 0x80
45# define DS1340_BIT_nEOSC 0x80 46# define DS1340_BIT_nEOSC 0x80
47# define MCP7941X_BIT_ST 0x80
46#define DS1307_REG_MIN 0x01 /* 00-59 */ 48#define DS1307_REG_MIN 0x01 /* 00-59 */
47#define DS1307_REG_HOUR 0x02 /* 00-23, or 1-12{am,pm} */ 49#define DS1307_REG_HOUR 0x02 /* 00-23, or 1-12{am,pm} */
48# define DS1307_BIT_12HR 0x40 /* in REG_HOUR */ 50# define DS1307_BIT_12HR 0x40 /* in REG_HOUR */
@@ -50,6 +52,7 @@ enum ds_type {
50# define DS1340_BIT_CENTURY_EN 0x80 /* in REG_HOUR */ 52# define DS1340_BIT_CENTURY_EN 0x80 /* in REG_HOUR */
51# define DS1340_BIT_CENTURY 0x40 /* in REG_HOUR */ 53# define DS1340_BIT_CENTURY 0x40 /* in REG_HOUR */
52#define DS1307_REG_WDAY 0x03 /* 01-07 */ 54#define DS1307_REG_WDAY 0x03 /* 01-07 */
55# define MCP7941X_BIT_VBATEN 0x08
53#define DS1307_REG_MDAY 0x04 /* 01-31 */ 56#define DS1307_REG_MDAY 0x04 /* 01-31 */
54#define DS1307_REG_MONTH 0x05 /* 01-12 */ 57#define DS1307_REG_MONTH 0x05 /* 01-12 */
55# define DS1337_BIT_CENTURY 0x80 /* in REG_MONTH */ 58# define DS1337_BIT_CENTURY 0x80 /* in REG_MONTH */
@@ -137,6 +140,8 @@ static const struct chip_desc chips[] = {
137}, 140},
138[m41t00] = { 141[m41t00] = {
139}, 142},
143[mcp7941x] = {
144},
140[rx_8025] = { 145[rx_8025] = {
141}, }; 146}, };
142 147
@@ -149,6 +154,7 @@ static const struct i2c_device_id ds1307_id[] = {
149 { "ds1340", ds_1340 }, 154 { "ds1340", ds_1340 },
150 { "ds3231", ds_3231 }, 155 { "ds3231", ds_3231 },
151 { "m41t00", m41t00 }, 156 { "m41t00", m41t00 },
157 { "mcp7941x", mcp7941x },
152 { "pt7c4338", ds_1307 }, 158 { "pt7c4338", ds_1307 },
153 { "rx8025", rx_8025 }, 159 { "rx8025", rx_8025 },
154 { } 160 { }
@@ -365,6 +371,10 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t)
365 buf[DS1307_REG_HOUR] |= DS1340_BIT_CENTURY_EN 371 buf[DS1307_REG_HOUR] |= DS1340_BIT_CENTURY_EN
366 | DS1340_BIT_CENTURY; 372 | DS1340_BIT_CENTURY;
367 break; 373 break;
374 case mcp7941x:
375 buf[DS1307_REG_SECS] |= MCP7941X_BIT_ST;
376 buf[DS1307_REG_WDAY] |= MCP7941X_BIT_VBATEN;
377 break;
368 default: 378 default:
369 break; 379 break;
370 } 380 }
@@ -809,6 +819,23 @@ read_rtc:
809 dev_warn(&client->dev, "SET TIME!\n"); 819 dev_warn(&client->dev, "SET TIME!\n");
810 } 820 }
811 break; 821 break;
822 case mcp7941x:
823 /* make sure that the backup battery is enabled */
824 if (!(ds1307->regs[DS1307_REG_WDAY] & MCP7941X_BIT_VBATEN)) {
825 i2c_smbus_write_byte_data(client, DS1307_REG_WDAY,
826 ds1307->regs[DS1307_REG_WDAY]
827 | MCP7941X_BIT_VBATEN);
828 }
829
830 /* clock halted? turn it on, so clock can tick. */
831 if (!(tmp & MCP7941X_BIT_ST)) {
832 i2c_smbus_write_byte_data(client, DS1307_REG_SECS,
833 MCP7941X_BIT_ST);
834 dev_warn(&client->dev, "SET TIME!\n");
835 goto read_rtc;
836 }
837
838 break;
812 case rx_8025: 839 case rx_8025:
813 case ds_1337: 840 case ds_1337:
814 case ds_1339: 841 case ds_1339:
diff --git a/drivers/rtc/rtc-ds1511.c b/drivers/rtc/rtc-ds1511.c
index 568ad30617e7..586c244a05d8 100644
--- a/drivers/rtc/rtc-ds1511.c
+++ b/drivers/rtc/rtc-ds1511.c
@@ -23,6 +23,7 @@
23#include <linux/rtc.h> 23#include <linux/rtc.h>
24#include <linux/platform_device.h> 24#include <linux/platform_device.h>
25#include <linux/io.h> 25#include <linux/io.h>
26#include <linux/module.h>
26 27
27#define DRV_VERSION "0.6" 28#define DRV_VERSION "0.6"
28 29
diff --git a/drivers/rtc/rtc-ds1553.c b/drivers/rtc/rtc-ds1553.c
index fee41b97c9e8..1350029044e6 100644
--- a/drivers/rtc/rtc-ds1553.c
+++ b/drivers/rtc/rtc-ds1553.c
@@ -18,6 +18,7 @@
18#include <linux/rtc.h> 18#include <linux/rtc.h>
19#include <linux/platform_device.h> 19#include <linux/platform_device.h>
20#include <linux/io.h> 20#include <linux/io.h>
21#include <linux/module.h>
21 22
22#define DRV_VERSION "0.3" 23#define DRV_VERSION "0.3"
23 24
diff --git a/drivers/rtc/rtc-ds1672.c b/drivers/rtc/rtc-ds1672.c
index 06dfb54f99b6..a319402a5447 100644
--- a/drivers/rtc/rtc-ds1672.c
+++ b/drivers/rtc/rtc-ds1672.c
@@ -11,6 +11,7 @@
11 11
12#include <linux/i2c.h> 12#include <linux/i2c.h>
13#include <linux/rtc.h> 13#include <linux/rtc.h>
14#include <linux/module.h>
14 15
15#define DRV_VERSION "0.4" 16#define DRV_VERSION "0.4"
16 17
diff --git a/drivers/rtc/rtc-ds1742.c b/drivers/rtc/rtc-ds1742.c
index d84a448dd754..e3e0f92b60f0 100644
--- a/drivers/rtc/rtc-ds1742.c
+++ b/drivers/rtc/rtc-ds1742.c
@@ -21,6 +21,7 @@
21#include <linux/rtc.h> 21#include <linux/rtc.h>
22#include <linux/platform_device.h> 22#include <linux/platform_device.h>
23#include <linux/io.h> 23#include <linux/io.h>
24#include <linux/module.h>
24 25
25#define DRV_VERSION "0.4" 26#define DRV_VERSION "0.4"
26 27
diff --git a/drivers/rtc/rtc-em3027.c b/drivers/rtc/rtc-em3027.c
index d8e1c2578553..8414dea5fb14 100644
--- a/drivers/rtc/rtc-em3027.c
+++ b/drivers/rtc/rtc-em3027.c
@@ -14,6 +14,7 @@
14#include <linux/i2c.h> 14#include <linux/i2c.h>
15#include <linux/rtc.h> 15#include <linux/rtc.h>
16#include <linux/bcd.h> 16#include <linux/bcd.h>
17#include <linux/module.h>
17 18
18/* Registers */ 19/* Registers */
19#define EM3027_REG_ON_OFF_CTRL 0x00 20#define EM3027_REG_ON_OFF_CTRL 0x00
diff --git a/drivers/rtc/rtc-isl12022.c b/drivers/rtc/rtc-isl12022.c
index ddbc797ea6cd..6186833973ee 100644
--- a/drivers/rtc/rtc-isl12022.c
+++ b/drivers/rtc/rtc-isl12022.c
@@ -15,6 +15,7 @@
15#include <linux/bcd.h> 15#include <linux/bcd.h>
16#include <linux/rtc.h> 16#include <linux/rtc.h>
17#include <linux/slab.h> 17#include <linux/slab.h>
18#include <linux/module.h>
18 19
19#define DRV_VERSION "0.1" 20#define DRV_VERSION "0.1"
20 21
diff --git a/drivers/rtc/rtc-mc13xxx.c b/drivers/rtc/rtc-mc13xxx.c
index a1a278bc340d..9d0c3b478d55 100644
--- a/drivers/rtc/rtc-mc13xxx.c
+++ b/drivers/rtc/rtc-mc13xxx.c
@@ -309,7 +309,7 @@ static irqreturn_t mc13xxx_rtc_reset_handler(int irq, void *dev)
309 return IRQ_HANDLED; 309 return IRQ_HANDLED;
310} 310}
311 311
312static int __devinit mc13xxx_rtc_probe(struct platform_device *pdev) 312static int __init mc13xxx_rtc_probe(struct platform_device *pdev)
313{ 313{
314 int ret; 314 int ret;
315 struct mc13xxx_rtc *priv; 315 struct mc13xxx_rtc *priv;
@@ -378,7 +378,7 @@ err_reset_irq_request:
378 return ret; 378 return ret;
379} 379}
380 380
381static int __devexit mc13xxx_rtc_remove(struct platform_device *pdev) 381static int __exit mc13xxx_rtc_remove(struct platform_device *pdev)
382{ 382{
383 struct mc13xxx_rtc *priv = platform_get_drvdata(pdev); 383 struct mc13xxx_rtc *priv = platform_get_drvdata(pdev);
384 384
@@ -410,7 +410,7 @@ const struct platform_device_id mc13xxx_rtc_idtable[] = {
410 410
411static struct platform_driver mc13xxx_rtc_driver = { 411static struct platform_driver mc13xxx_rtc_driver = {
412 .id_table = mc13xxx_rtc_idtable, 412 .id_table = mc13xxx_rtc_idtable,
413 .remove = __devexit_p(mc13xxx_rtc_remove), 413 .remove = __exit_p(mc13xxx_rtc_remove),
414 .driver = { 414 .driver = {
415 .name = DRIVER_NAME, 415 .name = DRIVER_NAME,
416 .owner = THIS_MODULE, 416 .owner = THIS_MODULE,
diff --git a/drivers/rtc/rtc-mv.c b/drivers/rtc/rtc-mv.c
index 60627a764514..768e2edb9678 100644
--- a/drivers/rtc/rtc-mv.c
+++ b/drivers/rtc/rtc-mv.c
@@ -14,6 +14,7 @@
14#include <linux/platform_device.h> 14#include <linux/platform_device.h>
15#include <linux/delay.h> 15#include <linux/delay.h>
16#include <linux/gfp.h> 16#include <linux/gfp.h>
17#include <linux/module.h>
17 18
18 19
19#define RTC_TIME_REG_OFFS 0 20#define RTC_TIME_REG_OFFS 0
diff --git a/drivers/rtc/rtc-pcf2123.c b/drivers/rtc/rtc-pcf2123.c
index 71bab0ef5443..2ee3bbf7e5ea 100644
--- a/drivers/rtc/rtc-pcf2123.c
+++ b/drivers/rtc/rtc-pcf2123.c
@@ -42,6 +42,7 @@
42#include <linux/slab.h> 42#include <linux/slab.h>
43#include <linux/rtc.h> 43#include <linux/rtc.h>
44#include <linux/spi/spi.h> 44#include <linux/spi/spi.h>
45#include <linux/module.h>
45 46
46#define DRV_VERSION "0.6" 47#define DRV_VERSION "0.6"
47 48
diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c
index b42c0c679266..606fdfab34e2 100644
--- a/drivers/rtc/rtc-pcf8563.c
+++ b/drivers/rtc/rtc-pcf8563.c
@@ -18,6 +18,7 @@
18#include <linux/bcd.h> 18#include <linux/bcd.h>
19#include <linux/rtc.h> 19#include <linux/rtc.h>
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/module.h>
21 22
22#define DRV_VERSION "0.4.3" 23#define DRV_VERSION "0.4.3"
23 24
diff --git a/drivers/rtc/rtc-rs5c348.c b/drivers/rtc/rtc-rs5c348.c
index 368d0e63cf83..971bc8e08da6 100644
--- a/drivers/rtc/rtc-rs5c348.c
+++ b/drivers/rtc/rtc-rs5c348.c
@@ -23,6 +23,7 @@
23#include <linux/rtc.h> 23#include <linux/rtc.h>
24#include <linux/workqueue.h> 24#include <linux/workqueue.h>
25#include <linux/spi/spi.h> 25#include <linux/spi/spi.h>
26#include <linux/module.h>
26 27
27#define DRV_VERSION "0.2" 28#define DRV_VERSION "0.2"
28 29
diff --git a/drivers/rtc/rtc-rs5c372.c b/drivers/rtc/rtc-rs5c372.c
index 85c1b848dd72..d29f5432c6e8 100644
--- a/drivers/rtc/rtc-rs5c372.c
+++ b/drivers/rtc/rtc-rs5c372.c
@@ -14,6 +14,7 @@
14#include <linux/rtc.h> 14#include <linux/rtc.h>
15#include <linux/bcd.h> 15#include <linux/bcd.h>
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <linux/module.h>
17 18
18#define DRV_VERSION "0.6" 19#define DRV_VERSION "0.6"
19 20
diff --git a/drivers/rtc/rtc-stk17ta8.c b/drivers/rtc/rtc-stk17ta8.c
index 3b943673cd3e..ed3e9b599031 100644
--- a/drivers/rtc/rtc-stk17ta8.c
+++ b/drivers/rtc/rtc-stk17ta8.c
@@ -21,6 +21,7 @@
21#include <linux/rtc.h> 21#include <linux/rtc.h>
22#include <linux/platform_device.h> 22#include <linux/platform_device.h>
23#include <linux/io.h> 23#include <linux/io.h>
24#include <linux/module.h>
24 25
25#define DRV_VERSION "0.1" 26#define DRV_VERSION "0.1"
26 27
diff --git a/drivers/rtc/rtc-tx4939.c b/drivers/rtc/rtc-tx4939.c
index ec6313d15359..aac0ffed4345 100644
--- a/drivers/rtc/rtc-tx4939.c
+++ b/drivers/rtc/rtc-tx4939.c
@@ -11,6 +11,7 @@
11#include <linux/rtc.h> 11#include <linux/rtc.h>
12#include <linux/platform_device.h> 12#include <linux/platform_device.h>
13#include <linux/interrupt.h> 13#include <linux/interrupt.h>
14#include <linux/module.h>
14#include <linux/io.h> 15#include <linux/io.h>
15#include <linux/gfp.h> 16#include <linux/gfp.h>
16#include <asm/txx9/tx4939.h> 17#include <asm/txx9/tx4939.h>
diff --git a/drivers/rtc/rtc-x1205.c b/drivers/rtc/rtc-x1205.c
index b00aad2620d4..8c051d3179db 100644
--- a/drivers/rtc/rtc-x1205.c
+++ b/drivers/rtc/rtc-x1205.c
@@ -21,6 +21,7 @@
21#include <linux/bcd.h> 21#include <linux/bcd.h>
22#include <linux/rtc.h> 22#include <linux/rtc.h>
23#include <linux/delay.h> 23#include <linux/delay.h>
24#include <linux/module.h>
24 25
25#define DRV_VERSION "1.0.8" 26#define DRV_VERSION "1.0.8"
26 27
diff --git a/drivers/s390/block/dcssblk.c b/drivers/s390/block/dcssblk.c
index 9b43ae94beba..a5a55da2a1ac 100644
--- a/drivers/s390/block/dcssblk.c
+++ b/drivers/s390/block/dcssblk.c
@@ -27,7 +27,7 @@
27 27
28static int dcssblk_open(struct block_device *bdev, fmode_t mode); 28static int dcssblk_open(struct block_device *bdev, fmode_t mode);
29static int dcssblk_release(struct gendisk *disk, fmode_t mode); 29static int dcssblk_release(struct gendisk *disk, fmode_t mode);
30static int dcssblk_make_request(struct request_queue *q, struct bio *bio); 30static void dcssblk_make_request(struct request_queue *q, struct bio *bio);
31static int dcssblk_direct_access(struct block_device *bdev, sector_t secnum, 31static int dcssblk_direct_access(struct block_device *bdev, sector_t secnum,
32 void **kaddr, unsigned long *pfn); 32 void **kaddr, unsigned long *pfn);
33 33
@@ -814,7 +814,7 @@ out:
814 return rc; 814 return rc;
815} 815}
816 816
817static int 817static void
818dcssblk_make_request(struct request_queue *q, struct bio *bio) 818dcssblk_make_request(struct request_queue *q, struct bio *bio)
819{ 819{
820 struct dcssblk_dev_info *dev_info; 820 struct dcssblk_dev_info *dev_info;
@@ -871,10 +871,9 @@ dcssblk_make_request(struct request_queue *q, struct bio *bio)
871 bytes_done += bvec->bv_len; 871 bytes_done += bvec->bv_len;
872 } 872 }
873 bio_endio(bio, 0); 873 bio_endio(bio, 0);
874 return 0; 874 return;
875fail: 875fail:
876 bio_io_error(bio); 876 bio_io_error(bio);
877 return 0;
878} 877}
879 878
880static int 879static int
diff --git a/drivers/s390/block/xpram.c b/drivers/s390/block/xpram.c
index 1f6a4d894e73..98f3e4ade924 100644
--- a/drivers/s390/block/xpram.c
+++ b/drivers/s390/block/xpram.c
@@ -181,7 +181,7 @@ static unsigned long xpram_highest_page_index(void)
181/* 181/*
182 * Block device make request function. 182 * Block device make request function.
183 */ 183 */
184static int xpram_make_request(struct request_queue *q, struct bio *bio) 184static void xpram_make_request(struct request_queue *q, struct bio *bio)
185{ 185{
186 xpram_device_t *xdev = bio->bi_bdev->bd_disk->private_data; 186 xpram_device_t *xdev = bio->bi_bdev->bd_disk->private_data;
187 struct bio_vec *bvec; 187 struct bio_vec *bvec;
@@ -221,10 +221,9 @@ static int xpram_make_request(struct request_queue *q, struct bio *bio)
221 } 221 }
222 set_bit(BIO_UPTODATE, &bio->bi_flags); 222 set_bit(BIO_UPTODATE, &bio->bi_flags);
223 bio_endio(bio, 0); 223 bio_endio(bio, 0);
224 return 0; 224 return;
225fail: 225fail:
226 bio_io_error(bio); 226 bio_io_error(bio);
227 return 0;
228} 227}
229 228
230static int xpram_getgeo(struct block_device *bdev, struct hd_geometry *geo) 229static int xpram_getgeo(struct block_device *bdev, struct hd_geometry *geo)
diff --git a/drivers/s390/char/fs3270.c b/drivers/s390/char/fs3270.c
index f6489eb7e976..e71298158f9e 100644
--- a/drivers/s390/char/fs3270.c
+++ b/drivers/s390/char/fs3270.c
@@ -11,6 +11,7 @@
11#include <linux/console.h> 11#include <linux/console.h>
12#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/interrupt.h> 13#include <linux/interrupt.h>
14#include <linux/module.h>
14#include <linux/list.h> 15#include <linux/list.h>
15#include <linux/slab.h> 16#include <linux/slab.h>
16#include <linux/types.h> 17#include <linux/types.h>
diff --git a/drivers/s390/char/sclp_cpi_sys.c b/drivers/s390/char/sclp_cpi_sys.c
index 4a51e3f09689..bd1b9c919051 100644
--- a/drivers/s390/char/sclp_cpi_sys.c
+++ b/drivers/s390/char/sclp_cpi_sys.c
@@ -21,6 +21,7 @@
21#include <linux/err.h> 21#include <linux/err.h>
22#include <linux/slab.h> 22#include <linux/slab.h>
23#include <linux/completion.h> 23#include <linux/completion.h>
24#include <linux/export.h>
24#include <asm/ebcdic.h> 25#include <asm/ebcdic.h>
25#include <asm/sclp.h> 26#include <asm/sclp.h>
26 27
diff --git a/drivers/s390/char/vmcp.c b/drivers/s390/char/vmcp.c
index 31a3ccbb6495..75bde6a8b7dc 100644
--- a/drivers/s390/char/vmcp.c
+++ b/drivers/s390/char/vmcp.c
@@ -16,6 +16,7 @@
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/miscdevice.h> 17#include <linux/miscdevice.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/export.h>
19#include <asm/compat.h> 20#include <asm/compat.h>
20#include <asm/cpcmd.h> 21#include <asm/cpcmd.h>
21#include <asm/debug.h> 22#include <asm/debug.h>
diff --git a/drivers/s390/char/vmur.c b/drivers/s390/char/vmur.c
index d291a54acfad..85f4a9a5d12e 100644
--- a/drivers/s390/char/vmur.c
+++ b/drivers/s390/char/vmur.c
@@ -13,6 +13,7 @@
13 13
14#include <linux/cdev.h> 14#include <linux/cdev.h>
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/module.h>
16 17
17#include <asm/uaccess.h> 18#include <asm/uaccess.h>
18#include <asm/cio.h> 19#include <asm/cio.h>
diff --git a/drivers/s390/cio/chp.c b/drivers/s390/cio/chp.c
index 2d32233943a9..e792436c9270 100644
--- a/drivers/s390/cio/chp.c
+++ b/drivers/s390/cio/chp.c
@@ -10,6 +10,8 @@
10#include <linux/bug.h> 10#include <linux/bug.h>
11#include <linux/workqueue.h> 11#include <linux/workqueue.h>
12#include <linux/spinlock.h> 12#include <linux/spinlock.h>
13#include <linux/export.h>
14#include <linux/sched.h>
13#include <linux/init.h> 15#include <linux/init.h>
14#include <linux/jiffies.h> 16#include <linux/jiffies.h>
15#include <linux/wait.h> 17#include <linux/wait.h>
diff --git a/drivers/s390/cio/qdio_debug.c b/drivers/s390/cio/qdio_debug.c
index ed68245f9741..29021f4e96b6 100644
--- a/drivers/s390/cio/qdio_debug.c
+++ b/drivers/s390/cio/qdio_debug.c
@@ -7,6 +7,8 @@
7 */ 7 */
8#include <linux/seq_file.h> 8#include <linux/seq_file.h>
9#include <linux/debugfs.h> 9#include <linux/debugfs.h>
10#include <linux/uaccess.h>
11#include <linux/export.h>
10#include <asm/debug.h> 12#include <asm/debug.h>
11#include "qdio_debug.h" 13#include "qdio_debug.h"
12#include "qdio.h" 14#include "qdio.h"
diff --git a/drivers/s390/cio/qdio_setup.c b/drivers/s390/cio/qdio_setup.c
index d9a46a429bcc..2acc01f90a6a 100644
--- a/drivers/s390/cio/qdio_setup.c
+++ b/drivers/s390/cio/qdio_setup.c
@@ -8,6 +8,7 @@
8 */ 8 */
9#include <linux/kernel.h> 9#include <linux/kernel.h>
10#include <linux/slab.h> 10#include <linux/slab.h>
11#include <linux/export.h>
11#include <asm/qdio.h> 12#include <asm/qdio.h>
12 13
13#include "cio.h" 14#include "cio.h"
diff --git a/drivers/s390/kvm/kvm_virtio.c b/drivers/s390/kvm/kvm_virtio.c
index 3c2c923d5c0a..94f49ffa70ba 100644
--- a/drivers/s390/kvm/kvm_virtio.c
+++ b/drivers/s390/kvm/kvm_virtio.c
@@ -20,6 +20,7 @@
20#include <linux/virtio_console.h> 20#include <linux/virtio_console.h>
21#include <linux/interrupt.h> 21#include <linux/interrupt.h>
22#include <linux/virtio_ring.h> 22#include <linux/virtio_ring.h>
23#include <linux/export.h>
23#include <linux/pfn.h> 24#include <linux/pfn.h>
24#include <asm/io.h> 25#include <asm/io.h>
25#include <asm/kvm_para.h> 26#include <asm/kvm_para.h>
diff --git a/drivers/s390/scsi/zfcp_aux.c b/drivers/s390/scsi/zfcp_aux.c
index 645b0fcbb370..086018109662 100644
--- a/drivers/s390/scsi/zfcp_aux.c
+++ b/drivers/s390/scsi/zfcp_aux.c
@@ -31,6 +31,7 @@
31#include <linux/miscdevice.h> 31#include <linux/miscdevice.h>
32#include <linux/seq_file.h> 32#include <linux/seq_file.h>
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include <linux/module.h>
34#include "zfcp_ext.h" 35#include "zfcp_ext.h"
35#include "zfcp_fc.h" 36#include "zfcp_fc.h"
36#include "zfcp_reqlist.h" 37#include "zfcp_reqlist.h"
diff --git a/drivers/s390/scsi/zfcp_ccw.c b/drivers/s390/scsi/zfcp_ccw.c
index e8b7cee62046..96f13ad88123 100644
--- a/drivers/s390/scsi/zfcp_ccw.c
+++ b/drivers/s390/scsi/zfcp_ccw.c
@@ -9,6 +9,7 @@
9#define KMSG_COMPONENT "zfcp" 9#define KMSG_COMPONENT "zfcp"
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt 10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11 11
12#include <linux/module.h>
12#include "zfcp_ext.h" 13#include "zfcp_ext.h"
13#include "zfcp_reqlist.h" 14#include "zfcp_reqlist.h"
14 15
diff --git a/drivers/s390/scsi/zfcp_dbf.c b/drivers/s390/scsi/zfcp_dbf.c
index 967e7b70e977..a9a816e4aa55 100644
--- a/drivers/s390/scsi/zfcp_dbf.c
+++ b/drivers/s390/scsi/zfcp_dbf.c
@@ -9,6 +9,7 @@
9#define KMSG_COMPONENT "zfcp" 9#define KMSG_COMPONENT "zfcp"
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt 10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11 11
12#include <linux/module.h>
12#include <linux/ctype.h> 13#include <linux/ctype.h>
13#include <linux/slab.h> 14#include <linux/slab.h>
14#include <asm/debug.h> 15#include <asm/debug.h>
diff --git a/drivers/s390/scsi/zfcp_qdio.c b/drivers/s390/scsi/zfcp_qdio.c
index df9e69f54742..e14da5751d32 100644
--- a/drivers/s390/scsi/zfcp_qdio.c
+++ b/drivers/s390/scsi/zfcp_qdio.c
@@ -10,6 +10,7 @@
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt 10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11 11
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/module.h>
13#include "zfcp_ext.h" 14#include "zfcp_ext.h"
14#include "zfcp_qdio.h" 15#include "zfcp_qdio.h"
15 16
diff --git a/drivers/s390/scsi/zfcp_scsi.c b/drivers/s390/scsi/zfcp_scsi.c
index 09126a9d62ff..11f07f888223 100644
--- a/drivers/s390/scsi/zfcp_scsi.c
+++ b/drivers/s390/scsi/zfcp_scsi.c
@@ -9,6 +9,7 @@
9#define KMSG_COMPONENT "zfcp" 9#define KMSG_COMPONENT "zfcp"
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt 10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11 11
12#include <linux/module.h>
12#include <linux/types.h> 13#include <linux/types.h>
13#include <linux/slab.h> 14#include <linux/slab.h>
14#include <scsi/fc/fc_fcp.h> 15#include <scsi/fc/fc_fcp.h>
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index aa573c39f596..06ea3bcfdd2a 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -617,20 +617,6 @@ config SCSI_ARCMSR
617 To compile this driver as a module, choose M here: the 617 To compile this driver as a module, choose M here: the
618 module will be called arcmsr (modprobe arcmsr). 618 module will be called arcmsr (modprobe arcmsr).
619 619
620config SCSI_ARCMSR_AER
621 bool "Enable PCI Error Recovery Capability in Areca Driver(ARCMSR)"
622 depends on SCSI_ARCMSR && PCIEAER
623 default n
624 help
625 The advanced error reporting(AER) capability is "NOT" provided by
626 ARC1200/1201/1202 SATA RAID controllers cards.
627 If your card is one of ARC1200/1201/1202, please use the default setting, n.
628 If your card is other models, you could pick it
629 on condition that the kernel version is greater than 2.6.19.
630 This function is maintained driver by Nick Cheng. If you have any
631 problems or suggestion, you are welcome to contact with <nick.cheng@areca.com.tw>.
632 To enable this function, choose Y here.
633
634source "drivers/scsi/megaraid/Kconfig.megaraid" 620source "drivers/scsi/megaraid/Kconfig.megaraid"
635source "drivers/scsi/mpt2sas/Kconfig" 621source "drivers/scsi/mpt2sas/Kconfig"
636 622
diff --git a/drivers/scsi/a2091.c b/drivers/scsi/a2091.c
index 1bb5d3f0e260..79a30633d4aa 100644
--- a/drivers/scsi/a2091.c
+++ b/drivers/scsi/a2091.c
@@ -5,6 +5,7 @@
5#include <linux/slab.h> 5#include <linux/slab.h>
6#include <linux/spinlock.h> 6#include <linux/spinlock.h>
7#include <linux/zorro.h> 7#include <linux/zorro.h>
8#include <linux/module.h>
8 9
9#include <asm/page.h> 10#include <asm/page.h>
10#include <asm/pgtable.h> 11#include <asm/pgtable.h>
diff --git a/drivers/scsi/a3000.c b/drivers/scsi/a3000.c
index d9468027fb61..e29fe0e708f8 100644
--- a/drivers/scsi/a3000.c
+++ b/drivers/scsi/a3000.c
@@ -6,6 +6,7 @@
6#include <linux/spinlock.h> 6#include <linux/spinlock.h>
7#include <linux/interrupt.h> 7#include <linux/interrupt.h>
8#include <linux/platform_device.h> 8#include <linux/platform_device.h>
9#include <linux/module.h>
9 10
10#include <asm/page.h> 11#include <asm/page.h>
11#include <asm/pgtable.h> 12#include <asm/pgtable.h>
diff --git a/drivers/scsi/aacraid/aachba.c b/drivers/scsi/aacraid/aachba.c
index 061995741444..409f5805bdd6 100644
--- a/drivers/scsi/aacraid/aachba.c
+++ b/drivers/scsi/aacraid/aachba.c
@@ -34,6 +34,7 @@
34#include <linux/blkdev.h> 34#include <linux/blkdev.h>
35#include <asm/uaccess.h> 35#include <asm/uaccess.h>
36#include <linux/highmem.h> /* For flush_kernel_dcache_page */ 36#include <linux/highmem.h> /* For flush_kernel_dcache_page */
37#include <linux/module.h>
37 38
38#include <scsi/scsi.h> 39#include <scsi/scsi.h>
39#include <scsi/scsi_cmnd.h> 40#include <scsi/scsi_cmnd.h>
diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_main.c
index 7b0a8ab71049..379c696dac19 100644
--- a/drivers/scsi/be2iscsi/be_main.c
+++ b/drivers/scsi/be2iscsi/be_main.c
@@ -27,6 +27,7 @@
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#include <linux/iscsi_boot_sysfs.h>
30#include <linux/module.h>
30 31
31#include <scsi/libiscsi.h> 32#include <scsi/libiscsi.h>
32#include <scsi/scsi_transport_iscsi.h> 33#include <scsi/scsi_transport_iscsi.h>
diff --git a/drivers/scsi/bfa/bfad_debugfs.c b/drivers/scsi/bfa/bfad_debugfs.c
index b412e0300dd4..dee1a094c2c2 100644
--- a/drivers/scsi/bfa/bfad_debugfs.c
+++ b/drivers/scsi/bfa/bfad_debugfs.c
@@ -16,6 +16,7 @@
16 */ 16 */
17 17
18#include <linux/debugfs.h> 18#include <linux/debugfs.h>
19#include <linux/export.h>
19 20
20#include "bfad_drv.h" 21#include "bfad_drv.h"
21#include "bfad_im.h" 22#include "bfad_im.h"
diff --git a/drivers/scsi/bfa/bfad_im.c b/drivers/scsi/bfa/bfad_im.c
index 01312381639f..e5db649e8eb7 100644
--- a/drivers/scsi/bfa/bfad_im.c
+++ b/drivers/scsi/bfa/bfad_im.c
@@ -19,6 +19,8 @@
19 * bfad_im.c Linux driver IM module. 19 * bfad_im.c Linux driver IM module.
20 */ 20 */
21 21
22#include <linux/export.h>
23
22#include "bfad_drv.h" 24#include "bfad_drv.h"
23#include "bfad_im.h" 25#include "bfad_im.h"
24#include "bfa_fcs.h" 26#include "bfa_fcs.h"
diff --git a/drivers/scsi/bnx2fc/bnx2fc.h b/drivers/scsi/bnx2fc/bnx2fc.h
index 63de1c7cd0cb..049ea907e04a 100644
--- a/drivers/scsi/bnx2fc/bnx2fc.h
+++ b/drivers/scsi/bnx2fc/bnx2fc.h
@@ -62,7 +62,7 @@
62#include "bnx2fc_constants.h" 62#include "bnx2fc_constants.h"
63 63
64#define BNX2FC_NAME "bnx2fc" 64#define BNX2FC_NAME "bnx2fc"
65#define BNX2FC_VERSION "1.0.8" 65#define BNX2FC_VERSION "1.0.9"
66 66
67#define PFX "bnx2fc: " 67#define PFX "bnx2fc: "
68 68
@@ -145,6 +145,9 @@
145#define REC_RETRY_COUNT 1 145#define REC_RETRY_COUNT 1
146#define BNX2FC_NUM_ERR_BITS 63 146#define BNX2FC_NUM_ERR_BITS 63
147 147
148#define BNX2FC_RELOGIN_WAIT_TIME 200
149#define BNX2FC_RELOGIN_WAIT_CNT 10
150
148/* bnx2fc driver uses only one instance of fcoe_percpu_s */ 151/* bnx2fc driver uses only one instance of fcoe_percpu_s */
149extern struct fcoe_percpu_s bnx2fc_global; 152extern struct fcoe_percpu_s bnx2fc_global;
150 153
diff --git a/drivers/scsi/bnx2fc/bnx2fc_els.c b/drivers/scsi/bnx2fc/bnx2fc_els.c
index fd382fe33f6e..ce0ce3e32f33 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_els.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_els.c
@@ -268,17 +268,6 @@ void bnx2fc_srr_compl(struct bnx2fc_els_cb_arg *cb_arg)
268 268
269 orig_io_req = cb_arg->aborted_io_req; 269 orig_io_req = cb_arg->aborted_io_req;
270 srr_req = cb_arg->io_req; 270 srr_req = cb_arg->io_req;
271 if (test_bit(BNX2FC_FLAG_IO_COMPL, &orig_io_req->req_flags)) {
272 BNX2FC_IO_DBG(srr_req, "srr_compl: xid - 0x%x completed",
273 orig_io_req->xid);
274 goto srr_compl_done;
275 }
276 if (test_bit(BNX2FC_FLAG_ISSUE_ABTS, &orig_io_req->req_flags)) {
277 BNX2FC_IO_DBG(srr_req, "rec abts in prog "
278 "orig_io - 0x%x\n",
279 orig_io_req->xid);
280 goto srr_compl_done;
281 }
282 if (test_and_clear_bit(BNX2FC_FLAG_ELS_TIMEOUT, &srr_req->req_flags)) { 271 if (test_and_clear_bit(BNX2FC_FLAG_ELS_TIMEOUT, &srr_req->req_flags)) {
283 /* SRR timedout */ 272 /* SRR timedout */
284 BNX2FC_IO_DBG(srr_req, "srr timed out, abort " 273 BNX2FC_IO_DBG(srr_req, "srr timed out, abort "
@@ -290,6 +279,12 @@ void bnx2fc_srr_compl(struct bnx2fc_els_cb_arg *cb_arg)
290 "failed. issue cleanup\n"); 279 "failed. issue cleanup\n");
291 bnx2fc_initiate_cleanup(srr_req); 280 bnx2fc_initiate_cleanup(srr_req);
292 } 281 }
282 if (test_bit(BNX2FC_FLAG_IO_COMPL, &orig_io_req->req_flags) ||
283 test_bit(BNX2FC_FLAG_ISSUE_ABTS, &orig_io_req->req_flags)) {
284 BNX2FC_IO_DBG(srr_req, "srr_compl:xid 0x%x flags = %lx",
285 orig_io_req->xid, orig_io_req->req_flags);
286 goto srr_compl_done;
287 }
293 orig_io_req->srr_retry++; 288 orig_io_req->srr_retry++;
294 if (orig_io_req->srr_retry <= SRR_RETRY_COUNT) { 289 if (orig_io_req->srr_retry <= SRR_RETRY_COUNT) {
295 struct bnx2fc_rport *tgt = orig_io_req->tgt; 290 struct bnx2fc_rport *tgt = orig_io_req->tgt;
@@ -311,6 +306,12 @@ void bnx2fc_srr_compl(struct bnx2fc_els_cb_arg *cb_arg)
311 } 306 }
312 goto srr_compl_done; 307 goto srr_compl_done;
313 } 308 }
309 if (test_bit(BNX2FC_FLAG_IO_COMPL, &orig_io_req->req_flags) ||
310 test_bit(BNX2FC_FLAG_ISSUE_ABTS, &orig_io_req->req_flags)) {
311 BNX2FC_IO_DBG(srr_req, "srr_compl:xid - 0x%x flags = %lx",
312 orig_io_req->xid, orig_io_req->req_flags);
313 goto srr_compl_done;
314 }
314 mp_req = &(srr_req->mp_req); 315 mp_req = &(srr_req->mp_req);
315 fc_hdr = &(mp_req->resp_fc_hdr); 316 fc_hdr = &(mp_req->resp_fc_hdr);
316 resp_len = mp_req->resp_len; 317 resp_len = mp_req->resp_len;
diff --git a/drivers/scsi/bnx2fc/bnx2fc_fcoe.c b/drivers/scsi/bnx2fc/bnx2fc_fcoe.c
index 85bcc4b55965..8c6156a10d90 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_fcoe.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_fcoe.c
@@ -22,7 +22,7 @@ DEFINE_PER_CPU(struct bnx2fc_percpu_s, bnx2fc_percpu);
22 22
23#define DRV_MODULE_NAME "bnx2fc" 23#define DRV_MODULE_NAME "bnx2fc"
24#define DRV_MODULE_VERSION BNX2FC_VERSION 24#define DRV_MODULE_VERSION BNX2FC_VERSION
25#define DRV_MODULE_RELDATE "Oct 02, 2011" 25#define DRV_MODULE_RELDATE "Oct 21, 2011"
26 26
27 27
28static char version[] __devinitdata = 28static char version[] __devinitdata =
diff --git a/drivers/scsi/bnx2fc/bnx2fc_io.c b/drivers/scsi/bnx2fc/bnx2fc_io.c
index 0c64d184d731..84a78af83f90 100644
--- a/drivers/scsi/bnx2fc/bnx2fc_io.c
+++ b/drivers/scsi/bnx2fc/bnx2fc_io.c
@@ -1103,7 +1103,10 @@ int bnx2fc_eh_abort(struct scsi_cmnd *sc_cmd)
1103 struct fc_rport_libfc_priv *rp = rport->dd_data; 1103 struct fc_rport_libfc_priv *rp = rport->dd_data;
1104 struct bnx2fc_cmd *io_req; 1104 struct bnx2fc_cmd *io_req;
1105 struct fc_lport *lport; 1105 struct fc_lport *lport;
1106 struct fc_rport_priv *rdata;
1106 struct bnx2fc_rport *tgt; 1107 struct bnx2fc_rport *tgt;
1108 int logo_issued;
1109 int wait_cnt = 0;
1107 int rc = FAILED; 1110 int rc = FAILED;
1108 1111
1109 1112
@@ -1192,8 +1195,40 @@ int bnx2fc_eh_abort(struct scsi_cmnd *sc_cmd)
1192 } else { 1195 } else {
1193 printk(KERN_ERR PFX "eh_abort: io_req (xid = 0x%x) " 1196 printk(KERN_ERR PFX "eh_abort: io_req (xid = 0x%x) "
1194 "already in abts processing\n", io_req->xid); 1197 "already in abts processing\n", io_req->xid);
1198 if (cancel_delayed_work(&io_req->timeout_work))
1199 kref_put(&io_req->refcount,
1200 bnx2fc_cmd_release); /* drop timer hold */
1201 bnx2fc_initiate_cleanup(io_req);
1202
1203 spin_unlock_bh(&tgt->tgt_lock);
1204
1205 wait_for_completion(&io_req->tm_done);
1206
1207 spin_lock_bh(&tgt->tgt_lock);
1208 io_req->wait_for_comp = 0;
1209 rdata = io_req->tgt->rdata;
1210 logo_issued = test_and_set_bit(BNX2FC_FLAG_EXPL_LOGO,
1211 &tgt->flags);
1195 kref_put(&io_req->refcount, bnx2fc_cmd_release); 1212 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1196 spin_unlock_bh(&tgt->tgt_lock); 1213 spin_unlock_bh(&tgt->tgt_lock);
1214
1215 if (!logo_issued) {
1216 BNX2FC_IO_DBG(io_req, "Expl logo - tgt flags = 0x%lx\n",
1217 tgt->flags);
1218 mutex_lock(&lport->disc.disc_mutex);
1219 lport->tt.rport_logoff(rdata);
1220 mutex_unlock(&lport->disc.disc_mutex);
1221 do {
1222 msleep(BNX2FC_RELOGIN_WAIT_TIME);
1223 /*
1224 * If session not recovered, let SCSI-ml
1225 * escalate error recovery.
1226 */
1227 if (wait_cnt++ > BNX2FC_RELOGIN_WAIT_CNT)
1228 return FAILED;
1229 } while (!test_bit(BNX2FC_FLAG_SESSION_READY,
1230 &tgt->flags));
1231 }
1197 return SUCCESS; 1232 return SUCCESS;
1198 } 1233 }
1199 if (rc == FAILED) { 1234 if (rc == FAILED) {
@@ -1275,6 +1310,8 @@ void bnx2fc_process_cleanup_compl(struct bnx2fc_cmd *io_req,
1275 io_req->refcount.refcount.counter, io_req->cmd_type); 1310 io_req->refcount.refcount.counter, io_req->cmd_type);
1276 bnx2fc_scsi_done(io_req, DID_ERROR); 1311 bnx2fc_scsi_done(io_req, DID_ERROR);
1277 kref_put(&io_req->refcount, bnx2fc_cmd_release); 1312 kref_put(&io_req->refcount, bnx2fc_cmd_release);
1313 if (io_req->wait_for_comp)
1314 complete(&io_req->tm_done);
1278} 1315}
1279 1316
1280void bnx2fc_process_abts_compl(struct bnx2fc_cmd *io_req, 1317void bnx2fc_process_abts_compl(struct bnx2fc_cmd *io_req,
diff --git a/drivers/scsi/cxgbi/libcxgbi.c b/drivers/scsi/cxgbi/libcxgbi.c
index c363a4b260fd..c10f74a566f2 100644
--- a/drivers/scsi/cxgbi/libcxgbi.c
+++ b/drivers/scsi/cxgbi/libcxgbi.c
@@ -25,6 +25,7 @@
25#include <net/dst.h> 25#include <net/dst.h>
26#include <net/route.h> 26#include <net/route.h>
27#include <linux/inetdevice.h> /* ip_dev_find */ 27#include <linux/inetdevice.h> /* ip_dev_find */
28#include <linux/module.h>
28#include <net/tcp.h> 29#include <net/tcp.h>
29 30
30static unsigned int dbg_level; 31static unsigned int dbg_level;
diff --git a/drivers/scsi/device_handler/scsi_dh.c b/drivers/scsi/device_handler/scsi_dh.c
index 7c05fd9dccfd..23149b9e297c 100644
--- a/drivers/scsi/device_handler/scsi_dh.c
+++ b/drivers/scsi/device_handler/scsi_dh.c
@@ -22,6 +22,7 @@
22 */ 22 */
23 23
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/module.h>
25#include <scsi/scsi_dh.h> 26#include <scsi/scsi_dh.h>
26#include "../scsi_priv.h" 27#include "../scsi_priv.h"
27 28
@@ -441,7 +442,15 @@ int scsi_dh_activate(struct request_queue *q, activate_complete fn, void *data)
441 442
442 spin_lock_irqsave(q->queue_lock, flags); 443 spin_lock_irqsave(q->queue_lock, flags);
443 sdev = q->queuedata; 444 sdev = q->queuedata;
444 if (sdev && sdev->scsi_dh_data) 445 if (!sdev) {
446 spin_unlock_irqrestore(q->queue_lock, flags);
447 err = SCSI_DH_NOSYS;
448 if (fn)
449 fn(data, err);
450 return err;
451 }
452
453 if (sdev->scsi_dh_data)
445 scsi_dh = sdev->scsi_dh_data->scsi_dh; 454 scsi_dh = sdev->scsi_dh_data->scsi_dh;
446 dev = get_device(&sdev->sdev_gendev); 455 dev = get_device(&sdev->sdev_gendev);
447 if (!scsi_dh || !dev || 456 if (!scsi_dh || !dev ||
diff --git a/drivers/scsi/device_handler/scsi_dh_alua.c b/drivers/scsi/device_handler/scsi_dh_alua.c
index 627f4b5e5176..4ef021291a4d 100644
--- a/drivers/scsi/device_handler/scsi_dh_alua.c
+++ b/drivers/scsi/device_handler/scsi_dh_alua.c
@@ -21,6 +21,7 @@
21 */ 21 */
22#include <linux/slab.h> 22#include <linux/slab.h>
23#include <linux/delay.h> 23#include <linux/delay.h>
24#include <linux/module.h>
24#include <scsi/scsi.h> 25#include <scsi/scsi.h>
25#include <scsi/scsi_eh.h> 26#include <scsi/scsi_eh.h>
26#include <scsi/scsi_dh.h> 27#include <scsi/scsi_dh.h>
@@ -507,7 +508,7 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_dh_data *h)
507 int len, k, off, valid_states = 0; 508 int len, k, off, valid_states = 0;
508 unsigned char *ucp; 509 unsigned char *ucp;
509 unsigned err; 510 unsigned err;
510 unsigned long expiry, interval = 1; 511 unsigned long expiry, interval = 1000;
511 512
512 expiry = round_jiffies_up(jiffies + ALUA_FAILOVER_TIMEOUT); 513 expiry = round_jiffies_up(jiffies + ALUA_FAILOVER_TIMEOUT);
513 retry: 514 retry:
@@ -734,6 +735,7 @@ static int alua_bus_attach(struct scsi_device *sdev)
734 spin_lock_irqsave(sdev->request_queue->queue_lock, flags); 735 spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
735 sdev->scsi_dh_data = scsi_dh_data; 736 sdev->scsi_dh_data = scsi_dh_data;
736 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags); 737 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
738 sdev_printk(KERN_NOTICE, sdev, "%s: Attached\n", ALUA_DH_NAME);
737 739
738 return 0; 740 return 0;
739 741
diff --git a/drivers/scsi/device_handler/scsi_dh_emc.c b/drivers/scsi/device_handler/scsi_dh_emc.c
index 48441f6908a4..591186cf1896 100644
--- a/drivers/scsi/device_handler/scsi_dh_emc.c
+++ b/drivers/scsi/device_handler/scsi_dh_emc.c
@@ -21,6 +21,7 @@
21 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 21 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 */ 22 */
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/module.h>
24#include <scsi/scsi.h> 25#include <scsi/scsi.h>
25#include <scsi/scsi_eh.h> 26#include <scsi/scsi_eh.h>
26#include <scsi/scsi_dh.h> 27#include <scsi/scsi_dh.h>
diff --git a/drivers/scsi/device_handler/scsi_dh_hp_sw.c b/drivers/scsi/device_handler/scsi_dh_hp_sw.c
index b479f1eef968..0f86a18b157d 100644
--- a/drivers/scsi/device_handler/scsi_dh_hp_sw.c
+++ b/drivers/scsi/device_handler/scsi_dh_hp_sw.c
@@ -22,6 +22,7 @@
22 */ 22 */
23 23
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/module.h>
25#include <scsi/scsi.h> 26#include <scsi/scsi.h>
26#include <scsi/scsi_dbg.h> 27#include <scsi/scsi_dbg.h>
27#include <scsi/scsi_eh.h> 28#include <scsi/scsi_eh.h>
diff --git a/drivers/scsi/device_handler/scsi_dh_rdac.c b/drivers/scsi/device_handler/scsi_dh_rdac.c
index 82d612f0c49d..1d3127920063 100644
--- a/drivers/scsi/device_handler/scsi_dh_rdac.c
+++ b/drivers/scsi/device_handler/scsi_dh_rdac.c
@@ -24,6 +24,7 @@
24#include <scsi/scsi_dh.h> 24#include <scsi/scsi_dh.h>
25#include <linux/workqueue.h> 25#include <linux/workqueue.h>
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/module.h>
27 28
28#define RDAC_NAME "rdac" 29#define RDAC_NAME "rdac"
29#define RDAC_RETRY_COUNT 5 30#define RDAC_RETRY_COUNT 5
diff --git a/drivers/scsi/fcoe/fcoe.c b/drivers/scsi/fcoe/fcoe.c
index 61384ee4049b..cefbe44bb84a 100644
--- a/drivers/scsi/fcoe/fcoe.c
+++ b/drivers/scsi/fcoe/fcoe.c
@@ -2347,14 +2347,11 @@ static void fcoe_flogi_resp(struct fc_seq *seq, struct fc_frame *fp, void *arg)
2347 goto done; 2347 goto done;
2348 2348
2349 mac = fr_cb(fp)->granted_mac; 2349 mac = fr_cb(fp)->granted_mac;
2350 if (is_zero_ether_addr(mac)) { 2350 /* pre-FIP */
2351 /* pre-FIP */ 2351 if (is_zero_ether_addr(mac))
2352 if (fcoe_ctlr_recv_flogi(fip, lport, fp)) { 2352 fcoe_ctlr_recv_flogi(fip, lport, fp);
2353 fc_frame_free(fp); 2353 if (!is_zero_ether_addr(mac))
2354 return; 2354 fcoe_update_src_mac(lport, mac);
2355 }
2356 }
2357 fcoe_update_src_mac(lport, mac);
2358done: 2355done:
2359 fc_lport_flogi_resp(seq, fp, lport); 2356 fc_lport_flogi_resp(seq, fp, lport);
2360} 2357}
diff --git a/drivers/scsi/gvp11.c b/drivers/scsi/gvp11.c
index 50bb54150a78..488fbc648656 100644
--- a/drivers/scsi/gvp11.c
+++ b/drivers/scsi/gvp11.c
@@ -5,6 +5,7 @@
5#include <linux/slab.h> 5#include <linux/slab.h>
6#include <linux/spinlock.h> 6#include <linux/spinlock.h>
7#include <linux/zorro.h> 7#include <linux/zorro.h>
8#include <linux/module.h>
8 9
9#include <asm/page.h> 10#include <asm/page.h>
10#include <asm/pgtable.h> 11#include <asm/pgtable.h>
diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
index 4f7a5829ea4c..351dc0b86fab 100644
--- a/drivers/scsi/hosts.c
+++ b/drivers/scsi/hosts.c
@@ -286,6 +286,7 @@ static void scsi_host_dev_release(struct device *dev)
286{ 286{
287 struct Scsi_Host *shost = dev_to_shost(dev); 287 struct Scsi_Host *shost = dev_to_shost(dev);
288 struct device *parent = dev->parent; 288 struct device *parent = dev->parent;
289 struct request_queue *q;
289 290
290 scsi_proc_hostdir_rm(shost->hostt); 291 scsi_proc_hostdir_rm(shost->hostt);
291 292
@@ -293,9 +294,11 @@ static void scsi_host_dev_release(struct device *dev)
293 kthread_stop(shost->ehandler); 294 kthread_stop(shost->ehandler);
294 if (shost->work_q) 295 if (shost->work_q)
295 destroy_workqueue(shost->work_q); 296 destroy_workqueue(shost->work_q);
296 if (shost->uspace_req_q) { 297 q = shost->uspace_req_q;
297 kfree(shost->uspace_req_q->queuedata); 298 if (q) {
298 scsi_free_queue(shost->uspace_req_q); 299 kfree(q->queuedata);
300 q->queuedata = NULL;
301 scsi_free_queue(q);
299 } 302 }
300 303
301 scsi_destroy_command_freelist(shost); 304 scsi_destroy_command_freelist(shost);
diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
index 9825ecf34957..e76107b2ade3 100644
--- a/drivers/scsi/hpsa.c
+++ b/drivers/scsi/hpsa.c
@@ -48,6 +48,7 @@
48#include <linux/bitmap.h> 48#include <linux/bitmap.h>
49#include <linux/atomic.h> 49#include <linux/atomic.h>
50#include <linux/kthread.h> 50#include <linux/kthread.h>
51#include <linux/jiffies.h>
51#include "hpsa_cmd.h" 52#include "hpsa_cmd.h"
52#include "hpsa.h" 53#include "hpsa.h"
53 54
@@ -127,6 +128,10 @@ static struct board_type products[] = {
127 128
128static int number_of_controllers; 129static int number_of_controllers;
129 130
131static struct list_head hpsa_ctlr_list = LIST_HEAD_INIT(hpsa_ctlr_list);
132static spinlock_t lockup_detector_lock;
133static struct task_struct *hpsa_lockup_detector;
134
130static irqreturn_t do_hpsa_intr_intx(int irq, void *dev_id); 135static irqreturn_t do_hpsa_intr_intx(int irq, void *dev_id);
131static irqreturn_t do_hpsa_intr_msi(int irq, void *dev_id); 136static irqreturn_t do_hpsa_intr_msi(int irq, void *dev_id);
132static int hpsa_ioctl(struct scsi_device *dev, int cmd, void *arg); 137static int hpsa_ioctl(struct scsi_device *dev, int cmd, void *arg);
@@ -484,6 +489,7 @@ static struct scsi_host_template hpsa_driver_template = {
484#endif 489#endif
485 .sdev_attrs = hpsa_sdev_attrs, 490 .sdev_attrs = hpsa_sdev_attrs,
486 .shost_attrs = hpsa_shost_attrs, 491 .shost_attrs = hpsa_shost_attrs,
492 .max_sectors = 8192,
487}; 493};
488 494
489 495
@@ -566,16 +572,16 @@ static int hpsa_find_target_lun(struct ctlr_info *h,
566 * assumes h->devlock is held 572 * assumes h->devlock is held
567 */ 573 */
568 int i, found = 0; 574 int i, found = 0;
569 DECLARE_BITMAP(lun_taken, HPSA_MAX_SCSI_DEVS_PER_HBA); 575 DECLARE_BITMAP(lun_taken, HPSA_MAX_DEVICES);
570 576
571 memset(&lun_taken[0], 0, HPSA_MAX_SCSI_DEVS_PER_HBA >> 3); 577 memset(&lun_taken[0], 0, HPSA_MAX_DEVICES >> 3);
572 578
573 for (i = 0; i < h->ndevices; i++) { 579 for (i = 0; i < h->ndevices; i++) {
574 if (h->dev[i]->bus == bus && h->dev[i]->target != -1) 580 if (h->dev[i]->bus == bus && h->dev[i]->target != -1)
575 set_bit(h->dev[i]->target, lun_taken); 581 set_bit(h->dev[i]->target, lun_taken);
576 } 582 }
577 583
578 for (i = 0; i < HPSA_MAX_SCSI_DEVS_PER_HBA; i++) { 584 for (i = 0; i < HPSA_MAX_DEVICES; i++) {
579 if (!test_bit(i, lun_taken)) { 585 if (!test_bit(i, lun_taken)) {
580 /* *bus = 1; */ 586 /* *bus = 1; */
581 *target = i; 587 *target = i;
@@ -598,7 +604,7 @@ static int hpsa_scsi_add_entry(struct ctlr_info *h, int hostno,
598 unsigned char addr1[8], addr2[8]; 604 unsigned char addr1[8], addr2[8];
599 struct hpsa_scsi_dev_t *sd; 605 struct hpsa_scsi_dev_t *sd;
600 606
601 if (n >= HPSA_MAX_SCSI_DEVS_PER_HBA) { 607 if (n >= HPSA_MAX_DEVICES) {
602 dev_err(&h->pdev->dev, "too many devices, some will be " 608 dev_err(&h->pdev->dev, "too many devices, some will be "
603 "inaccessible.\n"); 609 "inaccessible.\n");
604 return -1; 610 return -1;
@@ -673,7 +679,7 @@ static void hpsa_scsi_replace_entry(struct ctlr_info *h, int hostno,
673 struct hpsa_scsi_dev_t *removed[], int *nremoved) 679 struct hpsa_scsi_dev_t *removed[], int *nremoved)
674{ 680{
675 /* assumes h->devlock is held */ 681 /* assumes h->devlock is held */
676 BUG_ON(entry < 0 || entry >= HPSA_MAX_SCSI_DEVS_PER_HBA); 682 BUG_ON(entry < 0 || entry >= HPSA_MAX_DEVICES);
677 removed[*nremoved] = h->dev[entry]; 683 removed[*nremoved] = h->dev[entry];
678 (*nremoved)++; 684 (*nremoved)++;
679 685
@@ -702,7 +708,7 @@ static void hpsa_scsi_remove_entry(struct ctlr_info *h, int hostno, int entry,
702 int i; 708 int i;
703 struct hpsa_scsi_dev_t *sd; 709 struct hpsa_scsi_dev_t *sd;
704 710
705 BUG_ON(entry < 0 || entry >= HPSA_MAX_SCSI_DEVS_PER_HBA); 711 BUG_ON(entry < 0 || entry >= HPSA_MAX_DEVICES);
706 712
707 sd = h->dev[entry]; 713 sd = h->dev[entry];
708 removed[*nremoved] = h->dev[entry]; 714 removed[*nremoved] = h->dev[entry];
@@ -814,10 +820,8 @@ static void adjust_hpsa_scsi_table(struct ctlr_info *h, int hostno,
814 int nadded, nremoved; 820 int nadded, nremoved;
815 struct Scsi_Host *sh = NULL; 821 struct Scsi_Host *sh = NULL;
816 822
817 added = kzalloc(sizeof(*added) * HPSA_MAX_SCSI_DEVS_PER_HBA, 823 added = kzalloc(sizeof(*added) * HPSA_MAX_DEVICES, GFP_KERNEL);
818 GFP_KERNEL); 824 removed = kzalloc(sizeof(*removed) * HPSA_MAX_DEVICES, GFP_KERNEL);
819 removed = kzalloc(sizeof(*removed) * HPSA_MAX_SCSI_DEVS_PER_HBA,
820 GFP_KERNEL);
821 825
822 if (!added || !removed) { 826 if (!added || !removed) {
823 dev_warn(&h->pdev->dev, "out of memory in " 827 dev_warn(&h->pdev->dev, "out of memory in "
@@ -1338,6 +1342,22 @@ static inline void hpsa_scsi_do_simple_cmd_core(struct ctlr_info *h,
1338 wait_for_completion(&wait); 1342 wait_for_completion(&wait);
1339} 1343}
1340 1344
1345static void hpsa_scsi_do_simple_cmd_core_if_no_lockup(struct ctlr_info *h,
1346 struct CommandList *c)
1347{
1348 unsigned long flags;
1349
1350 /* If controller lockup detected, fake a hardware error. */
1351 spin_lock_irqsave(&h->lock, flags);
1352 if (unlikely(h->lockup_detected)) {
1353 spin_unlock_irqrestore(&h->lock, flags);
1354 c->err_info->CommandStatus = CMD_HARDWARE_ERR;
1355 } else {
1356 spin_unlock_irqrestore(&h->lock, flags);
1357 hpsa_scsi_do_simple_cmd_core(h, c);
1358 }
1359}
1360
1341static void hpsa_scsi_do_simple_cmd_with_retry(struct ctlr_info *h, 1361static void hpsa_scsi_do_simple_cmd_with_retry(struct ctlr_info *h,
1342 struct CommandList *c, int data_direction) 1362 struct CommandList *c, int data_direction)
1343{ 1363{
@@ -1735,7 +1755,6 @@ static int add_msa2xxx_enclosure_device(struct ctlr_info *h,
1735 if (is_scsi_rev_5(h)) 1755 if (is_scsi_rev_5(h))
1736 return 0; /* p1210m doesn't need to do this. */ 1756 return 0; /* p1210m doesn't need to do this. */
1737 1757
1738#define MAX_MSA2XXX_ENCLOSURES 32
1739 if (*nmsa2xxx_enclosures >= MAX_MSA2XXX_ENCLOSURES) { 1758 if (*nmsa2xxx_enclosures >= MAX_MSA2XXX_ENCLOSURES) {
1740 dev_warn(&h->pdev->dev, "Maximum number of MSA2XXX " 1759 dev_warn(&h->pdev->dev, "Maximum number of MSA2XXX "
1741 "enclosures exceeded. Check your hardware " 1760 "enclosures exceeded. Check your hardware "
@@ -1846,8 +1865,7 @@ static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno)
1846 int raid_ctlr_position; 1865 int raid_ctlr_position;
1847 DECLARE_BITMAP(lunzerobits, HPSA_MAX_TARGETS_PER_CTLR); 1866 DECLARE_BITMAP(lunzerobits, HPSA_MAX_TARGETS_PER_CTLR);
1848 1867
1849 currentsd = kzalloc(sizeof(*currentsd) * HPSA_MAX_SCSI_DEVS_PER_HBA, 1868 currentsd = kzalloc(sizeof(*currentsd) * HPSA_MAX_DEVICES, GFP_KERNEL);
1850 GFP_KERNEL);
1851 physdev_list = kzalloc(reportlunsize, GFP_KERNEL); 1869 physdev_list = kzalloc(reportlunsize, GFP_KERNEL);
1852 logdev_list = kzalloc(reportlunsize, GFP_KERNEL); 1870 logdev_list = kzalloc(reportlunsize, GFP_KERNEL);
1853 tmpdevice = kzalloc(sizeof(*tmpdevice), GFP_KERNEL); 1871 tmpdevice = kzalloc(sizeof(*tmpdevice), GFP_KERNEL);
@@ -1870,6 +1888,13 @@ static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno)
1870 1888
1871 /* Allocate the per device structures */ 1889 /* Allocate the per device structures */
1872 for (i = 0; i < ndevs_to_allocate; i++) { 1890 for (i = 0; i < ndevs_to_allocate; i++) {
1891 if (i >= HPSA_MAX_DEVICES) {
1892 dev_warn(&h->pdev->dev, "maximum devices (%d) exceeded."
1893 " %d devices ignored.\n", HPSA_MAX_DEVICES,
1894 ndevs_to_allocate - HPSA_MAX_DEVICES);
1895 break;
1896 }
1897
1873 currentsd[i] = kzalloc(sizeof(*currentsd[i]), GFP_KERNEL); 1898 currentsd[i] = kzalloc(sizeof(*currentsd[i]), GFP_KERNEL);
1874 if (!currentsd[i]) { 1899 if (!currentsd[i]) {
1875 dev_warn(&h->pdev->dev, "out of memory at %s:%d\n", 1900 dev_warn(&h->pdev->dev, "out of memory at %s:%d\n",
@@ -1956,7 +1981,7 @@ static void hpsa_update_scsi_devices(struct ctlr_info *h, int hostno)
1956 default: 1981 default:
1957 break; 1982 break;
1958 } 1983 }
1959 if (ncurrent >= HPSA_MAX_SCSI_DEVS_PER_HBA) 1984 if (ncurrent >= HPSA_MAX_DEVICES)
1960 break; 1985 break;
1961 } 1986 }
1962 adjust_hpsa_scsi_table(h, hostno, currentsd, ncurrent); 1987 adjust_hpsa_scsi_table(h, hostno, currentsd, ncurrent);
@@ -2048,8 +2073,14 @@ static int hpsa_scsi_queue_command_lck(struct scsi_cmnd *cmd,
2048 } 2073 }
2049 memcpy(scsi3addr, dev->scsi3addr, sizeof(scsi3addr)); 2074 memcpy(scsi3addr, dev->scsi3addr, sizeof(scsi3addr));
2050 2075
2051 /* Need a lock as this is being allocated from the pool */
2052 spin_lock_irqsave(&h->lock, flags); 2076 spin_lock_irqsave(&h->lock, flags);
2077 if (unlikely(h->lockup_detected)) {
2078 spin_unlock_irqrestore(&h->lock, flags);
2079 cmd->result = DID_ERROR << 16;
2080 done(cmd);
2081 return 0;
2082 }
2083 /* Need a lock as this is being allocated from the pool */
2053 c = cmd_alloc(h); 2084 c = cmd_alloc(h);
2054 spin_unlock_irqrestore(&h->lock, flags); 2085 spin_unlock_irqrestore(&h->lock, flags);
2055 if (c == NULL) { /* trouble... */ 2086 if (c == NULL) { /* trouble... */
@@ -2601,7 +2632,7 @@ static int hpsa_passthru_ioctl(struct ctlr_info *h, void __user *argp)
2601 c->SG[0].Len = iocommand.buf_size; 2632 c->SG[0].Len = iocommand.buf_size;
2602 c->SG[0].Ext = 0; /* we are not chaining*/ 2633 c->SG[0].Ext = 0; /* we are not chaining*/
2603 } 2634 }
2604 hpsa_scsi_do_simple_cmd_core(h, c); 2635 hpsa_scsi_do_simple_cmd_core_if_no_lockup(h, c);
2605 if (iocommand.buf_size > 0) 2636 if (iocommand.buf_size > 0)
2606 hpsa_pci_unmap(h->pdev, c, 1, PCI_DMA_BIDIRECTIONAL); 2637 hpsa_pci_unmap(h->pdev, c, 1, PCI_DMA_BIDIRECTIONAL);
2607 check_ioctl_unit_attention(h, c); 2638 check_ioctl_unit_attention(h, c);
@@ -2724,7 +2755,7 @@ static int hpsa_big_passthru_ioctl(struct ctlr_info *h, void __user *argp)
2724 c->SG[i].Ext = 0; 2755 c->SG[i].Ext = 0;
2725 } 2756 }
2726 } 2757 }
2727 hpsa_scsi_do_simple_cmd_core(h, c); 2758 hpsa_scsi_do_simple_cmd_core_if_no_lockup(h, c);
2728 if (sg_used) 2759 if (sg_used)
2729 hpsa_pci_unmap(h->pdev, c, sg_used, PCI_DMA_BIDIRECTIONAL); 2760 hpsa_pci_unmap(h->pdev, c, sg_used, PCI_DMA_BIDIRECTIONAL);
2730 check_ioctl_unit_attention(h, c); 2761 check_ioctl_unit_attention(h, c);
@@ -2872,6 +2903,8 @@ static void fill_cmd(struct CommandList *c, u8 cmd, struct ctlr_info *h,
2872 c->Request.Timeout = 0; 2903 c->Request.Timeout = 0;
2873 c->Request.CDB[0] = BMIC_WRITE; 2904 c->Request.CDB[0] = BMIC_WRITE;
2874 c->Request.CDB[6] = BMIC_CACHE_FLUSH; 2905 c->Request.CDB[6] = BMIC_CACHE_FLUSH;
2906 c->Request.CDB[7] = (size >> 8) & 0xFF;
2907 c->Request.CDB[8] = size & 0xFF;
2875 break; 2908 break;
2876 case TEST_UNIT_READY: 2909 case TEST_UNIT_READY:
2877 c->Request.CDBLen = 6; 2910 c->Request.CDBLen = 6;
@@ -3091,6 +3124,7 @@ static irqreturn_t hpsa_intx_discard_completions(int irq, void *dev_id)
3091 if (interrupt_not_for_us(h)) 3124 if (interrupt_not_for_us(h))
3092 return IRQ_NONE; 3125 return IRQ_NONE;
3093 spin_lock_irqsave(&h->lock, flags); 3126 spin_lock_irqsave(&h->lock, flags);
3127 h->last_intr_timestamp = get_jiffies_64();
3094 while (interrupt_pending(h)) { 3128 while (interrupt_pending(h)) {
3095 raw_tag = get_next_completion(h); 3129 raw_tag = get_next_completion(h);
3096 while (raw_tag != FIFO_EMPTY) 3130 while (raw_tag != FIFO_EMPTY)
@@ -3110,6 +3144,7 @@ static irqreturn_t hpsa_msix_discard_completions(int irq, void *dev_id)
3110 return IRQ_NONE; 3144 return IRQ_NONE;
3111 3145
3112 spin_lock_irqsave(&h->lock, flags); 3146 spin_lock_irqsave(&h->lock, flags);
3147 h->last_intr_timestamp = get_jiffies_64();
3113 raw_tag = get_next_completion(h); 3148 raw_tag = get_next_completion(h);
3114 while (raw_tag != FIFO_EMPTY) 3149 while (raw_tag != FIFO_EMPTY)
3115 raw_tag = next_command(h); 3150 raw_tag = next_command(h);
@@ -3126,6 +3161,7 @@ static irqreturn_t do_hpsa_intr_intx(int irq, void *dev_id)
3126 if (interrupt_not_for_us(h)) 3161 if (interrupt_not_for_us(h))
3127 return IRQ_NONE; 3162 return IRQ_NONE;
3128 spin_lock_irqsave(&h->lock, flags); 3163 spin_lock_irqsave(&h->lock, flags);
3164 h->last_intr_timestamp = get_jiffies_64();
3129 while (interrupt_pending(h)) { 3165 while (interrupt_pending(h)) {
3130 raw_tag = get_next_completion(h); 3166 raw_tag = get_next_completion(h);
3131 while (raw_tag != FIFO_EMPTY) { 3167 while (raw_tag != FIFO_EMPTY) {
@@ -3146,6 +3182,7 @@ static irqreturn_t do_hpsa_intr_msi(int irq, void *dev_id)
3146 u32 raw_tag; 3182 u32 raw_tag;
3147 3183
3148 spin_lock_irqsave(&h->lock, flags); 3184 spin_lock_irqsave(&h->lock, flags);
3185 h->last_intr_timestamp = get_jiffies_64();
3149 raw_tag = get_next_completion(h); 3186 raw_tag = get_next_completion(h);
3150 while (raw_tag != FIFO_EMPTY) { 3187 while (raw_tag != FIFO_EMPTY) {
3151 if (hpsa_tag_contains_index(raw_tag)) 3188 if (hpsa_tag_contains_index(raw_tag))
@@ -3300,6 +3337,13 @@ static int hpsa_controller_hard_reset(struct pci_dev *pdev,
3300 pmcsr &= ~PCI_PM_CTRL_STATE_MASK; 3337 pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
3301 pmcsr |= PCI_D0; 3338 pmcsr |= PCI_D0;
3302 pci_write_config_word(pdev, pos + PCI_PM_CTRL, pmcsr); 3339 pci_write_config_word(pdev, pos + PCI_PM_CTRL, pmcsr);
3340
3341 /*
3342 * The P600 requires a small delay when changing states.
3343 * Otherwise we may think the board did not reset and we bail.
3344 * This for kdump only and is particular to the P600.
3345 */
3346 msleep(500);
3303 } 3347 }
3304 return 0; 3348 return 0;
3305} 3349}
@@ -4083,6 +4127,149 @@ static void hpsa_undo_allocations_after_kdump_soft_reset(struct ctlr_info *h)
4083 kfree(h); 4127 kfree(h);
4084} 4128}
4085 4129
4130static void remove_ctlr_from_lockup_detector_list(struct ctlr_info *h)
4131{
4132 assert_spin_locked(&lockup_detector_lock);
4133 if (!hpsa_lockup_detector)
4134 return;
4135 if (h->lockup_detected)
4136 return; /* already stopped the lockup detector */
4137 list_del(&h->lockup_list);
4138}
4139
4140/* Called when controller lockup detected. */
4141static void fail_all_cmds_on_list(struct ctlr_info *h, struct list_head *list)
4142{
4143 struct CommandList *c = NULL;
4144
4145 assert_spin_locked(&h->lock);
4146 /* Mark all outstanding commands as failed and complete them. */
4147 while (!list_empty(list)) {
4148 c = list_entry(list->next, struct CommandList, list);
4149 c->err_info->CommandStatus = CMD_HARDWARE_ERR;
4150 finish_cmd(c, c->Header.Tag.lower);
4151 }
4152}
4153
4154static void controller_lockup_detected(struct ctlr_info *h)
4155{
4156 unsigned long flags;
4157
4158 assert_spin_locked(&lockup_detector_lock);
4159 remove_ctlr_from_lockup_detector_list(h);
4160 h->access.set_intr_mask(h, HPSA_INTR_OFF);
4161 spin_lock_irqsave(&h->lock, flags);
4162 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
4163 spin_unlock_irqrestore(&h->lock, flags);
4164 dev_warn(&h->pdev->dev, "Controller lockup detected: 0x%08x\n",
4165 h->lockup_detected);
4166 pci_disable_device(h->pdev);
4167 spin_lock_irqsave(&h->lock, flags);
4168 fail_all_cmds_on_list(h, &h->cmpQ);
4169 fail_all_cmds_on_list(h, &h->reqQ);
4170 spin_unlock_irqrestore(&h->lock, flags);
4171}
4172
4173#define HEARTBEAT_SAMPLE_INTERVAL (10 * HZ)
4174#define HEARTBEAT_CHECK_MINIMUM_INTERVAL (HEARTBEAT_SAMPLE_INTERVAL / 2)
4175
4176static void detect_controller_lockup(struct ctlr_info *h)
4177{
4178 u64 now;
4179 u32 heartbeat;
4180 unsigned long flags;
4181
4182 assert_spin_locked(&lockup_detector_lock);
4183 now = get_jiffies_64();
4184 /* If we've received an interrupt recently, we're ok. */
4185 if (time_after64(h->last_intr_timestamp +
4186 (HEARTBEAT_CHECK_MINIMUM_INTERVAL), now))
4187 return;
4188
4189 /*
4190 * If we've already checked the heartbeat recently, we're ok.
4191 * This could happen if someone sends us a signal. We
4192 * otherwise don't care about signals in this thread.
4193 */
4194 if (time_after64(h->last_heartbeat_timestamp +
4195 (HEARTBEAT_CHECK_MINIMUM_INTERVAL), now))
4196 return;
4197
4198 /* If heartbeat has not changed since we last looked, we're not ok. */
4199 spin_lock_irqsave(&h->lock, flags);
4200 heartbeat = readl(&h->cfgtable->HeartBeat);
4201 spin_unlock_irqrestore(&h->lock, flags);
4202 if (h->last_heartbeat == heartbeat) {
4203 controller_lockup_detected(h);
4204 return;
4205 }
4206
4207 /* We're ok. */
4208 h->last_heartbeat = heartbeat;
4209 h->last_heartbeat_timestamp = now;
4210}
4211
4212static int detect_controller_lockup_thread(void *notused)
4213{
4214 struct ctlr_info *h;
4215 unsigned long flags;
4216
4217 while (1) {
4218 struct list_head *this, *tmp;
4219
4220 schedule_timeout_interruptible(HEARTBEAT_SAMPLE_INTERVAL);
4221 if (kthread_should_stop())
4222 break;
4223 spin_lock_irqsave(&lockup_detector_lock, flags);
4224 list_for_each_safe(this, tmp, &hpsa_ctlr_list) {
4225 h = list_entry(this, struct ctlr_info, lockup_list);
4226 detect_controller_lockup(h);
4227 }
4228 spin_unlock_irqrestore(&lockup_detector_lock, flags);
4229 }
4230 return 0;
4231}
4232
4233static void add_ctlr_to_lockup_detector_list(struct ctlr_info *h)
4234{
4235 unsigned long flags;
4236
4237 spin_lock_irqsave(&lockup_detector_lock, flags);
4238 list_add_tail(&h->lockup_list, &hpsa_ctlr_list);
4239 spin_unlock_irqrestore(&lockup_detector_lock, flags);
4240}
4241
4242static void start_controller_lockup_detector(struct ctlr_info *h)
4243{
4244 /* Start the lockup detector thread if not already started */
4245 if (!hpsa_lockup_detector) {
4246 spin_lock_init(&lockup_detector_lock);
4247 hpsa_lockup_detector =
4248 kthread_run(detect_controller_lockup_thread,
4249 NULL, "hpsa");
4250 }
4251 if (!hpsa_lockup_detector) {
4252 dev_warn(&h->pdev->dev,
4253 "Could not start lockup detector thread\n");
4254 return;
4255 }
4256 add_ctlr_to_lockup_detector_list(h);
4257}
4258
4259static void stop_controller_lockup_detector(struct ctlr_info *h)
4260{
4261 unsigned long flags;
4262
4263 spin_lock_irqsave(&lockup_detector_lock, flags);
4264 remove_ctlr_from_lockup_detector_list(h);
4265 /* If the list of ctlr's to monitor is empty, stop the thread */
4266 if (list_empty(&hpsa_ctlr_list)) {
4267 kthread_stop(hpsa_lockup_detector);
4268 hpsa_lockup_detector = NULL;
4269 }
4270 spin_unlock_irqrestore(&lockup_detector_lock, flags);
4271}
4272
4086static int __devinit hpsa_init_one(struct pci_dev *pdev, 4273static int __devinit hpsa_init_one(struct pci_dev *pdev,
4087 const struct pci_device_id *ent) 4274 const struct pci_device_id *ent)
4088{ 4275{
@@ -4120,7 +4307,6 @@ reinit_after_soft_reset:
4120 return -ENOMEM; 4307 return -ENOMEM;
4121 4308
4122 h->pdev = pdev; 4309 h->pdev = pdev;
4123 h->busy_initializing = 1;
4124 h->intr_mode = hpsa_simple_mode ? SIMPLE_MODE_INT : PERF_MODE_INT; 4310 h->intr_mode = hpsa_simple_mode ? SIMPLE_MODE_INT : PERF_MODE_INT;
4125 INIT_LIST_HEAD(&h->cmpQ); 4311 INIT_LIST_HEAD(&h->cmpQ);
4126 INIT_LIST_HEAD(&h->reqQ); 4312 INIT_LIST_HEAD(&h->reqQ);
@@ -4229,7 +4415,7 @@ reinit_after_soft_reset:
4229 4415
4230 hpsa_hba_inquiry(h); 4416 hpsa_hba_inquiry(h);
4231 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */ 4417 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
4232 h->busy_initializing = 0; 4418 start_controller_lockup_detector(h);
4233 return 1; 4419 return 1;
4234 4420
4235clean4: 4421clean4:
@@ -4238,7 +4424,6 @@ clean4:
4238 free_irq(h->intr[h->intr_mode], h); 4424 free_irq(h->intr[h->intr_mode], h);
4239clean2: 4425clean2:
4240clean1: 4426clean1:
4241 h->busy_initializing = 0;
4242 kfree(h); 4427 kfree(h);
4243 return rc; 4428 return rc;
4244} 4429}
@@ -4293,10 +4478,11 @@ static void __devexit hpsa_remove_one(struct pci_dev *pdev)
4293 struct ctlr_info *h; 4478 struct ctlr_info *h;
4294 4479
4295 if (pci_get_drvdata(pdev) == NULL) { 4480 if (pci_get_drvdata(pdev) == NULL) {
4296 dev_err(&pdev->dev, "unable to remove device \n"); 4481 dev_err(&pdev->dev, "unable to remove device\n");
4297 return; 4482 return;
4298 } 4483 }
4299 h = pci_get_drvdata(pdev); 4484 h = pci_get_drvdata(pdev);
4485 stop_controller_lockup_detector(h);
4300 hpsa_unregister_scsi(h); /* unhook from SCSI subsystem */ 4486 hpsa_unregister_scsi(h); /* unhook from SCSI subsystem */
4301 hpsa_shutdown(pdev); 4487 hpsa_shutdown(pdev);
4302 iounmap(h->vaddr); 4488 iounmap(h->vaddr);
diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
index 7f53ceaa7239..91edafb8c7e6 100644
--- a/drivers/scsi/hpsa.h
+++ b/drivers/scsi/hpsa.h
@@ -95,8 +95,6 @@ struct ctlr_info {
95 unsigned long *cmd_pool_bits; 95 unsigned long *cmd_pool_bits;
96 int nr_allocs; 96 int nr_allocs;
97 int nr_frees; 97 int nr_frees;
98 int busy_initializing;
99 int busy_scanning;
100 int scan_finished; 98 int scan_finished;
101 spinlock_t scan_lock; 99 spinlock_t scan_lock;
102 wait_queue_head_t scan_wait_queue; 100 wait_queue_head_t scan_wait_queue;
@@ -104,8 +102,7 @@ struct ctlr_info {
104 struct Scsi_Host *scsi_host; 102 struct Scsi_Host *scsi_host;
105 spinlock_t devlock; /* to protect hba[ctlr]->dev[]; */ 103 spinlock_t devlock; /* to protect hba[ctlr]->dev[]; */
106 int ndevices; /* number of used elements in .dev[] array. */ 104 int ndevices; /* number of used elements in .dev[] array. */
107#define HPSA_MAX_SCSI_DEVS_PER_HBA 256 105 struct hpsa_scsi_dev_t *dev[HPSA_MAX_DEVICES];
108 struct hpsa_scsi_dev_t *dev[HPSA_MAX_SCSI_DEVS_PER_HBA];
109 /* 106 /*
110 * Performant mode tables. 107 * Performant mode tables.
111 */ 108 */
@@ -124,6 +121,11 @@ struct ctlr_info {
124 unsigned char reply_pool_wraparound; 121 unsigned char reply_pool_wraparound;
125 u32 *blockFetchTable; 122 u32 *blockFetchTable;
126 unsigned char *hba_inquiry_data; 123 unsigned char *hba_inquiry_data;
124 u64 last_intr_timestamp;
125 u32 last_heartbeat;
126 u64 last_heartbeat_timestamp;
127 u32 lockup_detected;
128 struct list_head lockup_list;
127}; 129};
128#define HPSA_ABORT_MSG 0 130#define HPSA_ABORT_MSG 0
129#define HPSA_DEVICE_RESET_MSG 1 131#define HPSA_DEVICE_RESET_MSG 1
diff --git a/drivers/scsi/hpsa_cmd.h b/drivers/scsi/hpsa_cmd.h
index 55d741b019db..3fd4715935c2 100644
--- a/drivers/scsi/hpsa_cmd.h
+++ b/drivers/scsi/hpsa_cmd.h
@@ -123,8 +123,11 @@ union u64bit {
123 123
124/* FIXME this is a per controller value (barf!) */ 124/* FIXME this is a per controller value (barf!) */
125#define HPSA_MAX_TARGETS_PER_CTLR 16 125#define HPSA_MAX_TARGETS_PER_CTLR 16
126#define HPSA_MAX_LUN 256 126#define HPSA_MAX_LUN 1024
127#define HPSA_MAX_PHYS_LUN 1024 127#define HPSA_MAX_PHYS_LUN 1024
128#define MAX_MSA2XXX_ENCLOSURES 32
129#define HPSA_MAX_DEVICES (HPSA_MAX_PHYS_LUN + HPSA_MAX_LUN + \
130 MAX_MSA2XXX_ENCLOSURES + 1) /* + 1 is for the controller itself */
128 131
129/* SCSI-3 Commands */ 132/* SCSI-3 Commands */
130#pragma pack(1) 133#pragma pack(1)
diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
index 73e24b48dced..fd860d952b28 100644
--- a/drivers/scsi/ipr.c
+++ b/drivers/scsi/ipr.c
@@ -9123,6 +9123,8 @@ static struct pci_device_id ipr_pci_table[] __devinitdata = {
9123 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2, 9123 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
9124 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B2, 0, 0, 0 }, 9124 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B2, 0, 0, 0 },
9125 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2, 9125 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
9126 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C3, 0, 0, 0 },
9127 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
9126 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C4, 0, 0, 0 }, 9128 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C4, 0, 0, 0 },
9127 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_ASIC_E2, 9129 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_ASIC_E2,
9128 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B4, 0, 0, 0 }, 9130 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B4, 0, 0, 0 },
diff --git a/drivers/scsi/ipr.h b/drivers/scsi/ipr.h
index 6d257e0dd6a5..ac84736c1b9c 100644
--- a/drivers/scsi/ipr.h
+++ b/drivers/scsi/ipr.h
@@ -82,6 +82,7 @@
82 82
83#define IPR_SUBS_DEV_ID_57B4 0x033B 83#define IPR_SUBS_DEV_ID_57B4 0x033B
84#define IPR_SUBS_DEV_ID_57B2 0x035F 84#define IPR_SUBS_DEV_ID_57B2 0x035F
85#define IPR_SUBS_DEV_ID_57C3 0x0353
85#define IPR_SUBS_DEV_ID_57C4 0x0354 86#define IPR_SUBS_DEV_ID_57C4 0x0354
86#define IPR_SUBS_DEV_ID_57C6 0x0357 87#define IPR_SUBS_DEV_ID_57C6 0x0357
87#define IPR_SUBS_DEV_ID_57CC 0x035C 88#define IPR_SUBS_DEV_ID_57CC 0x035C
diff --git a/drivers/scsi/isci/host.c b/drivers/scsi/isci/host.c
index f07f30fada1b..e7fe9c4c85b8 100644
--- a/drivers/scsi/isci/host.c
+++ b/drivers/scsi/isci/host.c
@@ -1350,7 +1350,7 @@ static void isci_user_parameters_get(struct sci_user_parameters *u)
1350 u->stp_max_occupancy_timeout = stp_max_occ_to; 1350 u->stp_max_occupancy_timeout = stp_max_occ_to;
1351 u->ssp_max_occupancy_timeout = ssp_max_occ_to; 1351 u->ssp_max_occupancy_timeout = ssp_max_occ_to;
1352 u->no_outbound_task_timeout = no_outbound_task_to; 1352 u->no_outbound_task_timeout = no_outbound_task_to;
1353 u->max_number_concurrent_device_spin_up = max_concurr_spinup; 1353 u->max_concurr_spinup = max_concurr_spinup;
1354} 1354}
1355 1355
1356static void sci_controller_initial_state_enter(struct sci_base_state_machine *sm) 1356static void sci_controller_initial_state_enter(struct sci_base_state_machine *sm)
@@ -1661,7 +1661,7 @@ static void sci_controller_set_default_config_parameters(struct isci_host *ihost
1661 ihost->oem_parameters.controller.mode_type = SCIC_PORT_AUTOMATIC_CONFIGURATION_MODE; 1661 ihost->oem_parameters.controller.mode_type = SCIC_PORT_AUTOMATIC_CONFIGURATION_MODE;
1662 1662
1663 /* Default to APC mode. */ 1663 /* Default to APC mode. */
1664 ihost->oem_parameters.controller.max_concurrent_dev_spin_up = 1; 1664 ihost->oem_parameters.controller.max_concurr_spin_up = 1;
1665 1665
1666 /* Default to no SSC operation. */ 1666 /* Default to no SSC operation. */
1667 ihost->oem_parameters.controller.do_enable_ssc = false; 1667 ihost->oem_parameters.controller.do_enable_ssc = false;
@@ -1787,7 +1787,8 @@ int sci_oem_parameters_validate(struct sci_oem_params *oem)
1787 } else 1787 } else
1788 return -EINVAL; 1788 return -EINVAL;
1789 1789
1790 if (oem->controller.max_concurrent_dev_spin_up > MAX_CONCURRENT_DEVICE_SPIN_UP_COUNT) 1790 if (oem->controller.max_concurr_spin_up > MAX_CONCURRENT_DEVICE_SPIN_UP_COUNT ||
1791 oem->controller.max_concurr_spin_up < 1)
1791 return -EINVAL; 1792 return -EINVAL;
1792 1793
1793 return 0; 1794 return 0;
@@ -1810,6 +1811,16 @@ static enum sci_status sci_oem_parameters_set(struct isci_host *ihost)
1810 return SCI_FAILURE_INVALID_STATE; 1811 return SCI_FAILURE_INVALID_STATE;
1811} 1812}
1812 1813
1814static u8 max_spin_up(struct isci_host *ihost)
1815{
1816 if (ihost->user_parameters.max_concurr_spinup)
1817 return min_t(u8, ihost->user_parameters.max_concurr_spinup,
1818 MAX_CONCURRENT_DEVICE_SPIN_UP_COUNT);
1819 else
1820 return min_t(u8, ihost->oem_parameters.controller.max_concurr_spin_up,
1821 MAX_CONCURRENT_DEVICE_SPIN_UP_COUNT);
1822}
1823
1813static void power_control_timeout(unsigned long data) 1824static void power_control_timeout(unsigned long data)
1814{ 1825{
1815 struct sci_timer *tmr = (struct sci_timer *)data; 1826 struct sci_timer *tmr = (struct sci_timer *)data;
@@ -1839,8 +1850,7 @@ static void power_control_timeout(unsigned long data)
1839 if (iphy == NULL) 1850 if (iphy == NULL)
1840 continue; 1851 continue;
1841 1852
1842 if (ihost->power_control.phys_granted_power >= 1853 if (ihost->power_control.phys_granted_power >= max_spin_up(ihost))
1843 ihost->oem_parameters.controller.max_concurrent_dev_spin_up)
1844 break; 1854 break;
1845 1855
1846 ihost->power_control.requesters[i] = NULL; 1856 ihost->power_control.requesters[i] = NULL;
@@ -1865,8 +1875,7 @@ void sci_controller_power_control_queue_insert(struct isci_host *ihost,
1865{ 1875{
1866 BUG_ON(iphy == NULL); 1876 BUG_ON(iphy == NULL);
1867 1877
1868 if (ihost->power_control.phys_granted_power < 1878 if (ihost->power_control.phys_granted_power < max_spin_up(ihost)) {
1869 ihost->oem_parameters.controller.max_concurrent_dev_spin_up) {
1870 ihost->power_control.phys_granted_power++; 1879 ihost->power_control.phys_granted_power++;
1871 sci_phy_consume_power_handler(iphy); 1880 sci_phy_consume_power_handler(iphy);
1872 1881
diff --git a/drivers/scsi/isci/init.c b/drivers/scsi/isci/init.c
index 43fe840fbe9c..a97edabcb85a 100644
--- a/drivers/scsi/isci/init.c
+++ b/drivers/scsi/isci/init.c
@@ -118,7 +118,7 @@ unsigned char phy_gen = 3;
118module_param(phy_gen, byte, 0); 118module_param(phy_gen, byte, 0);
119MODULE_PARM_DESC(phy_gen, "PHY generation (1: 1.5Gbps 2: 3.0Gbps 3: 6.0Gbps)"); 119MODULE_PARM_DESC(phy_gen, "PHY generation (1: 1.5Gbps 2: 3.0Gbps 3: 6.0Gbps)");
120 120
121unsigned char max_concurr_spinup = 1; 121unsigned char max_concurr_spinup;
122module_param(max_concurr_spinup, byte, 0); 122module_param(max_concurr_spinup, byte, 0);
123MODULE_PARM_DESC(max_concurr_spinup, "Max concurrent device spinup"); 123MODULE_PARM_DESC(max_concurr_spinup, "Max concurrent device spinup");
124 124
diff --git a/drivers/scsi/isci/port.c b/drivers/scsi/isci/port.c
index 8e59c8865dcd..ac7f27749f97 100644
--- a/drivers/scsi/isci/port.c
+++ b/drivers/scsi/isci/port.c
@@ -145,48 +145,15 @@ static void sci_port_bcn_enable(struct isci_port *iport)
145 } 145 }
146} 146}
147 147
148/* called under sci_lock to stabilize phy:port associations */
149void isci_port_bcn_enable(struct isci_host *ihost, struct isci_port *iport)
150{
151 int i;
152
153 clear_bit(IPORT_BCN_BLOCKED, &iport->flags);
154 wake_up(&ihost->eventq);
155
156 if (!test_and_clear_bit(IPORT_BCN_PENDING, &iport->flags))
157 return;
158
159 for (i = 0; i < ARRAY_SIZE(iport->phy_table); i++) {
160 struct isci_phy *iphy = iport->phy_table[i];
161
162 if (!iphy)
163 continue;
164
165 ihost->sas_ha.notify_port_event(&iphy->sas_phy,
166 PORTE_BROADCAST_RCVD);
167 break;
168 }
169}
170
171static void isci_port_bc_change_received(struct isci_host *ihost, 148static void isci_port_bc_change_received(struct isci_host *ihost,
172 struct isci_port *iport, 149 struct isci_port *iport,
173 struct isci_phy *iphy) 150 struct isci_phy *iphy)
174{ 151{
175 if (iport && test_bit(IPORT_BCN_BLOCKED, &iport->flags)) { 152 dev_dbg(&ihost->pdev->dev,
176 dev_dbg(&ihost->pdev->dev, 153 "%s: isci_phy = %p, sas_phy = %p\n",
177 "%s: disabled BCN; isci_phy = %p, sas_phy = %p\n", 154 __func__, iphy, &iphy->sas_phy);
178 __func__, iphy, &iphy->sas_phy);
179 set_bit(IPORT_BCN_PENDING, &iport->flags);
180 atomic_inc(&iport->event);
181 wake_up(&ihost->eventq);
182 } else {
183 dev_dbg(&ihost->pdev->dev,
184 "%s: isci_phy = %p, sas_phy = %p\n",
185 __func__, iphy, &iphy->sas_phy);
186 155
187 ihost->sas_ha.notify_port_event(&iphy->sas_phy, 156 ihost->sas_ha.notify_port_event(&iphy->sas_phy, PORTE_BROADCAST_RCVD);
188 PORTE_BROADCAST_RCVD);
189 }
190 sci_port_bcn_enable(iport); 157 sci_port_bcn_enable(iport);
191} 158}
192 159
@@ -278,9 +245,6 @@ static void isci_port_link_down(struct isci_host *isci_host,
278 /* check to see if this is the last phy on this port. */ 245 /* check to see if this is the last phy on this port. */
279 if (isci_phy->sas_phy.port && 246 if (isci_phy->sas_phy.port &&
280 isci_phy->sas_phy.port->num_phys == 1) { 247 isci_phy->sas_phy.port->num_phys == 1) {
281 atomic_inc(&isci_port->event);
282 isci_port_bcn_enable(isci_host, isci_port);
283
284 /* change the state for all devices on this port. The 248 /* change the state for all devices on this port. The
285 * next task sent to this device will be returned as 249 * next task sent to this device will be returned as
286 * SAS_TASK_UNDELIVERED, and the scsi mid layer will 250 * SAS_TASK_UNDELIVERED, and the scsi mid layer will
@@ -350,6 +314,34 @@ static void isci_port_stop_complete(struct isci_host *ihost,
350 dev_dbg(&ihost->pdev->dev, "Port stop complete\n"); 314 dev_dbg(&ihost->pdev->dev, "Port stop complete\n");
351} 315}
352 316
317
318static bool is_port_ready_state(enum sci_port_states state)
319{
320 switch (state) {
321 case SCI_PORT_READY:
322 case SCI_PORT_SUB_WAITING:
323 case SCI_PORT_SUB_OPERATIONAL:
324 case SCI_PORT_SUB_CONFIGURING:
325 return true;
326 default:
327 return false;
328 }
329}
330
331/* flag dummy rnc hanling when exiting a ready state */
332static void port_state_machine_change(struct isci_port *iport,
333 enum sci_port_states state)
334{
335 struct sci_base_state_machine *sm = &iport->sm;
336 enum sci_port_states old_state = sm->current_state_id;
337
338 if (is_port_ready_state(old_state) && !is_port_ready_state(state))
339 iport->ready_exit = true;
340
341 sci_change_state(sm, state);
342 iport->ready_exit = false;
343}
344
353/** 345/**
354 * isci_port_hard_reset_complete() - This function is called by the sci core 346 * isci_port_hard_reset_complete() - This function is called by the sci core
355 * when the hard reset complete notification has been received. 347 * when the hard reset complete notification has been received.
@@ -368,6 +360,26 @@ static void isci_port_hard_reset_complete(struct isci_port *isci_port,
368 /* Save the status of the hard reset from the port. */ 360 /* Save the status of the hard reset from the port. */
369 isci_port->hard_reset_status = completion_status; 361 isci_port->hard_reset_status = completion_status;
370 362
363 if (completion_status != SCI_SUCCESS) {
364
365 /* The reset failed. The port state is now SCI_PORT_FAILED. */
366 if (isci_port->active_phy_mask == 0) {
367
368 /* Generate the link down now to the host, since it
369 * was intercepted by the hard reset state machine when
370 * it really happened.
371 */
372 isci_port_link_down(isci_port->isci_host,
373 &isci_port->isci_host->phys[
374 isci_port->last_active_phy],
375 isci_port);
376 }
377 /* Advance the port state so that link state changes will be
378 * noticed.
379 */
380 port_state_machine_change(isci_port, SCI_PORT_SUB_WAITING);
381
382 }
371 complete_all(&isci_port->hard_reset_complete); 383 complete_all(&isci_port->hard_reset_complete);
372} 384}
373 385
@@ -657,6 +669,8 @@ void sci_port_deactivate_phy(struct isci_port *iport, struct isci_phy *iphy,
657 struct isci_host *ihost = iport->owning_controller; 669 struct isci_host *ihost = iport->owning_controller;
658 670
659 iport->active_phy_mask &= ~(1 << iphy->phy_index); 671 iport->active_phy_mask &= ~(1 << iphy->phy_index);
672 if (!iport->active_phy_mask)
673 iport->last_active_phy = iphy->phy_index;
660 674
661 iphy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN; 675 iphy->max_negotiated_speed = SAS_LINK_RATE_UNKNOWN;
662 676
@@ -683,33 +697,6 @@ static void sci_port_invalid_link_up(struct isci_port *iport, struct isci_phy *i
683 } 697 }
684} 698}
685 699
686static bool is_port_ready_state(enum sci_port_states state)
687{
688 switch (state) {
689 case SCI_PORT_READY:
690 case SCI_PORT_SUB_WAITING:
691 case SCI_PORT_SUB_OPERATIONAL:
692 case SCI_PORT_SUB_CONFIGURING:
693 return true;
694 default:
695 return false;
696 }
697}
698
699/* flag dummy rnc hanling when exiting a ready state */
700static void port_state_machine_change(struct isci_port *iport,
701 enum sci_port_states state)
702{
703 struct sci_base_state_machine *sm = &iport->sm;
704 enum sci_port_states old_state = sm->current_state_id;
705
706 if (is_port_ready_state(old_state) && !is_port_ready_state(state))
707 iport->ready_exit = true;
708
709 sci_change_state(sm, state);
710 iport->ready_exit = false;
711}
712
713/** 700/**
714 * sci_port_general_link_up_handler - phy can be assigned to port? 701 * sci_port_general_link_up_handler - phy can be assigned to port?
715 * @sci_port: sci_port object for which has a phy that has gone link up. 702 * @sci_port: sci_port object for which has a phy that has gone link up.
@@ -1622,7 +1609,8 @@ void sci_port_construct(struct isci_port *iport, u8 index,
1622 iport->logical_port_index = SCIC_SDS_DUMMY_PORT; 1609 iport->logical_port_index = SCIC_SDS_DUMMY_PORT;
1623 iport->physical_port_index = index; 1610 iport->physical_port_index = index;
1624 iport->active_phy_mask = 0; 1611 iport->active_phy_mask = 0;
1625 iport->ready_exit = false; 1612 iport->last_active_phy = 0;
1613 iport->ready_exit = false;
1626 1614
1627 iport->owning_controller = ihost; 1615 iport->owning_controller = ihost;
1628 1616
@@ -1648,7 +1636,6 @@ void isci_port_init(struct isci_port *iport, struct isci_host *ihost, int index)
1648 init_completion(&iport->start_complete); 1636 init_completion(&iport->start_complete);
1649 iport->isci_host = ihost; 1637 iport->isci_host = ihost;
1650 isci_port_change_state(iport, isci_freed); 1638 isci_port_change_state(iport, isci_freed);
1651 atomic_set(&iport->event, 0);
1652} 1639}
1653 1640
1654/** 1641/**
@@ -1676,7 +1663,7 @@ int isci_port_perform_hard_reset(struct isci_host *ihost, struct isci_port *ipor
1676{ 1663{
1677 unsigned long flags; 1664 unsigned long flags;
1678 enum sci_status status; 1665 enum sci_status status;
1679 int idx, ret = TMF_RESP_FUNC_COMPLETE; 1666 int ret = TMF_RESP_FUNC_COMPLETE;
1680 1667
1681 dev_dbg(&ihost->pdev->dev, "%s: iport = %p\n", 1668 dev_dbg(&ihost->pdev->dev, "%s: iport = %p\n",
1682 __func__, iport); 1669 __func__, iport);
@@ -1697,8 +1684,13 @@ int isci_port_perform_hard_reset(struct isci_host *ihost, struct isci_port *ipor
1697 "%s: iport = %p; hard reset completion\n", 1684 "%s: iport = %p; hard reset completion\n",
1698 __func__, iport); 1685 __func__, iport);
1699 1686
1700 if (iport->hard_reset_status != SCI_SUCCESS) 1687 if (iport->hard_reset_status != SCI_SUCCESS) {
1701 ret = TMF_RESP_FUNC_FAILED; 1688 ret = TMF_RESP_FUNC_FAILED;
1689
1690 dev_err(&ihost->pdev->dev,
1691 "%s: iport = %p; hard reset failed (0x%x)\n",
1692 __func__, iport, iport->hard_reset_status);
1693 }
1702 } else { 1694 } else {
1703 ret = TMF_RESP_FUNC_FAILED; 1695 ret = TMF_RESP_FUNC_FAILED;
1704 1696
@@ -1718,18 +1710,6 @@ int isci_port_perform_hard_reset(struct isci_host *ihost, struct isci_port *ipor
1718 "%s: iport = %p; hard reset failed " 1710 "%s: iport = %p; hard reset failed "
1719 "(0x%x) - driving explicit link fail for all phys\n", 1711 "(0x%x) - driving explicit link fail for all phys\n",
1720 __func__, iport, iport->hard_reset_status); 1712 __func__, iport, iport->hard_reset_status);
1721
1722 /* Down all phys in the port. */
1723 spin_lock_irqsave(&ihost->scic_lock, flags);
1724 for (idx = 0; idx < SCI_MAX_PHYS; ++idx) {
1725 struct isci_phy *iphy = iport->phy_table[idx];
1726
1727 if (!iphy)
1728 continue;
1729 sci_phy_stop(iphy);
1730 sci_phy_start(iphy);
1731 }
1732 spin_unlock_irqrestore(&ihost->scic_lock, flags);
1733 } 1713 }
1734 return ret; 1714 return ret;
1735} 1715}
diff --git a/drivers/scsi/isci/port.h b/drivers/scsi/isci/port.h
index b50ecd4e8f9c..cb5ffbc38603 100644
--- a/drivers/scsi/isci/port.h
+++ b/drivers/scsi/isci/port.h
@@ -77,7 +77,6 @@ enum isci_status {
77 77
78/** 78/**
79 * struct isci_port - isci direct attached sas port object 79 * struct isci_port - isci direct attached sas port object
80 * @event: counts bcns and port stop events (for bcn filtering)
81 * @ready_exit: several states constitute 'ready'. When exiting ready we 80 * @ready_exit: several states constitute 'ready'. When exiting ready we
82 * need to take extra port-teardown actions that are 81 * need to take extra port-teardown actions that are
83 * skipped when exiting to another 'ready' state. 82 * skipped when exiting to another 'ready' state.
@@ -92,10 +91,6 @@ enum isci_status {
92 */ 91 */
93struct isci_port { 92struct isci_port {
94 enum isci_status status; 93 enum isci_status status;
95 #define IPORT_BCN_BLOCKED 0
96 #define IPORT_BCN_PENDING 1
97 unsigned long flags;
98 atomic_t event;
99 struct isci_host *isci_host; 94 struct isci_host *isci_host;
100 struct asd_sas_port sas_port; 95 struct asd_sas_port sas_port;
101 struct list_head remote_dev_list; 96 struct list_head remote_dev_list;
@@ -109,6 +104,7 @@ struct isci_port {
109 u8 logical_port_index; 104 u8 logical_port_index;
110 u8 physical_port_index; 105 u8 physical_port_index;
111 u8 active_phy_mask; 106 u8 active_phy_mask;
107 u8 last_active_phy;
112 u16 reserved_rni; 108 u16 reserved_rni;
113 u16 reserved_tag; 109 u16 reserved_tag;
114 u32 started_request_count; 110 u32 started_request_count;
diff --git a/drivers/scsi/isci/probe_roms.h b/drivers/scsi/isci/probe_roms.h
index dc007e692f4e..2c75248ca326 100644
--- a/drivers/scsi/isci/probe_roms.h
+++ b/drivers/scsi/isci/probe_roms.h
@@ -112,7 +112,7 @@ struct sci_user_parameters {
112 * This field specifies the maximum number of direct attached devices 112 * This field specifies the maximum number of direct attached devices
113 * that can have power supplied to them simultaneously. 113 * that can have power supplied to them simultaneously.
114 */ 114 */
115 u8 max_number_concurrent_device_spin_up; 115 u8 max_concurr_spinup;
116 116
117 /** 117 /**
118 * This field specifies the number of seconds to allow a phy to consume 118 * This field specifies the number of seconds to allow a phy to consume
@@ -219,7 +219,7 @@ struct sci_bios_oem_param_block_hdr {
219struct sci_oem_params { 219struct sci_oem_params {
220 struct { 220 struct {
221 uint8_t mode_type; 221 uint8_t mode_type;
222 uint8_t max_concurrent_dev_spin_up; 222 uint8_t max_concurr_spin_up;
223 uint8_t do_enable_ssc; 223 uint8_t do_enable_ssc;
224 uint8_t reserved; 224 uint8_t reserved;
225 } controller; 225 } controller;
diff --git a/drivers/scsi/isci/remote_device.c b/drivers/scsi/isci/remote_device.c
index fbf9ce28c3f5..b207cd3b15a0 100644
--- a/drivers/scsi/isci/remote_device.c
+++ b/drivers/scsi/isci/remote_device.c
@@ -1438,88 +1438,3 @@ int isci_remote_device_found(struct domain_device *domain_dev)
1438 1438
1439 return status == SCI_SUCCESS ? 0 : -ENODEV; 1439 return status == SCI_SUCCESS ? 0 : -ENODEV;
1440} 1440}
1441/**
1442 * isci_device_is_reset_pending() - This function will check if there is any
1443 * pending reset condition on the device.
1444 * @request: This parameter is the isci_device object.
1445 *
1446 * true if there is a reset pending for the device.
1447 */
1448bool isci_device_is_reset_pending(
1449 struct isci_host *isci_host,
1450 struct isci_remote_device *isci_device)
1451{
1452 struct isci_request *isci_request;
1453 struct isci_request *tmp_req;
1454 bool reset_is_pending = false;
1455 unsigned long flags;
1456
1457 dev_dbg(&isci_host->pdev->dev,
1458 "%s: isci_device = %p\n", __func__, isci_device);
1459
1460 spin_lock_irqsave(&isci_host->scic_lock, flags);
1461
1462 /* Check for reset on all pending requests. */
1463 list_for_each_entry_safe(isci_request, tmp_req,
1464 &isci_device->reqs_in_process, dev_node) {
1465 dev_dbg(&isci_host->pdev->dev,
1466 "%s: isci_device = %p request = %p\n",
1467 __func__, isci_device, isci_request);
1468
1469 if (isci_request->ttype == io_task) {
1470 struct sas_task *task = isci_request_access_task(
1471 isci_request);
1472
1473 spin_lock(&task->task_state_lock);
1474 if (task->task_state_flags & SAS_TASK_NEED_DEV_RESET)
1475 reset_is_pending = true;
1476 spin_unlock(&task->task_state_lock);
1477 }
1478 }
1479
1480 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
1481
1482 dev_dbg(&isci_host->pdev->dev,
1483 "%s: isci_device = %p reset_is_pending = %d\n",
1484 __func__, isci_device, reset_is_pending);
1485
1486 return reset_is_pending;
1487}
1488
1489/**
1490 * isci_device_clear_reset_pending() - This function will clear if any pending
1491 * reset condition flags on the device.
1492 * @request: This parameter is the isci_device object.
1493 *
1494 * true if there is a reset pending for the device.
1495 */
1496void isci_device_clear_reset_pending(struct isci_host *ihost, struct isci_remote_device *idev)
1497{
1498 struct isci_request *isci_request;
1499 struct isci_request *tmp_req;
1500 unsigned long flags = 0;
1501
1502 dev_dbg(&ihost->pdev->dev, "%s: idev=%p, ihost=%p\n",
1503 __func__, idev, ihost);
1504
1505 spin_lock_irqsave(&ihost->scic_lock, flags);
1506
1507 /* Clear reset pending on all pending requests. */
1508 list_for_each_entry_safe(isci_request, tmp_req,
1509 &idev->reqs_in_process, dev_node) {
1510 dev_dbg(&ihost->pdev->dev, "%s: idev = %p request = %p\n",
1511 __func__, idev, isci_request);
1512
1513 if (isci_request->ttype == io_task) {
1514
1515 unsigned long flags2;
1516 struct sas_task *task = isci_request_access_task(
1517 isci_request);
1518
1519 spin_lock_irqsave(&task->task_state_lock, flags2);
1520 task->task_state_flags &= ~SAS_TASK_NEED_DEV_RESET;
1521 spin_unlock_irqrestore(&task->task_state_lock, flags2);
1522 }
1523 }
1524 spin_unlock_irqrestore(&ihost->scic_lock, flags);
1525}
diff --git a/drivers/scsi/isci/remote_device.h b/drivers/scsi/isci/remote_device.h
index e1747ea0d0ea..483ee50152f3 100644
--- a/drivers/scsi/isci/remote_device.h
+++ b/drivers/scsi/isci/remote_device.h
@@ -132,10 +132,7 @@ void isci_remote_device_nuke_requests(struct isci_host *ihost,
132 struct isci_remote_device *idev); 132 struct isci_remote_device *idev);
133void isci_remote_device_gone(struct domain_device *domain_dev); 133void isci_remote_device_gone(struct domain_device *domain_dev);
134int isci_remote_device_found(struct domain_device *domain_dev); 134int isci_remote_device_found(struct domain_device *domain_dev);
135bool isci_device_is_reset_pending(struct isci_host *ihost, 135
136 struct isci_remote_device *idev);
137void isci_device_clear_reset_pending(struct isci_host *ihost,
138 struct isci_remote_device *idev);
139/** 136/**
140 * sci_remote_device_stop() - This method will stop both transmission and 137 * sci_remote_device_stop() - This method will stop both transmission and
141 * reception of link activity for the supplied remote device. This method 138 * reception of link activity for the supplied remote device. This method
diff --git a/drivers/scsi/isci/request.c b/drivers/scsi/isci/request.c
index 565a9f0a9bc2..192cb48d849a 100644
--- a/drivers/scsi/isci/request.c
+++ b/drivers/scsi/isci/request.c
@@ -191,7 +191,7 @@ static void sci_task_request_build_ssp_task_iu(struct isci_request *ireq)
191 191
192 task_iu->task_func = isci_tmf->tmf_code; 192 task_iu->task_func = isci_tmf->tmf_code;
193 task_iu->task_tag = 193 task_iu->task_tag =
194 (ireq->ttype == tmf_task) ? 194 (test_bit(IREQ_TMF, &ireq->flags)) ?
195 isci_tmf->io_tag : 195 isci_tmf->io_tag :
196 SCI_CONTROLLER_INVALID_IO_TAG; 196 SCI_CONTROLLER_INVALID_IO_TAG;
197} 197}
@@ -516,7 +516,7 @@ sci_io_request_construct_sata(struct isci_request *ireq,
516 struct domain_device *dev = ireq->target_device->domain_dev; 516 struct domain_device *dev = ireq->target_device->domain_dev;
517 517
518 /* check for management protocols */ 518 /* check for management protocols */
519 if (ireq->ttype == tmf_task) { 519 if (test_bit(IREQ_TMF, &ireq->flags)) {
520 struct isci_tmf *tmf = isci_request_access_tmf(ireq); 520 struct isci_tmf *tmf = isci_request_access_tmf(ireq);
521 521
522 if (tmf->tmf_code == isci_tmf_sata_srst_high || 522 if (tmf->tmf_code == isci_tmf_sata_srst_high ||
@@ -632,7 +632,7 @@ enum sci_status sci_task_request_construct_sata(struct isci_request *ireq)
632 enum sci_status status = SCI_SUCCESS; 632 enum sci_status status = SCI_SUCCESS;
633 633
634 /* check for management protocols */ 634 /* check for management protocols */
635 if (ireq->ttype == tmf_task) { 635 if (test_bit(IREQ_TMF, &ireq->flags)) {
636 struct isci_tmf *tmf = isci_request_access_tmf(ireq); 636 struct isci_tmf *tmf = isci_request_access_tmf(ireq);
637 637
638 if (tmf->tmf_code == isci_tmf_sata_srst_high || 638 if (tmf->tmf_code == isci_tmf_sata_srst_high ||
@@ -2630,14 +2630,8 @@ static void isci_task_save_for_upper_layer_completion(
2630 switch (task_notification_selection) { 2630 switch (task_notification_selection) {
2631 2631
2632 case isci_perform_normal_io_completion: 2632 case isci_perform_normal_io_completion:
2633
2634 /* Normal notification (task_done) */ 2633 /* Normal notification (task_done) */
2635 dev_dbg(&host->pdev->dev, 2634
2636 "%s: Normal - task = %p, response=%d (%d), status=%d (%d)\n",
2637 __func__,
2638 task,
2639 task->task_status.resp, response,
2640 task->task_status.stat, status);
2641 /* Add to the completed list. */ 2635 /* Add to the completed list. */
2642 list_add(&request->completed_node, 2636 list_add(&request->completed_node,
2643 &host->requests_to_complete); 2637 &host->requests_to_complete);
@@ -2650,13 +2644,6 @@ static void isci_task_save_for_upper_layer_completion(
2650 /* No notification to libsas because this request is 2644 /* No notification to libsas because this request is
2651 * already in the abort path. 2645 * already in the abort path.
2652 */ 2646 */
2653 dev_dbg(&host->pdev->dev,
2654 "%s: Aborted - task = %p, response=%d (%d), status=%d (%d)\n",
2655 __func__,
2656 task,
2657 task->task_status.resp, response,
2658 task->task_status.stat, status);
2659
2660 /* Wake up whatever process was waiting for this 2647 /* Wake up whatever process was waiting for this
2661 * request to complete. 2648 * request to complete.
2662 */ 2649 */
@@ -2673,30 +2660,22 @@ static void isci_task_save_for_upper_layer_completion(
2673 2660
2674 case isci_perform_error_io_completion: 2661 case isci_perform_error_io_completion:
2675 /* Use sas_task_abort */ 2662 /* Use sas_task_abort */
2676 dev_dbg(&host->pdev->dev,
2677 "%s: Error - task = %p, response=%d (%d), status=%d (%d)\n",
2678 __func__,
2679 task,
2680 task->task_status.resp, response,
2681 task->task_status.stat, status);
2682 /* Add to the aborted list. */ 2663 /* Add to the aborted list. */
2683 list_add(&request->completed_node, 2664 list_add(&request->completed_node,
2684 &host->requests_to_errorback); 2665 &host->requests_to_errorback);
2685 break; 2666 break;
2686 2667
2687 default: 2668 default:
2688 dev_dbg(&host->pdev->dev,
2689 "%s: Unknown - task = %p, response=%d (%d), status=%d (%d)\n",
2690 __func__,
2691 task,
2692 task->task_status.resp, response,
2693 task->task_status.stat, status);
2694
2695 /* Add to the error to libsas list. */ 2669 /* Add to the error to libsas list. */
2696 list_add(&request->completed_node, 2670 list_add(&request->completed_node,
2697 &host->requests_to_errorback); 2671 &host->requests_to_errorback);
2698 break; 2672 break;
2699 } 2673 }
2674 dev_dbg(&host->pdev->dev,
2675 "%s: %d - task = %p, response=%d (%d), status=%d (%d)\n",
2676 __func__, task_notification_selection, task,
2677 (task) ? task->task_status.resp : 0, response,
2678 (task) ? task->task_status.stat : 0, status);
2700} 2679}
2701 2680
2702static void isci_process_stp_response(struct sas_task *task, struct dev_to_host_fis *fis) 2681static void isci_process_stp_response(struct sas_task *task, struct dev_to_host_fis *fis)
@@ -2728,9 +2707,9 @@ static void isci_request_io_request_complete(struct isci_host *ihost,
2728 struct sas_task *task = isci_request_access_task(request); 2707 struct sas_task *task = isci_request_access_task(request);
2729 struct ssp_response_iu *resp_iu; 2708 struct ssp_response_iu *resp_iu;
2730 unsigned long task_flags; 2709 unsigned long task_flags;
2731 struct isci_remote_device *idev = isci_lookup_device(task->dev); 2710 struct isci_remote_device *idev = request->target_device;
2732 enum service_response response = SAS_TASK_UNDELIVERED; 2711 enum service_response response = SAS_TASK_UNDELIVERED;
2733 enum exec_status status = SAS_ABORTED_TASK; 2712 enum exec_status status = SAS_ABORTED_TASK;
2734 enum isci_request_status request_status; 2713 enum isci_request_status request_status;
2735 enum isci_completion_selection complete_to_host 2714 enum isci_completion_selection complete_to_host
2736 = isci_perform_normal_io_completion; 2715 = isci_perform_normal_io_completion;
@@ -3061,7 +3040,6 @@ static void isci_request_io_request_complete(struct isci_host *ihost,
3061 3040
3062 /* complete the io request to the core. */ 3041 /* complete the io request to the core. */
3063 sci_controller_complete_io(ihost, request->target_device, request); 3042 sci_controller_complete_io(ihost, request->target_device, request);
3064 isci_put_device(idev);
3065 3043
3066 /* set terminated handle so it cannot be completed or 3044 /* set terminated handle so it cannot be completed or
3067 * terminated again, and to cause any calls into abort 3045 * terminated again, and to cause any calls into abort
@@ -3080,7 +3058,7 @@ static void sci_request_started_state_enter(struct sci_base_state_machine *sm)
3080 /* XXX as hch said always creating an internal sas_task for tmf 3058 /* XXX as hch said always creating an internal sas_task for tmf
3081 * requests would simplify the driver 3059 * requests would simplify the driver
3082 */ 3060 */
3083 task = ireq->ttype == io_task ? isci_request_access_task(ireq) : NULL; 3061 task = (test_bit(IREQ_TMF, &ireq->flags)) ? NULL : isci_request_access_task(ireq);
3084 3062
3085 /* all unaccelerated request types (non ssp or ncq) handled with 3063 /* all unaccelerated request types (non ssp or ncq) handled with
3086 * substates 3064 * substates
@@ -3564,7 +3542,7 @@ static struct isci_request *isci_io_request_from_tag(struct isci_host *ihost,
3564 3542
3565 ireq = isci_request_from_tag(ihost, tag); 3543 ireq = isci_request_from_tag(ihost, tag);
3566 ireq->ttype_ptr.io_task_ptr = task; 3544 ireq->ttype_ptr.io_task_ptr = task;
3567 ireq->ttype = io_task; 3545 clear_bit(IREQ_TMF, &ireq->flags);
3568 task->lldd_task = ireq; 3546 task->lldd_task = ireq;
3569 3547
3570 return ireq; 3548 return ireq;
@@ -3578,7 +3556,7 @@ struct isci_request *isci_tmf_request_from_tag(struct isci_host *ihost,
3578 3556
3579 ireq = isci_request_from_tag(ihost, tag); 3557 ireq = isci_request_from_tag(ihost, tag);
3580 ireq->ttype_ptr.tmf_task_ptr = isci_tmf; 3558 ireq->ttype_ptr.tmf_task_ptr = isci_tmf;
3581 ireq->ttype = tmf_task; 3559 set_bit(IREQ_TMF, &ireq->flags);
3582 3560
3583 return ireq; 3561 return ireq;
3584} 3562}
diff --git a/drivers/scsi/isci/request.h b/drivers/scsi/isci/request.h
index f720b97b7bb5..be38933dd6df 100644
--- a/drivers/scsi/isci/request.h
+++ b/drivers/scsi/isci/request.h
@@ -77,11 +77,6 @@ enum isci_request_status {
77 dead = 0x07 77 dead = 0x07
78}; 78};
79 79
80enum task_type {
81 io_task = 0,
82 tmf_task = 1
83};
84
85enum sci_request_protocol { 80enum sci_request_protocol {
86 SCIC_NO_PROTOCOL, 81 SCIC_NO_PROTOCOL,
87 SCIC_SMP_PROTOCOL, 82 SCIC_SMP_PROTOCOL,
@@ -116,7 +111,6 @@ struct isci_request {
116 #define IREQ_ACTIVE 3 111 #define IREQ_ACTIVE 3
117 unsigned long flags; 112 unsigned long flags;
118 /* XXX kill ttype and ttype_ptr, allocate full sas_task */ 113 /* XXX kill ttype and ttype_ptr, allocate full sas_task */
119 enum task_type ttype;
120 union ttype_ptr_union { 114 union ttype_ptr_union {
121 struct sas_task *io_task_ptr; /* When ttype==io_task */ 115 struct sas_task *io_task_ptr; /* When ttype==io_task */
122 struct isci_tmf *tmf_task_ptr; /* When ttype==tmf_task */ 116 struct isci_tmf *tmf_task_ptr; /* When ttype==tmf_task */
diff --git a/drivers/scsi/isci/task.c b/drivers/scsi/isci/task.c
index e2d9418683ce..66ad3dc89498 100644
--- a/drivers/scsi/isci/task.c
+++ b/drivers/scsi/isci/task.c
@@ -212,16 +212,27 @@ int isci_task_execute_task(struct sas_task *task, int num, gfp_t gfp_flags)
212 task->task_state_flags &= ~SAS_TASK_AT_INITIATOR; 212 task->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
213 spin_unlock_irqrestore(&task->task_state_lock, flags); 213 spin_unlock_irqrestore(&task->task_state_lock, flags);
214 214
215 /* Indicate QUEUE_FULL so that the scsi 215 if (test_bit(IDEV_GONE, &idev->flags)) {
216 * midlayer retries. if the request 216
217 * failed for remote device reasons, 217 /* Indicate that the device
218 * it gets returned as 218 * is gone.
219 * SAS_TASK_UNDELIVERED next time 219 */
220 * through. 220 isci_task_refuse(ihost, task,
221 */ 221 SAS_TASK_UNDELIVERED,
222 isci_task_refuse(ihost, task, 222 SAS_DEVICE_UNKNOWN);
223 SAS_TASK_COMPLETE, 223 } else {
224 SAS_QUEUE_FULL); 224 /* Indicate QUEUE_FULL so that
225 * the scsi midlayer retries.
226 * If the request failed for
227 * remote device reasons, it
228 * gets returned as
229 * SAS_TASK_UNDELIVERED next
230 * time through.
231 */
232 isci_task_refuse(ihost, task,
233 SAS_TASK_COMPLETE,
234 SAS_QUEUE_FULL);
235 }
225 } 236 }
226 } 237 }
227 } 238 }
@@ -243,7 +254,7 @@ static enum sci_status isci_sata_management_task_request_build(struct isci_reque
243 struct isci_tmf *isci_tmf; 254 struct isci_tmf *isci_tmf;
244 enum sci_status status; 255 enum sci_status status;
245 256
246 if (tmf_task != ireq->ttype) 257 if (!test_bit(IREQ_TMF, &ireq->flags))
247 return SCI_FAILURE; 258 return SCI_FAILURE;
248 259
249 isci_tmf = isci_request_access_tmf(ireq); 260 isci_tmf = isci_request_access_tmf(ireq);
@@ -327,6 +338,60 @@ static struct isci_request *isci_task_request_build(struct isci_host *ihost,
327 return ireq; 338 return ireq;
328} 339}
329 340
341/**
342* isci_request_mark_zombie() - This function must be called with scic_lock held.
343*/
344static void isci_request_mark_zombie(struct isci_host *ihost, struct isci_request *ireq)
345{
346 struct completion *tmf_completion = NULL;
347 struct completion *req_completion;
348
349 /* Set the request state to "dead". */
350 ireq->status = dead;
351
352 req_completion = ireq->io_request_completion;
353 ireq->io_request_completion = NULL;
354
355 if (test_bit(IREQ_TMF, &ireq->flags)) {
356 /* Break links with the TMF request. */
357 struct isci_tmf *tmf = isci_request_access_tmf(ireq);
358
359 /* In the case where a task request is dying,
360 * the thread waiting on the complete will sit and
361 * timeout unless we wake it now. Since the TMF
362 * has a default error status, complete it here
363 * to wake the waiting thread.
364 */
365 if (tmf) {
366 tmf_completion = tmf->complete;
367 tmf->complete = NULL;
368 }
369 ireq->ttype_ptr.tmf_task_ptr = NULL;
370 dev_dbg(&ihost->pdev->dev, "%s: tmf_code %d, managed tag %#x\n",
371 __func__, tmf->tmf_code, tmf->io_tag);
372 } else {
373 /* Break links with the sas_task - the callback is done
374 * elsewhere.
375 */
376 struct sas_task *task = isci_request_access_task(ireq);
377
378 if (task)
379 task->lldd_task = NULL;
380
381 ireq->ttype_ptr.io_task_ptr = NULL;
382 }
383
384 dev_warn(&ihost->pdev->dev, "task context unrecoverable (tag: %#x)\n",
385 ireq->io_tag);
386
387 /* Don't force waiting threads to timeout. */
388 if (req_completion)
389 complete(req_completion);
390
391 if (tmf_completion != NULL)
392 complete(tmf_completion);
393}
394
330static int isci_task_execute_tmf(struct isci_host *ihost, 395static int isci_task_execute_tmf(struct isci_host *ihost,
331 struct isci_remote_device *idev, 396 struct isci_remote_device *idev,
332 struct isci_tmf *tmf, unsigned long timeout_ms) 397 struct isci_tmf *tmf, unsigned long timeout_ms)
@@ -364,6 +429,7 @@ static int isci_task_execute_tmf(struct isci_host *ihost,
364 429
365 /* Assign the pointer to the TMF's completion kernel wait structure. */ 430 /* Assign the pointer to the TMF's completion kernel wait structure. */
366 tmf->complete = &completion; 431 tmf->complete = &completion;
432 tmf->status = SCI_FAILURE_TIMEOUT;
367 433
368 ireq = isci_task_request_build(ihost, idev, tag, tmf); 434 ireq = isci_task_request_build(ihost, idev, tag, tmf);
369 if (!ireq) 435 if (!ireq)
@@ -399,18 +465,35 @@ static int isci_task_execute_tmf(struct isci_host *ihost,
399 msecs_to_jiffies(timeout_ms)); 465 msecs_to_jiffies(timeout_ms));
400 466
401 if (timeleft == 0) { 467 if (timeleft == 0) {
468 /* The TMF did not complete - this could be because
469 * of an unplug. Terminate the TMF request now.
470 */
402 spin_lock_irqsave(&ihost->scic_lock, flags); 471 spin_lock_irqsave(&ihost->scic_lock, flags);
403 472
404 if (tmf->cb_state_func != NULL) 473 if (tmf->cb_state_func != NULL)
405 tmf->cb_state_func(isci_tmf_timed_out, tmf, tmf->cb_data); 474 tmf->cb_state_func(isci_tmf_timed_out, tmf,
475 tmf->cb_data);
406 476
407 sci_controller_terminate_request(ihost, 477 sci_controller_terminate_request(ihost, idev, ireq);
408 idev,
409 ireq);
410 478
411 spin_unlock_irqrestore(&ihost->scic_lock, flags); 479 spin_unlock_irqrestore(&ihost->scic_lock, flags);
412 480
413 wait_for_completion(tmf->complete); 481 timeleft = wait_for_completion_timeout(
482 &completion,
483 msecs_to_jiffies(ISCI_TERMINATION_TIMEOUT_MSEC));
484
485 if (!timeleft) {
486 /* Strange condition - the termination of the TMF
487 * request timed-out.
488 */
489 spin_lock_irqsave(&ihost->scic_lock, flags);
490
491 /* If the TMF status has not changed, kill it. */
492 if (tmf->status == SCI_FAILURE_TIMEOUT)
493 isci_request_mark_zombie(ihost, ireq);
494
495 spin_unlock_irqrestore(&ihost->scic_lock, flags);
496 }
414 } 497 }
415 498
416 isci_print_tmf(tmf); 499 isci_print_tmf(tmf);
@@ -501,48 +584,17 @@ static enum isci_request_status isci_task_validate_request_to_abort(
501 return old_state; 584 return old_state;
502} 585}
503 586
504/** 587static int isci_request_is_dealloc_managed(enum isci_request_status stat)
505* isci_request_cleanup_completed_loiterer() - This function will take care of
506* the final cleanup on any request which has been explicitly terminated.
507* @isci_host: This parameter specifies the ISCI host object
508* @isci_device: This is the device to which the request is pending.
509* @isci_request: This parameter specifies the terminated request object.
510* @task: This parameter is the libsas I/O request.
511*/
512static void isci_request_cleanup_completed_loiterer(
513 struct isci_host *isci_host,
514 struct isci_remote_device *isci_device,
515 struct isci_request *isci_request,
516 struct sas_task *task)
517{ 588{
518 unsigned long flags; 589 switch (stat) {
519 590 case aborted:
520 dev_dbg(&isci_host->pdev->dev, 591 case aborting:
521 "%s: isci_device=%p, request=%p, task=%p\n", 592 case terminating:
522 __func__, isci_device, isci_request, task); 593 case completed:
523 594 case dead:
524 if (task != NULL) { 595 return true;
525 596 default:
526 spin_lock_irqsave(&task->task_state_lock, flags); 597 return false;
527 task->lldd_task = NULL;
528
529 task->task_state_flags &= ~SAS_TASK_NEED_DEV_RESET;
530
531 isci_set_task_doneflags(task);
532
533 /* If this task is not in the abort path, call task_done. */
534 if (!(task->task_state_flags & SAS_TASK_STATE_ABORTED)) {
535
536 spin_unlock_irqrestore(&task->task_state_lock, flags);
537 task->task_done(task);
538 } else
539 spin_unlock_irqrestore(&task->task_state_lock, flags);
540 }
541
542 if (isci_request != NULL) {
543 spin_lock_irqsave(&isci_host->scic_lock, flags);
544 list_del_init(&isci_request->dev_node);
545 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
546 } 598 }
547} 599}
548 600
@@ -563,11 +615,9 @@ static void isci_terminate_request_core(struct isci_host *ihost,
563 enum sci_status status = SCI_SUCCESS; 615 enum sci_status status = SCI_SUCCESS;
564 bool was_terminated = false; 616 bool was_terminated = false;
565 bool needs_cleanup_handling = false; 617 bool needs_cleanup_handling = false;
566 enum isci_request_status request_status;
567 unsigned long flags; 618 unsigned long flags;
568 unsigned long termination_completed = 1; 619 unsigned long termination_completed = 1;
569 struct completion *io_request_completion; 620 struct completion *io_request_completion;
570 struct sas_task *task;
571 621
572 dev_dbg(&ihost->pdev->dev, 622 dev_dbg(&ihost->pdev->dev,
573 "%s: device = %p; request = %p\n", 623 "%s: device = %p; request = %p\n",
@@ -577,10 +627,6 @@ static void isci_terminate_request_core(struct isci_host *ihost,
577 627
578 io_request_completion = isci_request->io_request_completion; 628 io_request_completion = isci_request->io_request_completion;
579 629
580 task = (isci_request->ttype == io_task)
581 ? isci_request_access_task(isci_request)
582 : NULL;
583
584 /* Note that we are not going to control 630 /* Note that we are not going to control
585 * the target to abort the request. 631 * the target to abort the request.
586 */ 632 */
@@ -619,42 +665,27 @@ static void isci_terminate_request_core(struct isci_host *ihost,
619 __func__, isci_request, io_request_completion); 665 __func__, isci_request, io_request_completion);
620 666
621 /* Wait here for the request to complete. */ 667 /* Wait here for the request to complete. */
622 #define TERMINATION_TIMEOUT_MSEC 500
623 termination_completed 668 termination_completed
624 = wait_for_completion_timeout( 669 = wait_for_completion_timeout(
625 io_request_completion, 670 io_request_completion,
626 msecs_to_jiffies(TERMINATION_TIMEOUT_MSEC)); 671 msecs_to_jiffies(ISCI_TERMINATION_TIMEOUT_MSEC));
627 672
628 if (!termination_completed) { 673 if (!termination_completed) {
629 674
630 /* The request to terminate has timed out. */ 675 /* The request to terminate has timed out. */
631 spin_lock_irqsave(&ihost->scic_lock, 676 spin_lock_irqsave(&ihost->scic_lock, flags);
632 flags);
633 677
634 /* Check for state changes. */ 678 /* Check for state changes. */
635 if (!test_bit(IREQ_TERMINATED, &isci_request->flags)) { 679 if (!test_bit(IREQ_TERMINATED,
680 &isci_request->flags)) {
636 681
637 /* The best we can do is to have the 682 /* The best we can do is to have the
638 * request die a silent death if it 683 * request die a silent death if it
639 * ever really completes. 684 * ever really completes.
640 *
641 * Set the request state to "dead",
642 * and clear the task pointer so that
643 * an actual completion event callback
644 * doesn't do anything.
645 */ 685 */
646 isci_request->status = dead; 686 isci_request_mark_zombie(ihost,
647 isci_request->io_request_completion 687 isci_request);
648 = NULL; 688 needs_cleanup_handling = true;
649
650 if (isci_request->ttype == io_task) {
651
652 /* Break links with the
653 * sas_task.
654 */
655 isci_request->ttype_ptr.io_task_ptr
656 = NULL;
657 }
658 } else 689 } else
659 termination_completed = 1; 690 termination_completed = 1;
660 691
@@ -691,29 +722,28 @@ static void isci_terminate_request_core(struct isci_host *ihost,
691 * needs to be detached and freed here. 722 * needs to be detached and freed here.
692 */ 723 */
693 spin_lock_irqsave(&isci_request->state_lock, flags); 724 spin_lock_irqsave(&isci_request->state_lock, flags);
694 request_status = isci_request->status; 725
695 726 needs_cleanup_handling
696 if ((isci_request->ttype == io_task) /* TMFs are in their own thread */ 727 = isci_request_is_dealloc_managed(
697 && ((request_status == aborted) 728 isci_request->status);
698 || (request_status == aborting) 729
699 || (request_status == terminating)
700 || (request_status == completed)
701 || (request_status == dead)
702 )
703 ) {
704
705 /* The completion routine won't free a request in
706 * the aborted/aborting/etc. states, so we do
707 * it here.
708 */
709 needs_cleanup_handling = true;
710 }
711 spin_unlock_irqrestore(&isci_request->state_lock, flags); 730 spin_unlock_irqrestore(&isci_request->state_lock, flags);
712 731
713 } 732 }
714 if (needs_cleanup_handling) 733 if (needs_cleanup_handling) {
715 isci_request_cleanup_completed_loiterer( 734
716 ihost, idev, isci_request, task); 735 dev_dbg(&ihost->pdev->dev,
736 "%s: cleanup isci_device=%p, request=%p\n",
737 __func__, idev, isci_request);
738
739 if (isci_request != NULL) {
740 spin_lock_irqsave(&ihost->scic_lock, flags);
741 isci_free_tag(ihost, isci_request->io_tag);
742 isci_request_change_state(isci_request, unallocated);
743 list_del_init(&isci_request->dev_node);
744 spin_unlock_irqrestore(&ihost->scic_lock, flags);
745 }
746 }
717 } 747 }
718} 748}
719 749
@@ -772,7 +802,9 @@ void isci_terminate_pending_requests(struct isci_host *ihost,
772 dev_dbg(&ihost->pdev->dev, 802 dev_dbg(&ihost->pdev->dev,
773 "%s: idev=%p request=%p; task=%p old_state=%d\n", 803 "%s: idev=%p request=%p; task=%p old_state=%d\n",
774 __func__, idev, ireq, 804 __func__, idev, ireq,
775 ireq->ttype == io_task ? isci_request_access_task(ireq) : NULL, 805 (!test_bit(IREQ_TMF, &ireq->flags)
806 ? isci_request_access_task(ireq)
807 : NULL),
776 old_state); 808 old_state);
777 809
778 /* If the old_state is started: 810 /* If the old_state is started:
@@ -889,22 +921,14 @@ int isci_task_lu_reset(struct domain_device *domain_device, u8 *lun)
889 "%s: domain_device=%p, isci_host=%p; isci_device=%p\n", 921 "%s: domain_device=%p, isci_host=%p; isci_device=%p\n",
890 __func__, domain_device, isci_host, isci_device); 922 __func__, domain_device, isci_host, isci_device);
891 923
892 if (isci_device) 924 if (!isci_device) {
893 set_bit(IDEV_EH, &isci_device->flags); 925 /* If the device is gone, stop the escalations. */
926 dev_dbg(&isci_host->pdev->dev, "%s: No dev\n", __func__);
894 927
895 /* If there is a device reset pending on any request in the 928 ret = TMF_RESP_FUNC_COMPLETE;
896 * device's list, fail this LUN reset request in order to
897 * escalate to the device reset.
898 */
899 if (!isci_device ||
900 isci_device_is_reset_pending(isci_host, isci_device)) {
901 dev_dbg(&isci_host->pdev->dev,
902 "%s: No dev (%p), or "
903 "RESET PENDING: domain_device=%p\n",
904 __func__, isci_device, domain_device);
905 ret = TMF_RESP_FUNC_FAILED;
906 goto out; 929 goto out;
907 } 930 }
931 set_bit(IDEV_EH, &isci_device->flags);
908 932
909 /* Send the task management part of the reset. */ 933 /* Send the task management part of the reset. */
910 if (sas_protocol_ata(domain_device->tproto)) { 934 if (sas_protocol_ata(domain_device->tproto)) {
@@ -1013,7 +1037,7 @@ int isci_task_abort_task(struct sas_task *task)
1013 struct isci_tmf tmf; 1037 struct isci_tmf tmf;
1014 int ret = TMF_RESP_FUNC_FAILED; 1038 int ret = TMF_RESP_FUNC_FAILED;
1015 unsigned long flags; 1039 unsigned long flags;
1016 bool any_dev_reset = false; 1040 int perform_termination = 0;
1017 1041
1018 /* Get the isci_request reference from the task. Note that 1042 /* Get the isci_request reference from the task. Note that
1019 * this check does not depend on the pending request list 1043 * this check does not depend on the pending request list
@@ -1035,89 +1059,34 @@ int isci_task_abort_task(struct sas_task *task)
1035 spin_unlock_irqrestore(&isci_host->scic_lock, flags); 1059 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
1036 1060
1037 dev_dbg(&isci_host->pdev->dev, 1061 dev_dbg(&isci_host->pdev->dev,
1038 "%s: task = %p\n", __func__, task); 1062 "%s: dev = %p, task = %p, old_request == %p\n",
1039 1063 __func__, isci_device, task, old_request);
1040 if (!isci_device || !old_request)
1041 goto out;
1042
1043 set_bit(IDEV_EH, &isci_device->flags);
1044
1045 /* This version of the driver will fail abort requests for
1046 * SATA/STP. Failing the abort request this way will cause the
1047 * SCSI error handler thread to escalate to LUN reset
1048 */
1049 if (sas_protocol_ata(task->task_proto)) {
1050 dev_dbg(&isci_host->pdev->dev,
1051 " task %p is for a STP/SATA device;"
1052 " returning TMF_RESP_FUNC_FAILED\n"
1053 " to cause a LUN reset...\n", task);
1054 goto out;
1055 }
1056 1064
1057 dev_dbg(&isci_host->pdev->dev, 1065 if (isci_device)
1058 "%s: old_request == %p\n", __func__, old_request); 1066 set_bit(IDEV_EH, &isci_device->flags);
1059
1060 any_dev_reset = isci_device_is_reset_pending(isci_host, isci_device);
1061
1062 spin_lock_irqsave(&task->task_state_lock, flags);
1063
1064 any_dev_reset = any_dev_reset || (task->task_state_flags & SAS_TASK_NEED_DEV_RESET);
1065 1067
1066 /* If the extraction of the request reference from the task 1068 /* Device reset conditions signalled in task_state_flags are the
1067 * failed, then the request has been completed (or if there is a 1069 * responsbility of libsas to observe at the start of the error
1068 * pending reset then this abort request function must be failed 1070 * handler thread.
1069 * in order to escalate to the target reset).
1070 */ 1071 */
1071 if ((old_request == NULL) || any_dev_reset) { 1072 if (!isci_device || !old_request) {
1072 1073 /* The request has already completed and there
1073 /* If the device reset task flag is set, fail the task 1074 * is nothing to do here other than to set the task
1074 * management request. Otherwise, the original request 1075 * done bit, and indicate that the task abort function
1075 * has completed. 1076 * was sucessful.
1076 */ 1077 */
1077 if (any_dev_reset) { 1078 spin_lock_irqsave(&task->task_state_lock, flags);
1078 1079 task->task_state_flags |= SAS_TASK_STATE_DONE;
1079 /* Turn off the task's DONE to make sure this 1080 task->task_state_flags &= ~(SAS_TASK_AT_INITIATOR |
1080 * task is escalated to a target reset. 1081 SAS_TASK_STATE_PENDING);
1081 */ 1082 spin_unlock_irqrestore(&task->task_state_lock, flags);
1082 task->task_state_flags &= ~SAS_TASK_STATE_DONE;
1083
1084 /* Make the reset happen as soon as possible. */
1085 task->task_state_flags |= SAS_TASK_NEED_DEV_RESET;
1086
1087 spin_unlock_irqrestore(&task->task_state_lock, flags);
1088
1089 /* Fail the task management request in order to
1090 * escalate to the target reset.
1091 */
1092 ret = TMF_RESP_FUNC_FAILED;
1093
1094 dev_dbg(&isci_host->pdev->dev,
1095 "%s: Failing task abort in order to "
1096 "escalate to target reset because\n"
1097 "SAS_TASK_NEED_DEV_RESET is set for "
1098 "task %p on dev %p\n",
1099 __func__, task, isci_device);
1100
1101
1102 } else {
1103 /* The request has already completed and there
1104 * is nothing to do here other than to set the task
1105 * done bit, and indicate that the task abort function
1106 * was sucessful.
1107 */
1108 isci_set_task_doneflags(task);
1109
1110 spin_unlock_irqrestore(&task->task_state_lock, flags);
1111 1083
1112 ret = TMF_RESP_FUNC_COMPLETE; 1084 ret = TMF_RESP_FUNC_COMPLETE;
1113 1085
1114 dev_dbg(&isci_host->pdev->dev, 1086 dev_dbg(&isci_host->pdev->dev,
1115 "%s: abort task not needed for %p\n", 1087 "%s: abort task not needed for %p\n",
1116 __func__, task); 1088 __func__, task);
1117 }
1118 goto out; 1089 goto out;
1119 } else {
1120 spin_unlock_irqrestore(&task->task_state_lock, flags);
1121 } 1090 }
1122 1091
1123 spin_lock_irqsave(&isci_host->scic_lock, flags); 1092 spin_lock_irqsave(&isci_host->scic_lock, flags);
@@ -1146,24 +1115,44 @@ int isci_task_abort_task(struct sas_task *task)
1146 goto out; 1115 goto out;
1147 } 1116 }
1148 if (task->task_proto == SAS_PROTOCOL_SMP || 1117 if (task->task_proto == SAS_PROTOCOL_SMP ||
1118 sas_protocol_ata(task->task_proto) ||
1149 test_bit(IREQ_COMPLETE_IN_TARGET, &old_request->flags)) { 1119 test_bit(IREQ_COMPLETE_IN_TARGET, &old_request->flags)) {
1150 1120
1151 spin_unlock_irqrestore(&isci_host->scic_lock, flags); 1121 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
1152 1122
1153 dev_dbg(&isci_host->pdev->dev, 1123 dev_dbg(&isci_host->pdev->dev,
1154 "%s: SMP request (%d)" 1124 "%s: %s request"
1155 " or complete_in_target (%d), thus no TMF\n", 1125 " or complete_in_target (%d), thus no TMF\n",
1156 __func__, (task->task_proto == SAS_PROTOCOL_SMP), 1126 __func__,
1127 ((task->task_proto == SAS_PROTOCOL_SMP)
1128 ? "SMP"
1129 : (sas_protocol_ata(task->task_proto)
1130 ? "SATA/STP"
1131 : "<other>")
1132 ),
1157 test_bit(IREQ_COMPLETE_IN_TARGET, &old_request->flags)); 1133 test_bit(IREQ_COMPLETE_IN_TARGET, &old_request->flags));
1158 1134
1159 /* Set the state on the task. */ 1135 if (test_bit(IREQ_COMPLETE_IN_TARGET, &old_request->flags)) {
1160 isci_task_all_done(task); 1136 spin_lock_irqsave(&task->task_state_lock, flags);
1161 1137 task->task_state_flags |= SAS_TASK_STATE_DONE;
1162 ret = TMF_RESP_FUNC_COMPLETE; 1138 task->task_state_flags &= ~(SAS_TASK_AT_INITIATOR |
1139 SAS_TASK_STATE_PENDING);
1140 spin_unlock_irqrestore(&task->task_state_lock, flags);
1141 ret = TMF_RESP_FUNC_COMPLETE;
1142 } else {
1143 spin_lock_irqsave(&task->task_state_lock, flags);
1144 task->task_state_flags &= ~(SAS_TASK_AT_INITIATOR |
1145 SAS_TASK_STATE_PENDING);
1146 spin_unlock_irqrestore(&task->task_state_lock, flags);
1147 }
1163 1148
1164 /* Stopping and SMP devices are not sent a TMF, and are not 1149 /* STP and SMP devices are not sent a TMF, but the
1165 * reset, but the outstanding I/O request is terminated below. 1150 * outstanding I/O request is terminated below. This is
1151 * because SATA/STP and SMP discovery path timeouts directly
1152 * call the abort task interface for cleanup.
1166 */ 1153 */
1154 perform_termination = 1;
1155
1167 } else { 1156 } else {
1168 /* Fill in the tmf stucture */ 1157 /* Fill in the tmf stucture */
1169 isci_task_build_abort_task_tmf(&tmf, isci_tmf_ssp_task_abort, 1158 isci_task_build_abort_task_tmf(&tmf, isci_tmf_ssp_task_abort,
@@ -1172,22 +1161,24 @@ int isci_task_abort_task(struct sas_task *task)
1172 1161
1173 spin_unlock_irqrestore(&isci_host->scic_lock, flags); 1162 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
1174 1163
1175 #define ISCI_ABORT_TASK_TIMEOUT_MS 500 /* half second timeout. */ 1164 #define ISCI_ABORT_TASK_TIMEOUT_MS 500 /* 1/2 second timeout */
1176 ret = isci_task_execute_tmf(isci_host, isci_device, &tmf, 1165 ret = isci_task_execute_tmf(isci_host, isci_device, &tmf,
1177 ISCI_ABORT_TASK_TIMEOUT_MS); 1166 ISCI_ABORT_TASK_TIMEOUT_MS);
1178 1167
1179 if (ret != TMF_RESP_FUNC_COMPLETE) 1168 if (ret == TMF_RESP_FUNC_COMPLETE)
1169 perform_termination = 1;
1170 else
1180 dev_dbg(&isci_host->pdev->dev, 1171 dev_dbg(&isci_host->pdev->dev,
1181 "%s: isci_task_send_tmf failed\n", 1172 "%s: isci_task_send_tmf failed\n", __func__);
1182 __func__);
1183 } 1173 }
1184 if (ret == TMF_RESP_FUNC_COMPLETE) { 1174 if (perform_termination) {
1185 set_bit(IREQ_COMPLETE_IN_TARGET, &old_request->flags); 1175 set_bit(IREQ_COMPLETE_IN_TARGET, &old_request->flags);
1186 1176
1187 /* Clean up the request on our side, and wait for the aborted 1177 /* Clean up the request on our side, and wait for the aborted
1188 * I/O to complete. 1178 * I/O to complete.
1189 */ 1179 */
1190 isci_terminate_request_core(isci_host, isci_device, old_request); 1180 isci_terminate_request_core(isci_host, isci_device,
1181 old_request);
1191 } 1182 }
1192 1183
1193 /* Make sure we do not leave a reference to aborted_io_completion */ 1184 /* Make sure we do not leave a reference to aborted_io_completion */
@@ -1288,7 +1279,8 @@ isci_task_request_complete(struct isci_host *ihost,
1288 enum sci_task_status completion_status) 1279 enum sci_task_status completion_status)
1289{ 1280{
1290 struct isci_tmf *tmf = isci_request_access_tmf(ireq); 1281 struct isci_tmf *tmf = isci_request_access_tmf(ireq);
1291 struct completion *tmf_complete; 1282 struct completion *tmf_complete = NULL;
1283 struct completion *request_complete = ireq->io_request_completion;
1292 1284
1293 dev_dbg(&ihost->pdev->dev, 1285 dev_dbg(&ihost->pdev->dev,
1294 "%s: request = %p, status=%d\n", 1286 "%s: request = %p, status=%d\n",
@@ -1296,255 +1288,53 @@ isci_task_request_complete(struct isci_host *ihost,
1296 1288
1297 isci_request_change_state(ireq, completed); 1289 isci_request_change_state(ireq, completed);
1298 1290
1299 tmf->status = completion_status;
1300 set_bit(IREQ_COMPLETE_IN_TARGET, &ireq->flags); 1291 set_bit(IREQ_COMPLETE_IN_TARGET, &ireq->flags);
1301 1292
1302 if (tmf->proto == SAS_PROTOCOL_SSP) { 1293 if (tmf) {
1303 memcpy(&tmf->resp.resp_iu, 1294 tmf->status = completion_status;
1304 &ireq->ssp.rsp, 1295
1305 SSP_RESP_IU_MAX_SIZE); 1296 if (tmf->proto == SAS_PROTOCOL_SSP) {
1306 } else if (tmf->proto == SAS_PROTOCOL_SATA) { 1297 memcpy(&tmf->resp.resp_iu,
1307 memcpy(&tmf->resp.d2h_fis, 1298 &ireq->ssp.rsp,
1308 &ireq->stp.rsp, 1299 SSP_RESP_IU_MAX_SIZE);
1309 sizeof(struct dev_to_host_fis)); 1300 } else if (tmf->proto == SAS_PROTOCOL_SATA) {
1301 memcpy(&tmf->resp.d2h_fis,
1302 &ireq->stp.rsp,
1303 sizeof(struct dev_to_host_fis));
1304 }
1305 /* PRINT_TMF( ((struct isci_tmf *)request->task)); */
1306 tmf_complete = tmf->complete;
1310 } 1307 }
1311
1312 /* PRINT_TMF( ((struct isci_tmf *)request->task)); */
1313 tmf_complete = tmf->complete;
1314
1315 sci_controller_complete_io(ihost, ireq->target_device, ireq); 1308 sci_controller_complete_io(ihost, ireq->target_device, ireq);
1316 /* set the 'terminated' flag handle to make sure it cannot be terminated 1309 /* set the 'terminated' flag handle to make sure it cannot be terminated
1317 * or completed again. 1310 * or completed again.
1318 */ 1311 */
1319 set_bit(IREQ_TERMINATED, &ireq->flags); 1312 set_bit(IREQ_TERMINATED, &ireq->flags);
1320 1313
1321 isci_request_change_state(ireq, unallocated); 1314 /* As soon as something is in the terminate path, deallocation is
1322 list_del_init(&ireq->dev_node); 1315 * managed there. Note that the final non-managed state of a task
1323 1316 * request is "completed".
1324 /* The task management part completes last. */ 1317 */
1325 complete(tmf_complete); 1318 if ((ireq->status == completed) ||
1326} 1319 !isci_request_is_dealloc_managed(ireq->status)) {
1327 1320 isci_request_change_state(ireq, unallocated);
1328static void isci_smp_task_timedout(unsigned long _task) 1321 isci_free_tag(ihost, ireq->io_tag);
1329{ 1322 list_del_init(&ireq->dev_node);
1330 struct sas_task *task = (void *) _task;
1331 unsigned long flags;
1332
1333 spin_lock_irqsave(&task->task_state_lock, flags);
1334 if (!(task->task_state_flags & SAS_TASK_STATE_DONE))
1335 task->task_state_flags |= SAS_TASK_STATE_ABORTED;
1336 spin_unlock_irqrestore(&task->task_state_lock, flags);
1337
1338 complete(&task->completion);
1339}
1340
1341static void isci_smp_task_done(struct sas_task *task)
1342{
1343 if (!del_timer(&task->timer))
1344 return;
1345 complete(&task->completion);
1346}
1347
1348static int isci_smp_execute_task(struct isci_host *ihost,
1349 struct domain_device *dev, void *req,
1350 int req_size, void *resp, int resp_size)
1351{
1352 int res, retry;
1353 struct sas_task *task = NULL;
1354
1355 for (retry = 0; retry < 3; retry++) {
1356 task = sas_alloc_task(GFP_KERNEL);
1357 if (!task)
1358 return -ENOMEM;
1359
1360 task->dev = dev;
1361 task->task_proto = dev->tproto;
1362 sg_init_one(&task->smp_task.smp_req, req, req_size);
1363 sg_init_one(&task->smp_task.smp_resp, resp, resp_size);
1364
1365 task->task_done = isci_smp_task_done;
1366
1367 task->timer.data = (unsigned long) task;
1368 task->timer.function = isci_smp_task_timedout;
1369 task->timer.expires = jiffies + 10*HZ;
1370 add_timer(&task->timer);
1371
1372 res = isci_task_execute_task(task, 1, GFP_KERNEL);
1373
1374 if (res) {
1375 del_timer(&task->timer);
1376 dev_dbg(&ihost->pdev->dev,
1377 "%s: executing SMP task failed:%d\n",
1378 __func__, res);
1379 goto ex_err;
1380 }
1381
1382 wait_for_completion(&task->completion);
1383 res = -ECOMM;
1384 if ((task->task_state_flags & SAS_TASK_STATE_ABORTED)) {
1385 dev_dbg(&ihost->pdev->dev,
1386 "%s: smp task timed out or aborted\n",
1387 __func__);
1388 isci_task_abort_task(task);
1389 if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) {
1390 dev_dbg(&ihost->pdev->dev,
1391 "%s: SMP task aborted and not done\n",
1392 __func__);
1393 goto ex_err;
1394 }
1395 }
1396 if (task->task_status.resp == SAS_TASK_COMPLETE &&
1397 task->task_status.stat == SAM_STAT_GOOD) {
1398 res = 0;
1399 break;
1400 }
1401 if (task->task_status.resp == SAS_TASK_COMPLETE &&
1402 task->task_status.stat == SAS_DATA_UNDERRUN) {
1403 /* no error, but return the number of bytes of
1404 * underrun */
1405 res = task->task_status.residual;
1406 break;
1407 }
1408 if (task->task_status.resp == SAS_TASK_COMPLETE &&
1409 task->task_status.stat == SAS_DATA_OVERRUN) {
1410 res = -EMSGSIZE;
1411 break;
1412 } else {
1413 dev_dbg(&ihost->pdev->dev,
1414 "%s: task to dev %016llx response: 0x%x "
1415 "status 0x%x\n", __func__,
1416 SAS_ADDR(dev->sas_addr),
1417 task->task_status.resp,
1418 task->task_status.stat);
1419 sas_free_task(task);
1420 task = NULL;
1421 }
1422 }
1423ex_err:
1424 BUG_ON(retry == 3 && task != NULL);
1425 sas_free_task(task);
1426 return res;
1427}
1428
1429#define DISCOVER_REQ_SIZE 16
1430#define DISCOVER_RESP_SIZE 56
1431
1432int isci_smp_get_phy_attached_dev_type(struct isci_host *ihost,
1433 struct domain_device *dev,
1434 int phy_id, int *adt)
1435{
1436 struct smp_resp *disc_resp;
1437 u8 *disc_req;
1438 int res;
1439
1440 disc_resp = kzalloc(DISCOVER_RESP_SIZE, GFP_KERNEL);
1441 if (!disc_resp)
1442 return -ENOMEM;
1443
1444 disc_req = kzalloc(DISCOVER_REQ_SIZE, GFP_KERNEL);
1445 if (disc_req) {
1446 disc_req[0] = SMP_REQUEST;
1447 disc_req[1] = SMP_DISCOVER;
1448 disc_req[9] = phy_id;
1449 } else {
1450 kfree(disc_resp);
1451 return -ENOMEM;
1452 }
1453 res = isci_smp_execute_task(ihost, dev, disc_req, DISCOVER_REQ_SIZE,
1454 disc_resp, DISCOVER_RESP_SIZE);
1455 if (!res) {
1456 if (disc_resp->result != SMP_RESP_FUNC_ACC)
1457 res = disc_resp->result;
1458 else
1459 *adt = disc_resp->disc.attached_dev_type;
1460 } 1323 }
1461 kfree(disc_req);
1462 kfree(disc_resp);
1463
1464 return res;
1465}
1466
1467static void isci_wait_for_smp_phy_reset(struct isci_remote_device *idev, int phy_num)
1468{
1469 struct domain_device *dev = idev->domain_dev;
1470 struct isci_port *iport = idev->isci_port;
1471 struct isci_host *ihost = iport->isci_host;
1472 int res, iteration = 0, attached_device_type;
1473 #define STP_WAIT_MSECS 25000
1474 unsigned long tmo = msecs_to_jiffies(STP_WAIT_MSECS);
1475 unsigned long deadline = jiffies + tmo;
1476 enum {
1477 SMP_PHYWAIT_PHYDOWN,
1478 SMP_PHYWAIT_PHYUP,
1479 SMP_PHYWAIT_DONE
1480 } phy_state = SMP_PHYWAIT_PHYDOWN;
1481
1482 /* While there is time, wait for the phy to go away and come back */
1483 while (time_is_after_jiffies(deadline) && phy_state != SMP_PHYWAIT_DONE) {
1484 int event = atomic_read(&iport->event);
1485
1486 ++iteration;
1487
1488 tmo = wait_event_timeout(ihost->eventq,
1489 event != atomic_read(&iport->event) ||
1490 !test_bit(IPORT_BCN_BLOCKED, &iport->flags),
1491 tmo);
1492 /* link down, stop polling */
1493 if (!test_bit(IPORT_BCN_BLOCKED, &iport->flags))
1494 break;
1495 1324
1496 dev_dbg(&ihost->pdev->dev, 1325 /* "request_complete" is set if the task was being terminated. */
1497 "%s: iport %p, iteration %d," 1326 if (request_complete)
1498 " phase %d: time_remaining %lu, bcns = %d\n", 1327 complete(request_complete);
1499 __func__, iport, iteration, phy_state,
1500 tmo, test_bit(IPORT_BCN_PENDING, &iport->flags));
1501
1502 res = isci_smp_get_phy_attached_dev_type(ihost, dev, phy_num,
1503 &attached_device_type);
1504 tmo = deadline - jiffies;
1505
1506 if (res) {
1507 dev_dbg(&ihost->pdev->dev,
1508 "%s: iteration %d, phase %d:"
1509 " SMP error=%d, time_remaining=%lu\n",
1510 __func__, iteration, phy_state, res, tmo);
1511 break;
1512 }
1513 dev_dbg(&ihost->pdev->dev,
1514 "%s: iport %p, iteration %d,"
1515 " phase %d: time_remaining %lu, bcns = %d, "
1516 "attdevtype = %x\n",
1517 __func__, iport, iteration, phy_state,
1518 tmo, test_bit(IPORT_BCN_PENDING, &iport->flags),
1519 attached_device_type);
1520
1521 switch (phy_state) {
1522 case SMP_PHYWAIT_PHYDOWN:
1523 /* Has the device gone away? */
1524 if (!attached_device_type)
1525 phy_state = SMP_PHYWAIT_PHYUP;
1526
1527 break;
1528
1529 case SMP_PHYWAIT_PHYUP:
1530 /* Has the device come back? */
1531 if (attached_device_type)
1532 phy_state = SMP_PHYWAIT_DONE;
1533 break;
1534
1535 case SMP_PHYWAIT_DONE:
1536 break;
1537 }
1538 1328
1539 } 1329 /* The task management part completes last. */
1540 dev_dbg(&ihost->pdev->dev, "%s: done\n", __func__); 1330 if (tmf_complete)
1331 complete(tmf_complete);
1541} 1332}
1542 1333
1543static int isci_reset_device(struct isci_host *ihost, 1334static int isci_reset_device(struct isci_host *ihost,
1544 struct isci_remote_device *idev) 1335 struct isci_remote_device *idev)
1545{ 1336{
1546 struct sas_phy *phy = sas_find_local_phy(idev->domain_dev); 1337 struct sas_phy *phy = sas_find_local_phy(idev->domain_dev);
1547 struct isci_port *iport = idev->isci_port;
1548 enum sci_status status; 1338 enum sci_status status;
1549 unsigned long flags; 1339 unsigned long flags;
1550 int rc; 1340 int rc;
@@ -1564,13 +1354,6 @@ static int isci_reset_device(struct isci_host *ihost,
1564 } 1354 }
1565 spin_unlock_irqrestore(&ihost->scic_lock, flags); 1355 spin_unlock_irqrestore(&ihost->scic_lock, flags);
1566 1356
1567 /* Make sure all pending requests are able to be fully terminated. */
1568 isci_device_clear_reset_pending(ihost, idev);
1569
1570 /* If this is a device on an expander, disable BCN processing. */
1571 if (!scsi_is_sas_phy_local(phy))
1572 set_bit(IPORT_BCN_BLOCKED, &iport->flags);
1573
1574 rc = sas_phy_reset(phy, true); 1357 rc = sas_phy_reset(phy, true);
1575 1358
1576 /* Terminate in-progress I/O now. */ 1359 /* Terminate in-progress I/O now. */
@@ -1581,21 +1364,6 @@ static int isci_reset_device(struct isci_host *ihost,
1581 status = sci_remote_device_reset_complete(idev); 1364 status = sci_remote_device_reset_complete(idev);
1582 spin_unlock_irqrestore(&ihost->scic_lock, flags); 1365 spin_unlock_irqrestore(&ihost->scic_lock, flags);
1583 1366
1584 /* If this is a device on an expander, bring the phy back up. */
1585 if (!scsi_is_sas_phy_local(phy)) {
1586 /* A phy reset will cause the device to go away then reappear.
1587 * Since libsas will take action on incoming BCNs (eg. remove
1588 * a device going through an SMP phy-control driven reset),
1589 * we need to wait until the phy comes back up before letting
1590 * discovery proceed in libsas.
1591 */
1592 isci_wait_for_smp_phy_reset(idev, phy->number);
1593
1594 spin_lock_irqsave(&ihost->scic_lock, flags);
1595 isci_port_bcn_enable(ihost, idev->isci_port);
1596 spin_unlock_irqrestore(&ihost->scic_lock, flags);
1597 }
1598
1599 if (status != SCI_SUCCESS) { 1367 if (status != SCI_SUCCESS) {
1600 dev_dbg(&ihost->pdev->dev, 1368 dev_dbg(&ihost->pdev->dev,
1601 "%s: sci_remote_device_reset_complete(%p) " 1369 "%s: sci_remote_device_reset_complete(%p) "
diff --git a/drivers/scsi/isci/task.h b/drivers/scsi/isci/task.h
index 15b18d158993..bc78c0a41d5c 100644
--- a/drivers/scsi/isci/task.h
+++ b/drivers/scsi/isci/task.h
@@ -58,6 +58,8 @@
58#include <scsi/sas_ata.h> 58#include <scsi/sas_ata.h>
59#include "host.h" 59#include "host.h"
60 60
61#define ISCI_TERMINATION_TIMEOUT_MSEC 500
62
61struct isci_request; 63struct isci_request;
62 64
63/** 65/**
@@ -224,35 +226,6 @@ enum isci_completion_selection {
224 isci_perform_error_io_completion /* Use sas_task_abort */ 226 isci_perform_error_io_completion /* Use sas_task_abort */
225}; 227};
226 228
227static inline void isci_set_task_doneflags(
228 struct sas_task *task)
229{
230 /* Since no futher action will be taken on this task,
231 * make sure to mark it complete from the lldd perspective.
232 */
233 task->task_state_flags |= SAS_TASK_STATE_DONE;
234 task->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
235 task->task_state_flags &= ~SAS_TASK_STATE_PENDING;
236}
237/**
238 * isci_task_all_done() - This function clears the task bits to indicate the
239 * LLDD is done with the task.
240 *
241 *
242 */
243static inline void isci_task_all_done(
244 struct sas_task *task)
245{
246 unsigned long flags;
247
248 /* Since no futher action will be taken on this task,
249 * make sure to mark it complete from the lldd perspective.
250 */
251 spin_lock_irqsave(&task->task_state_lock, flags);
252 isci_set_task_doneflags(task);
253 spin_unlock_irqrestore(&task->task_state_lock, flags);
254}
255
256/** 229/**
257 * isci_task_set_completion_status() - This function sets the completion status 230 * isci_task_set_completion_status() - This function sets the completion status
258 * for the request. 231 * for the request.
@@ -334,7 +307,9 @@ isci_task_set_completion_status(
334 /* Fall through to the normal case... */ 307 /* Fall through to the normal case... */
335 case isci_perform_normal_io_completion: 308 case isci_perform_normal_io_completion:
336 /* Normal notification (task_done) */ 309 /* Normal notification (task_done) */
337 isci_set_task_doneflags(task); 310 task->task_state_flags |= SAS_TASK_STATE_DONE;
311 task->task_state_flags &= ~(SAS_TASK_AT_INITIATOR |
312 SAS_TASK_STATE_PENDING);
338 break; 313 break;
339 default: 314 default:
340 WARN_ONCE(1, "unknown task_notification_selection: %d\n", 315 WARN_ONCE(1, "unknown task_notification_selection: %d\n",
diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index 23e706673d06..7c34d8e7cc75 100644
--- a/drivers/scsi/iscsi_tcp.c
+++ b/drivers/scsi/iscsi_tcp.c
@@ -35,6 +35,7 @@
35#include <linux/delay.h> 35#include <linux/delay.h>
36#include <linux/kfifo.h> 36#include <linux/kfifo.h>
37#include <linux/scatterlist.h> 37#include <linux/scatterlist.h>
38#include <linux/module.h>
38#include <net/tcp.h> 39#include <net/tcp.h>
39#include <scsi/scsi_cmnd.h> 40#include <scsi/scsi_cmnd.h>
40#include <scsi/scsi_device.h> 41#include <scsi/scsi_device.h>
diff --git a/drivers/scsi/libfc/fc_disc.c b/drivers/scsi/libfc/fc_disc.c
index b9cb8140b398..7269e928824a 100644
--- a/drivers/scsi/libfc/fc_disc.c
+++ b/drivers/scsi/libfc/fc_disc.c
@@ -35,6 +35,7 @@
35#include <linux/timer.h> 35#include <linux/timer.h>
36#include <linux/slab.h> 36#include <linux/slab.h>
37#include <linux/err.h> 37#include <linux/err.h>
38#include <linux/export.h>
38#include <asm/unaligned.h> 39#include <asm/unaligned.h>
39 40
40#include <scsi/fc/fc_gs.h> 41#include <scsi/fc/fc_gs.h>
diff --git a/drivers/scsi/libfc/fc_elsct.c b/drivers/scsi/libfc/fc_elsct.c
index 9b25969e2ad0..fb9161dc4ca6 100644
--- a/drivers/scsi/libfc/fc_elsct.c
+++ b/drivers/scsi/libfc/fc_elsct.c
@@ -21,6 +21,7 @@
21 * Provide interface to send ELS/CT FC frames 21 * Provide interface to send ELS/CT FC frames
22 */ 22 */
23 23
24#include <linux/export.h>
24#include <asm/unaligned.h> 25#include <asm/unaligned.h>
25#include <scsi/fc/fc_gs.h> 26#include <scsi/fc/fc_gs.h>
26#include <scsi/fc/fc_ns.h> 27#include <scsi/fc/fc_ns.h>
diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
index 7c055fdca45d..9de9db27e874 100644
--- a/drivers/scsi/libfc/fc_exch.c
+++ b/drivers/scsi/libfc/fc_exch.c
@@ -26,6 +26,7 @@
26#include <linux/timer.h> 26#include <linux/timer.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/err.h> 28#include <linux/err.h>
29#include <linux/export.h>
29 30
30#include <scsi/fc/fc_fc2.h> 31#include <scsi/fc/fc_fc2.h>
31 32
@@ -469,6 +470,7 @@ static int fc_seq_send(struct fc_lport *lport, struct fc_seq *sp,
469 struct fc_frame_header *fh = fc_frame_header_get(fp); 470 struct fc_frame_header *fh = fc_frame_header_get(fp);
470 int error; 471 int error;
471 u32 f_ctl; 472 u32 f_ctl;
473 u8 fh_type = fh->fh_type;
472 474
473 ep = fc_seq_exch(sp); 475 ep = fc_seq_exch(sp);
474 WARN_ON((ep->esb_stat & ESB_ST_SEQ_INIT) != ESB_ST_SEQ_INIT); 476 WARN_ON((ep->esb_stat & ESB_ST_SEQ_INIT) != ESB_ST_SEQ_INIT);
@@ -493,7 +495,7 @@ static int fc_seq_send(struct fc_lport *lport, struct fc_seq *sp,
493 */ 495 */
494 error = lport->tt.frame_send(lport, fp); 496 error = lport->tt.frame_send(lport, fp);
495 497
496 if (fh->fh_type == FC_TYPE_BLS) 498 if (fh_type == FC_TYPE_BLS)
497 return error; 499 return error;
498 500
499 /* 501 /*
@@ -1792,6 +1794,9 @@ restart:
1792 goto restart; 1794 goto restart;
1793 } 1795 }
1794 } 1796 }
1797 pool->next_index = 0;
1798 pool->left = FC_XID_UNKNOWN;
1799 pool->right = FC_XID_UNKNOWN;
1795 spin_unlock_bh(&pool->lock); 1800 spin_unlock_bh(&pool->lock);
1796} 1801}
1797 1802
@@ -2280,6 +2285,7 @@ struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport *lport,
2280 goto free_mempool; 2285 goto free_mempool;
2281 for_each_possible_cpu(cpu) { 2286 for_each_possible_cpu(cpu) {
2282 pool = per_cpu_ptr(mp->pool, cpu); 2287 pool = per_cpu_ptr(mp->pool, cpu);
2288 pool->next_index = 0;
2283 pool->left = FC_XID_UNKNOWN; 2289 pool->left = FC_XID_UNKNOWN;
2284 pool->right = FC_XID_UNKNOWN; 2290 pool->right = FC_XID_UNKNOWN;
2285 spin_lock_init(&pool->lock); 2291 spin_lock_init(&pool->lock);
diff --git a/drivers/scsi/libfc/fc_libfc.c b/drivers/scsi/libfc/fc_libfc.c
index b7735129f1f3..1bf9841ef154 100644
--- a/drivers/scsi/libfc/fc_libfc.c
+++ b/drivers/scsi/libfc/fc_libfc.c
@@ -21,6 +21,7 @@
21#include <linux/types.h> 21#include <linux/types.h>
22#include <linux/scatterlist.h> 22#include <linux/scatterlist.h>
23#include <linux/crc32.h> 23#include <linux/crc32.h>
24#include <linux/module.h>
24 25
25#include <scsi/libfc.h> 26#include <scsi/libfc.h>
26#include <scsi/fc_encode.h> 27#include <scsi/fc_encode.h>
diff --git a/drivers/scsi/libfc/fc_lport.c b/drivers/scsi/libfc/fc_lport.c
index 628f347404f9..e77094a587ed 100644
--- a/drivers/scsi/libfc/fc_lport.c
+++ b/drivers/scsi/libfc/fc_lport.c
@@ -89,6 +89,7 @@
89 89
90#include <linux/timer.h> 90#include <linux/timer.h>
91#include <linux/delay.h> 91#include <linux/delay.h>
92#include <linux/module.h>
92#include <linux/slab.h> 93#include <linux/slab.h>
93#include <asm/unaligned.h> 94#include <asm/unaligned.h>
94 95
@@ -1030,16 +1031,8 @@ static void fc_lport_enter_reset(struct fc_lport *lport)
1030 FCH_EVT_LIPRESET, 0); 1031 FCH_EVT_LIPRESET, 0);
1031 fc_vports_linkchange(lport); 1032 fc_vports_linkchange(lport);
1032 fc_lport_reset_locked(lport); 1033 fc_lport_reset_locked(lport);
1033 if (lport->link_up) { 1034 if (lport->link_up)
1034 /*
1035 * Wait upto resource allocation time out before
1036 * doing re-login since incomplete FIP exchanged
1037 * from last session may collide with exchanges
1038 * in new session.
1039 */
1040 msleep(lport->r_a_tov);
1041 fc_lport_enter_flogi(lport); 1035 fc_lport_enter_flogi(lport);
1042 }
1043} 1036}
1044 1037
1045/** 1038/**
@@ -1481,6 +1474,7 @@ void fc_lport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp,
1481 void *lp_arg) 1474 void *lp_arg)
1482{ 1475{
1483 struct fc_lport *lport = lp_arg; 1476 struct fc_lport *lport = lp_arg;
1477 struct fc_frame_header *fh;
1484 struct fc_els_flogi *flp; 1478 struct fc_els_flogi *flp;
1485 u32 did; 1479 u32 did;
1486 u16 csp_flags; 1480 u16 csp_flags;
@@ -1508,49 +1502,56 @@ void fc_lport_flogi_resp(struct fc_seq *sp, struct fc_frame *fp,
1508 goto err; 1502 goto err;
1509 } 1503 }
1510 1504
1505 fh = fc_frame_header_get(fp);
1511 did = fc_frame_did(fp); 1506 did = fc_frame_did(fp);
1512 if (fc_frame_payload_op(fp) == ELS_LS_ACC && did) { 1507 if (fh->fh_r_ctl != FC_RCTL_ELS_REP || did == 0 ||
1513 flp = fc_frame_payload_get(fp, sizeof(*flp)); 1508 fc_frame_payload_op(fp) != ELS_LS_ACC) {
1514 if (flp) { 1509 FC_LPORT_DBG(lport, "FLOGI not accepted or bad response\n");
1515 mfs = ntohs(flp->fl_csp.sp_bb_data) &
1516 FC_SP_BB_DATA_MASK;
1517 if (mfs >= FC_SP_MIN_MAX_PAYLOAD &&
1518 mfs < lport->mfs)
1519 lport->mfs = mfs;
1520 csp_flags = ntohs(flp->fl_csp.sp_features);
1521 r_a_tov = ntohl(flp->fl_csp.sp_r_a_tov);
1522 e_d_tov = ntohl(flp->fl_csp.sp_e_d_tov);
1523 if (csp_flags & FC_SP_FT_EDTR)
1524 e_d_tov /= 1000000;
1525
1526 lport->npiv_enabled = !!(csp_flags & FC_SP_FT_NPIV_ACC);
1527
1528 if ((csp_flags & FC_SP_FT_FPORT) == 0) {
1529 if (e_d_tov > lport->e_d_tov)
1530 lport->e_d_tov = e_d_tov;
1531 lport->r_a_tov = 2 * e_d_tov;
1532 fc_lport_set_port_id(lport, did, fp);
1533 printk(KERN_INFO "host%d: libfc: "
1534 "Port (%6.6x) entered "
1535 "point-to-point mode\n",
1536 lport->host->host_no, did);
1537 fc_lport_ptp_setup(lport, fc_frame_sid(fp),
1538 get_unaligned_be64(
1539 &flp->fl_wwpn),
1540 get_unaligned_be64(
1541 &flp->fl_wwnn));
1542 } else {
1543 lport->e_d_tov = e_d_tov;
1544 lport->r_a_tov = r_a_tov;
1545 fc_host_fabric_name(lport->host) =
1546 get_unaligned_be64(&flp->fl_wwnn);
1547 fc_lport_set_port_id(lport, did, fp);
1548 fc_lport_enter_dns(lport);
1549 }
1550 }
1551 } else {
1552 FC_LPORT_DBG(lport, "FLOGI RJT or bad response\n");
1553 fc_lport_error(lport, fp); 1510 fc_lport_error(lport, fp);
1511 goto err;
1512 }
1513
1514 flp = fc_frame_payload_get(fp, sizeof(*flp));
1515 if (!flp) {
1516 FC_LPORT_DBG(lport, "FLOGI bad response\n");
1517 fc_lport_error(lport, fp);
1518 goto err;
1519 }
1520
1521 mfs = ntohs(flp->fl_csp.sp_bb_data) &
1522 FC_SP_BB_DATA_MASK;
1523 if (mfs >= FC_SP_MIN_MAX_PAYLOAD &&
1524 mfs < lport->mfs)
1525 lport->mfs = mfs;
1526 csp_flags = ntohs(flp->fl_csp.sp_features);
1527 r_a_tov = ntohl(flp->fl_csp.sp_r_a_tov);
1528 e_d_tov = ntohl(flp->fl_csp.sp_e_d_tov);
1529 if (csp_flags & FC_SP_FT_EDTR)
1530 e_d_tov /= 1000000;
1531
1532 lport->npiv_enabled = !!(csp_flags & FC_SP_FT_NPIV_ACC);
1533
1534 if ((csp_flags & FC_SP_FT_FPORT) == 0) {
1535 if (e_d_tov > lport->e_d_tov)
1536 lport->e_d_tov = e_d_tov;
1537 lport->r_a_tov = 2 * e_d_tov;
1538 fc_lport_set_port_id(lport, did, fp);
1539 printk(KERN_INFO "host%d: libfc: "
1540 "Port (%6.6x) entered "
1541 "point-to-point mode\n",
1542 lport->host->host_no, did);
1543 fc_lport_ptp_setup(lport, fc_frame_sid(fp),
1544 get_unaligned_be64(
1545 &flp->fl_wwpn),
1546 get_unaligned_be64(
1547 &flp->fl_wwnn));
1548 } else {
1549 lport->e_d_tov = e_d_tov;
1550 lport->r_a_tov = r_a_tov;
1551 fc_host_fabric_name(lport->host) =
1552 get_unaligned_be64(&flp->fl_wwnn);
1553 fc_lport_set_port_id(lport, did, fp);
1554 fc_lport_enter_dns(lport);
1554 } 1555 }
1555 1556
1556out: 1557out:
diff --git a/drivers/scsi/libfc/fc_npiv.c b/drivers/scsi/libfc/fc_npiv.c
index f33b897e4784..9fbf78ed821b 100644
--- a/drivers/scsi/libfc/fc_npiv.c
+++ b/drivers/scsi/libfc/fc_npiv.c
@@ -22,6 +22,7 @@
22 */ 22 */
23 23
24#include <scsi/libfc.h> 24#include <scsi/libfc.h>
25#include <linux/export.h>
25 26
26/** 27/**
27 * fc_vport_create() - Create a new NPIV vport instance 28 * fc_vport_create() - Create a new NPIV vport instance
diff --git a/drivers/scsi/libfc/fc_rport.c b/drivers/scsi/libfc/fc_rport.c
index 760db7619446..b9e434844a69 100644
--- a/drivers/scsi/libfc/fc_rport.c
+++ b/drivers/scsi/libfc/fc_rport.c
@@ -51,6 +51,7 @@
51#include <linux/rcupdate.h> 51#include <linux/rcupdate.h>
52#include <linux/timer.h> 52#include <linux/timer.h>
53#include <linux/workqueue.h> 53#include <linux/workqueue.h>
54#include <linux/export.h>
54#include <asm/unaligned.h> 55#include <asm/unaligned.h>
55 56
56#include <scsi/libfc.h> 57#include <scsi/libfc.h>
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index d7c76f2eb636..143bbe448bec 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -26,6 +26,7 @@
26#include <linux/delay.h> 26#include <linux/delay.h>
27#include <linux/log2.h> 27#include <linux/log2.h>
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/module.h>
29#include <asm/unaligned.h> 30#include <asm/unaligned.h>
30#include <net/tcp.h> 31#include <net/tcp.h>
31#include <scsi/scsi_cmnd.h> 32#include <scsi/scsi_cmnd.h>
diff --git a/drivers/scsi/libiscsi_tcp.c b/drivers/scsi/libiscsi_tcp.c
index 09b232fd9a1b..5715a3d0a3d3 100644
--- a/drivers/scsi/libiscsi_tcp.c
+++ b/drivers/scsi/libiscsi_tcp.c
@@ -36,6 +36,7 @@
36#include <linux/delay.h> 36#include <linux/delay.h>
37#include <linux/kfifo.h> 37#include <linux/kfifo.h>
38#include <linux/scatterlist.h> 38#include <linux/scatterlist.h>
39#include <linux/module.h>
39#include <net/tcp.h> 40#include <net/tcp.h>
40#include <scsi/scsi_cmnd.h> 41#include <scsi/scsi_cmnd.h>
41#include <scsi/scsi_device.h> 42#include <scsi/scsi_device.h>
diff --git a/drivers/scsi/libsas/sas_host_smp.c b/drivers/scsi/libsas/sas_host_smp.c
index e1aa17840c5b..bb8f49269a68 100644
--- a/drivers/scsi/libsas/sas_host_smp.c
+++ b/drivers/scsi/libsas/sas_host_smp.c
@@ -11,6 +11,7 @@
11#include <linux/scatterlist.h> 11#include <linux/scatterlist.h>
12#include <linux/blkdev.h> 12#include <linux/blkdev.h>
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/export.h>
14 15
15#include "sas_internal.h" 16#include "sas_internal.h"
16 17
diff --git a/drivers/scsi/libsas/sas_scsi_host.c b/drivers/scsi/libsas/sas_scsi_host.c
index b2c4a7731656..b6e233d9a0a1 100644
--- a/drivers/scsi/libsas/sas_scsi_host.c
+++ b/drivers/scsi/libsas/sas_scsi_host.c
@@ -25,6 +25,7 @@
25 25
26#include <linux/kthread.h> 26#include <linux/kthread.h>
27#include <linux/firmware.h> 27#include <linux/firmware.h>
28#include <linux/export.h>
28#include <linux/ctype.h> 29#include <linux/ctype.h>
29 30
30#include "sas_internal.h" 31#include "sas_internal.h"
diff --git a/drivers/scsi/libsas/sas_task.c b/drivers/scsi/libsas/sas_task.c
index b13a3346894c..a78e5bd3e514 100644
--- a/drivers/scsi/libsas/sas_task.c
+++ b/drivers/scsi/libsas/sas_task.c
@@ -1,4 +1,5 @@
1#include <linux/kernel.h> 1#include <linux/kernel.h>
2#include <linux/export.h>
2#include <scsi/sas.h> 3#include <scsi/sas.h>
3#include <scsi/libsas.h> 4#include <scsi/libsas.h>
4 5
diff --git a/drivers/scsi/libsrp.c b/drivers/scsi/libsrp.c
index ff6a28ce9b69..0707ecdbaa32 100644
--- a/drivers/scsi/libsrp.c
+++ b/drivers/scsi/libsrp.c
@@ -23,6 +23,7 @@
23#include <linux/kfifo.h> 23#include <linux/kfifo.h>
24#include <linux/scatterlist.h> 24#include <linux/scatterlist.h>
25#include <linux/dma-mapping.h> 25#include <linux/dma-mapping.h>
26#include <linux/module.h>
26#include <scsi/scsi.h> 27#include <scsi/scsi.h>
27#include <scsi/scsi_cmnd.h> 28#include <scsi/scsi_cmnd.h>
28#include <scsi/scsi_tcq.h> 29#include <scsi/scsi_tcq.h>
diff --git a/drivers/scsi/lpfc/lpfc_attr.c b/drivers/scsi/lpfc/lpfc_attr.c
index 4b0333ee2d94..d0ebaeb7ef60 100644
--- a/drivers/scsi/lpfc/lpfc_attr.c
+++ b/drivers/scsi/lpfc/lpfc_attr.c
@@ -23,6 +23,7 @@
23#include <linux/delay.h> 23#include <linux/delay.h>
24#include <linux/pci.h> 24#include <linux/pci.h>
25#include <linux/interrupt.h> 25#include <linux/interrupt.h>
26#include <linux/module.h>
26#include <linux/aer.h> 27#include <linux/aer.h>
27#include <linux/gfp.h> 28#include <linux/gfp.h>
28#include <linux/kernel.h> 29#include <linux/kernel.h>
diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
index 2cd844f7058f..28382596fb9a 100644
--- a/drivers/scsi/lpfc/lpfc_debugfs.c
+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
@@ -20,6 +20,7 @@
20 20
21#include <linux/blkdev.h> 21#include <linux/blkdev.h>
22#include <linux/delay.h> 22#include <linux/delay.h>
23#include <linux/module.h>
23#include <linux/dma-mapping.h> 24#include <linux/dma-mapping.h>
24#include <linux/idr.h> 25#include <linux/idr.h>
25#include <linux/interrupt.h> 26#include <linux/interrupt.h>
diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index 907c94b9245d..55bc4fc7376f 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -24,6 +24,7 @@
24#include <linux/dma-mapping.h> 24#include <linux/dma-mapping.h>
25#include <linux/idr.h> 25#include <linux/idr.h>
26#include <linux/interrupt.h> 26#include <linux/interrupt.h>
27#include <linux/module.h>
27#include <linux/kthread.h> 28#include <linux/kthread.h>
28#include <linux/pci.h> 29#include <linux/pci.h>
29#include <linux/spinlock.h> 30#include <linux/spinlock.h>
diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
index 5b8790b3cf4b..2e1e54e5c3ae 100644
--- a/drivers/scsi/lpfc/lpfc_scsi.c
+++ b/drivers/scsi/lpfc/lpfc_scsi.c
@@ -21,6 +21,7 @@
21#include <linux/pci.h> 21#include <linux/pci.h>
22#include <linux/slab.h> 22#include <linux/slab.h>
23#include <linux/interrupt.h> 23#include <linux/interrupt.h>
24#include <linux/export.h>
24#include <linux/delay.h> 25#include <linux/delay.h>
25#include <asm/unaligned.h> 26#include <asm/unaligned.h>
26 27
diff --git a/drivers/scsi/mac53c94.c b/drivers/scsi/mac53c94.c
index 6c42dff0f4d3..e6173376605d 100644
--- a/drivers/scsi/mac53c94.c
+++ b/drivers/scsi/mac53c94.c
@@ -17,6 +17,7 @@
17#include <linux/stat.h> 17#include <linux/stat.h>
18#include <linux/spinlock.h> 18#include <linux/spinlock.h>
19#include <linux/interrupt.h> 19#include <linux/interrupt.h>
20#include <linux/module.h>
20#include <asm/dbdma.h> 21#include <asm/dbdma.h>
21#include <asm/io.h> 22#include <asm/io.h>
22#include <asm/pgtable.h> 23#include <asm/pgtable.h>
diff --git a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c
index 8883ca36f932..35bd13879fed 100644
--- a/drivers/scsi/megaraid/megaraid_mbox.c
+++ b/drivers/scsi/megaraid/megaraid_mbox.c
@@ -71,6 +71,7 @@
71 */ 71 */
72 72
73#include <linux/slab.h> 73#include <linux/slab.h>
74#include <linux/module.h>
74#include "megaraid_mbox.h" 75#include "megaraid_mbox.h"
75 76
76static int megaraid_init(void); 77static int megaraid_init(void);
diff --git a/drivers/scsi/mpt2sas/mpi/mpi2.h b/drivers/scsi/mpt2sas/mpi/mpi2.h
index 3105d5e8d908..8dc1b32918dd 100644
--- a/drivers/scsi/mpt2sas/mpi/mpi2.h
+++ b/drivers/scsi/mpt2sas/mpi/mpi2.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2000-2010 LSI Corporation. 2 * Copyright (c) 2000-2011 LSI Corporation.
3 * 3 *
4 * 4 *
5 * Name: mpi2.h 5 * Name: mpi2.h
@@ -8,7 +8,7 @@
8 * scatter/gather formats. 8 * scatter/gather formats.
9 * Creation Date: June 21, 2006 9 * Creation Date: June 21, 2006
10 * 10 *
11 * mpi2.h Version: 02.00.18 11 * mpi2.h Version: 02.00.20
12 * 12 *
13 * Version History 13 * Version History
14 * --------------- 14 * ---------------
@@ -66,6 +66,9 @@
66 * 08-11-10 02.00.17 Bumped MPI2_HEADER_VERSION_UNIT. 66 * 08-11-10 02.00.17 Bumped MPI2_HEADER_VERSION_UNIT.
67 * 11-10-10 02.00.18 Bumped MPI2_HEADER_VERSION_UNIT. 67 * 11-10-10 02.00.18 Bumped MPI2_HEADER_VERSION_UNIT.
68 * Added MPI2_IEEE_SGE_FLAGS_SYSTEMPLBCPI_ADDR define. 68 * Added MPI2_IEEE_SGE_FLAGS_SYSTEMPLBCPI_ADDR define.
69 * 02-23-11 02.00.19 Bumped MPI2_HEADER_VERSION_UNIT.
70 * Added MPI2_FUNCTION_SEND_HOST_MESSAGE.
71 * 03-09-11 02.00.20 Bumped MPI2_HEADER_VERSION_UNIT.
69 * -------------------------------------------------------------------------- 72 * --------------------------------------------------------------------------
70 */ 73 */
71 74
@@ -91,7 +94,7 @@
91#define MPI2_VERSION_02_00 (0x0200) 94#define MPI2_VERSION_02_00 (0x0200)
92 95
93/* versioning for this MPI header set */ 96/* versioning for this MPI header set */
94#define MPI2_HEADER_VERSION_UNIT (0x12) 97#define MPI2_HEADER_VERSION_UNIT (0x14)
95#define MPI2_HEADER_VERSION_DEV (0x00) 98#define MPI2_HEADER_VERSION_DEV (0x00)
96#define MPI2_HEADER_VERSION_UNIT_MASK (0xFF00) 99#define MPI2_HEADER_VERSION_UNIT_MASK (0xFF00)
97#define MPI2_HEADER_VERSION_UNIT_SHIFT (8) 100#define MPI2_HEADER_VERSION_UNIT_SHIFT (8)
@@ -515,6 +518,8 @@ typedef union _MPI2_REPLY_DESCRIPTORS_UNION
515#define MPI2_FUNCTION_HOST_BASED_DISCOVERY_ACTION (0x2F) 518#define MPI2_FUNCTION_HOST_BASED_DISCOVERY_ACTION (0x2F)
516/* Power Management Control */ 519/* Power Management Control */
517#define MPI2_FUNCTION_PWR_MGMT_CONTROL (0x30) 520#define MPI2_FUNCTION_PWR_MGMT_CONTROL (0x30)
521/* Send Host Message */
522#define MPI2_FUNCTION_SEND_HOST_MESSAGE (0x31)
518/* beginning of product-specific range */ 523/* beginning of product-specific range */
519#define MPI2_FUNCTION_MIN_PRODUCT_SPECIFIC (0xF0) 524#define MPI2_FUNCTION_MIN_PRODUCT_SPECIFIC (0xF0)
520/* end of product-specific range */ 525/* end of product-specific range */
diff --git a/drivers/scsi/mpt2sas/mpi/mpi2_cnfg.h b/drivers/scsi/mpt2sas/mpi/mpi2_cnfg.h
index 61475a6480e3..cfd95b4e3004 100644
--- a/drivers/scsi/mpt2sas/mpi/mpi2_cnfg.h
+++ b/drivers/scsi/mpt2sas/mpi/mpi2_cnfg.h
@@ -1,12 +1,12 @@
1/* 1/*
2 * Copyright (c) 2000-2010 LSI Corporation. 2 * Copyright (c) 2000-2011 LSI Corporation.
3 * 3 *
4 * 4 *
5 * Name: mpi2_cnfg.h 5 * Name: mpi2_cnfg.h
6 * Title: MPI Configuration messages and pages 6 * Title: MPI Configuration messages and pages
7 * Creation Date: November 10, 2006 7 * Creation Date: November 10, 2006
8 * 8 *
9 * mpi2_cnfg.h Version: 02.00.17 9 * mpi2_cnfg.h Version: 02.00.19
10 * 10 *
11 * Version History 11 * Version History
12 * --------------- 12 * ---------------
@@ -134,6 +134,12 @@
134 * to MPI2_CONFIG_PAGE_IO_UNIT_7. 134 * to MPI2_CONFIG_PAGE_IO_UNIT_7.
135 * Added MPI2_CONFIG_EXTPAGETYPE_EXT_MANUFACTURING define 135 * Added MPI2_CONFIG_EXTPAGETYPE_EXT_MANUFACTURING define
136 * and MPI2_CONFIG_PAGE_EXT_MAN_PS structure. 136 * and MPI2_CONFIG_PAGE_EXT_MAN_PS structure.
137 * 02-23-11 02.00.18 Added ProxyVF_ID field to MPI2_CONFIG_REQUEST.
138 * Added IO Unit Page 8, IO Unit Page 9,
139 * and IO Unit Page 10.
140 * Added SASNotifyPrimitiveMasks field to
141 * MPI2_CONFIG_PAGE_IOC_7.
142 * 03-09-11 02.00.19 Fixed IO Unit Page 10 (to match the spec).
137 * -------------------------------------------------------------------------- 143 * --------------------------------------------------------------------------
138 */ 144 */
139 145
@@ -329,7 +335,9 @@ typedef struct _MPI2_CONFIG_REQUEST
329 U8 VP_ID; /* 0x08 */ 335 U8 VP_ID; /* 0x08 */
330 U8 VF_ID; /* 0x09 */ 336 U8 VF_ID; /* 0x09 */
331 U16 Reserved1; /* 0x0A */ 337 U16 Reserved1; /* 0x0A */
332 U32 Reserved2; /* 0x0C */ 338 U8 Reserved2; /* 0x0C */
339 U8 ProxyVF_ID; /* 0x0D */
340 U16 Reserved4; /* 0x0E */
333 U32 Reserved3; /* 0x10 */ 341 U32 Reserved3; /* 0x10 */
334 MPI2_CONFIG_PAGE_HEADER Header; /* 0x14 */ 342 MPI2_CONFIG_PAGE_HEADER Header; /* 0x14 */
335 U32 PageAddress; /* 0x18 */ 343 U32 PageAddress; /* 0x18 */
@@ -915,6 +923,120 @@ typedef struct _MPI2_CONFIG_PAGE_IO_UNIT_7 {
915#define MPI2_IOUNITPAGE7_BOARD_TEMP_FAHRENHEIT (0x01) 923#define MPI2_IOUNITPAGE7_BOARD_TEMP_FAHRENHEIT (0x01)
916#define MPI2_IOUNITPAGE7_BOARD_TEMP_CELSIUS (0x02) 924#define MPI2_IOUNITPAGE7_BOARD_TEMP_CELSIUS (0x02)
917 925
926/* IO Unit Page 8 */
927
928#define MPI2_IOUNIT8_NUM_THRESHOLDS (4)
929
930typedef struct _MPI2_IOUNIT8_SENSOR {
931 U16 Flags; /* 0x00 */
932 U16 Reserved1; /* 0x02 */
933 U16
934 Threshold[MPI2_IOUNIT8_NUM_THRESHOLDS]; /* 0x04 */
935 U32 Reserved2; /* 0x0C */
936 U32 Reserved3; /* 0x10 */
937 U32 Reserved4; /* 0x14 */
938} MPI2_IOUNIT8_SENSOR, MPI2_POINTER PTR_MPI2_IOUNIT8_SENSOR,
939Mpi2IOUnit8Sensor_t, MPI2_POINTER pMpi2IOUnit8Sensor_t;
940
941/* defines for IO Unit Page 8 Sensor Flags field */
942#define MPI2_IOUNIT8_SENSOR_FLAGS_T3_ENABLE (0x0008)
943#define MPI2_IOUNIT8_SENSOR_FLAGS_T2_ENABLE (0x0004)
944#define MPI2_IOUNIT8_SENSOR_FLAGS_T1_ENABLE (0x0002)
945#define MPI2_IOUNIT8_SENSOR_FLAGS_T0_ENABLE (0x0001)
946
947/*
948 * Host code (drivers, BIOS, utilities, etc.) should leave this define set to
949 * one and check the value returned for NumSensors at runtime.
950 */
951#ifndef MPI2_IOUNITPAGE8_SENSOR_ENTRIES
952#define MPI2_IOUNITPAGE8_SENSOR_ENTRIES (1)
953#endif
954
955typedef struct _MPI2_CONFIG_PAGE_IO_UNIT_8 {
956 MPI2_CONFIG_PAGE_HEADER Header; /* 0x00 */
957 U32 Reserved1; /* 0x04 */
958 U32 Reserved2; /* 0x08 */
959 U8 NumSensors; /* 0x0C */
960 U8 PollingInterval; /* 0x0D */
961 U16 Reserved3; /* 0x0E */
962 MPI2_IOUNIT8_SENSOR
963 Sensor[MPI2_IOUNITPAGE8_SENSOR_ENTRIES];/* 0x10 */
964} MPI2_CONFIG_PAGE_IO_UNIT_8, MPI2_POINTER PTR_MPI2_CONFIG_PAGE_IO_UNIT_8,
965Mpi2IOUnitPage8_t, MPI2_POINTER pMpi2IOUnitPage8_t;
966
967#define MPI2_IOUNITPAGE8_PAGEVERSION (0x00)
968
969
970/* IO Unit Page 9 */
971
972typedef struct _MPI2_IOUNIT9_SENSOR {
973 U16 CurrentTemperature; /* 0x00 */
974 U16 Reserved1; /* 0x02 */
975 U8 Flags; /* 0x04 */
976 U8 Reserved2; /* 0x05 */
977 U16 Reserved3; /* 0x06 */
978 U32 Reserved4; /* 0x08 */
979 U32 Reserved5; /* 0x0C */
980} MPI2_IOUNIT9_SENSOR, MPI2_POINTER PTR_MPI2_IOUNIT9_SENSOR,
981Mpi2IOUnit9Sensor_t, MPI2_POINTER pMpi2IOUnit9Sensor_t;
982
983/* defines for IO Unit Page 9 Sensor Flags field */
984#define MPI2_IOUNIT9_SENSOR_FLAGS_TEMP_VALID (0x01)
985
986/*
987 * Host code (drivers, BIOS, utilities, etc.) should leave this define set to
988 * one and check the value returned for NumSensors at runtime.
989 */
990#ifndef MPI2_IOUNITPAGE9_SENSOR_ENTRIES
991#define MPI2_IOUNITPAGE9_SENSOR_ENTRIES (1)
992#endif
993
994typedef struct _MPI2_CONFIG_PAGE_IO_UNIT_9 {
995 MPI2_CONFIG_PAGE_HEADER Header; /* 0x00 */
996 U32 Reserved1; /* 0x04 */
997 U32 Reserved2; /* 0x08 */
998 U8 NumSensors; /* 0x0C */
999 U8 Reserved4; /* 0x0D */
1000 U16 Reserved3; /* 0x0E */
1001 MPI2_IOUNIT9_SENSOR
1002 Sensor[MPI2_IOUNITPAGE9_SENSOR_ENTRIES];/* 0x10 */
1003} MPI2_CONFIG_PAGE_IO_UNIT_9, MPI2_POINTER PTR_MPI2_CONFIG_PAGE_IO_UNIT_9,
1004Mpi2IOUnitPage9_t, MPI2_POINTER pMpi2IOUnitPage9_t;
1005
1006#define MPI2_IOUNITPAGE9_PAGEVERSION (0x00)
1007
1008
1009/* IO Unit Page 10 */
1010
1011typedef struct _MPI2_IOUNIT10_FUNCTION {
1012 U8 CreditPercent; /* 0x00 */
1013 U8 Reserved1; /* 0x01 */
1014 U16 Reserved2; /* 0x02 */
1015} MPI2_IOUNIT10_FUNCTION, MPI2_POINTER PTR_MPI2_IOUNIT10_FUNCTION,
1016Mpi2IOUnit10Function_t, MPI2_POINTER pMpi2IOUnit10Function_t;
1017
1018/*
1019 * Host code (drivers, BIOS, utilities, etc.) should leave this define set to
1020 * one and check the value returned for NumFunctions at runtime.
1021 */
1022#ifndef MPI2_IOUNITPAGE10_FUNCTION_ENTRIES
1023#define MPI2_IOUNITPAGE10_FUNCTION_ENTRIES (1)
1024#endif
1025
1026typedef struct _MPI2_CONFIG_PAGE_IO_UNIT_10 {
1027 MPI2_CONFIG_PAGE_HEADER Header; /* 0x00 */
1028 U8 NumFunctions; /* 0x04 */
1029 U8 Reserved1; /* 0x05 */
1030 U16 Reserved2; /* 0x06 */
1031 U32 Reserved3; /* 0x08 */
1032 U32 Reserved4; /* 0x0C */
1033 MPI2_IOUNIT10_FUNCTION
1034 Function[MPI2_IOUNITPAGE10_FUNCTION_ENTRIES];/* 0x10 */
1035} MPI2_CONFIG_PAGE_IO_UNIT_10, MPI2_POINTER PTR_MPI2_CONFIG_PAGE_IO_UNIT_10,
1036Mpi2IOUnitPage10_t, MPI2_POINTER pMpi2IOUnitPage10_t;
1037
1038#define MPI2_IOUNITPAGE10_PAGEVERSION (0x01)
1039
918 1040
919 1041
920/**************************************************************************** 1042/****************************************************************************
@@ -1022,12 +1144,12 @@ typedef struct _MPI2_CONFIG_PAGE_IOC_7
1022 U32 Reserved1; /* 0x04 */ 1144 U32 Reserved1; /* 0x04 */
1023 U32 EventMasks[MPI2_IOCPAGE7_EVENTMASK_WORDS];/* 0x08 */ 1145 U32 EventMasks[MPI2_IOCPAGE7_EVENTMASK_WORDS];/* 0x08 */
1024 U16 SASBroadcastPrimitiveMasks; /* 0x18 */ 1146 U16 SASBroadcastPrimitiveMasks; /* 0x18 */
1025 U16 Reserved2; /* 0x1A */ 1147 U16 SASNotifyPrimitiveMasks; /* 0x1A */
1026 U32 Reserved3; /* 0x1C */ 1148 U32 Reserved3; /* 0x1C */
1027} MPI2_CONFIG_PAGE_IOC_7, MPI2_POINTER PTR_MPI2_CONFIG_PAGE_IOC_7, 1149} MPI2_CONFIG_PAGE_IOC_7, MPI2_POINTER PTR_MPI2_CONFIG_PAGE_IOC_7,
1028 Mpi2IOCPage7_t, MPI2_POINTER pMpi2IOCPage7_t; 1150 Mpi2IOCPage7_t, MPI2_POINTER pMpi2IOCPage7_t;
1029 1151
1030#define MPI2_IOCPAGE7_PAGEVERSION (0x01) 1152#define MPI2_IOCPAGE7_PAGEVERSION (0x02)
1031 1153
1032 1154
1033/* IOC Page 8 */ 1155/* IOC Page 8 */
@@ -2070,16 +2192,16 @@ typedef struct _MPI2_CONFIG_PAGE_SASIOUNIT_8 {
2070#define MPI2_SASIOUNITPAGE8_PAGEVERSION (0x00) 2192#define MPI2_SASIOUNITPAGE8_PAGEVERSION (0x00)
2071 2193
2072/* defines for PowerManagementCapabilities field */ 2194/* defines for PowerManagementCapabilities field */
2073#define MPI2_SASIOUNIT8_PM_HOST_PORT_WIDTH_MOD (0x000001000) 2195#define MPI2_SASIOUNIT8_PM_HOST_PORT_WIDTH_MOD (0x00001000)
2074#define MPI2_SASIOUNIT8_PM_HOST_SAS_SLUMBER_MODE (0x000000800) 2196#define MPI2_SASIOUNIT8_PM_HOST_SAS_SLUMBER_MODE (0x00000800)
2075#define MPI2_SASIOUNIT8_PM_HOST_SAS_PARTIAL_MODE (0x000000400) 2197#define MPI2_SASIOUNIT8_PM_HOST_SAS_PARTIAL_MODE (0x00000400)
2076#define MPI2_SASIOUNIT8_PM_HOST_SATA_SLUMBER_MODE (0x000000200) 2198#define MPI2_SASIOUNIT8_PM_HOST_SATA_SLUMBER_MODE (0x00000200)
2077#define MPI2_SASIOUNIT8_PM_HOST_SATA_PARTIAL_MODE (0x000000100) 2199#define MPI2_SASIOUNIT8_PM_HOST_SATA_PARTIAL_MODE (0x00000100)
2078#define MPI2_SASIOUNIT8_PM_IOUNIT_PORT_WIDTH_MOD (0x000000010) 2200#define MPI2_SASIOUNIT8_PM_IOUNIT_PORT_WIDTH_MOD (0x00000010)
2079#define MPI2_SASIOUNIT8_PM_IOUNIT_SAS_SLUMBER_MODE (0x000000008) 2201#define MPI2_SASIOUNIT8_PM_IOUNIT_SAS_SLUMBER_MODE (0x00000008)
2080#define MPI2_SASIOUNIT8_PM_IOUNIT_SAS_PARTIAL_MODE (0x000000004) 2202#define MPI2_SASIOUNIT8_PM_IOUNIT_SAS_PARTIAL_MODE (0x00000004)
2081#define MPI2_SASIOUNIT8_PM_IOUNIT_SATA_SLUMBER_MODE (0x000000002) 2203#define MPI2_SASIOUNIT8_PM_IOUNIT_SATA_SLUMBER_MODE (0x00000002)
2082#define MPI2_SASIOUNIT8_PM_IOUNIT_SATA_PARTIAL_MODE (0x000000001) 2204#define MPI2_SASIOUNIT8_PM_IOUNIT_SATA_PARTIAL_MODE (0x00000001)
2083 2205
2084 2206
2085 2207
@@ -2266,6 +2388,7 @@ typedef struct _MPI2_CONFIG_PAGE_SAS_DEV_0
2266/* see mpi2_sas.h for values for SAS Device Page 0 DeviceInfo values */ 2388/* see mpi2_sas.h for values for SAS Device Page 0 DeviceInfo values */
2267 2389
2268/* values for SAS Device Page 0 Flags field */ 2390/* values for SAS Device Page 0 Flags field */
2391#define MPI2_SAS_DEVICE0_FLAGS_UNAUTHORIZED_DEVICE (0x8000)
2269#define MPI2_SAS_DEVICE0_FLAGS_SLUMBER_PM_CAPABLE (0x1000) 2392#define MPI2_SAS_DEVICE0_FLAGS_SLUMBER_PM_CAPABLE (0x1000)
2270#define MPI2_SAS_DEVICE0_FLAGS_PARTIAL_PM_CAPABLE (0x0800) 2393#define MPI2_SAS_DEVICE0_FLAGS_PARTIAL_PM_CAPABLE (0x0800)
2271#define MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY (0x0400) 2394#define MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY (0x0400)
diff --git a/drivers/scsi/mpt2sas/mpi/mpi2_ioc.h b/drivers/scsi/mpt2sas/mpi/mpi2_ioc.h
index 1f0c190d336e..93d9b6956d05 100644
--- a/drivers/scsi/mpt2sas/mpi/mpi2_ioc.h
+++ b/drivers/scsi/mpt2sas/mpi/mpi2_ioc.h
@@ -1,12 +1,12 @@
1/* 1/*
2 * Copyright (c) 2000-2010 LSI Corporation. 2 * Copyright (c) 2000-2011 LSI Corporation.
3 * 3 *
4 * 4 *
5 * Name: mpi2_ioc.h 5 * Name: mpi2_ioc.h
6 * Title: MPI IOC, Port, Event, FW Download, and FW Upload messages 6 * Title: MPI IOC, Port, Event, FW Download, and FW Upload messages
7 * Creation Date: October 11, 2006 7 * Creation Date: October 11, 2006
8 * 8 *
9 * mpi2_ioc.h Version: 02.00.16 9 * mpi2_ioc.h Version: 02.00.17
10 * 10 *
11 * Version History 11 * Version History
12 * --------------- 12 * ---------------
@@ -104,6 +104,12 @@
104 * 05-12-10 02.00.15 Marked Task Set Full Event as obsolete. 104 * 05-12-10 02.00.15 Marked Task Set Full Event as obsolete.
105 * Added MPI2_EVENT_SAS_TOPO_LR_UNSUPPORTED_PHY define. 105 * Added MPI2_EVENT_SAS_TOPO_LR_UNSUPPORTED_PHY define.
106 * 11-10-10 02.00.16 Added MPI2_FW_DOWNLOAD_ITYPE_MIN_PRODUCT_SPECIFIC. 106 * 11-10-10 02.00.16 Added MPI2_FW_DOWNLOAD_ITYPE_MIN_PRODUCT_SPECIFIC.
107 * 02-23-11 02.00.17 Added SAS NOTIFY Primitive event, and added
108 * SASNotifyPrimitiveMasks field to
109 * MPI2_EVENT_NOTIFICATION_REQUEST.
110 * Added Temperature Threshold Event.
111 * Added Host Message Event.
112 * Added Send Host Message request and reply.
107 * -------------------------------------------------------------------------- 113 * --------------------------------------------------------------------------
108 */ 114 */
109 115
@@ -421,7 +427,7 @@ typedef struct _MPI2_EVENT_NOTIFICATION_REQUEST
421 U32 Reserved6; /* 0x10 */ 427 U32 Reserved6; /* 0x10 */
422 U32 EventMasks[MPI2_EVENT_NOTIFY_EVENTMASK_WORDS];/* 0x14 */ 428 U32 EventMasks[MPI2_EVENT_NOTIFY_EVENTMASK_WORDS];/* 0x14 */
423 U16 SASBroadcastPrimitiveMasks; /* 0x24 */ 429 U16 SASBroadcastPrimitiveMasks; /* 0x24 */
424 U16 Reserved7; /* 0x26 */ 430 U16 SASNotifyPrimitiveMasks; /* 0x26 */
425 U32 Reserved8; /* 0x28 */ 431 U32 Reserved8; /* 0x28 */
426} MPI2_EVENT_NOTIFICATION_REQUEST, 432} MPI2_EVENT_NOTIFICATION_REQUEST,
427 MPI2_POINTER PTR_MPI2_EVENT_NOTIFICATION_REQUEST, 433 MPI2_POINTER PTR_MPI2_EVENT_NOTIFICATION_REQUEST,
@@ -476,6 +482,9 @@ typedef struct _MPI2_EVENT_NOTIFICATION_REPLY
476#define MPI2_EVENT_GPIO_INTERRUPT (0x0023) 482#define MPI2_EVENT_GPIO_INTERRUPT (0x0023)
477#define MPI2_EVENT_HOST_BASED_DISCOVERY_PHY (0x0024) 483#define MPI2_EVENT_HOST_BASED_DISCOVERY_PHY (0x0024)
478#define MPI2_EVENT_SAS_QUIESCE (0x0025) 484#define MPI2_EVENT_SAS_QUIESCE (0x0025)
485#define MPI2_EVENT_SAS_NOTIFY_PRIMITIVE (0x0026)
486#define MPI2_EVENT_TEMP_THRESHOLD (0x0027)
487#define MPI2_EVENT_HOST_MESSAGE (0x0028)
479 488
480 489
481/* Log Entry Added Event data */ 490/* Log Entry Added Event data */
@@ -507,6 +516,39 @@ typedef struct _MPI2_EVENT_DATA_GPIO_INTERRUPT {
507 MPI2_POINTER PTR_MPI2_EVENT_DATA_GPIO_INTERRUPT, 516 MPI2_POINTER PTR_MPI2_EVENT_DATA_GPIO_INTERRUPT,
508 Mpi2EventDataGpioInterrupt_t, MPI2_POINTER pMpi2EventDataGpioInterrupt_t; 517 Mpi2EventDataGpioInterrupt_t, MPI2_POINTER pMpi2EventDataGpioInterrupt_t;
509 518
519/* Temperature Threshold Event data */
520
521typedef struct _MPI2_EVENT_DATA_TEMPERATURE {
522 U16 Status; /* 0x00 */
523 U8 SensorNum; /* 0x02 */
524 U8 Reserved1; /* 0x03 */
525 U16 CurrentTemperature; /* 0x04 */
526 U16 Reserved2; /* 0x06 */
527 U32 Reserved3; /* 0x08 */
528 U32 Reserved4; /* 0x0C */
529} MPI2_EVENT_DATA_TEMPERATURE,
530MPI2_POINTER PTR_MPI2_EVENT_DATA_TEMPERATURE,
531Mpi2EventDataTemperature_t, MPI2_POINTER pMpi2EventDataTemperature_t;
532
533/* Temperature Threshold Event data Status bits */
534#define MPI2_EVENT_TEMPERATURE3_EXCEEDED (0x0008)
535#define MPI2_EVENT_TEMPERATURE2_EXCEEDED (0x0004)
536#define MPI2_EVENT_TEMPERATURE1_EXCEEDED (0x0002)
537#define MPI2_EVENT_TEMPERATURE0_EXCEEDED (0x0001)
538
539
540/* Host Message Event data */
541
542typedef struct _MPI2_EVENT_DATA_HOST_MESSAGE {
543 U8 SourceVF_ID; /* 0x00 */
544 U8 Reserved1; /* 0x01 */
545 U16 Reserved2; /* 0x02 */
546 U32 Reserved3; /* 0x04 */
547 U32 HostData[1]; /* 0x08 */
548} MPI2_EVENT_DATA_HOST_MESSAGE, MPI2_POINTER PTR_MPI2_EVENT_DATA_HOST_MESSAGE,
549Mpi2EventDataHostMessage_t, MPI2_POINTER pMpi2EventDataHostMessage_t;
550
551
510/* Hard Reset Received Event data */ 552/* Hard Reset Received Event data */
511 553
512typedef struct _MPI2_EVENT_DATA_HARD_RESET_RECEIVED 554typedef struct _MPI2_EVENT_DATA_HARD_RESET_RECEIVED
@@ -749,6 +791,24 @@ typedef struct _MPI2_EVENT_DATA_SAS_BROADCAST_PRIMITIVE
749#define MPI2_EVENT_PRIMITIVE_CHANGE0_RESERVED (0x07) 791#define MPI2_EVENT_PRIMITIVE_CHANGE0_RESERVED (0x07)
750#define MPI2_EVENT_PRIMITIVE_CHANGE1_RESERVED (0x08) 792#define MPI2_EVENT_PRIMITIVE_CHANGE1_RESERVED (0x08)
751 793
794/* SAS Notify Primitive Event data */
795
796typedef struct _MPI2_EVENT_DATA_SAS_NOTIFY_PRIMITIVE {
797 U8 PhyNum; /* 0x00 */
798 U8 Port; /* 0x01 */
799 U8 Reserved1; /* 0x02 */
800 U8 Primitive; /* 0x03 */
801} MPI2_EVENT_DATA_SAS_NOTIFY_PRIMITIVE,
802MPI2_POINTER PTR_MPI2_EVENT_DATA_SAS_NOTIFY_PRIMITIVE,
803Mpi2EventDataSasNotifyPrimitive_t,
804MPI2_POINTER pMpi2EventDataSasNotifyPrimitive_t;
805
806/* defines for the Primitive field */
807#define MPI2_EVENT_NOTIFY_ENABLE_SPINUP (0x01)
808#define MPI2_EVENT_NOTIFY_POWER_LOSS_EXPECTED (0x02)
809#define MPI2_EVENT_NOTIFY_RESERVED1 (0x03)
810#define MPI2_EVENT_NOTIFY_RESERVED2 (0x04)
811
752 812
753/* SAS Initiator Device Status Change Event data */ 813/* SAS Initiator Device Status Change Event data */
754 814
@@ -1001,6 +1061,53 @@ typedef struct _MPI2_EVENT_ACK_REPLY
1001 1061
1002 1062
1003/**************************************************************************** 1063/****************************************************************************
1064* SendHostMessage message
1065****************************************************************************/
1066
1067/* SendHostMessage Request message */
1068typedef struct _MPI2_SEND_HOST_MESSAGE_REQUEST {
1069 U16 HostDataLength; /* 0x00 */
1070 U8 ChainOffset; /* 0x02 */
1071 U8 Function; /* 0x03 */
1072 U16 Reserved1; /* 0x04 */
1073 U8 Reserved2; /* 0x06 */
1074 U8 MsgFlags; /* 0x07 */
1075 U8 VP_ID; /* 0x08 */
1076 U8 VF_ID; /* 0x09 */
1077 U16 Reserved3; /* 0x0A */
1078 U8 Reserved4; /* 0x0C */
1079 U8 DestVF_ID; /* 0x0D */
1080 U16 Reserved5; /* 0x0E */
1081 U32 Reserved6; /* 0x10 */
1082 U32 Reserved7; /* 0x14 */
1083 U32 Reserved8; /* 0x18 */
1084 U32 Reserved9; /* 0x1C */
1085 U32 Reserved10; /* 0x20 */
1086 U32 HostData[1]; /* 0x24 */
1087} MPI2_SEND_HOST_MESSAGE_REQUEST,
1088MPI2_POINTER PTR_MPI2_SEND_HOST_MESSAGE_REQUEST,
1089Mpi2SendHostMessageRequest_t, MPI2_POINTER pMpi2SendHostMessageRequest_t;
1090
1091
1092/* SendHostMessage Reply message */
1093typedef struct _MPI2_SEND_HOST_MESSAGE_REPLY {
1094 U16 HostDataLength; /* 0x00 */
1095 U8 MsgLength; /* 0x02 */
1096 U8 Function; /* 0x03 */
1097 U16 Reserved1; /* 0x04 */
1098 U8 Reserved2; /* 0x06 */
1099 U8 MsgFlags; /* 0x07 */
1100 U8 VP_ID; /* 0x08 */
1101 U8 VF_ID; /* 0x09 */
1102 U16 Reserved3; /* 0x0A */
1103 U16 Reserved4; /* 0x0C */
1104 U16 IOCStatus; /* 0x0E */
1105 U32 IOCLogInfo; /* 0x10 */
1106} MPI2_SEND_HOST_MESSAGE_REPLY, MPI2_POINTER PTR_MPI2_SEND_HOST_MESSAGE_REPLY,
1107Mpi2SendHostMessageReply_t, MPI2_POINTER pMpi2SendHostMessageReply_t;
1108
1109
1110/****************************************************************************
1004* FWDownload message 1111* FWDownload message
1005****************************************************************************/ 1112****************************************************************************/
1006 1113
diff --git a/drivers/scsi/mpt2sas/mpt2sas_base.c b/drivers/scsi/mpt2sas/mpt2sas_base.c
index 81209ca87274..beda04a8404b 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_base.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_base.c
@@ -81,6 +81,15 @@ static int missing_delay[2] = {-1, -1};
81module_param_array(missing_delay, int, NULL, 0); 81module_param_array(missing_delay, int, NULL, 0);
82MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay"); 82MODULE_PARM_DESC(missing_delay, " device missing delay , io missing delay");
83 83
84static int mpt2sas_fwfault_debug;
85MODULE_PARM_DESC(mpt2sas_fwfault_debug, " enable detection of firmware fault "
86 "and halt firmware - (default=0)");
87
88static int disable_discovery = -1;
89module_param(disable_discovery, int, 0);
90MODULE_PARM_DESC(disable_discovery, " disable discovery ");
91
92
84/* diag_buffer_enable is bitwise 93/* diag_buffer_enable is bitwise
85 * bit 0 set = TRACE 94 * bit 0 set = TRACE
86 * bit 1 set = SNAPSHOT 95 * bit 1 set = SNAPSHOT
@@ -93,14 +102,6 @@ module_param(diag_buffer_enable, int, 0);
93MODULE_PARM_DESC(diag_buffer_enable, " post diag buffers " 102MODULE_PARM_DESC(diag_buffer_enable, " post diag buffers "
94 "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)"); 103 "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
95 104
96static int mpt2sas_fwfault_debug;
97MODULE_PARM_DESC(mpt2sas_fwfault_debug, " enable detection of firmware fault "
98 "and halt firmware - (default=0)");
99
100static int disable_discovery = -1;
101module_param(disable_discovery, int, 0);
102MODULE_PARM_DESC(disable_discovery, " disable discovery ");
103
104/** 105/**
105 * _scsih_set_fwfault_debug - global setting of ioc->fwfault_debug. 106 * _scsih_set_fwfault_debug - global setting of ioc->fwfault_debug.
106 * 107 *
@@ -691,6 +692,7 @@ mpt2sas_base_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
691 memcpy(ioc->base_cmds.reply, mpi_reply, mpi_reply->MsgLength*4); 692 memcpy(ioc->base_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
692 } 693 }
693 ioc->base_cmds.status &= ~MPT2_CMD_PENDING; 694 ioc->base_cmds.status &= ~MPT2_CMD_PENDING;
695
694 complete(&ioc->base_cmds.done); 696 complete(&ioc->base_cmds.done);
695 return 1; 697 return 1;
696} 698}
@@ -3470,6 +3472,58 @@ _base_send_ioc_init(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3470} 3472}
3471 3473
3472/** 3474/**
3475 * mpt2sas_port_enable_done - command completion routine for port enable
3476 * @ioc: per adapter object
3477 * @smid: system request message index
3478 * @msix_index: MSIX table index supplied by the OS
3479 * @reply: reply message frame(lower 32bit addr)
3480 *
3481 * Return 1 meaning mf should be freed from _base_interrupt
3482 * 0 means the mf is freed from this function.
3483 */
3484u8
3485mpt2sas_port_enable_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3486 u32 reply)
3487{
3488 MPI2DefaultReply_t *mpi_reply;
3489 u16 ioc_status;
3490
3491 mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
3492 if (mpi_reply && mpi_reply->Function == MPI2_FUNCTION_EVENT_ACK)
3493 return 1;
3494
3495 if (ioc->port_enable_cmds.status == MPT2_CMD_NOT_USED)
3496 return 1;
3497
3498 ioc->port_enable_cmds.status |= MPT2_CMD_COMPLETE;
3499 if (mpi_reply) {
3500 ioc->port_enable_cmds.status |= MPT2_CMD_REPLY_VALID;
3501 memcpy(ioc->port_enable_cmds.reply, mpi_reply,
3502 mpi_reply->MsgLength*4);
3503 }
3504 ioc->port_enable_cmds.status &= ~MPT2_CMD_PENDING;
3505
3506 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
3507
3508 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
3509 ioc->port_enable_failed = 1;
3510
3511 if (ioc->is_driver_loading) {
3512 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
3513 mpt2sas_port_enable_complete(ioc);
3514 return 1;
3515 } else {
3516 ioc->start_scan_failed = ioc_status;
3517 ioc->start_scan = 0;
3518 return 1;
3519 }
3520 }
3521 complete(&ioc->port_enable_cmds.done);
3522 return 1;
3523}
3524
3525
3526/**
3473 * _base_send_port_enable - send port_enable(discovery stuff) to firmware 3527 * _base_send_port_enable - send port_enable(discovery stuff) to firmware
3474 * @ioc: per adapter object 3528 * @ioc: per adapter object
3475 * @sleep_flag: CAN_SLEEP or NO_SLEEP 3529 * @sleep_flag: CAN_SLEEP or NO_SLEEP
@@ -3480,67 +3534,151 @@ static int
3480_base_send_port_enable(struct MPT2SAS_ADAPTER *ioc, int sleep_flag) 3534_base_send_port_enable(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3481{ 3535{
3482 Mpi2PortEnableRequest_t *mpi_request; 3536 Mpi2PortEnableRequest_t *mpi_request;
3483 u32 ioc_state; 3537 Mpi2PortEnableReply_t *mpi_reply;
3484 unsigned long timeleft; 3538 unsigned long timeleft;
3485 int r = 0; 3539 int r = 0;
3486 u16 smid; 3540 u16 smid;
3541 u16 ioc_status;
3487 3542
3488 printk(MPT2SAS_INFO_FMT "sending port enable !!\n", ioc->name); 3543 printk(MPT2SAS_INFO_FMT "sending port enable !!\n", ioc->name);
3489 3544
3490 if (ioc->base_cmds.status & MPT2_CMD_PENDING) { 3545 if (ioc->port_enable_cmds.status & MPT2_CMD_PENDING) {
3491 printk(MPT2SAS_ERR_FMT "%s: internal command already in use\n", 3546 printk(MPT2SAS_ERR_FMT "%s: internal command already in use\n",
3492 ioc->name, __func__); 3547 ioc->name, __func__);
3493 return -EAGAIN; 3548 return -EAGAIN;
3494 } 3549 }
3495 3550
3496 smid = mpt2sas_base_get_smid(ioc, ioc->base_cb_idx); 3551 smid = mpt2sas_base_get_smid(ioc, ioc->port_enable_cb_idx);
3497 if (!smid) { 3552 if (!smid) {
3498 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n", 3553 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3499 ioc->name, __func__); 3554 ioc->name, __func__);
3500 return -EAGAIN; 3555 return -EAGAIN;
3501 } 3556 }
3502 3557
3503 ioc->base_cmds.status = MPT2_CMD_PENDING; 3558 ioc->port_enable_cmds.status = MPT2_CMD_PENDING;
3504 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid); 3559 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3505 ioc->base_cmds.smid = smid; 3560 ioc->port_enable_cmds.smid = smid;
3506 memset(mpi_request, 0, sizeof(Mpi2PortEnableRequest_t)); 3561 memset(mpi_request, 0, sizeof(Mpi2PortEnableRequest_t));
3507 mpi_request->Function = MPI2_FUNCTION_PORT_ENABLE; 3562 mpi_request->Function = MPI2_FUNCTION_PORT_ENABLE;
3508 mpi_request->VF_ID = 0; /* TODO */
3509 mpi_request->VP_ID = 0;
3510 3563
3564 init_completion(&ioc->port_enable_cmds.done);
3511 mpt2sas_base_put_smid_default(ioc, smid); 3565 mpt2sas_base_put_smid_default(ioc, smid);
3512 init_completion(&ioc->base_cmds.done); 3566 timeleft = wait_for_completion_timeout(&ioc->port_enable_cmds.done,
3513 timeleft = wait_for_completion_timeout(&ioc->base_cmds.done,
3514 300*HZ); 3567 300*HZ);
3515 if (!(ioc->base_cmds.status & MPT2_CMD_COMPLETE)) { 3568 if (!(ioc->port_enable_cmds.status & MPT2_CMD_COMPLETE)) {
3516 printk(MPT2SAS_ERR_FMT "%s: timeout\n", 3569 printk(MPT2SAS_ERR_FMT "%s: timeout\n",
3517 ioc->name, __func__); 3570 ioc->name, __func__);
3518 _debug_dump_mf(mpi_request, 3571 _debug_dump_mf(mpi_request,
3519 sizeof(Mpi2PortEnableRequest_t)/4); 3572 sizeof(Mpi2PortEnableRequest_t)/4);
3520 if (ioc->base_cmds.status & MPT2_CMD_RESET) 3573 if (ioc->port_enable_cmds.status & MPT2_CMD_RESET)
3521 r = -EFAULT; 3574 r = -EFAULT;
3522 else 3575 else
3523 r = -ETIME; 3576 r = -ETIME;
3524 goto out; 3577 goto out;
3525 } else 3578 }
3526 dinitprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: complete\n", 3579 mpi_reply = ioc->port_enable_cmds.reply;
3527 ioc->name, __func__));
3528 3580
3529 ioc_state = _base_wait_on_iocstate(ioc, MPI2_IOC_STATE_OPERATIONAL, 3581 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) & MPI2_IOCSTATUS_MASK;
3530 60, sleep_flag); 3582 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
3531 if (ioc_state) { 3583 printk(MPT2SAS_ERR_FMT "%s: failed with (ioc_status=0x%08x)\n",
3532 printk(MPT2SAS_ERR_FMT "%s: failed going to operational state " 3584 ioc->name, __func__, ioc_status);
3533 " (ioc_state=0x%x)\n", ioc->name, __func__, ioc_state);
3534 r = -EFAULT; 3585 r = -EFAULT;
3586 goto out;
3535 } 3587 }
3536 out: 3588 out:
3537 ioc->base_cmds.status = MPT2_CMD_NOT_USED; 3589 ioc->port_enable_cmds.status = MPT2_CMD_NOT_USED;
3538 printk(MPT2SAS_INFO_FMT "port enable: %s\n", 3590 printk(MPT2SAS_INFO_FMT "port enable: %s\n", ioc->name, ((r == 0) ?
3539 ioc->name, ((r == 0) ? "SUCCESS" : "FAILED")); 3591 "SUCCESS" : "FAILED"));
3540 return r; 3592 return r;
3541} 3593}
3542 3594
3543/** 3595/**
3596 * mpt2sas_port_enable - initiate firmware discovery (don't wait for reply)
3597 * @ioc: per adapter object
3598 *
3599 * Returns 0 for success, non-zero for failure.
3600 */
3601int
3602mpt2sas_port_enable(struct MPT2SAS_ADAPTER *ioc)
3603{
3604 Mpi2PortEnableRequest_t *mpi_request;
3605 u16 smid;
3606
3607 printk(MPT2SAS_INFO_FMT "sending port enable !!\n", ioc->name);
3608
3609 if (ioc->port_enable_cmds.status & MPT2_CMD_PENDING) {
3610 printk(MPT2SAS_ERR_FMT "%s: internal command already in use\n",
3611 ioc->name, __func__);
3612 return -EAGAIN;
3613 }
3614
3615 smid = mpt2sas_base_get_smid(ioc, ioc->port_enable_cb_idx);
3616 if (!smid) {
3617 printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
3618 ioc->name, __func__);
3619 return -EAGAIN;
3620 }
3621
3622 ioc->port_enable_cmds.status = MPT2_CMD_PENDING;
3623 mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
3624 ioc->port_enable_cmds.smid = smid;
3625 memset(mpi_request, 0, sizeof(Mpi2PortEnableRequest_t));
3626 mpi_request->Function = MPI2_FUNCTION_PORT_ENABLE;
3627
3628 mpt2sas_base_put_smid_default(ioc, smid);
3629 return 0;
3630}
3631
3632/**
3633 * _base_determine_wait_on_discovery - desposition
3634 * @ioc: per adapter object
3635 *
3636 * Decide whether to wait on discovery to complete. Used to either
3637 * locate boot device, or report volumes ahead of physical devices.
3638 *
3639 * Returns 1 for wait, 0 for don't wait
3640 */
3641static int
3642_base_determine_wait_on_discovery(struct MPT2SAS_ADAPTER *ioc)
3643{
3644 /* We wait for discovery to complete if IR firmware is loaded.
3645 * The sas topology events arrive before PD events, so we need time to
3646 * turn on the bit in ioc->pd_handles to indicate PD
3647 * Also, it maybe required to report Volumes ahead of physical
3648 * devices when MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING is set.
3649 */
3650 if (ioc->ir_firmware)
3651 return 1;
3652
3653 /* if no Bios, then we don't need to wait */
3654 if (!ioc->bios_pg3.BiosVersion)
3655 return 0;
3656
3657 /* Bios is present, then we drop down here.
3658 *
3659 * If there any entries in the Bios Page 2, then we wait
3660 * for discovery to complete.
3661 */
3662
3663 /* Current Boot Device */
3664 if ((ioc->bios_pg2.CurrentBootDeviceForm &
3665 MPI2_BIOSPAGE2_FORM_MASK) ==
3666 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED &&
3667 /* Request Boot Device */
3668 (ioc->bios_pg2.ReqBootDeviceForm &
3669 MPI2_BIOSPAGE2_FORM_MASK) ==
3670 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED &&
3671 /* Alternate Request Boot Device */
3672 (ioc->bios_pg2.ReqAltBootDeviceForm &
3673 MPI2_BIOSPAGE2_FORM_MASK) ==
3674 MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED)
3675 return 0;
3676
3677 return 1;
3678}
3679
3680
3681/**
3544 * _base_unmask_events - turn on notification for this event 3682 * _base_unmask_events - turn on notification for this event
3545 * @ioc: per adapter object 3683 * @ioc: per adapter object
3546 * @event: firmware event 3684 * @event: firmware event
@@ -3962,6 +4100,7 @@ _base_make_ioc_operational(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3962 skip_init_reply_post_host_index: 4100 skip_init_reply_post_host_index:
3963 4101
3964 _base_unmask_interrupts(ioc); 4102 _base_unmask_interrupts(ioc);
4103
3965 r = _base_event_notification(ioc, sleep_flag); 4104 r = _base_event_notification(ioc, sleep_flag);
3966 if (r) 4105 if (r)
3967 return r; 4106 return r;
@@ -3969,7 +4108,18 @@ _base_make_ioc_operational(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3969 if (sleep_flag == CAN_SLEEP) 4108 if (sleep_flag == CAN_SLEEP)
3970 _base_static_config_pages(ioc); 4109 _base_static_config_pages(ioc);
3971 4110
3972 if (ioc->wait_for_port_enable_to_complete && ioc->is_warpdrive) { 4111
4112 if (ioc->is_driver_loading) {
4113
4114
4115
4116 ioc->wait_for_discovery_to_complete =
4117 _base_determine_wait_on_discovery(ioc);
4118 return r; /* scan_start and scan_finished support */
4119 }
4120
4121
4122 if (ioc->wait_for_discovery_to_complete && ioc->is_warpdrive) {
3973 if (ioc->manu_pg10.OEMIdentifier == 0x80) { 4123 if (ioc->manu_pg10.OEMIdentifier == 0x80) {
3974 hide_flag = (u8) (ioc->manu_pg10.OEMSpecificFlags0 & 4124 hide_flag = (u8) (ioc->manu_pg10.OEMSpecificFlags0 &
3975 MFG_PAGE10_HIDE_SSDS_MASK); 4125 MFG_PAGE10_HIDE_SSDS_MASK);
@@ -3978,13 +4128,6 @@ _base_make_ioc_operational(struct MPT2SAS_ADAPTER *ioc, int sleep_flag)
3978 } 4128 }
3979 } 4129 }
3980 4130
3981 if (ioc->wait_for_port_enable_to_complete) {
3982 if (diag_buffer_enable != 0)
3983 mpt2sas_enable_diag_buffer(ioc, diag_buffer_enable);
3984 if (disable_discovery > 0)
3985 return r;
3986 }
3987
3988 r = _base_send_port_enable(ioc, sleep_flag); 4131 r = _base_send_port_enable(ioc, sleep_flag);
3989 if (r) 4132 if (r)
3990 return r; 4133 return r;
@@ -4121,6 +4264,10 @@ mpt2sas_base_attach(struct MPT2SAS_ADAPTER *ioc)
4121 ioc->base_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); 4264 ioc->base_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4122 ioc->base_cmds.status = MPT2_CMD_NOT_USED; 4265 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
4123 4266
4267 /* port_enable command bits */
4268 ioc->port_enable_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4269 ioc->port_enable_cmds.status = MPT2_CMD_NOT_USED;
4270
4124 /* transport internal command bits */ 4271 /* transport internal command bits */
4125 ioc->transport_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL); 4272 ioc->transport_cmds.reply = kzalloc(ioc->reply_sz, GFP_KERNEL);
4126 ioc->transport_cmds.status = MPT2_CMD_NOT_USED; 4273 ioc->transport_cmds.status = MPT2_CMD_NOT_USED;
@@ -4162,8 +4309,6 @@ mpt2sas_base_attach(struct MPT2SAS_ADAPTER *ioc)
4162 goto out_free_resources; 4309 goto out_free_resources;
4163 } 4310 }
4164 4311
4165 init_completion(&ioc->shost_recovery_done);
4166
4167 for (i = 0; i < MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++) 4312 for (i = 0; i < MPI2_EVENT_NOTIFY_EVENTMASK_WORDS; i++)
4168 ioc->event_masks[i] = -1; 4313 ioc->event_masks[i] = -1;
4169 4314
@@ -4186,7 +4331,6 @@ mpt2sas_base_attach(struct MPT2SAS_ADAPTER *ioc)
4186 _base_update_missing_delay(ioc, missing_delay[0], 4331 _base_update_missing_delay(ioc, missing_delay[0],
4187 missing_delay[1]); 4332 missing_delay[1]);
4188 4333
4189 mpt2sas_base_start_watchdog(ioc);
4190 return 0; 4334 return 0;
4191 4335
4192 out_free_resources: 4336 out_free_resources:
@@ -4204,6 +4348,7 @@ mpt2sas_base_attach(struct MPT2SAS_ADAPTER *ioc)
4204 kfree(ioc->scsih_cmds.reply); 4348 kfree(ioc->scsih_cmds.reply);
4205 kfree(ioc->config_cmds.reply); 4349 kfree(ioc->config_cmds.reply);
4206 kfree(ioc->base_cmds.reply); 4350 kfree(ioc->base_cmds.reply);
4351 kfree(ioc->port_enable_cmds.reply);
4207 kfree(ioc->ctl_cmds.reply); 4352 kfree(ioc->ctl_cmds.reply);
4208 kfree(ioc->ctl_cmds.sense); 4353 kfree(ioc->ctl_cmds.sense);
4209 kfree(ioc->pfacts); 4354 kfree(ioc->pfacts);
@@ -4243,6 +4388,7 @@ mpt2sas_base_detach(struct MPT2SAS_ADAPTER *ioc)
4243 kfree(ioc->ctl_cmds.reply); 4388 kfree(ioc->ctl_cmds.reply);
4244 kfree(ioc->ctl_cmds.sense); 4389 kfree(ioc->ctl_cmds.sense);
4245 kfree(ioc->base_cmds.reply); 4390 kfree(ioc->base_cmds.reply);
4391 kfree(ioc->port_enable_cmds.reply);
4246 kfree(ioc->tm_cmds.reply); 4392 kfree(ioc->tm_cmds.reply);
4247 kfree(ioc->transport_cmds.reply); 4393 kfree(ioc->transport_cmds.reply);
4248 kfree(ioc->scsih_cmds.reply); 4394 kfree(ioc->scsih_cmds.reply);
@@ -4284,6 +4430,20 @@ _base_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
4284 mpt2sas_base_free_smid(ioc, ioc->base_cmds.smid); 4430 mpt2sas_base_free_smid(ioc, ioc->base_cmds.smid);
4285 complete(&ioc->base_cmds.done); 4431 complete(&ioc->base_cmds.done);
4286 } 4432 }
4433 if (ioc->port_enable_cmds.status & MPT2_CMD_PENDING) {
4434 ioc->port_enable_failed = 1;
4435 ioc->port_enable_cmds.status |= MPT2_CMD_RESET;
4436 mpt2sas_base_free_smid(ioc, ioc->port_enable_cmds.smid);
4437 if (ioc->is_driver_loading) {
4438 ioc->start_scan_failed =
4439 MPI2_IOCSTATUS_INTERNAL_ERROR;
4440 ioc->start_scan = 0;
4441 ioc->port_enable_cmds.status =
4442 MPT2_CMD_NOT_USED;
4443 } else
4444 complete(&ioc->port_enable_cmds.done);
4445
4446 }
4287 if (ioc->config_cmds.status & MPT2_CMD_PENDING) { 4447 if (ioc->config_cmds.status & MPT2_CMD_PENDING) {
4288 ioc->config_cmds.status |= MPT2_CMD_RESET; 4448 ioc->config_cmds.status |= MPT2_CMD_RESET;
4289 mpt2sas_base_free_smid(ioc, ioc->config_cmds.smid); 4449 mpt2sas_base_free_smid(ioc, ioc->config_cmds.smid);
@@ -4349,7 +4509,6 @@ mpt2sas_base_hard_reset_handler(struct MPT2SAS_ADAPTER *ioc, int sleep_flag,
4349{ 4509{
4350 int r; 4510 int r;
4351 unsigned long flags; 4511 unsigned long flags;
4352 u8 pe_complete = ioc->wait_for_port_enable_to_complete;
4353 4512
4354 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter\n", ioc->name, 4513 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter\n", ioc->name,
4355 __func__)); 4514 __func__));
@@ -4396,7 +4555,8 @@ mpt2sas_base_hard_reset_handler(struct MPT2SAS_ADAPTER *ioc, int sleep_flag,
4396 /* If this hard reset is called while port enable is active, then 4555 /* If this hard reset is called while port enable is active, then
4397 * there is no reason to call make_ioc_operational 4556 * there is no reason to call make_ioc_operational
4398 */ 4557 */
4399 if (pe_complete) { 4558 if (ioc->is_driver_loading && ioc->port_enable_failed) {
4559 ioc->remove_host = 1;
4400 r = -EFAULT; 4560 r = -EFAULT;
4401 goto out; 4561 goto out;
4402 } 4562 }
@@ -4410,7 +4570,6 @@ mpt2sas_base_hard_reset_handler(struct MPT2SAS_ADAPTER *ioc, int sleep_flag,
4410 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); 4570 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags);
4411 ioc->ioc_reset_in_progress_status = r; 4571 ioc->ioc_reset_in_progress_status = r;
4412 ioc->shost_recovery = 0; 4572 ioc->shost_recovery = 0;
4413 complete(&ioc->shost_recovery_done);
4414 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags); 4573 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock, flags);
4415 mutex_unlock(&ioc->reset_in_progress_mutex); 4574 mutex_unlock(&ioc->reset_in_progress_mutex);
4416 4575
diff --git a/drivers/scsi/mpt2sas/mpt2sas_base.h b/drivers/scsi/mpt2sas/mpt2sas_base.h
index 59354dba68c0..3c3babc7d260 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_base.h
+++ b/drivers/scsi/mpt2sas/mpt2sas_base.h
@@ -69,11 +69,11 @@
69#define MPT2SAS_DRIVER_NAME "mpt2sas" 69#define MPT2SAS_DRIVER_NAME "mpt2sas"
70#define MPT2SAS_AUTHOR "LSI Corporation <DL-MPTFusionLinux@lsi.com>" 70#define MPT2SAS_AUTHOR "LSI Corporation <DL-MPTFusionLinux@lsi.com>"
71#define MPT2SAS_DESCRIPTION "LSI MPT Fusion SAS 2.0 Device Driver" 71#define MPT2SAS_DESCRIPTION "LSI MPT Fusion SAS 2.0 Device Driver"
72#define MPT2SAS_DRIVER_VERSION "09.100.00.01" 72#define MPT2SAS_DRIVER_VERSION "10.100.00.00"
73#define MPT2SAS_MAJOR_VERSION 09 73#define MPT2SAS_MAJOR_VERSION 10
74#define MPT2SAS_MINOR_VERSION 100 74#define MPT2SAS_MINOR_VERSION 100
75#define MPT2SAS_BUILD_VERSION 00 75#define MPT2SAS_BUILD_VERSION 00
76#define MPT2SAS_RELEASE_VERSION 01 76#define MPT2SAS_RELEASE_VERSION 00
77 77
78/* 78/*
79 * Set MPT2SAS_SG_DEPTH value based on user input. 79 * Set MPT2SAS_SG_DEPTH value based on user input.
@@ -655,7 +655,12 @@ enum mutex_type {
655 * @ignore_loginfos: ignore loginfos during task management 655 * @ignore_loginfos: ignore loginfos during task management
656 * @remove_host: flag for when driver unloads, to avoid sending dev resets 656 * @remove_host: flag for when driver unloads, to avoid sending dev resets
657 * @pci_error_recovery: flag to prevent ioc access until slot reset completes 657 * @pci_error_recovery: flag to prevent ioc access until slot reset completes
658 * @wait_for_port_enable_to_complete: 658 * @wait_for_discovery_to_complete: flag set at driver load time when
659 * waiting on reporting devices
660 * @is_driver_loading: flag set at driver load time
661 * @port_enable_failed: flag set when port enable has failed
662 * @start_scan: flag set from scan_start callback, cleared from _mpt2sas_fw_work
663 * @start_scan_failed: means port enable failed, return's the ioc_status
659 * @msix_enable: flag indicating msix is enabled 664 * @msix_enable: flag indicating msix is enabled
660 * @msix_vector_count: number msix vectors 665 * @msix_vector_count: number msix vectors
661 * @cpu_msix_table: table for mapping cpus to msix index 666 * @cpu_msix_table: table for mapping cpus to msix index
@@ -790,15 +795,20 @@ struct MPT2SAS_ADAPTER {
790 u8 shost_recovery; 795 u8 shost_recovery;
791 796
792 struct mutex reset_in_progress_mutex; 797 struct mutex reset_in_progress_mutex;
793 struct completion shost_recovery_done;
794 spinlock_t ioc_reset_in_progress_lock; 798 spinlock_t ioc_reset_in_progress_lock;
795 u8 ioc_link_reset_in_progress; 799 u8 ioc_link_reset_in_progress;
796 int ioc_reset_in_progress_status; 800 u8 ioc_reset_in_progress_status;
797 801
798 u8 ignore_loginfos; 802 u8 ignore_loginfos;
799 u8 remove_host; 803 u8 remove_host;
800 u8 pci_error_recovery; 804 u8 pci_error_recovery;
801 u8 wait_for_port_enable_to_complete; 805 u8 wait_for_discovery_to_complete;
806 struct completion port_enable_done;
807 u8 is_driver_loading;
808 u8 port_enable_failed;
809
810 u8 start_scan;
811 u16 start_scan_failed;
802 812
803 u8 msix_enable; 813 u8 msix_enable;
804 u16 msix_vector_count; 814 u16 msix_vector_count;
@@ -814,11 +824,13 @@ struct MPT2SAS_ADAPTER {
814 u8 scsih_cb_idx; 824 u8 scsih_cb_idx;
815 u8 ctl_cb_idx; 825 u8 ctl_cb_idx;
816 u8 base_cb_idx; 826 u8 base_cb_idx;
827 u8 port_enable_cb_idx;
817 u8 config_cb_idx; 828 u8 config_cb_idx;
818 u8 tm_tr_cb_idx; 829 u8 tm_tr_cb_idx;
819 u8 tm_tr_volume_cb_idx; 830 u8 tm_tr_volume_cb_idx;
820 u8 tm_sas_control_cb_idx; 831 u8 tm_sas_control_cb_idx;
821 struct _internal_cmd base_cmds; 832 struct _internal_cmd base_cmds;
833 struct _internal_cmd port_enable_cmds;
822 struct _internal_cmd transport_cmds; 834 struct _internal_cmd transport_cmds;
823 struct _internal_cmd scsih_cmds; 835 struct _internal_cmd scsih_cmds;
824 struct _internal_cmd tm_cmds; 836 struct _internal_cmd tm_cmds;
@@ -1001,6 +1013,8 @@ void mpt2sas_base_release_callback_handler(u8 cb_idx);
1001 1013
1002u8 mpt2sas_base_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, 1014u8 mpt2sas_base_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
1003 u32 reply); 1015 u32 reply);
1016u8 mpt2sas_port_enable_done(struct MPT2SAS_ADAPTER *ioc, u16 smid,
1017 u8 msix_index, u32 reply);
1004void *mpt2sas_base_get_reply_virt_addr(struct MPT2SAS_ADAPTER *ioc, u32 phys_addr); 1018void *mpt2sas_base_get_reply_virt_addr(struct MPT2SAS_ADAPTER *ioc, u32 phys_addr);
1005 1019
1006u32 mpt2sas_base_get_iocstate(struct MPT2SAS_ADAPTER *ioc, int cooked); 1020u32 mpt2sas_base_get_iocstate(struct MPT2SAS_ADAPTER *ioc, int cooked);
@@ -1015,6 +1029,8 @@ void mpt2sas_base_validate_event_type(struct MPT2SAS_ADAPTER *ioc, u32 *event_ty
1015 1029
1016void mpt2sas_halt_firmware(struct MPT2SAS_ADAPTER *ioc); 1030void mpt2sas_halt_firmware(struct MPT2SAS_ADAPTER *ioc);
1017 1031
1032int mpt2sas_port_enable(struct MPT2SAS_ADAPTER *ioc);
1033
1018/* scsih shared API */ 1034/* scsih shared API */
1019u8 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index, 1035u8 mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
1020 u32 reply); 1036 u32 reply);
@@ -1032,6 +1048,8 @@ struct _sas_node *mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAP
1032struct _sas_device *mpt2sas_scsih_sas_device_find_by_sas_address( 1048struct _sas_device *mpt2sas_scsih_sas_device_find_by_sas_address(
1033 struct MPT2SAS_ADAPTER *ioc, u64 sas_address); 1049 struct MPT2SAS_ADAPTER *ioc, u64 sas_address);
1034 1050
1051void mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc);
1052
1035void mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase); 1053void mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase);
1036 1054
1037/* config shared API */ 1055/* config shared API */
diff --git a/drivers/scsi/mpt2sas/mpt2sas_config.c b/drivers/scsi/mpt2sas/mpt2sas_config.c
index 2b1101076cfe..36ea0b2d8020 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_config.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_config.c
@@ -1356,6 +1356,9 @@ mpt2sas_config_get_volume_handle(struct MPT2SAS_ADAPTER *ioc, u16 pd_handle,
1356 Mpi2ConfigReply_t mpi_reply; 1356 Mpi2ConfigReply_t mpi_reply;
1357 int r, i, config_page_sz; 1357 int r, i, config_page_sz;
1358 u16 ioc_status; 1358 u16 ioc_status;
1359 int config_num;
1360 u16 element_type;
1361 u16 phys_disk_dev_handle;
1359 1362
1360 *volume_handle = 0; 1363 *volume_handle = 0;
1361 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t)); 1364 memset(&mpi_request, 0, sizeof(Mpi2ConfigRequest_t));
@@ -1371,35 +1374,53 @@ mpt2sas_config_get_volume_handle(struct MPT2SAS_ADAPTER *ioc, u16 pd_handle,
1371 if (r) 1374 if (r)
1372 goto out; 1375 goto out;
1373 1376
1374 mpi_request.PageAddress =
1375 cpu_to_le32(MPI2_RAID_PGAD_FORM_ACTIVE_CONFIG);
1376 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT; 1377 mpi_request.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
1377 config_page_sz = (le16_to_cpu(mpi_reply.ExtPageLength) * 4); 1378 config_page_sz = (le16_to_cpu(mpi_reply.ExtPageLength) * 4);
1378 config_page = kmalloc(config_page_sz, GFP_KERNEL); 1379 config_page = kmalloc(config_page_sz, GFP_KERNEL);
1379 if (!config_page) 1380 if (!config_page) {
1380 goto out; 1381 r = -1;
1381 r = _config_request(ioc, &mpi_request, &mpi_reply,
1382 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
1383 config_page_sz);
1384 if (r)
1385 goto out; 1382 goto out;
1386 1383 }
1387 r = -1; 1384 config_num = 0xff;
1388 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK; 1385 while (1) {
1389 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) 1386 mpi_request.PageAddress = cpu_to_le32(config_num +
1390 goto out; 1387 MPI2_RAID_PGAD_FORM_GET_NEXT_CONFIGNUM);
1391 for (i = 0; i < config_page->NumElements; i++) { 1388 r = _config_request(ioc, &mpi_request, &mpi_reply,
1392 if ((le16_to_cpu(config_page->ConfigElement[i].ElementFlags) & 1389 MPT2_CONFIG_PAGE_DEFAULT_TIMEOUT, config_page,
1393 MPI2_RAIDCONFIG0_EFLAGS_MASK_ELEMENT_TYPE) != 1390 config_page_sz);
1394 MPI2_RAIDCONFIG0_EFLAGS_VOL_PHYS_DISK_ELEMENT) 1391 if (r)
1395 continue; 1392 goto out;
1396 if (le16_to_cpu(config_page->ConfigElement[i]. 1393 r = -1;
1397 PhysDiskDevHandle) == pd_handle) { 1394 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
1398 *volume_handle = le16_to_cpu(config_page-> 1395 MPI2_IOCSTATUS_MASK;
1399 ConfigElement[i].VolDevHandle); 1396 if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
1400 r = 0;
1401 goto out; 1397 goto out;
1398 for (i = 0; i < config_page->NumElements; i++) {
1399 element_type = le16_to_cpu(config_page->
1400 ConfigElement[i].ElementFlags) &
1401 MPI2_RAIDCONFIG0_EFLAGS_MASK_ELEMENT_TYPE;
1402 if (element_type ==
1403 MPI2_RAIDCONFIG0_EFLAGS_VOL_PHYS_DISK_ELEMENT ||
1404 element_type ==
1405 MPI2_RAIDCONFIG0_EFLAGS_OCE_ELEMENT) {
1406 phys_disk_dev_handle =
1407 le16_to_cpu(config_page->ConfigElement[i].
1408 PhysDiskDevHandle);
1409 if (phys_disk_dev_handle == pd_handle) {
1410 *volume_handle =
1411 le16_to_cpu(config_page->
1412 ConfigElement[i].VolDevHandle);
1413 r = 0;
1414 goto out;
1415 }
1416 } else if (element_type ==
1417 MPI2_RAIDCONFIG0_EFLAGS_HOT_SPARE_ELEMENT) {
1418 *volume_handle = 0;
1419 r = 0;
1420 goto out;
1421 }
1402 } 1422 }
1423 config_num = config_page->ConfigNum;
1403 } 1424 }
1404 out: 1425 out:
1405 kfree(config_page); 1426 kfree(config_page);
diff --git a/drivers/scsi/mpt2sas/mpt2sas_ctl.c b/drivers/scsi/mpt2sas/mpt2sas_ctl.c
index 9adb0133d6fb..aabcb911706e 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_ctl.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_ctl.c
@@ -1207,6 +1207,9 @@ _ctl_do_reset(void __user *arg)
1207 if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc) 1207 if (_ctl_verify_adapter(karg.hdr.ioc_number, &ioc) == -1 || !ioc)
1208 return -ENODEV; 1208 return -ENODEV;
1209 1209
1210 if (ioc->shost_recovery || ioc->pci_error_recovery ||
1211 ioc->is_driver_loading)
1212 return -EAGAIN;
1210 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter\n", ioc->name, 1213 dctlprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter\n", ioc->name,
1211 __func__)); 1214 __func__));
1212 1215
@@ -2178,7 +2181,8 @@ _ctl_ioctl_main(struct file *file, unsigned int cmd, void __user *arg)
2178 !ioc) 2181 !ioc)
2179 return -ENODEV; 2182 return -ENODEV;
2180 2183
2181 if (ioc->shost_recovery || ioc->pci_error_recovery) 2184 if (ioc->shost_recovery || ioc->pci_error_recovery ||
2185 ioc->is_driver_loading)
2182 return -EAGAIN; 2186 return -EAGAIN;
2183 2187
2184 if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_command)) { 2188 if (_IOC_SIZE(cmd) == sizeof(struct mpt2_ioctl_command)) {
@@ -2297,7 +2301,8 @@ _ctl_compat_mpt_command(struct file *file, unsigned cmd, unsigned long arg)
2297 if (_ctl_verify_adapter(karg32.hdr.ioc_number, &ioc) == -1 || !ioc) 2301 if (_ctl_verify_adapter(karg32.hdr.ioc_number, &ioc) == -1 || !ioc)
2298 return -ENODEV; 2302 return -ENODEV;
2299 2303
2300 if (ioc->shost_recovery || ioc->pci_error_recovery) 2304 if (ioc->shost_recovery || ioc->pci_error_recovery ||
2305 ioc->is_driver_loading)
2301 return -EAGAIN; 2306 return -EAGAIN;
2302 2307
2303 memset(&karg, 0, sizeof(struct mpt2_ioctl_command)); 2308 memset(&karg, 0, sizeof(struct mpt2_ioctl_command));
diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
index 1da1aa1a11e2..8889b1babcac 100644
--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
@@ -71,6 +71,9 @@ static void _firmware_event_work(struct work_struct *work);
71 71
72static u8 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid); 72static u8 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid);
73 73
74static void _scsih_scan_start(struct Scsi_Host *shost);
75static int _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time);
76
74/* global parameters */ 77/* global parameters */
75LIST_HEAD(mpt2sas_ioc_list); 78LIST_HEAD(mpt2sas_ioc_list);
76 79
@@ -79,6 +82,7 @@ static u8 scsi_io_cb_idx = -1;
79static u8 tm_cb_idx = -1; 82static u8 tm_cb_idx = -1;
80static u8 ctl_cb_idx = -1; 83static u8 ctl_cb_idx = -1;
81static u8 base_cb_idx = -1; 84static u8 base_cb_idx = -1;
85static u8 port_enable_cb_idx = -1;
82static u8 transport_cb_idx = -1; 86static u8 transport_cb_idx = -1;
83static u8 scsih_cb_idx = -1; 87static u8 scsih_cb_idx = -1;
84static u8 config_cb_idx = -1; 88static u8 config_cb_idx = -1;
@@ -103,6 +107,18 @@ static int max_lun = MPT2SAS_MAX_LUN;
103module_param(max_lun, int, 0); 107module_param(max_lun, int, 0);
104MODULE_PARM_DESC(max_lun, " max lun, default=16895 "); 108MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
105 109
110/* diag_buffer_enable is bitwise
111 * bit 0 set = TRACE
112 * bit 1 set = SNAPSHOT
113 * bit 2 set = EXTENDED
114 *
115 * Either bit can be set, or both
116 */
117static int diag_buffer_enable = -1;
118module_param(diag_buffer_enable, int, 0);
119MODULE_PARM_DESC(diag_buffer_enable, " post diag buffers "
120 "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
121
106/** 122/**
107 * struct sense_info - common structure for obtaining sense keys 123 * struct sense_info - common structure for obtaining sense keys
108 * @skey: sense key 124 * @skey: sense key
@@ -117,8 +133,8 @@ struct sense_info {
117 133
118 134
119#define MPT2SAS_TURN_ON_FAULT_LED (0xFFFC) 135#define MPT2SAS_TURN_ON_FAULT_LED (0xFFFC)
120#define MPT2SAS_RESCAN_AFTER_HOST_RESET (0xFFFF) 136#define MPT2SAS_PORT_ENABLE_COMPLETE (0xFFFD)
121 137#define MPT2SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
122/** 138/**
123 * struct fw_event_work - firmware event struct 139 * struct fw_event_work - firmware event struct
124 * @list: link list framework 140 * @list: link list framework
@@ -372,31 +388,34 @@ _scsih_get_sas_address(struct MPT2SAS_ADAPTER *ioc, u16 handle,
372 Mpi2SasDevicePage0_t sas_device_pg0; 388 Mpi2SasDevicePage0_t sas_device_pg0;
373 Mpi2ConfigReply_t mpi_reply; 389 Mpi2ConfigReply_t mpi_reply;
374 u32 ioc_status; 390 u32 ioc_status;
391 *sas_address = 0;
375 392
376 if (handle <= ioc->sas_hba.num_phys) { 393 if (handle <= ioc->sas_hba.num_phys) {
377 *sas_address = ioc->sas_hba.sas_address; 394 *sas_address = ioc->sas_hba.sas_address;
378 return 0; 395 return 0;
379 } else 396 }
380 *sas_address = 0;
381 397
382 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0, 398 if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
383 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) { 399 MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
384 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", 400 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
385 ioc->name, __FILE__, __LINE__, __func__); 401 __FILE__, __LINE__, __func__);
386 return -ENXIO; 402 return -ENXIO;
387 } 403 }
388 404
389 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & 405 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
390 MPI2_IOCSTATUS_MASK; 406 if (ioc_status == MPI2_IOCSTATUS_SUCCESS) {
391 if (ioc_status != MPI2_IOCSTATUS_SUCCESS) { 407 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
392 printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x)" 408 return 0;
393 "\nfailure at %s:%d/%s()!\n", ioc->name, handle, ioc_status,
394 __FILE__, __LINE__, __func__);
395 return -EIO;
396 } 409 }
397 410
398 *sas_address = le64_to_cpu(sas_device_pg0.SASAddress); 411 /* we hit this becuase the given parent handle doesn't exist */
399 return 0; 412 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
413 return -ENXIO;
414 /* else error case */
415 printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x), "
416 "failure at %s:%d/%s()!\n", ioc->name, handle, ioc_status,
417 __FILE__, __LINE__, __func__);
418 return -EIO;
400} 419}
401 420
402/** 421/**
@@ -424,7 +443,11 @@ _scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc,
424 u16 slot; 443 u16 slot;
425 444
426 /* only process this function when driver loads */ 445 /* only process this function when driver loads */
427 if (!ioc->wait_for_port_enable_to_complete) 446 if (!ioc->is_driver_loading)
447 return;
448
449 /* no Bios, return immediately */
450 if (!ioc->bios_pg3.BiosVersion)
428 return; 451 return;
429 452
430 if (!is_raid) { 453 if (!is_raid) {
@@ -587,8 +610,15 @@ _scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc,
587 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 610 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
588 611
589 if (!mpt2sas_transport_port_add(ioc, sas_device->handle, 612 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
590 sas_device->sas_address_parent)) 613 sas_device->sas_address_parent)) {
591 _scsih_sas_device_remove(ioc, sas_device); 614 _scsih_sas_device_remove(ioc, sas_device);
615 } else if (!sas_device->starget) {
616 if (!ioc->is_driver_loading)
617 mpt2sas_transport_port_remove(ioc,
618 sas_device->sas_address,
619 sas_device->sas_address_parent);
620 _scsih_sas_device_remove(ioc, sas_device);
621 }
592} 622}
593 623
594/** 624/**
@@ -1400,6 +1430,10 @@ _scsih_slave_destroy(struct scsi_device *sdev)
1400{ 1430{
1401 struct MPT2SAS_TARGET *sas_target_priv_data; 1431 struct MPT2SAS_TARGET *sas_target_priv_data;
1402 struct scsi_target *starget; 1432 struct scsi_target *starget;
1433 struct Scsi_Host *shost;
1434 struct MPT2SAS_ADAPTER *ioc;
1435 struct _sas_device *sas_device;
1436 unsigned long flags;
1403 1437
1404 if (!sdev->hostdata) 1438 if (!sdev->hostdata)
1405 return; 1439 return;
@@ -1407,6 +1441,19 @@ _scsih_slave_destroy(struct scsi_device *sdev)
1407 starget = scsi_target(sdev); 1441 starget = scsi_target(sdev);
1408 sas_target_priv_data = starget->hostdata; 1442 sas_target_priv_data = starget->hostdata;
1409 sas_target_priv_data->num_luns--; 1443 sas_target_priv_data->num_luns--;
1444
1445 shost = dev_to_shost(&starget->dev);
1446 ioc = shost_priv(shost);
1447
1448 if (!(sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME)) {
1449 spin_lock_irqsave(&ioc->sas_device_lock, flags);
1450 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
1451 sas_target_priv_data->sas_address);
1452 if (sas_device)
1453 sas_device->starget = NULL;
1454 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
1455 }
1456
1410 kfree(sdev->hostdata); 1457 kfree(sdev->hostdata);
1411 sdev->hostdata = NULL; 1458 sdev->hostdata = NULL;
1412} 1459}
@@ -1598,8 +1645,10 @@ _scsih_set_level(struct scsi_device *sdev, struct _raid_device *raid_device)
1598 * _scsih_get_volume_capabilities - volume capabilities 1645 * _scsih_get_volume_capabilities - volume capabilities
1599 * @ioc: per adapter object 1646 * @ioc: per adapter object
1600 * @sas_device: the raid_device object 1647 * @sas_device: the raid_device object
1648 *
1649 * Returns 0 for success, else 1
1601 */ 1650 */
1602static void 1651static int
1603_scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc, 1652_scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
1604 struct _raid_device *raid_device) 1653 struct _raid_device *raid_device)
1605{ 1654{
@@ -1612,9 +1661,10 @@ _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
1612 1661
1613 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle, 1662 if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
1614 &num_pds)) || !num_pds) { 1663 &num_pds)) || !num_pds) {
1615 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", 1664 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1616 ioc->name, __FILE__, __LINE__, __func__); 1665 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1617 return; 1666 __func__));
1667 return 1;
1618 } 1668 }
1619 1669
1620 raid_device->num_pds = num_pds; 1670 raid_device->num_pds = num_pds;
@@ -1622,17 +1672,19 @@ _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
1622 sizeof(Mpi2RaidVol0PhysDisk_t)); 1672 sizeof(Mpi2RaidVol0PhysDisk_t));
1623 vol_pg0 = kzalloc(sz, GFP_KERNEL); 1673 vol_pg0 = kzalloc(sz, GFP_KERNEL);
1624 if (!vol_pg0) { 1674 if (!vol_pg0) {
1625 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", 1675 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1626 ioc->name, __FILE__, __LINE__, __func__); 1676 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1627 return; 1677 __func__));
1678 return 1;
1628 } 1679 }
1629 1680
1630 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0, 1681 if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
1631 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) { 1682 MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
1632 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", 1683 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1633 ioc->name, __FILE__, __LINE__, __func__); 1684 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
1685 __func__));
1634 kfree(vol_pg0); 1686 kfree(vol_pg0);
1635 return; 1687 return 1;
1636 } 1688 }
1637 1689
1638 raid_device->volume_type = vol_pg0->VolumeType; 1690 raid_device->volume_type = vol_pg0->VolumeType;
@@ -1652,6 +1704,7 @@ _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
1652 } 1704 }
1653 1705
1654 kfree(vol_pg0); 1706 kfree(vol_pg0);
1707 return 0;
1655} 1708}
1656/** 1709/**
1657 * _scsih_disable_ddio - Disable direct I/O for all the volumes 1710 * _scsih_disable_ddio - Disable direct I/O for all the volumes
@@ -1922,13 +1975,20 @@ _scsih_slave_configure(struct scsi_device *sdev)
1922 sas_target_priv_data->handle); 1975 sas_target_priv_data->handle);
1923 spin_unlock_irqrestore(&ioc->raid_device_lock, flags); 1976 spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
1924 if (!raid_device) { 1977 if (!raid_device) {
1925 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", 1978 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1926 ioc->name, __FILE__, __LINE__, __func__); 1979 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1927 return 0; 1980 __LINE__, __func__));
1981 return 1;
1928 } 1982 }
1929 1983
1930 _scsih_get_volume_capabilities(ioc, raid_device); 1984 _scsih_get_volume_capabilities(ioc, raid_device);
1931 1985
1986 if (_scsih_get_volume_capabilities(ioc, raid_device)) {
1987 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
1988 "failure at %s:%d/%s()!\n", ioc->name, __FILE__,
1989 __LINE__, __func__));
1990 return 1;
1991 }
1932 /* 1992 /*
1933 * WARPDRIVE: Initialize the required data for Direct IO 1993 * WARPDRIVE: Initialize the required data for Direct IO
1934 */ 1994 */
@@ -2002,11 +2062,22 @@ _scsih_slave_configure(struct scsi_device *sdev)
2002 if (sas_device) { 2062 if (sas_device) {
2003 if (sas_target_priv_data->flags & 2063 if (sas_target_priv_data->flags &
2004 MPT_TARGET_FLAGS_RAID_COMPONENT) { 2064 MPT_TARGET_FLAGS_RAID_COMPONENT) {
2005 mpt2sas_config_get_volume_handle(ioc, 2065 if (mpt2sas_config_get_volume_handle(ioc,
2006 sas_device->handle, &sas_device->volume_handle); 2066 sas_device->handle, &sas_device->volume_handle)) {
2007 mpt2sas_config_get_volume_wwid(ioc, 2067 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2068 "failure at %s:%d/%s()!\n", ioc->name,
2069 __FILE__, __LINE__, __func__));
2070 return 1;
2071 }
2072 if (sas_device->volume_handle &&
2073 mpt2sas_config_get_volume_wwid(ioc,
2008 sas_device->volume_handle, 2074 sas_device->volume_handle,
2009 &sas_device->volume_wwid); 2075 &sas_device->volume_wwid)) {
2076 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2077 "failure at %s:%d/%s()!\n", ioc->name,
2078 __FILE__, __LINE__, __func__));
2079 return 1;
2080 }
2010 } 2081 }
2011 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) { 2082 if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
2012 qdepth = MPT2SAS_SAS_QUEUE_DEPTH; 2083 qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
@@ -2035,6 +2106,11 @@ _scsih_slave_configure(struct scsi_device *sdev)
2035 2106
2036 if (!ssp_target) 2107 if (!ssp_target)
2037 _scsih_display_sata_capabilities(ioc, sas_device, sdev); 2108 _scsih_display_sata_capabilities(ioc, sas_device, sdev);
2109 } else {
2110 dfailprintk(ioc, printk(MPT2SAS_WARN_FMT
2111 "failure at %s:%d/%s()!\n", ioc->name, __FILE__, __LINE__,
2112 __func__));
2113 return 1;
2038 } 2114 }
2039 2115
2040 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT); 2116 _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
@@ -2714,22 +2790,38 @@ _scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
2714 2790
2715 2791
2716/** 2792/**
2717 * _scsih_queue_rescan - queue a topology rescan from user context 2793 * _scsih_error_recovery_delete_devices - remove devices not responding
2718 * @ioc: per adapter object 2794 * @ioc: per adapter object
2719 * 2795 *
2720 * Return nothing. 2796 * Return nothing.
2721 */ 2797 */
2722static void 2798static void
2723_scsih_queue_rescan(struct MPT2SAS_ADAPTER *ioc) 2799_scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER *ioc)
2724{ 2800{
2725 struct fw_event_work *fw_event; 2801 struct fw_event_work *fw_event;
2726 2802
2727 if (ioc->wait_for_port_enable_to_complete) 2803 if (ioc->is_driver_loading)
2728 return; 2804 return;
2805 fw_event->event = MPT2SAS_REMOVE_UNRESPONDING_DEVICES;
2806 fw_event->ioc = ioc;
2807 _scsih_fw_event_add(ioc, fw_event);
2808}
2809
2810/**
2811 * mpt2sas_port_enable_complete - port enable completed (fake event)
2812 * @ioc: per adapter object
2813 *
2814 * Return nothing.
2815 */
2816void
2817mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc)
2818{
2819 struct fw_event_work *fw_event;
2820
2729 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC); 2821 fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
2730 if (!fw_event) 2822 if (!fw_event)
2731 return; 2823 return;
2732 fw_event->event = MPT2SAS_RESCAN_AFTER_HOST_RESET; 2824 fw_event->event = MPT2SAS_PORT_ENABLE_COMPLETE;
2733 fw_event->ioc = ioc; 2825 fw_event->ioc = ioc;
2734 _scsih_fw_event_add(ioc, fw_event); 2826 _scsih_fw_event_add(ioc, fw_event);
2735} 2827}
@@ -2977,14 +3069,27 @@ _scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2977 Mpi2SCSITaskManagementRequest_t *mpi_request; 3069 Mpi2SCSITaskManagementRequest_t *mpi_request;
2978 u16 smid; 3070 u16 smid;
2979 struct _sas_device *sas_device; 3071 struct _sas_device *sas_device;
2980 struct MPT2SAS_TARGET *sas_target_priv_data; 3072 struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
3073 u64 sas_address = 0;
2981 unsigned long flags; 3074 unsigned long flags;
2982 struct _tr_list *delayed_tr; 3075 struct _tr_list *delayed_tr;
3076 u32 ioc_state;
2983 3077
2984 if (ioc->shost_recovery || ioc->remove_host || 3078 if (ioc->remove_host) {
2985 ioc->pci_error_recovery) { 3079 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
2986 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in " 3080 "removed: handle(0x%04x)\n", __func__, ioc->name, handle));
2987 "progress!\n", __func__, ioc->name)); 3081 return;
3082 } else if (ioc->pci_error_recovery) {
3083 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3084 "error recovery: handle(0x%04x)\n", __func__, ioc->name,
3085 handle));
3086 return;
3087 }
3088 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3089 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3090 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3091 "operational: handle(0x%04x)\n", __func__, ioc->name,
3092 handle));
2988 return; 3093 return;
2989 } 3094 }
2990 3095
@@ -2998,13 +3103,18 @@ _scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
2998 sas_device->starget->hostdata) { 3103 sas_device->starget->hostdata) {
2999 sas_target_priv_data = sas_device->starget->hostdata; 3104 sas_target_priv_data = sas_device->starget->hostdata;
3000 sas_target_priv_data->deleted = 1; 3105 sas_target_priv_data->deleted = 1;
3001 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT 3106 sas_address = sas_device->sas_address;
3002 "setting delete flag: handle(0x%04x), "
3003 "sas_addr(0x%016llx)\n", ioc->name, handle,
3004 (unsigned long long) sas_device->sas_address));
3005 } 3107 }
3006 spin_unlock_irqrestore(&ioc->sas_device_lock, flags); 3108 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
3007 3109
3110 if (sas_target_priv_data) {
3111 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "setting delete flag: "
3112 "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, handle,
3113 (unsigned long long)sas_address));
3114 _scsih_ublock_io_device(ioc, handle);
3115 sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
3116 }
3117
3008 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx); 3118 smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
3009 if (!smid) { 3119 if (!smid) {
3010 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC); 3120 delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
@@ -3185,11 +3295,21 @@ _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
3185 mpt2sas_base_get_reply_virt_addr(ioc, reply); 3295 mpt2sas_base_get_reply_virt_addr(ioc, reply);
3186 Mpi2SasIoUnitControlRequest_t *mpi_request; 3296 Mpi2SasIoUnitControlRequest_t *mpi_request;
3187 u16 smid_sas_ctrl; 3297 u16 smid_sas_ctrl;
3298 u32 ioc_state;
3188 3299
3189 if (ioc->shost_recovery || ioc->remove_host || 3300 if (ioc->remove_host) {
3190 ioc->pci_error_recovery) { 3301 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host has been "
3191 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in " 3302 "removed\n", __func__, ioc->name));
3192 "progress!\n", __func__, ioc->name)); 3303 return 1;
3304 } else if (ioc->pci_error_recovery) {
3305 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host in pci "
3306 "error recovery\n", __func__, ioc->name));
3307 return 1;
3308 }
3309 ioc_state = mpt2sas_base_get_iocstate(ioc, 1);
3310 if (ioc_state != MPI2_IOC_STATE_OPERATIONAL) {
3311 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host is not "
3312 "operational\n", __func__, ioc->name));
3193 return 1; 3313 return 1;
3194 } 3314 }
3195 3315
@@ -5099,7 +5219,7 @@ _scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd)
5099 /* get device name */ 5219 /* get device name */
5100 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName); 5220 sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
5101 5221
5102 if (ioc->wait_for_port_enable_to_complete) 5222 if (ioc->wait_for_discovery_to_complete)
5103 _scsih_sas_device_init_add(ioc, sas_device); 5223 _scsih_sas_device_init_add(ioc, sas_device);
5104 else 5224 else
5105 _scsih_sas_device_add(ioc, sas_device); 5225 _scsih_sas_device_add(ioc, sas_device);
@@ -5135,6 +5255,9 @@ _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc,
5135 if (sas_device_backup.starget && sas_device_backup.starget->hostdata) { 5255 if (sas_device_backup.starget && sas_device_backup.starget->hostdata) {
5136 sas_target_priv_data = sas_device_backup.starget->hostdata; 5256 sas_target_priv_data = sas_device_backup.starget->hostdata;
5137 sas_target_priv_data->deleted = 1; 5257 sas_target_priv_data->deleted = 1;
5258 _scsih_ublock_io_device(ioc, sas_device_backup.handle);
5259 sas_target_priv_data->handle =
5260 MPT2SAS_INVALID_DEVICE_HANDLE;
5138 } 5261 }
5139 5262
5140 _scsih_ublock_io_device(ioc, sas_device_backup.handle); 5263 _scsih_ublock_io_device(ioc, sas_device_backup.handle);
@@ -5288,7 +5411,7 @@ _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
5288 _scsih_sas_topology_change_event_debug(ioc, event_data); 5411 _scsih_sas_topology_change_event_debug(ioc, event_data);
5289#endif 5412#endif
5290 5413
5291 if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery) 5414 if (ioc->remove_host || ioc->pci_error_recovery)
5292 return; 5415 return;
5293 5416
5294 if (!ioc->sas_hba.num_phys) 5417 if (!ioc->sas_hba.num_phys)
@@ -5349,6 +5472,9 @@ _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
5349 switch (reason_code) { 5472 switch (reason_code) {
5350 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED: 5473 case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
5351 5474
5475 if (ioc->shost_recovery)
5476 break;
5477
5352 if (link_rate == prev_link_rate) 5478 if (link_rate == prev_link_rate)
5353 break; 5479 break;
5354 5480
@@ -5362,6 +5488,9 @@ _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
5362 break; 5488 break;
5363 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED: 5489 case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
5364 5490
5491 if (ioc->shost_recovery)
5492 break;
5493
5365 mpt2sas_transport_update_links(ioc, sas_address, 5494 mpt2sas_transport_update_links(ioc, sas_address,
5366 handle, phy_number, link_rate); 5495 handle, phy_number, link_rate);
5367 5496
@@ -5622,7 +5751,7 @@ broadcast_aen_retry:
5622 termination_count = 0; 5751 termination_count = 0;
5623 query_count = 0; 5752 query_count = 0;
5624 for (smid = 1; smid <= ioc->scsiio_depth; smid++) { 5753 for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
5625 if (ioc->ioc_reset_in_progress_status) 5754 if (ioc->shost_recovery)
5626 goto out; 5755 goto out;
5627 scmd = _scsih_scsi_lookup_get(ioc, smid); 5756 scmd = _scsih_scsi_lookup_get(ioc, smid);
5628 if (!scmd) 5757 if (!scmd)
@@ -5644,7 +5773,7 @@ broadcast_aen_retry:
5644 lun = sas_device_priv_data->lun; 5773 lun = sas_device_priv_data->lun;
5645 query_count++; 5774 query_count++;
5646 5775
5647 if (ioc->ioc_reset_in_progress_status) 5776 if (ioc->shost_recovery)
5648 goto out; 5777 goto out;
5649 5778
5650 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags); 5779 spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
@@ -5686,7 +5815,7 @@ broadcast_aen_retry:
5686 goto broadcast_aen_retry; 5815 goto broadcast_aen_retry;
5687 } 5816 }
5688 5817
5689 if (ioc->ioc_reset_in_progress_status) 5818 if (ioc->shost_recovery)
5690 goto out_no_lock; 5819 goto out_no_lock;
5691 5820
5692 r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id, 5821 r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
@@ -5725,7 +5854,7 @@ broadcast_aen_retry:
5725 ioc->name, __func__, query_count, termination_count)); 5854 ioc->name, __func__, query_count, termination_count));
5726 5855
5727 ioc->broadcast_aen_busy = 0; 5856 ioc->broadcast_aen_busy = 0;
5728 if (!ioc->ioc_reset_in_progress_status) 5857 if (!ioc->shost_recovery)
5729 _scsih_ublock_io_all_device(ioc); 5858 _scsih_ublock_io_all_device(ioc);
5730 mutex_unlock(&ioc->tm_cmds.mutex); 5859 mutex_unlock(&ioc->tm_cmds.mutex);
5731} 5860}
@@ -5789,8 +5918,11 @@ _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
5789static void 5918static void
5790_scsih_reprobe_target(struct scsi_target *starget, int no_uld_attach) 5919_scsih_reprobe_target(struct scsi_target *starget, int no_uld_attach)
5791{ 5920{
5792 struct MPT2SAS_TARGET *sas_target_priv_data = starget->hostdata; 5921 struct MPT2SAS_TARGET *sas_target_priv_data;
5793 5922
5923 if (starget == NULL)
5924 return;
5925 sas_target_priv_data = starget->hostdata;
5794 if (no_uld_attach) 5926 if (no_uld_attach)
5795 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_RAID_COMPONENT; 5927 sas_target_priv_data->flags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
5796 else 5928 else
@@ -5845,7 +5977,7 @@ _scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc,
5845 raid_device->handle = handle; 5977 raid_device->handle = handle;
5846 raid_device->wwid = wwid; 5978 raid_device->wwid = wwid;
5847 _scsih_raid_device_add(ioc, raid_device); 5979 _scsih_raid_device_add(ioc, raid_device);
5848 if (!ioc->wait_for_port_enable_to_complete) { 5980 if (!ioc->wait_for_discovery_to_complete) {
5849 rc = scsi_add_device(ioc->shost, RAID_CHANNEL, 5981 rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
5850 raid_device->id, 0); 5982 raid_device->id, 0);
5851 if (rc) 5983 if (rc)
@@ -6127,6 +6259,10 @@ _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc,
6127 _scsih_sas_ir_config_change_event_debug(ioc, event_data); 6259 _scsih_sas_ir_config_change_event_debug(ioc, event_data);
6128 6260
6129#endif 6261#endif
6262
6263 if (ioc->shost_recovery)
6264 return;
6265
6130 foreign_config = (le32_to_cpu(event_data->Flags) & 6266 foreign_config = (le32_to_cpu(event_data->Flags) &
6131 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0; 6267 MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
6132 6268
@@ -6185,6 +6321,9 @@ _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc,
6185 int rc; 6321 int rc;
6186 Mpi2EventDataIrVolume_t *event_data = fw_event->event_data; 6322 Mpi2EventDataIrVolume_t *event_data = fw_event->event_data;
6187 6323
6324 if (ioc->shost_recovery)
6325 return;
6326
6188 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED) 6327 if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
6189 return; 6328 return;
6190 6329
@@ -6267,6 +6406,9 @@ _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc,
6267 Mpi2EventDataIrPhysicalDisk_t *event_data = fw_event->event_data; 6406 Mpi2EventDataIrPhysicalDisk_t *event_data = fw_event->event_data;
6268 u64 sas_address; 6407 u64 sas_address;
6269 6408
6409 if (ioc->shost_recovery)
6410 return;
6411
6270 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED) 6412 if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
6271 return; 6413 return;
6272 6414
@@ -6510,10 +6652,10 @@ _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6510 u32 device_info; 6652 u32 device_info;
6511 u16 slot; 6653 u16 slot;
6512 6654
6513 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__); 6655 printk(MPT2SAS_INFO_FMT "search for end-devices: start\n", ioc->name);
6514 6656
6515 if (list_empty(&ioc->sas_device_list)) 6657 if (list_empty(&ioc->sas_device_list))
6516 return; 6658 goto out;
6517 6659
6518 handle = 0xFFFF; 6660 handle = 0xFFFF;
6519 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, 6661 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
@@ -6532,6 +6674,9 @@ _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6532 _scsih_mark_responding_sas_device(ioc, sas_address, slot, 6674 _scsih_mark_responding_sas_device(ioc, sas_address, slot,
6533 handle); 6675 handle);
6534 } 6676 }
6677out:
6678 printk(MPT2SAS_INFO_FMT "search for end-devices: complete\n",
6679 ioc->name);
6535} 6680}
6536 6681
6537/** 6682/**
@@ -6607,10 +6752,14 @@ _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
6607 u16 handle; 6752 u16 handle;
6608 u8 phys_disk_num; 6753 u8 phys_disk_num;
6609 6754
6610 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__); 6755 if (!ioc->ir_firmware)
6756 return;
6757
6758 printk(MPT2SAS_INFO_FMT "search for raid volumes: start\n",
6759 ioc->name);
6611 6760
6612 if (list_empty(&ioc->raid_device_list)) 6761 if (list_empty(&ioc->raid_device_list))
6613 return; 6762 goto out;
6614 6763
6615 handle = 0xFFFF; 6764 handle = 0xFFFF;
6616 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply, 6765 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
@@ -6649,6 +6798,9 @@ _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
6649 set_bit(handle, ioc->pd_handles); 6798 set_bit(handle, ioc->pd_handles);
6650 } 6799 }
6651 } 6800 }
6801out:
6802 printk(MPT2SAS_INFO_FMT "search for responding raid volumes: "
6803 "complete\n", ioc->name);
6652} 6804}
6653 6805
6654/** 6806/**
@@ -6708,10 +6860,10 @@ _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
6708 u64 sas_address; 6860 u64 sas_address;
6709 u16 handle; 6861 u16 handle;
6710 6862
6711 printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__); 6863 printk(MPT2SAS_INFO_FMT "search for expanders: start\n", ioc->name);
6712 6864
6713 if (list_empty(&ioc->sas_expander_list)) 6865 if (list_empty(&ioc->sas_expander_list))
6714 return; 6866 goto out;
6715 6867
6716 handle = 0xFFFF; 6868 handle = 0xFFFF;
6717 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0, 6869 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
@@ -6730,6 +6882,8 @@ _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
6730 _scsih_mark_responding_expander(ioc, sas_address, handle); 6882 _scsih_mark_responding_expander(ioc, sas_address, handle);
6731 } 6883 }
6732 6884
6885 out:
6886 printk(MPT2SAS_INFO_FMT "search for expanders: complete\n", ioc->name);
6733} 6887}
6734 6888
6735/** 6889/**
@@ -6745,6 +6899,8 @@ _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6745 struct _sas_node *sas_expander; 6899 struct _sas_node *sas_expander;
6746 struct _raid_device *raid_device, *raid_device_next; 6900 struct _raid_device *raid_device, *raid_device_next;
6747 6901
6902 printk(MPT2SAS_INFO_FMT "removing unresponding devices: start\n",
6903 ioc->name);
6748 6904
6749 list_for_each_entry_safe(sas_device, sas_device_next, 6905 list_for_each_entry_safe(sas_device, sas_device_next,
6750 &ioc->sas_device_list, list) { 6906 &ioc->sas_device_list, list) {
@@ -6764,6 +6920,9 @@ _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6764 _scsih_remove_device(ioc, sas_device); 6920 _scsih_remove_device(ioc, sas_device);
6765 } 6921 }
6766 6922
6923 if (!ioc->ir_firmware)
6924 goto retry_expander_search;
6925
6767 list_for_each_entry_safe(raid_device, raid_device_next, 6926 list_for_each_entry_safe(raid_device, raid_device_next,
6768 &ioc->raid_device_list, list) { 6927 &ioc->raid_device_list, list) {
6769 if (raid_device->responding) { 6928 if (raid_device->responding) {
@@ -6790,52 +6949,170 @@ _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
6790 mpt2sas_expander_remove(ioc, sas_expander->sas_address); 6949 mpt2sas_expander_remove(ioc, sas_expander->sas_address);
6791 goto retry_expander_search; 6950 goto retry_expander_search;
6792 } 6951 }
6952 printk(MPT2SAS_INFO_FMT "removing unresponding devices: complete\n",
6953 ioc->name);
6954 /* unblock devices */
6955 _scsih_ublock_io_all_device(ioc);
6956}
6957
6958static void
6959_scsih_refresh_expander_links(struct MPT2SAS_ADAPTER *ioc,
6960 struct _sas_node *sas_expander, u16 handle)
6961{
6962 Mpi2ExpanderPage1_t expander_pg1;
6963 Mpi2ConfigReply_t mpi_reply;
6964 int i;
6965
6966 for (i = 0 ; i < sas_expander->num_phys ; i++) {
6967 if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
6968 &expander_pg1, i, handle))) {
6969 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
6970 ioc->name, __FILE__, __LINE__, __func__);
6971 return;
6972 }
6973
6974 mpt2sas_transport_update_links(ioc, sas_expander->sas_address,
6975 le16_to_cpu(expander_pg1.AttachedDevHandle), i,
6976 expander_pg1.NegotiatedLinkRate >> 4);
6977 }
6793} 6978}
6794 6979
6795/** 6980/**
6796 * _scsih_hide_unhide_sas_devices - add/remove device to/from OS 6981 * _scsih_scan_for_devices_after_reset - scan for devices after host reset
6797 * @ioc: per adapter object 6982 * @ioc: per adapter object
6798 * 6983 *
6799 * Return nothing. 6984 * Return nothing.
6800 */ 6985 */
6801static void 6986static void
6802_scsih_hide_unhide_sas_devices(struct MPT2SAS_ADAPTER *ioc) 6987_scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
6803{ 6988{
6804 struct _sas_device *sas_device, *sas_device_next; 6989 Mpi2ExpanderPage0_t expander_pg0;
6990 Mpi2SasDevicePage0_t sas_device_pg0;
6991 Mpi2RaidVolPage1_t volume_pg1;
6992 Mpi2RaidVolPage0_t volume_pg0;
6993 Mpi2RaidPhysDiskPage0_t pd_pg0;
6994 Mpi2EventIrConfigElement_t element;
6995 Mpi2ConfigReply_t mpi_reply;
6996 u8 phys_disk_num;
6997 u16 ioc_status;
6998 u16 handle, parent_handle;
6999 u64 sas_address;
7000 struct _sas_device *sas_device;
7001 struct _sas_node *expander_device;
7002 static struct _raid_device *raid_device;
6805 7003
6806 if (!ioc->is_warpdrive || ioc->mfg_pg10_hide_flag != 7004 printk(MPT2SAS_INFO_FMT "scan devices: start\n", ioc->name);
6807 MFG_PAGE10_HIDE_IF_VOL_PRESENT)
6808 return;
6809 7005
6810 if (ioc->hide_drives) { 7006 _scsih_sas_host_refresh(ioc);
6811 if (_scsih_get_num_volumes(ioc)) 7007
6812 return; 7008 /* expanders */
6813 ioc->hide_drives = 0; 7009 handle = 0xFFFF;
6814 list_for_each_entry_safe(sas_device, sas_device_next, 7010 while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
6815 &ioc->sas_device_list, list) { 7011 MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
6816 if (!mpt2sas_transport_port_add(ioc, sas_device->handle, 7012 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6817 sas_device->sas_address_parent)) { 7013 MPI2_IOCSTATUS_MASK;
6818 _scsih_sas_device_remove(ioc, sas_device); 7014 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
6819 } else if (!sas_device->starget) { 7015 break;
6820 mpt2sas_transport_port_remove(ioc, 7016 handle = le16_to_cpu(expander_pg0.DevHandle);
6821 sas_device->sas_address, 7017 expander_device = mpt2sas_scsih_expander_find_by_sas_address(
6822 sas_device->sas_address_parent); 7018 ioc, le64_to_cpu(expander_pg0.SASAddress));
6823 _scsih_sas_device_remove(ioc, sas_device); 7019 if (expander_device)
6824 } 7020 _scsih_refresh_expander_links(ioc, expander_device,
7021 handle);
7022 else
7023 _scsih_expander_add(ioc, handle);
7024 }
7025
7026 if (!ioc->ir_firmware)
7027 goto skip_to_sas;
7028
7029 /* phys disk */
7030 phys_disk_num = 0xFF;
7031 while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
7032 &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
7033 phys_disk_num))) {
7034 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7035 MPI2_IOCSTATUS_MASK;
7036 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
7037 break;
7038 phys_disk_num = pd_pg0.PhysDiskNum;
7039 handle = le16_to_cpu(pd_pg0.DevHandle);
7040 sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
7041 if (sas_device)
7042 continue;
7043 if (mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7044 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
7045 handle) != 0)
7046 continue;
7047 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7048 if (!_scsih_get_sas_address(ioc, parent_handle,
7049 &sas_address)) {
7050 mpt2sas_transport_update_links(ioc, sas_address,
7051 handle, sas_device_pg0.PhyNum,
7052 MPI2_SAS_NEG_LINK_RATE_1_5);
7053 set_bit(handle, ioc->pd_handles);
7054 _scsih_add_device(ioc, handle, 0, 1);
6825 } 7055 }
6826 } else { 7056 }
6827 if (!_scsih_get_num_volumes(ioc)) 7057
6828 return; 7058 /* volumes */
6829 ioc->hide_drives = 1; 7059 handle = 0xFFFF;
6830 list_for_each_entry_safe(sas_device, sas_device_next, 7060 while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
6831 &ioc->sas_device_list, list) { 7061 &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
6832 mpt2sas_transport_port_remove(ioc, 7062 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
6833 sas_device->sas_address, 7063 MPI2_IOCSTATUS_MASK;
6834 sas_device->sas_address_parent); 7064 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
7065 break;
7066 handle = le16_to_cpu(volume_pg1.DevHandle);
7067 raid_device = _scsih_raid_device_find_by_wwid(ioc,
7068 le64_to_cpu(volume_pg1.WWID));
7069 if (raid_device)
7070 continue;
7071 if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
7072 &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
7073 sizeof(Mpi2RaidVolPage0_t)))
7074 continue;
7075 if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
7076 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
7077 volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
7078 memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
7079 element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
7080 element.VolDevHandle = volume_pg1.DevHandle;
7081 _scsih_sas_volume_add(ioc, &element);
6835 } 7082 }
6836 } 7083 }
7084
7085 skip_to_sas:
7086
7087 /* sas devices */
7088 handle = 0xFFFF;
7089 while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
7090 &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
7091 handle))) {
7092 ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
7093 MPI2_IOCSTATUS_MASK;
7094 if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
7095 break;
7096 handle = le16_to_cpu(sas_device_pg0.DevHandle);
7097 if (!(_scsih_is_end_device(
7098 le32_to_cpu(sas_device_pg0.DeviceInfo))))
7099 continue;
7100 sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
7101 le64_to_cpu(sas_device_pg0.SASAddress));
7102 if (sas_device)
7103 continue;
7104 parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
7105 if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
7106 mpt2sas_transport_update_links(ioc, sas_address, handle,
7107 sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
7108 _scsih_add_device(ioc, handle, 0, 0);
7109 }
7110 }
7111
7112 printk(MPT2SAS_INFO_FMT "scan devices: complete\n", ioc->name);
6837} 7113}
6838 7114
7115
6839/** 7116/**
6840 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih) 7117 * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
6841 * @ioc: per adapter object 7118 * @ioc: per adapter object
@@ -6871,7 +7148,6 @@ mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
6871 } 7148 }
6872 _scsih_fw_event_cleanup_queue(ioc); 7149 _scsih_fw_event_cleanup_queue(ioc);
6873 _scsih_flush_running_cmds(ioc); 7150 _scsih_flush_running_cmds(ioc);
6874 _scsih_queue_rescan(ioc);
6875 break; 7151 break;
6876 case MPT2_IOC_DONE_RESET: 7152 case MPT2_IOC_DONE_RESET:
6877 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: " 7153 dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
@@ -6881,6 +7157,13 @@ mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
6881 _scsih_search_responding_sas_devices(ioc); 7157 _scsih_search_responding_sas_devices(ioc);
6882 _scsih_search_responding_raid_devices(ioc); 7158 _scsih_search_responding_raid_devices(ioc);
6883 _scsih_search_responding_expanders(ioc); 7159 _scsih_search_responding_expanders(ioc);
7160 if (!ioc->is_driver_loading) {
7161 _scsih_prep_device_scan(ioc);
7162 _scsih_search_responding_sas_devices(ioc);
7163 _scsih_search_responding_raid_devices(ioc);
7164 _scsih_search_responding_expanders(ioc);
7165 _scsih_error_recovery_delete_devices(ioc);
7166 }
6884 break; 7167 break;
6885 } 7168 }
6886} 7169}
@@ -6898,7 +7181,6 @@ _firmware_event_work(struct work_struct *work)
6898{ 7181{
6899 struct fw_event_work *fw_event = container_of(work, 7182 struct fw_event_work *fw_event = container_of(work,
6900 struct fw_event_work, delayed_work.work); 7183 struct fw_event_work, delayed_work.work);
6901 unsigned long flags;
6902 struct MPT2SAS_ADAPTER *ioc = fw_event->ioc; 7184 struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
6903 7185
6904 /* the queue is being flushed so ignore this event */ 7186 /* the queue is being flushed so ignore this event */
@@ -6908,23 +7190,21 @@ _firmware_event_work(struct work_struct *work)
6908 return; 7190 return;
6909 } 7191 }
6910 7192
6911 if (fw_event->event == MPT2SAS_RESCAN_AFTER_HOST_RESET) { 7193 switch (fw_event->event) {
6912 _scsih_fw_event_free(ioc, fw_event); 7194 case MPT2SAS_REMOVE_UNRESPONDING_DEVICES:
6913 spin_lock_irqsave(&ioc->ioc_reset_in_progress_lock, flags); 7195 while (scsi_host_in_recovery(ioc->shost))
6914 if (ioc->shost_recovery) { 7196 ssleep(1);
6915 init_completion(&ioc->shost_recovery_done);
6916 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock,
6917 flags);
6918 wait_for_completion(&ioc->shost_recovery_done);
6919 } else
6920 spin_unlock_irqrestore(&ioc->ioc_reset_in_progress_lock,
6921 flags);
6922 _scsih_remove_unresponding_sas_devices(ioc); 7197 _scsih_remove_unresponding_sas_devices(ioc);
6923 _scsih_hide_unhide_sas_devices(ioc); 7198 _scsih_scan_for_devices_after_reset(ioc);
6924 return; 7199 break;
6925 } 7200 case MPT2SAS_PORT_ENABLE_COMPLETE:
7201 ioc->start_scan = 0;
6926 7202
6927 switch (fw_event->event) { 7203
7204
7205 dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "port enable: complete "
7206 "from worker thread\n", ioc->name));
7207 break;
6928 case MPT2SAS_TURN_ON_FAULT_LED: 7208 case MPT2SAS_TURN_ON_FAULT_LED:
6929 _scsih_turn_on_fault_led(ioc, fw_event->device_handle); 7209 _scsih_turn_on_fault_led(ioc, fw_event->device_handle);
6930 break; 7210 break;
@@ -7121,6 +7401,8 @@ static struct scsi_host_template scsih_driver_template = {
7121 .slave_configure = _scsih_slave_configure, 7401 .slave_configure = _scsih_slave_configure,
7122 .target_destroy = _scsih_target_destroy, 7402 .target_destroy = _scsih_target_destroy,
7123 .slave_destroy = _scsih_slave_destroy, 7403 .slave_destroy = _scsih_slave_destroy,
7404 .scan_finished = _scsih_scan_finished,
7405 .scan_start = _scsih_scan_start,
7124 .change_queue_depth = _scsih_change_queue_depth, 7406 .change_queue_depth = _scsih_change_queue_depth,
7125 .change_queue_type = _scsih_change_queue_type, 7407 .change_queue_type = _scsih_change_queue_type,
7126 .eh_abort_handler = _scsih_abort, 7408 .eh_abort_handler = _scsih_abort,
@@ -7381,7 +7663,12 @@ _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
7381 unsigned long flags; 7663 unsigned long flags;
7382 int rc; 7664 int rc;
7383 7665
7666 /* no Bios, return immediately */
7667 if (!ioc->bios_pg3.BiosVersion)
7668 return;
7669
7384 device = NULL; 7670 device = NULL;
7671 is_raid = 0;
7385 if (ioc->req_boot_device.device) { 7672 if (ioc->req_boot_device.device) {
7386 device = ioc->req_boot_device.device; 7673 device = ioc->req_boot_device.device;
7387 is_raid = ioc->req_boot_device.is_raid; 7674 is_raid = ioc->req_boot_device.is_raid;
@@ -7417,8 +7704,9 @@ _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
7417 sas_device->sas_address_parent)) { 7704 sas_device->sas_address_parent)) {
7418 _scsih_sas_device_remove(ioc, sas_device); 7705 _scsih_sas_device_remove(ioc, sas_device);
7419 } else if (!sas_device->starget) { 7706 } else if (!sas_device->starget) {
7420 mpt2sas_transport_port_remove(ioc, sas_address, 7707 if (!ioc->is_driver_loading)
7421 sas_address_parent); 7708 mpt2sas_transport_port_remove(ioc, sas_address,
7709 sas_address_parent);
7422 _scsih_sas_device_remove(ioc, sas_device); 7710 _scsih_sas_device_remove(ioc, sas_device);
7423 } 7711 }
7424 } 7712 }
@@ -7462,22 +7750,28 @@ _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
7462 /* SAS Device List */ 7750 /* SAS Device List */
7463 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list, 7751 list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
7464 list) { 7752 list) {
7465 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7466 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7467 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7468 7753
7469 if (ioc->hide_drives) 7754 if (ioc->hide_drives)
7470 continue; 7755 continue;
7471 7756
7472 if (!mpt2sas_transport_port_add(ioc, sas_device->handle, 7757 if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
7473 sas_device->sas_address_parent)) { 7758 sas_device->sas_address_parent)) {
7474 _scsih_sas_device_remove(ioc, sas_device); 7759 list_del(&sas_device->list);
7760 kfree(sas_device);
7761 continue;
7475 } else if (!sas_device->starget) { 7762 } else if (!sas_device->starget) {
7476 mpt2sas_transport_port_remove(ioc, 7763 if (!ioc->is_driver_loading)
7477 sas_device->sas_address, 7764 mpt2sas_transport_port_remove(ioc,
7478 sas_device->sas_address_parent); 7765 sas_device->sas_address,
7479 _scsih_sas_device_remove(ioc, sas_device); 7766 sas_device->sas_address_parent);
7767 list_del(&sas_device->list);
7768 kfree(sas_device);
7769 continue;
7770
7480 } 7771 }
7772 spin_lock_irqsave(&ioc->sas_device_lock, flags);
7773 list_move_tail(&sas_device->list, &ioc->sas_device_list);
7774 spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
7481 } 7775 }
7482} 7776}
7483 7777
@@ -7490,9 +7784,7 @@ _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
7490static void 7784static void
7491_scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc) 7785_scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
7492{ 7786{
7493 u16 volume_mapping_flags = 7787 u16 volume_mapping_flags;
7494 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
7495 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
7496 7788
7497 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR)) 7789 if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
7498 return; /* return when IOC doesn't support initiator mode */ 7790 return; /* return when IOC doesn't support initiator mode */
@@ -7500,18 +7792,93 @@ _scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
7500 _scsih_probe_boot_devices(ioc); 7792 _scsih_probe_boot_devices(ioc);
7501 7793
7502 if (ioc->ir_firmware) { 7794 if (ioc->ir_firmware) {
7503 if ((volume_mapping_flags & 7795 volume_mapping_flags =
7504 MPI2_IOCPAGE8_IRFLAGS_HIGH_VOLUME_MAPPING)) { 7796 le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
7505 _scsih_probe_sas(ioc); 7797 MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
7798 if (volume_mapping_flags ==
7799 MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
7506 _scsih_probe_raid(ioc); 7800 _scsih_probe_raid(ioc);
7801 _scsih_probe_sas(ioc);
7507 } else { 7802 } else {
7508 _scsih_probe_raid(ioc);
7509 _scsih_probe_sas(ioc); 7803 _scsih_probe_sas(ioc);
7804 _scsih_probe_raid(ioc);
7510 } 7805 }
7511 } else 7806 } else
7512 _scsih_probe_sas(ioc); 7807 _scsih_probe_sas(ioc);
7513} 7808}
7514 7809
7810
7811/**
7812 * _scsih_scan_start - scsi lld callback for .scan_start
7813 * @shost: SCSI host pointer
7814 *
7815 * The shost has the ability to discover targets on its own instead
7816 * of scanning the entire bus. In our implemention, we will kick off
7817 * firmware discovery.
7818 */
7819static void
7820_scsih_scan_start(struct Scsi_Host *shost)
7821{
7822 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7823 int rc;
7824
7825 if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
7826 mpt2sas_enable_diag_buffer(ioc, diag_buffer_enable);
7827
7828 ioc->start_scan = 1;
7829 rc = mpt2sas_port_enable(ioc);
7830
7831 if (rc != 0)
7832 printk(MPT2SAS_INFO_FMT "port enable: FAILED\n", ioc->name);
7833}
7834
7835/**
7836 * _scsih_scan_finished - scsi lld callback for .scan_finished
7837 * @shost: SCSI host pointer
7838 * @time: elapsed time of the scan in jiffies
7839 *
7840 * This function will be called periodically until it returns 1 with the
7841 * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
7842 * we wait for firmware discovery to complete, then return 1.
7843 */
7844static int
7845_scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
7846{
7847 struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
7848
7849 if (time >= (300 * HZ)) {
7850 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
7851 printk(MPT2SAS_INFO_FMT "port enable: FAILED with timeout "
7852 "(timeout=300s)\n", ioc->name);
7853 ioc->is_driver_loading = 0;
7854 return 1;
7855 }
7856
7857 if (ioc->start_scan)
7858 return 0;
7859
7860 if (ioc->start_scan_failed) {
7861 printk(MPT2SAS_INFO_FMT "port enable: FAILED with "
7862 "(ioc_status=0x%08x)\n", ioc->name, ioc->start_scan_failed);
7863 ioc->is_driver_loading = 0;
7864 ioc->wait_for_discovery_to_complete = 0;
7865 ioc->remove_host = 1;
7866 return 1;
7867 }
7868
7869 printk(MPT2SAS_INFO_FMT "port enable: SUCCESS\n", ioc->name);
7870 ioc->base_cmds.status = MPT2_CMD_NOT_USED;
7871
7872 if (ioc->wait_for_discovery_to_complete) {
7873 ioc->wait_for_discovery_to_complete = 0;
7874 _scsih_probe_devices(ioc);
7875 }
7876 mpt2sas_base_start_watchdog(ioc);
7877 ioc->is_driver_loading = 0;
7878 return 1;
7879}
7880
7881
7515/** 7882/**
7516 * _scsih_probe - attach and add scsi host 7883 * _scsih_probe - attach and add scsi host
7517 * @pdev: PCI device struct 7884 * @pdev: PCI device struct
@@ -7548,6 +7915,7 @@ _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
7548 ioc->tm_cb_idx = tm_cb_idx; 7915 ioc->tm_cb_idx = tm_cb_idx;
7549 ioc->ctl_cb_idx = ctl_cb_idx; 7916 ioc->ctl_cb_idx = ctl_cb_idx;
7550 ioc->base_cb_idx = base_cb_idx; 7917 ioc->base_cb_idx = base_cb_idx;
7918 ioc->port_enable_cb_idx = port_enable_cb_idx;
7551 ioc->transport_cb_idx = transport_cb_idx; 7919 ioc->transport_cb_idx = transport_cb_idx;
7552 ioc->scsih_cb_idx = scsih_cb_idx; 7920 ioc->scsih_cb_idx = scsih_cb_idx;
7553 ioc->config_cb_idx = config_cb_idx; 7921 ioc->config_cb_idx = config_cb_idx;
@@ -7620,14 +7988,14 @@ _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
7620 goto out_thread_fail; 7988 goto out_thread_fail;
7621 } 7989 }
7622 7990
7623 ioc->wait_for_port_enable_to_complete = 1; 7991 ioc->is_driver_loading = 1;
7624 if ((mpt2sas_base_attach(ioc))) { 7992 if ((mpt2sas_base_attach(ioc))) {
7625 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", 7993 printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
7626 ioc->name, __FILE__, __LINE__, __func__); 7994 ioc->name, __FILE__, __LINE__, __func__);
7627 goto out_attach_fail; 7995 goto out_attach_fail;
7628 } 7996 }
7629 7997
7630 ioc->wait_for_port_enable_to_complete = 0; 7998 scsi_scan_host(shost);
7631 if (ioc->is_warpdrive) { 7999 if (ioc->is_warpdrive) {
7632 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) 8000 if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
7633 ioc->hide_drives = 0; 8001 ioc->hide_drives = 0;
@@ -7650,6 +8018,7 @@ _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
7650 out_thread_fail: 8018 out_thread_fail:
7651 list_del(&ioc->list); 8019 list_del(&ioc->list);
7652 scsi_remove_host(shost); 8020 scsi_remove_host(shost);
8021 scsi_host_put(shost);
7653 out_add_shost_fail: 8022 out_add_shost_fail:
7654 return -ENODEV; 8023 return -ENODEV;
7655} 8024}
@@ -7896,6 +8265,8 @@ _scsih_init(void)
7896 8265
7897 /* base internal commands callback handler */ 8266 /* base internal commands callback handler */
7898 base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done); 8267 base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
8268 port_enable_cb_idx = mpt2sas_base_register_callback_handler(
8269 mpt2sas_port_enable_done);
7899 8270
7900 /* transport internal commands callback handler */ 8271 /* transport internal commands callback handler */
7901 transport_cb_idx = mpt2sas_base_register_callback_handler( 8272 transport_cb_idx = mpt2sas_base_register_callback_handler(
@@ -7950,6 +8321,7 @@ _scsih_exit(void)
7950 mpt2sas_base_release_callback_handler(scsi_io_cb_idx); 8321 mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
7951 mpt2sas_base_release_callback_handler(tm_cb_idx); 8322 mpt2sas_base_release_callback_handler(tm_cb_idx);
7952 mpt2sas_base_release_callback_handler(base_cb_idx); 8323 mpt2sas_base_release_callback_handler(base_cb_idx);
8324 mpt2sas_base_release_callback_handler(port_enable_cb_idx);
7953 mpt2sas_base_release_callback_handler(transport_cb_idx); 8325 mpt2sas_base_release_callback_handler(transport_cb_idx);
7954 mpt2sas_base_release_callback_handler(scsih_cb_idx); 8326 mpt2sas_base_release_callback_handler(scsih_cb_idx);
7955 mpt2sas_base_release_callback_handler(config_cb_idx); 8327 mpt2sas_base_release_callback_handler(config_cb_idx);
diff --git a/drivers/scsi/mvsas/mv_init.c b/drivers/scsi/mvsas/mv_init.c
index 621b5e072758..6f589195746c 100644
--- a/drivers/scsi/mvsas/mv_init.c
+++ b/drivers/scsi/mvsas/mv_init.c
@@ -732,6 +732,16 @@ static struct pci_device_id __devinitdata mvs_pci_table[] = {
732 .class_mask = 0, 732 .class_mask = 0,
733 .driver_data = chip_9485, 733 .driver_data = chip_9485,
734 }, 734 },
735 { PCI_VDEVICE(OCZ, 0x1021), chip_9485}, /* OCZ RevoDrive3 */
736 { PCI_VDEVICE(OCZ, 0x1022), chip_9485}, /* OCZ RevoDrive3/zDriveR4 (exact model unknown) */
737 { PCI_VDEVICE(OCZ, 0x1040), chip_9485}, /* OCZ RevoDrive3/zDriveR4 (exact model unknown) */
738 { PCI_VDEVICE(OCZ, 0x1041), chip_9485}, /* OCZ RevoDrive3/zDriveR4 (exact model unknown) */
739 { PCI_VDEVICE(OCZ, 0x1042), chip_9485}, /* OCZ RevoDrive3/zDriveR4 (exact model unknown) */
740 { PCI_VDEVICE(OCZ, 0x1043), chip_9485}, /* OCZ RevoDrive3/zDriveR4 (exact model unknown) */
741 { PCI_VDEVICE(OCZ, 0x1044), chip_9485}, /* OCZ RevoDrive3/zDriveR4 (exact model unknown) */
742 { PCI_VDEVICE(OCZ, 0x1080), chip_9485}, /* OCZ RevoDrive3/zDriveR4 (exact model unknown) */
743 { PCI_VDEVICE(OCZ, 0x1083), chip_9485}, /* OCZ RevoDrive3/zDriveR4 (exact model unknown) */
744 { PCI_VDEVICE(OCZ, 0x1084), chip_9485}, /* OCZ RevoDrive3/zDriveR4 (exact model unknown) */
735 745
736 { } /* terminate list */ 746 { } /* terminate list */
737}; 747};
diff --git a/drivers/scsi/osd/osd_initiator.c b/drivers/scsi/osd/osd_initiator.c
index 86afb13f1e79..c06b8e5aa2cf 100644
--- a/drivers/scsi/osd/osd_initiator.c
+++ b/drivers/scsi/osd/osd_initiator.c
@@ -40,6 +40,7 @@
40 */ 40 */
41 41
42#include <linux/slab.h> 42#include <linux/slab.h>
43#include <linux/module.h>
43 44
44#include <scsi/osd_initiator.h> 45#include <scsi/osd_initiator.h>
45#include <scsi/osd_sec.h> 46#include <scsi/osd_sec.h>
diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
index b86db84d6f32..5163edb925cb 100644
--- a/drivers/scsi/pmcraid.c
+++ b/drivers/scsi/pmcraid.c
@@ -4102,7 +4102,7 @@ static long pmcraid_chr_ioctl(
4102 struct pmcraid_ioctl_header *hdr = NULL; 4102 struct pmcraid_ioctl_header *hdr = NULL;
4103 int retval = -ENOTTY; 4103 int retval = -ENOTTY;
4104 4104
4105 hdr = kmalloc(GFP_KERNEL, sizeof(struct pmcraid_ioctl_header)); 4105 hdr = kmalloc(sizeof(struct pmcraid_ioctl_header), GFP_KERNEL);
4106 4106
4107 if (!hdr) { 4107 if (!hdr) {
4108 pmcraid_err("faile to allocate memory for ioctl header\n"); 4108 pmcraid_err("faile to allocate memory for ioctl header\n");
diff --git a/drivers/scsi/ps3rom.c b/drivers/scsi/ps3rom.c
index cd178b9e40cd..959f10055be7 100644
--- a/drivers/scsi/ps3rom.c
+++ b/drivers/scsi/ps3rom.c
@@ -20,6 +20,7 @@
20 20
21#include <linux/cdrom.h> 21#include <linux/cdrom.h>
22#include <linux/highmem.h> 22#include <linux/highmem.h>
23#include <linux/module.h>
23#include <linux/slab.h> 24#include <linux/slab.h>
24 25
25#include <scsi/scsi.h> 26#include <scsi/scsi.h>
diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index 3474e86e98ab..2516adf1aeea 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -2279,7 +2279,7 @@ qla25xx_msix_rsp_q(int irq, void *dev_id)
2279 ha = rsp->hw; 2279 ha = rsp->hw;
2280 2280
2281 /* Clear the interrupt, if enabled, for this response queue */ 2281 /* Clear the interrupt, if enabled, for this response queue */
2282 if (rsp->options & ~BIT_6) { 2282 if (!ha->flags.disable_msix_handshake) {
2283 reg = &ha->iobase->isp24; 2283 reg = &ha->iobase->isp24;
2284 spin_lock_irqsave(&ha->hardware_lock, flags); 2284 spin_lock_irqsave(&ha->hardware_lock, flags);
2285 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT); 2285 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index fc3f168decb4..06bc26554a67 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -12,6 +12,7 @@
12#include <linux/blkdev.h> 12#include <linux/blkdev.h>
13#include <linux/completion.h> 13#include <linux/completion.h>
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/export.h>
15#include <linux/mempool.h> 16#include <linux/mempool.h>
16#include <linux/slab.h> 17#include <linux/slab.h>
17#include <linux/init.h> 18#include <linux/init.h>
@@ -1698,6 +1699,15 @@ struct request_queue *scsi_alloc_queue(struct scsi_device *sdev)
1698 1699
1699void scsi_free_queue(struct request_queue *q) 1700void scsi_free_queue(struct request_queue *q)
1700{ 1701{
1702 unsigned long flags;
1703
1704 WARN_ON(q->queuedata);
1705
1706 /* cause scsi_request_fn() to kill all non-finished requests */
1707 spin_lock_irqsave(q->queue_lock, flags);
1708 q->request_fn(q);
1709 spin_unlock_irqrestore(q->queue_lock, flags);
1710
1701 blk_cleanup_queue(q); 1711 blk_cleanup_queue(q);
1702} 1712}
1703 1713
diff --git a/drivers/scsi/scsi_lib_dma.c b/drivers/scsi/scsi_lib_dma.c
index dcd128583b89..2ac3f3975f78 100644
--- a/drivers/scsi/scsi_lib_dma.c
+++ b/drivers/scsi/scsi_lib_dma.c
@@ -4,6 +4,7 @@
4 4
5#include <linux/blkdev.h> 5#include <linux/blkdev.h>
6#include <linux/device.h> 6#include <linux/device.h>
7#include <linux/export.h>
7#include <linux/kernel.h> 8#include <linux/kernel.h>
8 9
9#include <scsi/scsi.h> 10#include <scsi/scsi.h>
diff --git a/drivers/scsi/scsi_netlink.c b/drivers/scsi/scsi_netlink.c
index 26a8a45584ef..44f76e8b58af 100644
--- a/drivers/scsi/scsi_netlink.c
+++ b/drivers/scsi/scsi_netlink.c
@@ -23,6 +23,7 @@
23#include <linux/security.h> 23#include <linux/security.h>
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/export.h>
26#include <net/sock.h> 27#include <net/sock.h>
27#include <net/netlink.h> 28#include <net/netlink.h>
28 29
diff --git a/drivers/scsi/scsi_pm.c b/drivers/scsi/scsi_pm.c
index d82a023a9015..d329f8b12e2b 100644
--- a/drivers/scsi/scsi_pm.c
+++ b/drivers/scsi/scsi_pm.c
@@ -6,6 +6,7 @@
6 */ 6 */
7 7
8#include <linux/pm_runtime.h> 8#include <linux/pm_runtime.h>
9#include <linux/export.h>
9 10
10#include <scsi/scsi.h> 11#include <scsi/scsi.h>
11#include <scsi/scsi_device.h> 12#include <scsi/scsi_device.h>
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 44e8ca398efa..72273a0e5666 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -322,6 +322,7 @@ out_device_destroy:
322 scsi_device_set_state(sdev, SDEV_DEL); 322 scsi_device_set_state(sdev, SDEV_DEL);
323 transport_destroy_device(&sdev->sdev_gendev); 323 transport_destroy_device(&sdev->sdev_gendev);
324 put_device(&sdev->sdev_dev); 324 put_device(&sdev->sdev_dev);
325 scsi_free_queue(sdev->request_queue);
325 put_device(&sdev->sdev_gendev); 326 put_device(&sdev->sdev_gendev);
326out: 327out:
327 if (display_failure_msg) 328 if (display_failure_msg)
diff --git a/drivers/scsi/scsi_tgt_if.c b/drivers/scsi/scsi_tgt_if.c
index 0172de197008..6209110f295d 100644
--- a/drivers/scsi/scsi_tgt_if.c
+++ b/drivers/scsi/scsi_tgt_if.c
@@ -22,6 +22,7 @@
22#include <linux/miscdevice.h> 22#include <linux/miscdevice.h>
23#include <linux/gfp.h> 23#include <linux/gfp.h>
24#include <linux/file.h> 24#include <linux/file.h>
25#include <linux/export.h>
25#include <net/tcp.h> 26#include <net/tcp.h>
26#include <scsi/scsi.h> 27#include <scsi/scsi.h>
27#include <scsi/scsi_cmnd.h> 28#include <scsi/scsi_cmnd.h>
diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
index 1bcd65a509e6..96029e6d027f 100644
--- a/drivers/scsi/scsi_transport_iscsi.c
+++ b/drivers/scsi/scsi_transport_iscsi.c
@@ -520,7 +520,7 @@ fail_host_msg:
520/** 520/**
521 * iscsi_bsg_host_add - Create and add the bsg hooks to receive requests 521 * iscsi_bsg_host_add - Create and add the bsg hooks to receive requests
522 * @shost: shost for iscsi_host 522 * @shost: shost for iscsi_host
523 * @cls_host: iscsi_cls_host adding the structures to 523 * @ihost: iscsi_cls_host adding the structures to
524 */ 524 */
525static int 525static int
526iscsi_bsg_host_add(struct Scsi_Host *shost, struct iscsi_cls_host *ihost) 526iscsi_bsg_host_add(struct Scsi_Host *shost, struct iscsi_cls_host *ihost)
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index a7942e5c8be8..fa3a5918009c 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -2590,18 +2590,16 @@ static int sd_probe(struct device *dev)
2590 spin_unlock(&sd_index_lock); 2590 spin_unlock(&sd_index_lock);
2591 } while (error == -EAGAIN); 2591 } while (error == -EAGAIN);
2592 2592
2593 if (error) 2593 if (error) {
2594 sdev_printk(KERN_WARNING, sdp, "sd_probe: memory exhausted.\n");
2594 goto out_put; 2595 goto out_put;
2595
2596 if (index >= SD_MAX_DISKS) {
2597 error = -ENODEV;
2598 sdev_printk(KERN_WARNING, sdp, "SCSI disk (sd) name space exhausted.\n");
2599 goto out_free_index;
2600 } 2596 }
2601 2597
2602 error = sd_format_disk_name("sd", index, gd->disk_name, DISK_NAME_LEN); 2598 error = sd_format_disk_name("sd", index, gd->disk_name, DISK_NAME_LEN);
2603 if (error) 2599 if (error) {
2600 sdev_printk(KERN_WARNING, sdp, "SCSI disk (sd) name length exceeded.\n");
2604 goto out_free_index; 2601 goto out_free_index;
2602 }
2605 2603
2606 sdkp->device = sdp; 2604 sdkp->device = sdp;
2607 sdkp->driver = &sd_template; 2605 sdkp->driver = &sd_template;
diff --git a/drivers/scsi/sd.h b/drivers/scsi/sd.h
index 6ad798bfd52a..4163f2910e3d 100644
--- a/drivers/scsi/sd.h
+++ b/drivers/scsi/sd.h
@@ -9,12 +9,6 @@
9#define SD_MAJORS 16 9#define SD_MAJORS 16
10 10
11/* 11/*
12 * This is limited by the naming scheme enforced in sd_probe,
13 * add another character to it if you really need more disks.
14 */
15#define SD_MAX_DISKS (((26 * 26) + 26 + 1) * 26)
16
17/*
18 * Time out in seconds for disks and Magneto-opticals (which are slower). 12 * Time out in seconds for disks and Magneto-opticals (which are slower).
19 */ 13 */
20#define SD_TIMEOUT (30 * HZ) 14#define SD_TIMEOUT (30 * HZ)
diff --git a/drivers/scsi/sr_ioctl.c b/drivers/scsi/sr_ioctl.c
index 8be30554119b..a3911c39ea50 100644
--- a/drivers/scsi/sr_ioctl.c
+++ b/drivers/scsi/sr_ioctl.c
@@ -4,6 +4,7 @@
4#include <linux/errno.h> 4#include <linux/errno.h>
5#include <linux/string.h> 5#include <linux/string.h>
6#include <linux/blkdev.h> 6#include <linux/blkdev.h>
7#include <linux/module.h>
7#include <linux/blkpg.h> 8#include <linux/blkpg.h>
8#include <linux/cdrom.h> 9#include <linux/cdrom.h>
9#include <linux/delay.h> 10#include <linux/delay.h>
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index 1871b8ae83ae..9b28f39bac26 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -462,14 +462,16 @@ static void st_scsi_execute_end(struct request *req, int uptodate)
462{ 462{
463 struct st_request *SRpnt = req->end_io_data; 463 struct st_request *SRpnt = req->end_io_data;
464 struct scsi_tape *STp = SRpnt->stp; 464 struct scsi_tape *STp = SRpnt->stp;
465 struct bio *tmp;
465 466
466 STp->buffer->cmdstat.midlevel_result = SRpnt->result = req->errors; 467 STp->buffer->cmdstat.midlevel_result = SRpnt->result = req->errors;
467 STp->buffer->cmdstat.residual = req->resid_len; 468 STp->buffer->cmdstat.residual = req->resid_len;
468 469
470 tmp = SRpnt->bio;
469 if (SRpnt->waiting) 471 if (SRpnt->waiting)
470 complete(SRpnt->waiting); 472 complete(SRpnt->waiting);
471 473
472 blk_rq_unmap_user(SRpnt->bio); 474 blk_rq_unmap_user(tmp);
473 __blk_put_request(req->q, req); 475 __blk_put_request(req->q, req);
474} 476}
475 477
diff --git a/drivers/sfi/sfi_core.h b/drivers/sfi/sfi_core.h
index b7cf220d44ec..1d5cfe854cf7 100644
--- a/drivers/sfi/sfi_core.h
+++ b/drivers/sfi/sfi_core.h
@@ -55,6 +55,9 @@
55 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 55 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56 56
57*/ 57*/
58
59#include <linux/sysfs.h>
60
58struct sfi_table_key{ 61struct sfi_table_key{
59 char *sig; 62 char *sig;
60 char *oem_id; 63 char *oem_id;
diff --git a/drivers/sh/intc/chip.c b/drivers/sh/intc/chip.c
index 33b2ed451e09..7b246efa94ea 100644
--- a/drivers/sh/intc/chip.c
+++ b/drivers/sh/intc/chip.c
@@ -186,7 +186,7 @@ static unsigned char intc_irq_sense_table[IRQ_TYPE_SENSE_MASK + 1] = {
186 !defined(CONFIG_CPU_SUBTYPE_SH7709) 186 !defined(CONFIG_CPU_SUBTYPE_SH7709)
187 [IRQ_TYPE_LEVEL_HIGH] = VALID(3), 187 [IRQ_TYPE_LEVEL_HIGH] = VALID(3),
188#endif 188#endif
189#if defined(CONFIG_ARCH_SH7372) 189#if defined(CONFIG_ARM) /* all recent SH-Mobile / R-Mobile ARM support this */
190 [IRQ_TYPE_EDGE_BOTH] = VALID(4), 190 [IRQ_TYPE_EDGE_BOTH] = VALID(4),
191#endif 191#endif
192}; 192};
@@ -202,11 +202,16 @@ static int intc_set_type(struct irq_data *data, unsigned int type)
202 if (!value) 202 if (!value)
203 return -EINVAL; 203 return -EINVAL;
204 204
205 value &= ~SENSE_VALID_FLAG;
206
205 ihp = intc_find_irq(d->sense, d->nr_sense, irq); 207 ihp = intc_find_irq(d->sense, d->nr_sense, irq);
206 if (ihp) { 208 if (ihp) {
209 /* PINT has 2-bit sense registers, should fail on EDGE_BOTH */
210 if (value >= (1 << _INTC_WIDTH(ihp->handle)))
211 return -EINVAL;
212
207 addr = INTC_REG(d, _INTC_ADDR_E(ihp->handle), 0); 213 addr = INTC_REG(d, _INTC_ADDR_E(ihp->handle), 0);
208 intc_reg_fns[_INTC_FN(ihp->handle)](addr, ihp->handle, 214 intc_reg_fns[_INTC_FN(ihp->handle)](addr, ihp->handle, value);
209 value & ~SENSE_VALID_FLAG);
210 } 215 }
211 216
212 return 0; 217 return 0;
diff --git a/drivers/sh/intc/core.c b/drivers/sh/intc/core.c
index c6ca115c71df..8b7a141ff35e 100644
--- a/drivers/sh/intc/core.c
+++ b/drivers/sh/intc/core.c
@@ -22,6 +22,7 @@
22#include <linux/irq.h> 22#include <linux/irq.h>
23#include <linux/io.h> 23#include <linux/io.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/stat.h>
25#include <linux/interrupt.h> 26#include <linux/interrupt.h>
26#include <linux/sh_intc.h> 27#include <linux/sh_intc.h>
27#include <linux/sysdev.h> 28#include <linux/sysdev.h>
@@ -29,6 +30,7 @@
29#include <linux/list.h> 30#include <linux/list.h>
30#include <linux/spinlock.h> 31#include <linux/spinlock.h>
31#include <linux/radix-tree.h> 32#include <linux/radix-tree.h>
33#include <linux/export.h>
32#include "internals.h" 34#include "internals.h"
33 35
34LIST_HEAD(intc_list); 36LIST_HEAD(intc_list);
diff --git a/drivers/sh/intc/dynamic.c b/drivers/sh/intc/dynamic.c
index a3677c9dfe36..5fea1ee8799a 100644
--- a/drivers/sh/intc/dynamic.c
+++ b/drivers/sh/intc/dynamic.c
@@ -14,6 +14,7 @@
14#include <linux/irq.h> 14#include <linux/irq.h>
15#include <linux/bitmap.h> 15#include <linux/bitmap.h>
16#include <linux/spinlock.h> 16#include <linux/spinlock.h>
17#include <linux/module.h>
17#include "internals.h" /* only for activate_irq() damage.. */ 18#include "internals.h" /* only for activate_irq() damage.. */
18 19
19/* 20/*
diff --git a/drivers/sh/intc/userimask.c b/drivers/sh/intc/userimask.c
index e32304b66cf1..56bf9336b92b 100644
--- a/drivers/sh/intc/userimask.c
+++ b/drivers/sh/intc/userimask.c
@@ -13,6 +13,7 @@
13#include <linux/sysdev.h> 13#include <linux/sysdev.h>
14#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/io.h> 15#include <linux/io.h>
16#include <linux/stat.h>
16#include <asm/sizes.h> 17#include <asm/sizes.h>
17#include "internals.h" 18#include "internals.h"
18 19
diff --git a/drivers/sh/intc/virq.c b/drivers/sh/intc/virq.c
index 1e6e2d0353ea..c7ec49ffd9f6 100644
--- a/drivers/sh/intc/virq.c
+++ b/drivers/sh/intc/virq.c
@@ -14,6 +14,7 @@
14#include <linux/list.h> 14#include <linux/list.h>
15#include <linux/radix-tree.h> 15#include <linux/radix-tree.h>
16#include <linux/spinlock.h> 16#include <linux/spinlock.h>
17#include <linux/export.h>
17#include "internals.h" 18#include "internals.h"
18 19
19static struct intc_map_entry intc_irq_xlate[NR_IRQS]; 20static struct intc_map_entry intc_irq_xlate[NR_IRQS];
diff --git a/drivers/sh/maple/maple.c b/drivers/sh/maple/maple.c
index 1e20604257af..bec81c2404f7 100644
--- a/drivers/sh/maple/maple.c
+++ b/drivers/sh/maple/maple.c
@@ -20,6 +20,7 @@
20#include <linux/maple.h> 20#include <linux/maple.h>
21#include <linux/dma-mapping.h> 21#include <linux/dma-mapping.h>
22#include <linux/delay.h> 22#include <linux/delay.h>
23#include <linux/module.h>
23#include <asm/cacheflush.h> 24#include <asm/cacheflush.h>
24#include <asm/dma.h> 25#include <asm/dma.h>
25#include <asm/io.h> 26#include <asm/io.h>
diff --git a/drivers/sh/pfc.c b/drivers/sh/pfc.c
index 75934e3ea34e..e67fe170d8d5 100644
--- a/drivers/sh/pfc.c
+++ b/drivers/sh/pfc.c
@@ -217,7 +217,7 @@ static int get_config_reg(struct pinmux_info *gpioc, pinmux_enum_t enum_id,
217 217
218 if (!r_width) 218 if (!r_width)
219 break; 219 break;
220 for (n = 0; n < (r_width / f_width) * 1 << f_width; n++) { 220 for (n = 0; n < (r_width / f_width) * (1 << f_width); n++) {
221 if (config_reg->enum_ids[n] == enum_id) { 221 if (config_reg->enum_ids[n] == enum_id) {
222 *crp = config_reg; 222 *crp = config_reg;
223 *indexp = n; 223 *indexp = n;
@@ -577,6 +577,32 @@ static void sh_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
577 sh_gpio_set_value(chip_to_pinmux(chip), offset, value); 577 sh_gpio_set_value(chip_to_pinmux(chip), offset, value);
578} 578}
579 579
580static int sh_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
581{
582 struct pinmux_info *gpioc = chip_to_pinmux(chip);
583 pinmux_enum_t enum_id;
584 pinmux_enum_t *enum_ids;
585 int i, k, pos;
586
587 pos = 0;
588 enum_id = 0;
589 while (1) {
590 pos = get_gpio_enum_id(gpioc, offset, pos, &enum_id);
591 if (pos <= 0 || !enum_id)
592 break;
593
594 for (i = 0; i < gpioc->gpio_irq_size; i++) {
595 enum_ids = gpioc->gpio_irq[i].enum_ids;
596 for (k = 0; enum_ids[k]; k++) {
597 if (enum_ids[k] == enum_id)
598 return gpioc->gpio_irq[i].irq;
599 }
600 }
601 }
602
603 return -ENOSYS;
604}
605
580int register_pinmux(struct pinmux_info *pip) 606int register_pinmux(struct pinmux_info *pip)
581{ 607{
582 struct gpio_chip *chip = &pip->chip; 608 struct gpio_chip *chip = &pip->chip;
@@ -592,6 +618,7 @@ int register_pinmux(struct pinmux_info *pip)
592 chip->get = sh_gpio_get; 618 chip->get = sh_gpio_get;
593 chip->direction_output = sh_gpio_direction_output; 619 chip->direction_output = sh_gpio_direction_output;
594 chip->set = sh_gpio_set; 620 chip->set = sh_gpio_set;
621 chip->to_irq = sh_gpio_to_irq;
595 622
596 WARN_ON(pip->first_gpio != 0); /* needs testing */ 623 WARN_ON(pip->first_gpio != 0); /* needs testing */
597 624
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index 52e2900d9d8e..a1fd73df5416 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -88,7 +88,7 @@ config SPI_BFIN_SPORT
88 88
89config SPI_AU1550 89config SPI_AU1550
90 tristate "Au1550/Au12x0 SPI Controller" 90 tristate "Au1550/Au12x0 SPI Controller"
91 depends on (SOC_AU1550 || SOC_AU1200) && EXPERIMENTAL 91 depends on MIPS_ALCHEMY && EXPERIMENTAL
92 select SPI_BITBANG 92 select SPI_BITBANG
93 help 93 help
94 If you say yes to this option, support will be included for the 94 If you say yes to this option, support will be included for the
diff --git a/drivers/spi/spi-altera.c b/drivers/spi/spi-altera.c
index 881c1967741d..c00d00e96ee4 100644
--- a/drivers/spi/spi-altera.c
+++ b/drivers/spi/spi-altera.c
@@ -16,6 +16,7 @@
16#include <linux/init.h> 16#include <linux/init.h>
17#include <linux/interrupt.h> 17#include <linux/interrupt.h>
18#include <linux/errno.h> 18#include <linux/errno.h>
19#include <linux/module.h>
19#include <linux/platform_device.h> 20#include <linux/platform_device.h>
20#include <linux/spi/spi.h> 21#include <linux/spi/spi.h>
21#include <linux/spi/spi_bitbang.h> 22#include <linux/spi/spi_bitbang.h>
diff --git a/drivers/spi/spi-au1550.c b/drivers/spi/spi-au1550.c
index bddee5f516b2..5784c8799616 100644
--- a/drivers/spi/spi-au1550.c
+++ b/drivers/spi/spi-au1550.c
@@ -25,6 +25,7 @@
25#include <linux/interrupt.h> 25#include <linux/interrupt.h>
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/errno.h> 27#include <linux/errno.h>
28#include <linux/module.h>
28#include <linux/device.h> 29#include <linux/device.h>
29#include <linux/platform_device.h> 30#include <linux/platform_device.h>
30#include <linux/resource.h> 31#include <linux/resource.h>
diff --git a/drivers/spi/spi-bitbang.c b/drivers/spi/spi-bitbang.c
index 02d57fbba295..aef59b1a15f7 100644
--- a/drivers/spi/spi-bitbang.c
+++ b/drivers/spi/spi-bitbang.c
@@ -20,6 +20,7 @@
20#include <linux/spinlock.h> 20#include <linux/spinlock.h>
21#include <linux/workqueue.h> 21#include <linux/workqueue.h>
22#include <linux/interrupt.h> 22#include <linux/interrupt.h>
23#include <linux/module.h>
23#include <linux/delay.h> 24#include <linux/delay.h>
24#include <linux/errno.h> 25#include <linux/errno.h>
25#include <linux/platform_device.h> 26#include <linux/platform_device.h>
diff --git a/drivers/spi/spi-butterfly.c b/drivers/spi/spi-butterfly.c
index 9f907ec52def..5ed08e537433 100644
--- a/drivers/spi/spi-butterfly.c
+++ b/drivers/spi/spi-butterfly.c
@@ -20,6 +20,7 @@
20#include <linux/kernel.h> 20#include <linux/kernel.h>
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/delay.h> 22#include <linux/delay.h>
23#include <linux/module.h>
23#include <linux/device.h> 24#include <linux/device.h>
24#include <linux/parport.h> 25#include <linux/parport.h>
25 26
diff --git a/drivers/spi/spi-dw-mmio.c b/drivers/spi/spi-dw-mmio.c
index fac399c3022c..db2f1ba06eab 100644
--- a/drivers/spi/spi-dw-mmio.c
+++ b/drivers/spi/spi-dw-mmio.c
@@ -15,6 +15,7 @@
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/spi/spi.h> 16#include <linux/spi/spi.h>
17#include <linux/scatterlist.h> 17#include <linux/scatterlist.h>
18#include <linux/module.h>
18 19
19#include "spi-dw.h" 20#include "spi-dw.h"
20 21
diff --git a/drivers/spi/spi-dw-pci.c b/drivers/spi/spi-dw-pci.c
index c5f37f03ac8b..f64250ea1611 100644
--- a/drivers/spi/spi-dw-pci.c
+++ b/drivers/spi/spi-dw-pci.c
@@ -21,6 +21,7 @@
21#include <linux/pci.h> 21#include <linux/pci.h>
22#include <linux/slab.h> 22#include <linux/slab.h>
23#include <linux/spi/spi.h> 23#include <linux/spi/spi.h>
24#include <linux/module.h>
24 25
25#include "spi-dw.h" 26#include "spi-dw.h"
26 27
diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c
index 296d94f4cf72..082458d73ce9 100644
--- a/drivers/spi/spi-dw.c
+++ b/drivers/spi/spi-dw.c
@@ -19,6 +19,7 @@
19 19
20#include <linux/dma-mapping.h> 20#include <linux/dma-mapping.h>
21#include <linux/interrupt.h> 21#include <linux/interrupt.h>
22#include <linux/module.h>
22#include <linux/highmem.h> 23#include <linux/highmem.h>
23#include <linux/delay.h> 24#include <linux/delay.h>
24#include <linux/slab.h> 25#include <linux/slab.h>
diff --git a/drivers/spi/spi-gpio.c b/drivers/spi/spi-gpio.c
index 635ff08b377f..e093d3ec41ba 100644
--- a/drivers/spi/spi-gpio.c
+++ b/drivers/spi/spi-gpio.c
@@ -18,6 +18,7 @@
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */ 19 */
20#include <linux/kernel.h> 20#include <linux/kernel.h>
21#include <linux/module.h>
21#include <linux/init.h> 22#include <linux/init.h>
22#include <linux/platform_device.h> 23#include <linux/platform_device.h>
23#include <linux/gpio.h> 24#include <linux/gpio.h>
diff --git a/drivers/spi/spi-oc-tiny.c b/drivers/spi/spi-oc-tiny.c
index 897274e8715c..698018fd992b 100644
--- a/drivers/spi/spi-oc-tiny.c
+++ b/drivers/spi/spi-oc-tiny.c
@@ -18,6 +18,7 @@
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/interrupt.h> 19#include <linux/interrupt.h>
20#include <linux/errno.h> 20#include <linux/errno.h>
21#include <linux/module.h>
21#include <linux/platform_device.h> 22#include <linux/platform_device.h>
22#include <linux/spi/spi.h> 23#include <linux/spi/spi.h>
23#include <linux/spi/spi_bitbang.h> 24#include <linux/spi/spi_bitbang.h>
diff --git a/drivers/spi/spi-omap-uwire.c b/drivers/spi/spi-omap-uwire.c
index 00a8e9d7dbe4..610f7391456e 100644
--- a/drivers/spi/spi-omap-uwire.c
+++ b/drivers/spi/spi-omap-uwire.c
@@ -45,6 +45,7 @@
45 45
46#include <linux/spi/spi.h> 46#include <linux/spi/spi.h>
47#include <linux/spi/spi_bitbang.h> 47#include <linux/spi/spi_bitbang.h>
48#include <linux/module.h>
48 49
49#include <asm/system.h> 50#include <asm/system.h>
50#include <asm/irq.h> 51#include <asm/irq.h>
diff --git a/drivers/spi/spi-orion.c b/drivers/spi/spi-orion.c
index 9421a390a5e3..13448c832c44 100644
--- a/drivers/spi/spi-orion.c
+++ b/drivers/spi/spi-orion.c
@@ -17,6 +17,7 @@
17#include <linux/io.h> 17#include <linux/io.h>
18#include <linux/spi/spi.h> 18#include <linux/spi/spi.h>
19#include <linux/spi/orion_spi.h> 19#include <linux/spi/orion_spi.h>
20#include <linux/module.h>
20#include <asm/unaligned.h> 21#include <asm/unaligned.h>
21 22
22#define DRIVER_NAME "orion_spi" 23#define DRIVER_NAME "orion_spi"
diff --git a/drivers/spi/spi-pxa2xx-pci.c b/drivers/spi/spi-pxa2xx-pci.c
index 378e504f89eb..8caa07d58e69 100644
--- a/drivers/spi/spi-pxa2xx-pci.c
+++ b/drivers/spi/spi-pxa2xx-pci.c
@@ -5,6 +5,7 @@
5#include <linux/pci.h> 5#include <linux/pci.h>
6#include <linux/platform_device.h> 6#include <linux/platform_device.h>
7#include <linux/of_device.h> 7#include <linux/of_device.h>
8#include <linux/module.h>
8#include <linux/spi/pxa2xx_spi.h> 9#include <linux/spi/pxa2xx_spi.h>
9 10
10struct ce4100_info { 11struct ce4100_info {
diff --git a/drivers/spi/spi-s3c24xx.c b/drivers/spi/spi-s3c24xx.c
index b857a3e7af94..fc064535f4fc 100644
--- a/drivers/spi/spi-s3c24xx.c
+++ b/drivers/spi/spi-s3c24xx.c
@@ -24,6 +24,7 @@
24 24
25#include <linux/spi/spi.h> 25#include <linux/spi/spi.h>
26#include <linux/spi/spi_bitbang.h> 26#include <linux/spi/spi_bitbang.h>
27#include <linux/module.h>
27 28
28#include <plat/regs-spi.h> 29#include <plat/regs-spi.h>
29#include <mach/spi.h> 30#include <mach/spi.h>
diff --git a/drivers/spi/spi-s3c64xx.c b/drivers/spi/spi-s3c64xx.c
index 595dacc7645f..019a7163572f 100644
--- a/drivers/spi/spi-s3c64xx.c
+++ b/drivers/spi/spi-s3c64xx.c
@@ -131,6 +131,12 @@
131#define RXBUSY (1<<2) 131#define RXBUSY (1<<2)
132#define TXBUSY (1<<3) 132#define TXBUSY (1<<3)
133 133
134struct s3c64xx_spi_dma_data {
135 unsigned ch;
136 enum dma_data_direction direction;
137 enum dma_ch dmach;
138};
139
134/** 140/**
135 * struct s3c64xx_spi_driver_data - Runtime info holder for SPI driver. 141 * struct s3c64xx_spi_driver_data - Runtime info holder for SPI driver.
136 * @clk: Pointer to the spi clock. 142 * @clk: Pointer to the spi clock.
@@ -164,13 +170,14 @@ struct s3c64xx_spi_driver_data {
164 struct work_struct work; 170 struct work_struct work;
165 struct list_head queue; 171 struct list_head queue;
166 spinlock_t lock; 172 spinlock_t lock;
167 enum dma_ch rx_dmach;
168 enum dma_ch tx_dmach;
169 unsigned long sfr_start; 173 unsigned long sfr_start;
170 struct completion xfer_completion; 174 struct completion xfer_completion;
171 unsigned state; 175 unsigned state;
172 unsigned cur_mode, cur_bpw; 176 unsigned cur_mode, cur_bpw;
173 unsigned cur_speed; 177 unsigned cur_speed;
178 struct s3c64xx_spi_dma_data rx_dma;
179 struct s3c64xx_spi_dma_data tx_dma;
180 struct samsung_dma_ops *ops;
174}; 181};
175 182
176static struct s3c2410_dma_client s3c64xx_spi_dma_client = { 183static struct s3c2410_dma_client s3c64xx_spi_dma_client = {
@@ -226,6 +233,78 @@ static void flush_fifo(struct s3c64xx_spi_driver_data *sdd)
226 writel(val, regs + S3C64XX_SPI_CH_CFG); 233 writel(val, regs + S3C64XX_SPI_CH_CFG);
227} 234}
228 235
236static void s3c64xx_spi_dmacb(void *data)
237{
238 struct s3c64xx_spi_driver_data *sdd;
239 struct s3c64xx_spi_dma_data *dma = data;
240 unsigned long flags;
241
242 if (dma->direction == DMA_FROM_DEVICE)
243 sdd = container_of(data,
244 struct s3c64xx_spi_driver_data, rx_dma);
245 else
246 sdd = container_of(data,
247 struct s3c64xx_spi_driver_data, tx_dma);
248
249 spin_lock_irqsave(&sdd->lock, flags);
250
251 if (dma->direction == DMA_FROM_DEVICE) {
252 sdd->state &= ~RXBUSY;
253 if (!(sdd->state & TXBUSY))
254 complete(&sdd->xfer_completion);
255 } else {
256 sdd->state &= ~TXBUSY;
257 if (!(sdd->state & RXBUSY))
258 complete(&sdd->xfer_completion);
259 }
260
261 spin_unlock_irqrestore(&sdd->lock, flags);
262}
263
264static void prepare_dma(struct s3c64xx_spi_dma_data *dma,
265 unsigned len, dma_addr_t buf)
266{
267 struct s3c64xx_spi_driver_data *sdd;
268 struct samsung_dma_prep_info info;
269
270 if (dma->direction == DMA_FROM_DEVICE)
271 sdd = container_of((void *)dma,
272 struct s3c64xx_spi_driver_data, rx_dma);
273 else
274 sdd = container_of((void *)dma,
275 struct s3c64xx_spi_driver_data, tx_dma);
276
277 info.cap = DMA_SLAVE;
278 info.len = len;
279 info.fp = s3c64xx_spi_dmacb;
280 info.fp_param = dma;
281 info.direction = dma->direction;
282 info.buf = buf;
283
284 sdd->ops->prepare(dma->ch, &info);
285 sdd->ops->trigger(dma->ch);
286}
287
288static int acquire_dma(struct s3c64xx_spi_driver_data *sdd)
289{
290 struct samsung_dma_info info;
291
292 sdd->ops = samsung_dma_get_ops();
293
294 info.cap = DMA_SLAVE;
295 info.client = &s3c64xx_spi_dma_client;
296 info.width = sdd->cur_bpw / 8;
297
298 info.direction = sdd->rx_dma.direction;
299 info.fifo = sdd->sfr_start + S3C64XX_SPI_RX_DATA;
300 sdd->rx_dma.ch = sdd->ops->request(sdd->rx_dma.dmach, &info);
301 info.direction = sdd->tx_dma.direction;
302 info.fifo = sdd->sfr_start + S3C64XX_SPI_TX_DATA;
303 sdd->tx_dma.ch = sdd->ops->request(sdd->tx_dma.dmach, &info);
304
305 return 1;
306}
307
229static void enable_datapath(struct s3c64xx_spi_driver_data *sdd, 308static void enable_datapath(struct s3c64xx_spi_driver_data *sdd,
230 struct spi_device *spi, 309 struct spi_device *spi,
231 struct spi_transfer *xfer, int dma_mode) 310 struct spi_transfer *xfer, int dma_mode)
@@ -258,10 +337,7 @@ static void enable_datapath(struct s3c64xx_spi_driver_data *sdd,
258 chcfg |= S3C64XX_SPI_CH_TXCH_ON; 337 chcfg |= S3C64XX_SPI_CH_TXCH_ON;
259 if (dma_mode) { 338 if (dma_mode) {
260 modecfg |= S3C64XX_SPI_MODE_TXDMA_ON; 339 modecfg |= S3C64XX_SPI_MODE_TXDMA_ON;
261 s3c2410_dma_config(sdd->tx_dmach, sdd->cur_bpw / 8); 340 prepare_dma(&sdd->tx_dma, xfer->len, xfer->tx_dma);
262 s3c2410_dma_enqueue(sdd->tx_dmach, (void *)sdd,
263 xfer->tx_dma, xfer->len);
264 s3c2410_dma_ctrl(sdd->tx_dmach, S3C2410_DMAOP_START);
265 } else { 341 } else {
266 switch (sdd->cur_bpw) { 342 switch (sdd->cur_bpw) {
267 case 32: 343 case 32:
@@ -293,10 +369,7 @@ static void enable_datapath(struct s3c64xx_spi_driver_data *sdd,
293 writel(((xfer->len * 8 / sdd->cur_bpw) & 0xffff) 369 writel(((xfer->len * 8 / sdd->cur_bpw) & 0xffff)
294 | S3C64XX_SPI_PACKET_CNT_EN, 370 | S3C64XX_SPI_PACKET_CNT_EN,
295 regs + S3C64XX_SPI_PACKET_CNT); 371 regs + S3C64XX_SPI_PACKET_CNT);
296 s3c2410_dma_config(sdd->rx_dmach, sdd->cur_bpw / 8); 372 prepare_dma(&sdd->rx_dma, xfer->len, xfer->rx_dma);
297 s3c2410_dma_enqueue(sdd->rx_dmach, (void *)sdd,
298 xfer->rx_dma, xfer->len);
299 s3c2410_dma_ctrl(sdd->rx_dmach, S3C2410_DMAOP_START);
300 } 373 }
301 } 374 }
302 375
@@ -482,46 +555,6 @@ static void s3c64xx_spi_config(struct s3c64xx_spi_driver_data *sdd)
482 } 555 }
483} 556}
484 557
485static void s3c64xx_spi_dma_rxcb(struct s3c2410_dma_chan *chan, void *buf_id,
486 int size, enum s3c2410_dma_buffresult res)
487{
488 struct s3c64xx_spi_driver_data *sdd = buf_id;
489 unsigned long flags;
490
491 spin_lock_irqsave(&sdd->lock, flags);
492
493 if (res == S3C2410_RES_OK)
494 sdd->state &= ~RXBUSY;
495 else
496 dev_err(&sdd->pdev->dev, "DmaAbrtRx-%d\n", size);
497
498 /* If the other done */
499 if (!(sdd->state & TXBUSY))
500 complete(&sdd->xfer_completion);
501
502 spin_unlock_irqrestore(&sdd->lock, flags);
503}
504
505static void s3c64xx_spi_dma_txcb(struct s3c2410_dma_chan *chan, void *buf_id,
506 int size, enum s3c2410_dma_buffresult res)
507{
508 struct s3c64xx_spi_driver_data *sdd = buf_id;
509 unsigned long flags;
510
511 spin_lock_irqsave(&sdd->lock, flags);
512
513 if (res == S3C2410_RES_OK)
514 sdd->state &= ~TXBUSY;
515 else
516 dev_err(&sdd->pdev->dev, "DmaAbrtTx-%d \n", size);
517
518 /* If the other done */
519 if (!(sdd->state & RXBUSY))
520 complete(&sdd->xfer_completion);
521
522 spin_unlock_irqrestore(&sdd->lock, flags);
523}
524
525#define XFER_DMAADDR_INVALID DMA_BIT_MASK(32) 558#define XFER_DMAADDR_INVALID DMA_BIT_MASK(32)
526 559
527static int s3c64xx_spi_map_mssg(struct s3c64xx_spi_driver_data *sdd, 560static int s3c64xx_spi_map_mssg(struct s3c64xx_spi_driver_data *sdd,
@@ -696,12 +729,10 @@ static void handle_msg(struct s3c64xx_spi_driver_data *sdd,
696 if (use_dma) { 729 if (use_dma) {
697 if (xfer->tx_buf != NULL 730 if (xfer->tx_buf != NULL
698 && (sdd->state & TXBUSY)) 731 && (sdd->state & TXBUSY))
699 s3c2410_dma_ctrl(sdd->tx_dmach, 732 sdd->ops->stop(sdd->tx_dma.ch);
700 S3C2410_DMAOP_FLUSH);
701 if (xfer->rx_buf != NULL 733 if (xfer->rx_buf != NULL
702 && (sdd->state & RXBUSY)) 734 && (sdd->state & RXBUSY))
703 s3c2410_dma_ctrl(sdd->rx_dmach, 735 sdd->ops->stop(sdd->rx_dma.ch);
704 S3C2410_DMAOP_FLUSH);
705 } 736 }
706 737
707 goto out; 738 goto out;
@@ -739,30 +770,6 @@ out:
739 msg->complete(msg->context); 770 msg->complete(msg->context);
740} 771}
741 772
742static int acquire_dma(struct s3c64xx_spi_driver_data *sdd)
743{
744 if (s3c2410_dma_request(sdd->rx_dmach,
745 &s3c64xx_spi_dma_client, NULL) < 0) {
746 dev_err(&sdd->pdev->dev, "cannot get RxDMA\n");
747 return 0;
748 }
749 s3c2410_dma_set_buffdone_fn(sdd->rx_dmach, s3c64xx_spi_dma_rxcb);
750 s3c2410_dma_devconfig(sdd->rx_dmach, S3C2410_DMASRC_HW,
751 sdd->sfr_start + S3C64XX_SPI_RX_DATA);
752
753 if (s3c2410_dma_request(sdd->tx_dmach,
754 &s3c64xx_spi_dma_client, NULL) < 0) {
755 dev_err(&sdd->pdev->dev, "cannot get TxDMA\n");
756 s3c2410_dma_free(sdd->rx_dmach, &s3c64xx_spi_dma_client);
757 return 0;
758 }
759 s3c2410_dma_set_buffdone_fn(sdd->tx_dmach, s3c64xx_spi_dma_txcb);
760 s3c2410_dma_devconfig(sdd->tx_dmach, S3C2410_DMASRC_MEM,
761 sdd->sfr_start + S3C64XX_SPI_TX_DATA);
762
763 return 1;
764}
765
766static void s3c64xx_spi_work(struct work_struct *work) 773static void s3c64xx_spi_work(struct work_struct *work)
767{ 774{
768 struct s3c64xx_spi_driver_data *sdd = container_of(work, 775 struct s3c64xx_spi_driver_data *sdd = container_of(work,
@@ -799,8 +806,8 @@ static void s3c64xx_spi_work(struct work_struct *work)
799 spin_unlock_irqrestore(&sdd->lock, flags); 806 spin_unlock_irqrestore(&sdd->lock, flags);
800 807
801 /* Free DMA channels */ 808 /* Free DMA channels */
802 s3c2410_dma_free(sdd->tx_dmach, &s3c64xx_spi_dma_client); 809 sdd->ops->release(sdd->rx_dma.ch, &s3c64xx_spi_dma_client);
803 s3c2410_dma_free(sdd->rx_dmach, &s3c64xx_spi_dma_client); 810 sdd->ops->release(sdd->tx_dma.ch, &s3c64xx_spi_dma_client);
804} 811}
805 812
806static int s3c64xx_spi_transfer(struct spi_device *spi, 813static int s3c64xx_spi_transfer(struct spi_device *spi,
@@ -1017,8 +1024,10 @@ static int __init s3c64xx_spi_probe(struct platform_device *pdev)
1017 sdd->cntrlr_info = sci; 1024 sdd->cntrlr_info = sci;
1018 sdd->pdev = pdev; 1025 sdd->pdev = pdev;
1019 sdd->sfr_start = mem_res->start; 1026 sdd->sfr_start = mem_res->start;
1020 sdd->tx_dmach = dmatx_res->start; 1027 sdd->tx_dma.dmach = dmatx_res->start;
1021 sdd->rx_dmach = dmarx_res->start; 1028 sdd->tx_dma.direction = DMA_TO_DEVICE;
1029 sdd->rx_dma.dmach = dmarx_res->start;
1030 sdd->rx_dma.direction = DMA_FROM_DEVICE;
1022 1031
1023 sdd->cur_bpw = 8; 1032 sdd->cur_bpw = 8;
1024 1033
@@ -1106,7 +1115,7 @@ static int __init s3c64xx_spi_probe(struct platform_device *pdev)
1106 pdev->id, master->num_chipselect); 1115 pdev->id, master->num_chipselect);
1107 dev_dbg(&pdev->dev, "\tIOmem=[0x%x-0x%x]\tDMA=[Rx-%d, Tx-%d]\n", 1116 dev_dbg(&pdev->dev, "\tIOmem=[0x%x-0x%x]\tDMA=[Rx-%d, Tx-%d]\n",
1108 mem_res->end, mem_res->start, 1117 mem_res->end, mem_res->start,
1109 sdd->rx_dmach, sdd->tx_dmach); 1118 sdd->rx_dma.dmach, sdd->tx_dma.dmach);
1110 1119
1111 return 0; 1120 return 0;
1112 1121
diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
index 0f4834ae28cd..1f466bc66d9d 100644
--- a/drivers/spi/spi-sh-msiof.c
+++ b/drivers/spi/spi-sh-msiof.c
@@ -19,6 +19,7 @@
19#include <linux/interrupt.h> 19#include <linux/interrupt.h>
20#include <linux/io.h> 20#include <linux/io.h>
21#include <linux/kernel.h> 21#include <linux/kernel.h>
22#include <linux/module.h>
22#include <linux/platform_device.h> 23#include <linux/platform_device.h>
23#include <linux/pm_runtime.h> 24#include <linux/pm_runtime.h>
24 25
diff --git a/drivers/spi/spi-sh-sci.c b/drivers/spi/spi-sh-sci.c
index 8844bc342782..097e506042be 100644
--- a/drivers/spi/spi-sh-sci.c
+++ b/drivers/spi/spi-sh-sci.c
@@ -22,6 +22,7 @@
22 22
23#include <linux/spi/spi.h> 23#include <linux/spi/spi.h>
24#include <linux/spi/spi_bitbang.h> 24#include <linux/spi/spi_bitbang.h>
25#include <linux/module.h>
25 26
26#include <asm/spi.h> 27#include <asm/spi.h>
27#include <asm/io.h> 28#include <asm/io.h>
diff --git a/drivers/spi/spi-ti-ssp.c b/drivers/spi/spi-ti-ssp.c
index 7963c60063d6..3f6f6e81c655 100644
--- a/drivers/spi/spi-ti-ssp.c
+++ b/drivers/spi/spi-ti-ssp.c
@@ -22,6 +22,7 @@
22#include <linux/err.h> 22#include <linux/err.h>
23#include <linux/completion.h> 23#include <linux/completion.h>
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <linux/module.h>
25#include <linux/platform_device.h> 26#include <linux/platform_device.h>
26#include <linux/spi/spi.h> 27#include <linux/spi/spi.h>
27#include <linux/mfd/ti_ssp.h> 28#include <linux/mfd/ti_ssp.h>
diff --git a/drivers/spi/spi-tle62x0.c b/drivers/spi/spi-tle62x0.c
index 940e73d1cf09..0ce5c12aab55 100644
--- a/drivers/spi/spi-tle62x0.c
+++ b/drivers/spi/spi-tle62x0.c
@@ -11,6 +11,7 @@
11 11
12#include <linux/device.h> 12#include <linux/device.h>
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/module.h>
14#include <linux/slab.h> 15#include <linux/slab.h>
15 16
16#include <linux/spi/spi.h> 17#include <linux/spi/spi.h>
diff --git a/drivers/spi/spi-txx9.c b/drivers/spi/spi-txx9.c
index f0a2ab0428a3..d5a3cbb646cb 100644
--- a/drivers/spi/spi-txx9.c
+++ b/drivers/spi/spi-txx9.c
@@ -25,6 +25,7 @@
25#include <linux/err.h> 25#include <linux/err.h>
26#include <linux/clk.h> 26#include <linux/clk.h>
27#include <linux/io.h> 27#include <linux/io.h>
28#include <linux/module.h>
28#include <asm/gpio.h> 29#include <asm/gpio.h>
29 30
30 31
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 4d1b9f517ce8..77eae99af11c 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -29,6 +29,7 @@
29#include <linux/spi/spi.h> 29#include <linux/spi/spi.h>
30#include <linux/of_spi.h> 30#include <linux/of_spi.h>
31#include <linux/pm_runtime.h> 31#include <linux/pm_runtime.h>
32#include <linux/export.h>
32 33
33static void spidev_release(struct device *dev) 34static void spidev_release(struct device *dev)
34{ 35{
diff --git a/drivers/ssb/b43_pci_bridge.c b/drivers/ssb/b43_pci_bridge.c
index bf53e44c82a1..bad7ba517a1c 100644
--- a/drivers/ssb/b43_pci_bridge.c
+++ b/drivers/ssb/b43_pci_bridge.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <linux/pci.h> 13#include <linux/pci.h>
14#include <linux/module.h>
14#include <linux/ssb/ssb.h> 15#include <linux/ssb/ssb.h>
15 16
16#include "ssb_private.h" 17#include "ssb_private.h"
diff --git a/drivers/ssb/driver_chipcommon.c b/drivers/ssb/driver_chipcommon.c
index 5d9c97c24797..e9d2ca11283b 100644
--- a/drivers/ssb/driver_chipcommon.c
+++ b/drivers/ssb/driver_chipcommon.c
@@ -10,6 +10,7 @@
10 10
11#include <linux/ssb/ssb.h> 11#include <linux/ssb/ssb.h>
12#include <linux/ssb/ssb_regs.h> 12#include <linux/ssb/ssb_regs.h>
13#include <linux/export.h>
13#include <linux/pci.h> 14#include <linux/pci.h>
14 15
15#include "ssb_private.h" 16#include "ssb_private.h"
diff --git a/drivers/ssb/driver_chipcommon_pmu.c b/drivers/ssb/driver_chipcommon_pmu.c
index 52901c14c68b..e5a2e0e9bc19 100644
--- a/drivers/ssb/driver_chipcommon_pmu.c
+++ b/drivers/ssb/driver_chipcommon_pmu.c
@@ -12,6 +12,7 @@
12#include <linux/ssb/ssb_regs.h> 12#include <linux/ssb/ssb_regs.h>
13#include <linux/ssb/ssb_driver_chipcommon.h> 13#include <linux/ssb/ssb_driver_chipcommon.h>
14#include <linux/delay.h> 14#include <linux/delay.h>
15#include <linux/export.h>
15 16
16#include "ssb_private.h" 17#include "ssb_private.h"
17 18
diff --git a/drivers/ssb/driver_gige.c b/drivers/ssb/driver_gige.c
index 3adb98dad70c..f30ea689933a 100644
--- a/drivers/ssb/driver_gige.c
+++ b/drivers/ssb/driver_gige.c
@@ -10,6 +10,7 @@
10 10
11#include <linux/ssb/ssb.h> 11#include <linux/ssb/ssb.h>
12#include <linux/ssb/ssb_driver_gige.h> 12#include <linux/ssb/ssb_driver_gige.h>
13#include <linux/export.h>
13#include <linux/pci.h> 14#include <linux/pci.h>
14#include <linux/pci_regs.h> 15#include <linux/pci_regs.h>
15#include <linux/slab.h> 16#include <linux/slab.h>
diff --git a/drivers/ssb/driver_pcicore.c b/drivers/ssb/driver_pcicore.c
index e6ac3177fbbe..84c934c0a545 100644
--- a/drivers/ssb/driver_pcicore.c
+++ b/drivers/ssb/driver_pcicore.c
@@ -10,6 +10,7 @@
10 10
11#include <linux/ssb/ssb.h> 11#include <linux/ssb/ssb.h>
12#include <linux/pci.h> 12#include <linux/pci.h>
13#include <linux/export.h>
13#include <linux/delay.h> 14#include <linux/delay.h>
14#include <linux/ssb/ssb_embedded.h> 15#include <linux/ssb/ssb_embedded.h>
15 16
diff --git a/drivers/ssb/embedded.c b/drivers/ssb/embedded.c
index eec3e267be4d..9ef124f9ee2d 100644
--- a/drivers/ssb/embedded.c
+++ b/drivers/ssb/embedded.c
@@ -8,6 +8,7 @@
8 * Licensed under the GNU/GPL. See COPYING for details. 8 * Licensed under the GNU/GPL. See COPYING for details.
9 */ 9 */
10 10
11#include <linux/export.h>
11#include <linux/ssb/ssb.h> 12#include <linux/ssb/ssb.h>
12#include <linux/ssb/ssb_embedded.h> 13#include <linux/ssb/ssb_embedded.h>
13#include <linux/ssb/ssb_driver_pci.h> 14#include <linux/ssb/ssb_driver_pci.h>
diff --git a/drivers/ssb/main.c b/drivers/ssb/main.c
index d0cbdb0cf9d5..bb6317fb925c 100644
--- a/drivers/ssb/main.c
+++ b/drivers/ssb/main.c
@@ -12,6 +12,7 @@
12 12
13#include <linux/delay.h> 13#include <linux/delay.h>
14#include <linux/io.h> 14#include <linux/io.h>
15#include <linux/module.h>
15#include <linux/ssb/ssb.h> 16#include <linux/ssb/ssb.h>
16#include <linux/ssb/ssb_regs.h> 17#include <linux/ssb/ssb_regs.h>
17#include <linux/ssb/ssb_driver_gige.h> 18#include <linux/ssb/ssb_driver_gige.h>
diff --git a/drivers/ssb/pcihost_wrapper.c b/drivers/ssb/pcihost_wrapper.c
index 116a8116984b..af5448f5e2d2 100644
--- a/drivers/ssb/pcihost_wrapper.c
+++ b/drivers/ssb/pcihost_wrapper.c
@@ -12,6 +12,7 @@
12 */ 12 */
13 13
14#include <linux/pci.h> 14#include <linux/pci.h>
15#include <linux/export.h>
15#include <linux/slab.h> 16#include <linux/slab.h>
16#include <linux/ssb/ssb.h> 17#include <linux/ssb/ssb.h>
17 18
diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
index d132c27dfb3f..25cdff36a78a 100644
--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -30,12 +30,6 @@ source "drivers/staging/et131x/Kconfig"
30 30
31source "drivers/staging/slicoss/Kconfig" 31source "drivers/staging/slicoss/Kconfig"
32 32
33source "drivers/staging/go7007/Kconfig"
34
35source "drivers/staging/cx25821/Kconfig"
36
37source "drivers/staging/cxd2099/Kconfig"
38
39source "drivers/staging/usbip/Kconfig" 33source "drivers/staging/usbip/Kconfig"
40 34
41source "drivers/staging/winbond/Kconfig" 35source "drivers/staging/winbond/Kconfig"
@@ -104,20 +98,12 @@ source "drivers/staging/wlags49_h25/Kconfig"
104 98
105source "drivers/staging/sm7xx/Kconfig" 99source "drivers/staging/sm7xx/Kconfig"
106 100
107source "drivers/staging/dt3155v4l/Kconfig"
108
109source "drivers/staging/crystalhd/Kconfig" 101source "drivers/staging/crystalhd/Kconfig"
110 102
111source "drivers/staging/cxt1e1/Kconfig" 103source "drivers/staging/cxt1e1/Kconfig"
112 104
113source "drivers/staging/xgifb/Kconfig" 105source "drivers/staging/xgifb/Kconfig"
114 106
115source "drivers/staging/lirc/Kconfig"
116
117source "drivers/staging/easycap/Kconfig"
118
119source "drivers/staging/solo6x10/Kconfig"
120
121source "drivers/staging/tidspbridge/Kconfig" 107source "drivers/staging/tidspbridge/Kconfig"
122 108
123source "drivers/staging/quickstart/Kconfig" 109source "drivers/staging/quickstart/Kconfig"
@@ -144,4 +130,6 @@ source "drivers/staging/mei/Kconfig"
144 130
145source "drivers/staging/nvec/Kconfig" 131source "drivers/staging/nvec/Kconfig"
146 132
133source "drivers/staging/media/Kconfig"
134
147endif # STAGING 135endif # STAGING
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
index 936b7c22e18e..a25f3f26c7ff 100644
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -4,12 +4,9 @@
4obj-$(CONFIG_STAGING) += staging.o 4obj-$(CONFIG_STAGING) += staging.o
5 5
6obj-y += serial/ 6obj-y += serial/
7obj-y += media/
7obj-$(CONFIG_ET131X) += et131x/ 8obj-$(CONFIG_ET131X) += et131x/
8obj-$(CONFIG_SLICOSS) += slicoss/ 9obj-$(CONFIG_SLICOSS) += slicoss/
9obj-$(CONFIG_VIDEO_GO7007) += go7007/
10obj-$(CONFIG_VIDEO_CX25821) += cx25821/
11obj-$(CONFIG_DVB_CXD2099) += cxd2099/
12obj-$(CONFIG_LIRC_STAGING) += lirc/
13obj-$(CONFIG_USBIP_CORE) += usbip/ 10obj-$(CONFIG_USBIP_CORE) += usbip/
14obj-$(CONFIG_W35UND) += winbond/ 11obj-$(CONFIG_W35UND) += winbond/
15obj-$(CONFIG_PRISM2_USB) += wlan-ng/ 12obj-$(CONFIG_PRISM2_USB) += wlan-ng/
@@ -44,12 +41,9 @@ obj-$(CONFIG_ZCACHE) += zcache/
44obj-$(CONFIG_WLAGS49_H2) += wlags49_h2/ 41obj-$(CONFIG_WLAGS49_H2) += wlags49_h2/
45obj-$(CONFIG_WLAGS49_H25) += wlags49_h25/ 42obj-$(CONFIG_WLAGS49_H25) += wlags49_h25/
46obj-$(CONFIG_FB_SM7XX) += sm7xx/ 43obj-$(CONFIG_FB_SM7XX) += sm7xx/
47obj-$(CONFIG_VIDEO_DT3155) += dt3155v4l/
48obj-$(CONFIG_CRYSTALHD) += crystalhd/ 44obj-$(CONFIG_CRYSTALHD) += crystalhd/
49obj-$(CONFIG_CXT1E1) += cxt1e1/ 45obj-$(CONFIG_CXT1E1) += cxt1e1/
50obj-$(CONFIG_FB_XGI) += xgifb/ 46obj-$(CONFIG_FB_XGI) += xgifb/
51obj-$(CONFIG_EASYCAP) += easycap/
52obj-$(CONFIG_SOLO6X10) += solo6x10/
53obj-$(CONFIG_TIDSPBRIDGE) += tidspbridge/ 47obj-$(CONFIG_TIDSPBRIDGE) += tidspbridge/
54obj-$(CONFIG_ACPI_QUICKSTART) += quickstart/ 48obj-$(CONFIG_ACPI_QUICKSTART) += quickstart/
55obj-$(CONFIG_SBE_2T3E3) += sbe-2t3e3/ 49obj-$(CONFIG_SBE_2T3E3) += sbe-2t3e3/
diff --git a/drivers/staging/cx25821/README b/drivers/staging/cx25821/README
deleted file mode 100644
index a9ba50b9888b..000000000000
--- a/drivers/staging/cx25821/README
+++ /dev/null
@@ -1,6 +0,0 @@
1Todo:
2 - checkpatch.pl cleanups
3 - sparse cleanups
4
5Please send patches to linux-media@vger.kernel.org
6
diff --git a/drivers/staging/cxt1e1/linux.c b/drivers/staging/cxt1e1/linux.c
index 24e009c0149b..911c0e4375fd 100644
--- a/drivers/staging/cxt1e1/linux.c
+++ b/drivers/staging/cxt1e1/linux.c
@@ -16,6 +16,7 @@
16 16
17#include <linux/types.h> 17#include <linux/types.h>
18#include <linux/netdevice.h> 18#include <linux/netdevice.h>
19#include <linux/module.h>
19#include <linux/hdlc.h> 20#include <linux/hdlc.h>
20#include <linux/if_arp.h> 21#include <linux/if_arp.h>
21#include <linux/init.h> 22#include <linux/init.h>
diff --git a/drivers/staging/gma500/intel_i2c.c b/drivers/staging/gma500/intel_i2c.c
index e33432df510c..51cbf65268e6 100644
--- a/drivers/staging/gma500/intel_i2c.c
+++ b/drivers/staging/gma500/intel_i2c.c
@@ -20,6 +20,7 @@
20 20
21#include <linux/i2c.h> 21#include <linux/i2c.h>
22#include <linux/i2c-algo-bit.h> 22#include <linux/i2c-algo-bit.h>
23#include <linux/export.h>
23 24
24#include "psb_drv.h" 25#include "psb_drv.h"
25#include "psb_intel_reg.h" 26#include "psb_intel_reg.h"
diff --git a/drivers/staging/gma500/mdfld_dsi_output.c b/drivers/staging/gma500/mdfld_dsi_output.c
index 9050c0f78b15..3f979db2c3a5 100644
--- a/drivers/staging/gma500/mdfld_dsi_output.c
+++ b/drivers/staging/gma500/mdfld_dsi_output.c
@@ -32,6 +32,7 @@
32#include <asm/intel_scu_ipc.h> 32#include <asm/intel_scu_ipc.h>
33#include "mdfld_dsi_pkg_sender.h" 33#include "mdfld_dsi_pkg_sender.h"
34#include <linux/pm_runtime.h> 34#include <linux/pm_runtime.h>
35#include <linux/moduleparam.h>
35 36
36#define MDFLD_DSI_BRIGHTNESS_MAX_LEVEL 100 37#define MDFLD_DSI_BRIGHTNESS_MAX_LEVEL 100
37 38
diff --git a/drivers/staging/gma500/mdfld_output.c b/drivers/staging/gma500/mdfld_output.c
index ee55f87ba1fd..eabf53d58f92 100644
--- a/drivers/staging/gma500/mdfld_output.c
+++ b/drivers/staging/gma500/mdfld_output.c
@@ -26,6 +26,7 @@
26*/ 26*/
27 27
28#include <linux/init.h> 28#include <linux/init.h>
29#include <linux/moduleparam.h>
29#include "mdfld_dsi_dbi.h" 30#include "mdfld_dsi_dbi.h"
30#include "mdfld_dsi_dpi.h" 31#include "mdfld_dsi_dpi.h"
31#include "mdfld_dsi_output.h" 32#include "mdfld_dsi_output.h"
@@ -167,4 +168,4 @@ void mdfld_output_setup(struct drm_device *dev)
167 else 168 else
168 mdfld_dbi_dsr_init(dev); 169 mdfld_dbi_dsr_init(dev);
169 } 170 }
170} \ No newline at end of file 171}
diff --git a/drivers/staging/gma500/mid_bios.c b/drivers/staging/gma500/mid_bios.c
index 8cfe301f8fb2..ee3c0368e320 100644
--- a/drivers/staging/gma500/mid_bios.c
+++ b/drivers/staging/gma500/mid_bios.c
@@ -23,6 +23,7 @@
23 * - Check ioremap failures 23 * - Check ioremap failures
24 */ 24 */
25 25
26#include <linux/moduleparam.h>
26#include <drm/drmP.h> 27#include <drm/drmP.h>
27#include <drm/drm.h> 28#include <drm/drm.h>
28#include "psb_drm.h" 29#include "psb_drm.h"
diff --git a/drivers/staging/gma500/mrst_hdmi_i2c.c b/drivers/staging/gma500/mrst_hdmi_i2c.c
index 351b9d897b9f..36e7edc4d14c 100644
--- a/drivers/staging/gma500/mrst_hdmi_i2c.c
+++ b/drivers/staging/gma500/mrst_hdmi_i2c.c
@@ -29,6 +29,7 @@
29#include <linux/i2c.h> 29#include <linux/i2c.h>
30#include <linux/interrupt.h> 30#include <linux/interrupt.h>
31#include <linux/delay.h> 31#include <linux/delay.h>
32#include <linux/export.h>
32#include "psb_drv.h" 33#include "psb_drv.h"
33 34
34#define HDMI_READ(reg) readl(hdmi_dev->regs + (reg)) 35#define HDMI_READ(reg) readl(hdmi_dev->regs + (reg))
diff --git a/drivers/staging/gma500/psb_drv.c b/drivers/staging/gma500/psb_drv.c
index dc676c2ce810..986a04d16ba8 100644
--- a/drivers/staging/gma500/psb_drv.c
+++ b/drivers/staging/gma500/psb_drv.c
@@ -35,6 +35,7 @@
35#include <linux/notifier.h> 35#include <linux/notifier.h>
36#include <linux/spinlock.h> 36#include <linux/spinlock.h>
37#include <linux/pm_runtime.h> 37#include <linux/pm_runtime.h>
38#include <linux/module.h>
38#include <acpi/video.h> 39#include <acpi/video.h>
39 40
40static int drm_psb_trap_pagefaults; 41static int drm_psb_trap_pagefaults;
diff --git a/drivers/staging/iio/accel/adis16201_ring.c b/drivers/staging/iio/accel/adis16201_ring.c
index dbd883294d6c..0016ed378e3a 100644
--- a/drivers/staging/iio/accel/adis16201_ring.c
+++ b/drivers/staging/iio/accel/adis16201_ring.c
@@ -1,3 +1,4 @@
1#include <linux/export.h>
1#include <linux/interrupt.h> 2#include <linux/interrupt.h>
2#include <linux/mutex.h> 3#include <linux/mutex.h>
3#include <linux/kernel.h> 4#include <linux/kernel.h>
diff --git a/drivers/staging/iio/accel/adis16201_trigger.c b/drivers/staging/iio/accel/adis16201_trigger.c
index f448258884c5..bce505e716d0 100644
--- a/drivers/staging/iio/accel/adis16201_trigger.c
+++ b/drivers/staging/iio/accel/adis16201_trigger.c
@@ -1,6 +1,7 @@
1#include <linux/interrupt.h> 1#include <linux/interrupt.h>
2#include <linux/kernel.h> 2#include <linux/kernel.h>
3#include <linux/spi/spi.h> 3#include <linux/spi/spi.h>
4#include <linux/export.h>
4 5
5#include "../iio.h" 6#include "../iio.h"
6#include "../trigger.h" 7#include "../trigger.h"
diff --git a/drivers/staging/iio/accel/adis16203_ring.c b/drivers/staging/iio/accel/adis16203_ring.c
index 838d3012c87b..1fdfe6f6ac6e 100644
--- a/drivers/staging/iio/accel/adis16203_ring.c
+++ b/drivers/staging/iio/accel/adis16203_ring.c
@@ -1,3 +1,4 @@
1#include <linux/export.h>
1#include <linux/interrupt.h> 2#include <linux/interrupt.h>
2#include <linux/mutex.h> 3#include <linux/mutex.h>
3#include <linux/kernel.h> 4#include <linux/kernel.h>
diff --git a/drivers/staging/iio/accel/adis16203_trigger.c b/drivers/staging/iio/accel/adis16203_trigger.c
index 50165f9ddc52..24bcb8e15c55 100644
--- a/drivers/staging/iio/accel/adis16203_trigger.c
+++ b/drivers/staging/iio/accel/adis16203_trigger.c
@@ -1,6 +1,7 @@
1#include <linux/interrupt.h> 1#include <linux/interrupt.h>
2#include <linux/kernel.h> 2#include <linux/kernel.h>
3#include <linux/spi/spi.h> 3#include <linux/spi/spi.h>
4#include <linux/export.h>
4 5
5#include "../iio.h" 6#include "../iio.h"
6#include "../trigger.h" 7#include "../trigger.h"
diff --git a/drivers/staging/iio/accel/adis16204_ring.c b/drivers/staging/iio/accel/adis16204_ring.c
index 08551bb48f18..6fd3d8f51f2c 100644
--- a/drivers/staging/iio/accel/adis16204_ring.c
+++ b/drivers/staging/iio/accel/adis16204_ring.c
@@ -1,3 +1,4 @@
1#include <linux/export.h>
1#include <linux/interrupt.h> 2#include <linux/interrupt.h>
2#include <linux/mutex.h> 3#include <linux/mutex.h>
3#include <linux/kernel.h> 4#include <linux/kernel.h>
diff --git a/drivers/staging/iio/accel/adis16204_trigger.c b/drivers/staging/iio/accel/adis16204_trigger.c
index 55b661c98d2d..6e542af02c09 100644
--- a/drivers/staging/iio/accel/adis16204_trigger.c
+++ b/drivers/staging/iio/accel/adis16204_trigger.c
@@ -1,6 +1,7 @@
1#include <linux/interrupt.h> 1#include <linux/interrupt.h>
2#include <linux/kernel.h> 2#include <linux/kernel.h>
3#include <linux/spi/spi.h> 3#include <linux/spi/spi.h>
4#include <linux/export.h>
4 5
5#include "../iio.h" 6#include "../iio.h"
6#include "../trigger.h" 7#include "../trigger.h"
diff --git a/drivers/staging/iio/accel/adis16209_ring.c b/drivers/staging/iio/accel/adis16209_ring.c
index bb66364bef04..d17e39d95459 100644
--- a/drivers/staging/iio/accel/adis16209_ring.c
+++ b/drivers/staging/iio/accel/adis16209_ring.c
@@ -1,3 +1,4 @@
1#include <linux/export.h>
1#include <linux/interrupt.h> 2#include <linux/interrupt.h>
2#include <linux/mutex.h> 3#include <linux/mutex.h>
3#include <linux/kernel.h> 4#include <linux/kernel.h>
diff --git a/drivers/staging/iio/accel/adis16209_trigger.c b/drivers/staging/iio/accel/adis16209_trigger.c
index 8df8a9791d5e..c5d82c1a55d9 100644
--- a/drivers/staging/iio/accel/adis16209_trigger.c
+++ b/drivers/staging/iio/accel/adis16209_trigger.c
@@ -1,6 +1,7 @@
1#include <linux/interrupt.h> 1#include <linux/interrupt.h>
2#include <linux/kernel.h> 2#include <linux/kernel.h>
3#include <linux/spi/spi.h> 3#include <linux/spi/spi.h>
4#include <linux/export.h>
4 5
5#include "../iio.h" 6#include "../iio.h"
6#include "../trigger.h" 7#include "../trigger.h"
diff --git a/drivers/staging/iio/accel/adis16240_ring.c b/drivers/staging/iio/accel/adis16240_ring.c
index 34f1e7e6a56f..b907ca3f4fdf 100644
--- a/drivers/staging/iio/accel/adis16240_ring.c
+++ b/drivers/staging/iio/accel/adis16240_ring.c
@@ -1,3 +1,4 @@
1#include <linux/export.h>
1#include <linux/interrupt.h> 2#include <linux/interrupt.h>
2#include <linux/mutex.h> 3#include <linux/mutex.h>
3#include <linux/kernel.h> 4#include <linux/kernel.h>
diff --git a/drivers/staging/iio/accel/adis16240_trigger.c b/drivers/staging/iio/accel/adis16240_trigger.c
index 13f1d142eea3..8e0ce568e64c 100644
--- a/drivers/staging/iio/accel/adis16240_trigger.c
+++ b/drivers/staging/iio/accel/adis16240_trigger.c
@@ -1,6 +1,7 @@
1#include <linux/interrupt.h> 1#include <linux/interrupt.h>
2#include <linux/kernel.h> 2#include <linux/kernel.h>
3#include <linux/spi/spi.h> 3#include <linux/spi/spi.h>
4#include <linux/export.h>
4 5
5#include "../iio.h" 6#include "../iio.h"
6#include "../trigger.h" 7#include "../trigger.h"
diff --git a/drivers/staging/iio/accel/lis3l02dq_ring.c b/drivers/staging/iio/accel/lis3l02dq_ring.c
index 5c542dd04616..89527af8f4c5 100644
--- a/drivers/staging/iio/accel/lis3l02dq_ring.c
+++ b/drivers/staging/iio/accel/lis3l02dq_ring.c
@@ -4,6 +4,7 @@
4#include <linux/kernel.h> 4#include <linux/kernel.h>
5#include <linux/spi/spi.h> 5#include <linux/spi/spi.h>
6#include <linux/slab.h> 6#include <linux/slab.h>
7#include <linux/export.h>
7 8
8#include "../iio.h" 9#include "../iio.h"
9#include "../ring_sw.h" 10#include "../ring_sw.h"
diff --git a/drivers/staging/iio/adc/ad7793.c b/drivers/staging/iio/adc/ad7793.c
index a831b92cd082..999f8f746cff 100644
--- a/drivers/staging/iio/adc/ad7793.c
+++ b/drivers/staging/iio/adc/ad7793.c
@@ -16,6 +16,7 @@
16#include <linux/err.h> 16#include <linux/err.h>
17#include <linux/sched.h> 17#include <linux/sched.h>
18#include <linux/delay.h> 18#include <linux/delay.h>
19#include <linux/module.h>
19 20
20#include "../iio.h" 21#include "../iio.h"
21#include "../sysfs.h" 22#include "../sysfs.h"
diff --git a/drivers/staging/iio/dac/ad5686.c b/drivers/staging/iio/dac/ad5686.c
index 48389e1c19f1..974c6f5b60c4 100644
--- a/drivers/staging/iio/dac/ad5686.c
+++ b/drivers/staging/iio/dac/ad5686.c
@@ -15,6 +15,7 @@
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/sysfs.h> 16#include <linux/sysfs.h>
17#include <linux/regulator/consumer.h> 17#include <linux/regulator/consumer.h>
18#include <linux/module.h>
18 19
19#include "../iio.h" 20#include "../iio.h"
20#include "../sysfs.h" 21#include "../sysfs.h"
diff --git a/drivers/staging/iio/gyro/adis16060_core.c b/drivers/staging/iio/gyro/adis16060_core.c
index 38cf3f4bf726..ff1b5a82b3d6 100644
--- a/drivers/staging/iio/gyro/adis16060_core.c
+++ b/drivers/staging/iio/gyro/adis16060_core.c
@@ -6,6 +6,7 @@
6 * Licensed under the GPL-2 or later. 6 * Licensed under the GPL-2 or later.
7 */ 7 */
8 8
9#include <linux/module.h>
9#include <linux/delay.h> 10#include <linux/delay.h>
10#include <linux/mutex.h> 11#include <linux/mutex.h>
11#include <linux/device.h> 12#include <linux/device.h>
diff --git a/drivers/staging/iio/gyro/adis16260_ring.c b/drivers/staging/iio/gyro/adis16260_ring.c
index 679c15155716..52a9e784e7c8 100644
--- a/drivers/staging/iio/gyro/adis16260_ring.c
+++ b/drivers/staging/iio/gyro/adis16260_ring.c
@@ -1,3 +1,4 @@
1#include <linux/export.h>
1#include <linux/interrupt.h> 2#include <linux/interrupt.h>
2#include <linux/mutex.h> 3#include <linux/mutex.h>
3#include <linux/kernel.h> 4#include <linux/kernel.h>
diff --git a/drivers/staging/iio/gyro/adis16260_trigger.c b/drivers/staging/iio/gyro/adis16260_trigger.c
index 2f2b2160f44d..8299cd18d705 100644
--- a/drivers/staging/iio/gyro/adis16260_trigger.c
+++ b/drivers/staging/iio/gyro/adis16260_trigger.c
@@ -1,6 +1,7 @@
1#include <linux/interrupt.h> 1#include <linux/interrupt.h>
2#include <linux/kernel.h> 2#include <linux/kernel.h>
3#include <linux/spi/spi.h> 3#include <linux/spi/spi.h>
4#include <linux/export.h>
4 5
5#include "../iio.h" 6#include "../iio.h"
6#include "../trigger.h" 7#include "../trigger.h"
diff --git a/drivers/staging/iio/iio_simple_dummy_buffer.c b/drivers/staging/iio/iio_simple_dummy_buffer.c
index f0b36d25414d..edad0e7b4f4d 100644
--- a/drivers/staging/iio/iio_simple_dummy_buffer.c
+++ b/drivers/staging/iio/iio_simple_dummy_buffer.c
@@ -12,6 +12,7 @@
12 */ 12 */
13 13
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/export.h>
15#include <linux/slab.h> 16#include <linux/slab.h>
16#include <linux/interrupt.h> 17#include <linux/interrupt.h>
17#include <linux/irq.h> 18#include <linux/irq.h>
diff --git a/drivers/staging/iio/imu/adis16400_ring.c b/drivers/staging/iio/imu/adis16400_ring.c
index c3682458d78d..fd886bf51a6d 100644
--- a/drivers/staging/iio/imu/adis16400_ring.c
+++ b/drivers/staging/iio/imu/adis16400_ring.c
@@ -4,6 +4,7 @@
4#include <linux/spi/spi.h> 4#include <linux/spi/spi.h>
5#include <linux/slab.h> 5#include <linux/slab.h>
6#include <linux/bitops.h> 6#include <linux/bitops.h>
7#include <linux/export.h>
7 8
8#include "../iio.h" 9#include "../iio.h"
9#include "../ring_sw.h" 10#include "../ring_sw.h"
diff --git a/drivers/staging/iio/imu/adis16400_trigger.c b/drivers/staging/iio/imu/adis16400_trigger.c
index bf991531e0d6..5bf000757522 100644
--- a/drivers/staging/iio/imu/adis16400_trigger.c
+++ b/drivers/staging/iio/imu/adis16400_trigger.c
@@ -1,6 +1,7 @@
1#include <linux/interrupt.h> 1#include <linux/interrupt.h>
2#include <linux/kernel.h> 2#include <linux/kernel.h>
3#include <linux/spi/spi.h> 3#include <linux/spi/spi.h>
4#include <linux/export.h>
4 5
5#include "../iio.h" 6#include "../iio.h"
6#include "../trigger.h" 7#include "../trigger.h"
diff --git a/drivers/staging/iio/industrialio-buffer.c b/drivers/staging/iio/industrialio-buffer.c
index 6dd5d7d629a1..9df0ce81dade 100644
--- a/drivers/staging/iio/industrialio-buffer.c
+++ b/drivers/staging/iio/industrialio-buffer.c
@@ -14,6 +14,7 @@
14 * - Alternative access techniques? 14 * - Alternative access techniques?
15 */ 15 */
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/export.h>
17#include <linux/device.h> 18#include <linux/device.h>
18#include <linux/fs.h> 19#include <linux/fs.h>
19#include <linux/cdev.h> 20#include <linux/cdev.h>
diff --git a/drivers/staging/iio/meter/ade7758_ring.c b/drivers/staging/iio/meter/ade7758_ring.c
index 99ade658a2dc..00fa2ac5c459 100644
--- a/drivers/staging/iio/meter/ade7758_ring.c
+++ b/drivers/staging/iio/meter/ade7758_ring.c
@@ -5,6 +5,7 @@
5 * 5 *
6 * Licensed under the GPL-2. 6 * Licensed under the GPL-2.
7 */ 7 */
8#include <linux/export.h>
8#include <linux/interrupt.h> 9#include <linux/interrupt.h>
9#include <linux/kernel.h> 10#include <linux/kernel.h>
10#include <linux/spi/spi.h> 11#include <linux/spi/spi.h>
diff --git a/drivers/staging/iio/meter/ade7758_trigger.c b/drivers/staging/iio/meter/ade7758_trigger.c
index 392dfe302443..b6569c706651 100644
--- a/drivers/staging/iio/meter/ade7758_trigger.c
+++ b/drivers/staging/iio/meter/ade7758_trigger.c
@@ -9,6 +9,7 @@
9#include <linux/interrupt.h> 9#include <linux/interrupt.h>
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <linux/spi/spi.h> 11#include <linux/spi/spi.h>
12#include <linux/export.h>
12 13
13#include "../iio.h" 14#include "../iio.h"
14#include "../trigger.h" 15#include "../trigger.h"
diff --git a/drivers/staging/intel_sst/intel_sst.c b/drivers/staging/intel_sst/intel_sst.c
index c303d85011b0..ff9aaec0557f 100644
--- a/drivers/staging/intel_sst/intel_sst.c
+++ b/drivers/staging/intel_sst/intel_sst.c
@@ -37,6 +37,7 @@
37#include <linux/firmware.h> 37#include <linux/firmware.h>
38#include <linux/miscdevice.h> 38#include <linux/miscdevice.h>
39#include <linux/pm_runtime.h> 39#include <linux/pm_runtime.h>
40#include <linux/module.h>
40#include <asm/mrst.h> 41#include <asm/mrst.h>
41#include "intel_sst.h" 42#include "intel_sst.h"
42#include "intel_sst_ioctl.h" 43#include "intel_sst_ioctl.h"
diff --git a/drivers/staging/intel_sst/intel_sst_drv_interface.c b/drivers/staging/intel_sst/intel_sst_drv_interface.c
index 69daa1404b68..22bd29c0c439 100644
--- a/drivers/staging/intel_sst/intel_sst_drv_interface.c
+++ b/drivers/staging/intel_sst/intel_sst_drv_interface.c
@@ -33,6 +33,7 @@
33#include <linux/fs.h> 33#include <linux/fs.h>
34#include <linux/firmware.h> 34#include <linux/firmware.h>
35#include <linux/pm_runtime.h> 35#include <linux/pm_runtime.h>
36#include <linux/export.h>
36#include "intel_sst.h" 37#include "intel_sst.h"
37#include "intel_sst_ioctl.h" 38#include "intel_sst_ioctl.h"
38#include "intel_sst_fw_ipc.h" 39#include "intel_sst_fw_ipc.h"
diff --git a/drivers/staging/line6/audio.c b/drivers/staging/line6/audio.c
index 61db1f99b0c8..8e7398393a59 100644
--- a/drivers/staging/line6/audio.c
+++ b/drivers/staging/line6/audio.c
@@ -11,6 +11,7 @@
11 11
12#include <sound/core.h> 12#include <sound/core.h>
13#include <sound/initval.h> 13#include <sound/initval.h>
14#include <linux/export.h>
14 15
15#include "driver.h" 16#include "driver.h"
16#include "audio.h" 17#include "audio.h"
diff --git a/drivers/staging/media/Kconfig b/drivers/staging/media/Kconfig
new file mode 100644
index 000000000000..7e5caa39ed3f
--- /dev/null
+++ b/drivers/staging/media/Kconfig
@@ -0,0 +1,37 @@
1menuconfig STAGING_MEDIA
2 bool "Media staging drivers"
3 default n
4 ---help---
5 This option allows you to select a number of media drivers that
6 don't have the "normal" Linux kernel quality level.
7 Most of them don't follow properly the V4L, DVB and/or RC API's,
8 so, they won't likely work fine with the existing applications.
9 That also means that, one fixed, their API's will change to match
10 the existing ones.
11
12 If you wish to work on these drivers, to help improve them, or
13 to report problems you have with them, please use the
14 linux-media@vger.kernel.org mailing list.
15
16 If in doubt, say N here.
17
18
19if STAGING_MEDIA
20
21# Please keep them in alphabetic order
22source "drivers/staging/media/as102/Kconfig"
23
24source "drivers/staging/media/cxd2099/Kconfig"
25
26source "drivers/staging/media/dt3155v4l/Kconfig"
27
28source "drivers/staging/media/easycap/Kconfig"
29
30source "drivers/staging/media/go7007/Kconfig"
31
32source "drivers/staging/media/solo6x10/Kconfig"
33
34# Keep LIRC at the end, as it has sub-menus
35source "drivers/staging/media/lirc/Kconfig"
36
37endif
diff --git a/drivers/staging/media/Makefile b/drivers/staging/media/Makefile
new file mode 100644
index 000000000000..c69124cdb0d3
--- /dev/null
+++ b/drivers/staging/media/Makefile
@@ -0,0 +1,7 @@
1obj-$(CONFIG_DVB_AS102) += as102/
2obj-$(CONFIG_DVB_CXD2099) += cxd2099/
3obj-$(CONFIG_EASYCAP) += easycap/
4obj-$(CONFIG_LIRC_STAGING) += lirc/
5obj-$(CONFIG_SOLO6X10) += solo6x10/
6obj-$(CONFIG_VIDEO_DT3155) += dt3155v4l/
7obj-$(CONFIG_VIDEO_GO7007) += go7007/
diff --git a/drivers/staging/media/as102/Kconfig b/drivers/staging/media/as102/Kconfig
new file mode 100644
index 000000000000..5865029db0f6
--- /dev/null
+++ b/drivers/staging/media/as102/Kconfig
@@ -0,0 +1,7 @@
1config DVB_AS102
2 tristate "Abilis AS102 DVB receiver"
3 depends on DVB_CORE && USB && I2C && INPUT
4 help
5 Choose Y or M here if you have a device containing an AS102
6
7 To compile this driver as a module, choose M here
diff --git a/drivers/staging/media/as102/Makefile b/drivers/staging/media/as102/Makefile
new file mode 100644
index 000000000000..e7dbb6f814d5
--- /dev/null
+++ b/drivers/staging/media/as102/Makefile
@@ -0,0 +1,6 @@
1dvb-as102-objs := as102_drv.o as102_fw.o as10x_cmd.o as10x_cmd_stream.o \
2 as102_fe.o as102_usb_drv.o as10x_cmd_cfg.o
3
4obj-$(CONFIG_DVB_AS102) += dvb-as102.o
5
6EXTRA_CFLAGS += -DCONFIG_AS102_USB -Idrivers/media/dvb/dvb-core
diff --git a/drivers/staging/media/as102/as102_drv.c b/drivers/staging/media/as102/as102_drv.c
new file mode 100644
index 000000000000..d335c7d6fa0f
--- /dev/null
+++ b/drivers/staging/media/as102/as102_drv.c
@@ -0,0 +1,351 @@
1/*
2 * Abilis Systems Single DVB-T Receiver
3 * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
4 * Copyright (C) 2010 Devin Heitmueller <dheitmueller@kernellabs.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; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20#include <linux/kernel.h>
21#include <linux/errno.h>
22#include <linux/init.h>
23#include <linux/slab.h>
24#include <linux/module.h>
25#include <linux/mm.h>
26#include <linux/kref.h>
27#include <asm/uaccess.h>
28#include <linux/usb.h>
29
30/* header file for Usb device driver*/
31#include "as102_drv.h"
32#include "as102_fw.h"
33#include "dvbdev.h"
34
35int debug;
36module_param_named(debug, debug, int, 0644);
37MODULE_PARM_DESC(debug, "Turn on/off debugging (default: off)");
38
39int dual_tuner;
40module_param_named(dual_tuner, dual_tuner, int, 0644);
41MODULE_PARM_DESC(dual_tuner, "Activate Dual-Tuner config (default: off)");
42
43static int fw_upload = 1;
44module_param_named(fw_upload, fw_upload, int, 0644);
45MODULE_PARM_DESC(fw_upload, "Turn on/off default FW upload (default: on)");
46
47static int pid_filtering;
48module_param_named(pid_filtering, pid_filtering, int, 0644);
49MODULE_PARM_DESC(pid_filtering, "Activate HW PID filtering (default: off)");
50
51static int ts_auto_disable;
52module_param_named(ts_auto_disable, ts_auto_disable, int, 0644);
53MODULE_PARM_DESC(ts_auto_disable, "Stream Auto Enable on FW (default: off)");
54
55int elna_enable = 1;
56module_param_named(elna_enable, elna_enable, int, 0644);
57MODULE_PARM_DESC(elna_enable, "Activate eLNA (default: on)");
58
59#ifdef DVB_DEFINE_MOD_OPT_ADAPTER_NR
60DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
61#endif
62
63static void as102_stop_stream(struct as102_dev_t *dev)
64{
65 struct as102_bus_adapter_t *bus_adap;
66
67 if (dev != NULL)
68 bus_adap = &dev->bus_adap;
69 else
70 return;
71
72 if (bus_adap->ops->stop_stream != NULL)
73 bus_adap->ops->stop_stream(dev);
74
75 if (ts_auto_disable) {
76 if (mutex_lock_interruptible(&dev->bus_adap.lock))
77 return;
78
79 if (as10x_cmd_stop_streaming(bus_adap) < 0)
80 dprintk(debug, "as10x_cmd_stop_streaming failed\n");
81
82 mutex_unlock(&dev->bus_adap.lock);
83 }
84}
85
86static int as102_start_stream(struct as102_dev_t *dev)
87{
88 struct as102_bus_adapter_t *bus_adap;
89 int ret = -EFAULT;
90
91 if (dev != NULL)
92 bus_adap = &dev->bus_adap;
93 else
94 return ret;
95
96 if (bus_adap->ops->start_stream != NULL)
97 ret = bus_adap->ops->start_stream(dev);
98
99 if (ts_auto_disable) {
100 if (mutex_lock_interruptible(&dev->bus_adap.lock))
101 return -EFAULT;
102
103 ret = as10x_cmd_start_streaming(bus_adap);
104
105 mutex_unlock(&dev->bus_adap.lock);
106 }
107
108 return ret;
109}
110
111static int as10x_pid_filter(struct as102_dev_t *dev,
112 int index, u16 pid, int onoff) {
113
114 struct as102_bus_adapter_t *bus_adap = &dev->bus_adap;
115 int ret = -EFAULT;
116
117 ENTER();
118
119 if (mutex_lock_interruptible(&dev->bus_adap.lock)) {
120 dprintk(debug, "mutex_lock_interruptible(lock) failed !\n");
121 return -EBUSY;
122 }
123
124 switch (onoff) {
125 case 0:
126 ret = as10x_cmd_del_PID_filter(bus_adap, (uint16_t) pid);
127 dprintk(debug, "DEL_PID_FILTER([%02d] 0x%04x) ret = %d\n",
128 index, pid, ret);
129 break;
130 case 1:
131 {
132 struct as10x_ts_filter filter;
133
134 filter.type = TS_PID_TYPE_TS;
135 filter.idx = 0xFF;
136 filter.pid = pid;
137
138 ret = as10x_cmd_add_PID_filter(bus_adap, &filter);
139 dprintk(debug, "ADD_PID_FILTER([%02d -> %02d], 0x%04x) ret = %d\n",
140 index, filter.idx, filter.pid, ret);
141 break;
142 }
143 }
144
145 mutex_unlock(&dev->bus_adap.lock);
146
147 LEAVE();
148 return ret;
149}
150
151static int as102_dvb_dmx_start_feed(struct dvb_demux_feed *dvbdmxfeed)
152{
153 int ret = 0;
154 struct dvb_demux *demux = dvbdmxfeed->demux;
155 struct as102_dev_t *as102_dev = demux->priv;
156
157 ENTER();
158
159 if (mutex_lock_interruptible(&as102_dev->sem))
160 return -ERESTARTSYS;
161
162 if (pid_filtering) {
163 as10x_pid_filter(as102_dev,
164 dvbdmxfeed->index, dvbdmxfeed->pid, 1);
165 }
166
167 if (as102_dev->streaming++ == 0)
168 ret = as102_start_stream(as102_dev);
169
170 mutex_unlock(&as102_dev->sem);
171 LEAVE();
172 return ret;
173}
174
175static int as102_dvb_dmx_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
176{
177 struct dvb_demux *demux = dvbdmxfeed->demux;
178 struct as102_dev_t *as102_dev = demux->priv;
179
180 ENTER();
181
182 if (mutex_lock_interruptible(&as102_dev->sem))
183 return -ERESTARTSYS;
184
185 if (--as102_dev->streaming == 0)
186 as102_stop_stream(as102_dev);
187
188 if (pid_filtering) {
189 as10x_pid_filter(as102_dev,
190 dvbdmxfeed->index, dvbdmxfeed->pid, 0);
191 }
192
193 mutex_unlock(&as102_dev->sem);
194 LEAVE();
195 return 0;
196}
197
198int as102_dvb_register(struct as102_dev_t *as102_dev)
199{
200 int ret = 0;
201 ENTER();
202
203 ret = dvb_register_adapter(&as102_dev->dvb_adap,
204 as102_dev->name,
205 THIS_MODULE,
206#if defined(CONFIG_AS102_USB)
207 &as102_dev->bus_adap.usb_dev->dev
208#elif defined(CONFIG_AS102_SPI)
209 &as102_dev->bus_adap.spi_dev->dev
210#else
211#error >>> dvb_register_adapter <<<
212#endif
213#ifdef DVB_DEFINE_MOD_OPT_ADAPTER_NR
214 , adapter_nr
215#endif
216 );
217 if (ret < 0) {
218 err("%s: dvb_register_adapter() failed (errno = %d)",
219 __func__, ret);
220 goto failed;
221 }
222
223 as102_dev->dvb_dmx.priv = as102_dev;
224 as102_dev->dvb_dmx.filternum = pid_filtering ? 16 : 256;
225 as102_dev->dvb_dmx.feednum = 256;
226 as102_dev->dvb_dmx.start_feed = as102_dvb_dmx_start_feed;
227 as102_dev->dvb_dmx.stop_feed = as102_dvb_dmx_stop_feed;
228
229 as102_dev->dvb_dmx.dmx.capabilities = DMX_TS_FILTERING |
230 DMX_SECTION_FILTERING;
231
232 as102_dev->dvb_dmxdev.filternum = as102_dev->dvb_dmx.filternum;
233 as102_dev->dvb_dmxdev.demux = &as102_dev->dvb_dmx.dmx;
234 as102_dev->dvb_dmxdev.capabilities = 0;
235
236 ret = dvb_dmx_init(&as102_dev->dvb_dmx);
237 if (ret < 0) {
238 err("%s: dvb_dmx_init() failed (errno = %d)", __func__, ret);
239 goto failed;
240 }
241
242 ret = dvb_dmxdev_init(&as102_dev->dvb_dmxdev, &as102_dev->dvb_adap);
243 if (ret < 0) {
244 err("%s: dvb_dmxdev_init() failed (errno = %d)", __func__,
245 ret);
246 goto failed;
247 }
248
249 ret = as102_dvb_register_fe(as102_dev, &as102_dev->dvb_fe);
250 if (ret < 0) {
251 err("%s: as102_dvb_register_frontend() failed (errno = %d)",
252 __func__, ret);
253 goto failed;
254 }
255
256 /* init bus mutex for token locking */
257 mutex_init(&as102_dev->bus_adap.lock);
258
259 /* init start / stop stream mutex */
260 mutex_init(&as102_dev->sem);
261
262#if defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE)
263 /*
264 * try to load as102 firmware. If firmware upload failed, we'll be
265 * able to upload it later.
266 */
267 if (fw_upload)
268 try_then_request_module(as102_fw_upload(&as102_dev->bus_adap),
269 "firmware_class");
270#endif
271
272failed:
273 LEAVE();
274 /* FIXME: free dvb_XXX */
275 return ret;
276}
277
278void as102_dvb_unregister(struct as102_dev_t *as102_dev)
279{
280 ENTER();
281
282 /* unregister as102 frontend */
283 as102_dvb_unregister_fe(&as102_dev->dvb_fe);
284
285 /* unregister demux device */
286 dvb_dmxdev_release(&as102_dev->dvb_dmxdev);
287 dvb_dmx_release(&as102_dev->dvb_dmx);
288
289 /* unregister dvb adapter */
290 dvb_unregister_adapter(&as102_dev->dvb_adap);
291
292 LEAVE();
293}
294
295static int __init as102_driver_init(void)
296{
297 int ret = 0;
298
299 ENTER();
300
301 /* register this driver with the low level subsystem */
302#if defined(CONFIG_AS102_USB)
303 ret = usb_register(&as102_usb_driver);
304 if (ret)
305 err("usb_register failed (ret = %d)", ret);
306#endif
307#if defined(CONFIG_AS102_SPI)
308 ret = spi_register_driver(&as102_spi_driver);
309 if (ret)
310 printk(KERN_ERR "spi_register failed (ret = %d)", ret);
311#endif
312
313 LEAVE();
314 return ret;
315}
316
317/*
318 * Mandatory function : Adds a special section to the module indicating
319 * where initialisation function is defined
320 */
321module_init(as102_driver_init);
322
323/**
324 * as102_driver_exit - as102 driver exit point
325 *
326 * This function is called when device has to be removed.
327 */
328static void __exit as102_driver_exit(void)
329{
330 ENTER();
331 /* deregister this driver with the low level bus subsystem */
332#if defined(CONFIG_AS102_USB)
333 usb_deregister(&as102_usb_driver);
334#endif
335#if defined(CONFIG_AS102_SPI)
336 spi_unregister_driver(&as102_spi_driver);
337#endif
338 LEAVE();
339}
340
341/*
342 * required function for unload: Adds a special section to the module
343 * indicating where unload function is defined
344 */
345module_exit(as102_driver_exit);
346/* modinfo details */
347MODULE_DESCRIPTION(DRIVER_FULL_NAME);
348MODULE_LICENSE("GPL");
349MODULE_AUTHOR("Pierrick Hascoet <pierrick.hascoet@abilis.com>");
350
351/* EOF - vim: set textwidth=80 ts=8 sw=8 sts=8 noet: */
diff --git a/drivers/staging/media/as102/as102_drv.h b/drivers/staging/media/as102/as102_drv.h
new file mode 100644
index 000000000000..bcda635b5a99
--- /dev/null
+++ b/drivers/staging/media/as102/as102_drv.h
@@ -0,0 +1,141 @@
1/*
2 * Abilis Systems Single DVB-T Receiver
3 * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * 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#if defined(CONFIG_AS102_USB)
21#include <linux/usb.h>
22extern struct usb_driver as102_usb_driver;
23#endif
24
25#if defined(CONFIG_AS102_SPI)
26#include <linux/platform_device.h>
27#include <linux/spi/spi.h>
28#include <linux/cdev.h>
29
30extern struct spi_driver as102_spi_driver;
31#endif
32
33#include "dvb_demux.h"
34#include "dvb_frontend.h"
35#include "dmxdev.h"
36
37#define DRIVER_FULL_NAME "Abilis Systems as10x usb driver"
38#define DRIVER_NAME "as10x_usb"
39
40extern int debug;
41
42#define dprintk(debug, args...) \
43 do { if (debug) { \
44 printk(KERN_DEBUG "%s: ",__FUNCTION__); \
45 printk(args); \
46 } } while (0)
47
48#ifdef TRACE
49#define ENTER() printk(">> enter %s\n", __FUNCTION__)
50#define LEAVE() printk("<< leave %s\n", __FUNCTION__)
51#else
52#define ENTER()
53#define LEAVE()
54#endif
55
56#define AS102_DEVICE_MAJOR 192
57
58#define AS102_USB_BUF_SIZE 512
59#define MAX_STREAM_URB 32
60
61#include "as10x_cmd.h"
62
63#if defined(CONFIG_AS102_USB)
64#include "as102_usb_drv.h"
65#endif
66
67#if defined(CONFIG_AS102_SPI)
68#include "as10x_spi_drv.h"
69#endif
70
71
72struct as102_bus_adapter_t {
73#if defined(CONFIG_AS102_USB)
74 struct usb_device *usb_dev;
75#elif defined(CONFIG_AS102_SPI)
76 struct spi_device *spi_dev;
77 struct cdev cdev; /* spidev raw device */
78
79 struct timer_list timer;
80 struct completion xfer_done;
81#endif
82 /* bus token lock */
83 struct mutex lock;
84 /* low level interface for bus adapter */
85 union as10x_bus_token_t {
86#if defined(CONFIG_AS102_USB)
87 /* usb token */
88 struct as10x_usb_token_cmd_t usb;
89#endif
90#if defined(CONFIG_AS102_SPI)
91 /* spi token */
92 struct as10x_spi_token_cmd_t spi;
93#endif
94 } token;
95
96 /* token cmd xfer id */
97 uint16_t cmd_xid;
98
99 /* as10x command and response for dvb interface*/
100 struct as10x_cmd_t *cmd, *rsp;
101
102 /* bus adapter private ops callback */
103 struct as102_priv_ops_t *ops;
104};
105
106struct as102_dev_t {
107 const char *name;
108 struct as102_bus_adapter_t bus_adap;
109 struct list_head device_entry;
110 struct kref kref;
111 unsigned long minor;
112
113 struct dvb_adapter dvb_adap;
114 struct dvb_frontend dvb_fe;
115 struct dvb_demux dvb_dmx;
116 struct dmxdev dvb_dmxdev;
117
118 /* demodulator stats */
119 struct as10x_demod_stats demod_stats;
120 /* signal strength */
121 uint16_t signal_strength;
122 /* bit error rate */
123 uint32_t ber;
124
125 /* timer handle to trig ts stream download */
126 struct timer_list timer_handle;
127
128 struct mutex sem;
129 dma_addr_t dma_addr;
130 void *stream;
131 int streaming;
132 struct urb *stream_urb[MAX_STREAM_URB];
133};
134
135int as102_dvb_register(struct as102_dev_t *dev);
136void as102_dvb_unregister(struct as102_dev_t *dev);
137
138int as102_dvb_register_fe(struct as102_dev_t *dev, struct dvb_frontend *fe);
139int as102_dvb_unregister_fe(struct dvb_frontend *dev);
140
141/* EOF - vim: set textwidth=80 ts=8 sw=8 sts=8 noet: */
diff --git a/drivers/staging/media/as102/as102_fe.c b/drivers/staging/media/as102/as102_fe.c
new file mode 100644
index 000000000000..3550f905367e
--- /dev/null
+++ b/drivers/staging/media/as102/as102_fe.c
@@ -0,0 +1,603 @@
1/*
2 * Abilis Systems Single DVB-T Receiver
3 * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
4 * Copyright (C) 2010 Devin Heitmueller <dheitmueller@kernellabs.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; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20#include <linux/version.h>
21
22#include "as102_drv.h"
23#include "as10x_types.h"
24#include "as10x_cmd.h"
25
26extern int elna_enable;
27
28static void as10x_fe_copy_tps_parameters(struct dvb_frontend_parameters *dst,
29 struct as10x_tps *src);
30
31static void as102_fe_copy_tune_parameters(struct as10x_tune_args *dst,
32 struct dvb_frontend_parameters *src);
33
34static int as102_fe_set_frontend(struct dvb_frontend *fe,
35 struct dvb_frontend_parameters *params)
36{
37 int ret = 0;
38 struct as102_dev_t *dev;
39 struct as10x_tune_args tune_args = { 0 };
40
41 ENTER();
42
43 dev = (struct as102_dev_t *) fe->tuner_priv;
44 if (dev == NULL)
45 return -ENODEV;
46
47 if (mutex_lock_interruptible(&dev->bus_adap.lock))
48 return -EBUSY;
49
50 as102_fe_copy_tune_parameters(&tune_args, params);
51
52 /* send abilis command: SET_TUNE */
53 ret = as10x_cmd_set_tune(&dev->bus_adap, &tune_args);
54 if (ret != 0)
55 dprintk(debug, "as10x_cmd_set_tune failed. (err = %d)\n", ret);
56
57 mutex_unlock(&dev->bus_adap.lock);
58
59 LEAVE();
60 return (ret < 0) ? -EINVAL : 0;
61}
62
63static int as102_fe_get_frontend(struct dvb_frontend *fe,
64 struct dvb_frontend_parameters *p) {
65 int ret = 0;
66 struct as102_dev_t *dev;
67 struct as10x_tps tps = { 0 };
68
69 ENTER();
70
71 dev = (struct as102_dev_t *) fe->tuner_priv;
72 if (dev == NULL)
73 return -EINVAL;
74
75 if (mutex_lock_interruptible(&dev->bus_adap.lock))
76 return -EBUSY;
77
78 /* send abilis command: GET_TPS */
79 ret = as10x_cmd_get_tps(&dev->bus_adap, &tps);
80
81 if (ret == 0)
82 as10x_fe_copy_tps_parameters(p, &tps);
83
84 mutex_unlock(&dev->bus_adap.lock);
85
86 LEAVE();
87 return (ret < 0) ? -EINVAL : 0;
88}
89
90static int as102_fe_get_tune_settings(struct dvb_frontend *fe,
91 struct dvb_frontend_tune_settings *settings) {
92 ENTER();
93
94#if 0
95 dprintk(debug, "step_size = %d\n", settings->step_size);
96 dprintk(debug, "max_drift = %d\n", settings->max_drift);
97 dprintk(debug, "min_delay_ms = %d -> %d\n", settings->min_delay_ms,
98 1000);
99#endif
100
101 settings->min_delay_ms = 1000;
102
103 LEAVE();
104 return 0;
105}
106
107
108static int as102_fe_read_status(struct dvb_frontend *fe, fe_status_t *status)
109{
110 int ret = 0;
111 struct as102_dev_t *dev;
112 struct as10x_tune_status tstate = { 0 };
113
114 ENTER();
115
116 dev = (struct as102_dev_t *) fe->tuner_priv;
117 if (dev == NULL)
118 return -ENODEV;
119
120 if (mutex_lock_interruptible(&dev->bus_adap.lock))
121 return -EBUSY;
122
123 /* send abilis command: GET_TUNE_STATUS */
124 ret = as10x_cmd_get_tune_status(&dev->bus_adap, &tstate);
125 if (ret < 0) {
126 dprintk(debug, "as10x_cmd_get_tune_status failed (err = %d)\n",
127 ret);
128 goto out;
129 }
130
131 dev->signal_strength = tstate.signal_strength;
132 dev->ber = tstate.BER;
133
134 switch (tstate.tune_state) {
135 case TUNE_STATUS_SIGNAL_DVB_OK:
136 *status = FE_HAS_SIGNAL | FE_HAS_CARRIER;
137 break;
138 case TUNE_STATUS_STREAM_DETECTED:
139 *status = FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_SYNC;
140 break;
141 case TUNE_STATUS_STREAM_TUNED:
142 *status = FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_SYNC |
143 FE_HAS_LOCK;
144 break;
145 default:
146 *status = TUNE_STATUS_NOT_TUNED;
147 }
148
149 dprintk(debug, "tuner status: 0x%02x, strength %d, per: %d, ber: %d\n",
150 tstate.tune_state, tstate.signal_strength,
151 tstate.PER, tstate.BER);
152
153 if (*status & FE_HAS_LOCK) {
154 if (as10x_cmd_get_demod_stats(&dev->bus_adap,
155 (struct as10x_demod_stats *) &dev->demod_stats) < 0) {
156 memset(&dev->demod_stats, 0, sizeof(dev->demod_stats));
157 dprintk(debug, "as10x_cmd_get_demod_stats failed "
158 "(probably not tuned)\n");
159 } else {
160 dprintk(debug,
161 "demod status: fc: 0x%08x, bad fc: 0x%08x, "
162 "bytes corrected: 0x%08x , MER: 0x%04x\n",
163 dev->demod_stats.frame_count,
164 dev->demod_stats.bad_frame_count,
165 dev->demod_stats.bytes_fixed_by_rs,
166 dev->demod_stats.mer);
167 }
168 } else {
169 memset(&dev->demod_stats, 0, sizeof(dev->demod_stats));
170 }
171
172out:
173 mutex_unlock(&dev->bus_adap.lock);
174 LEAVE();
175 return ret;
176}
177
178/*
179 * Note:
180 * - in AS102 SNR=MER
181 * - the SNR will be returned in linear terms, i.e. not in dB
182 * - the accuracy equals ±2dB for a SNR range from 4dB to 30dB
183 * - the accuracy is >2dB for SNR values outside this range
184 */
185static int as102_fe_read_snr(struct dvb_frontend *fe, u16 *snr)
186{
187 struct as102_dev_t *dev;
188
189 ENTER();
190
191 dev = (struct as102_dev_t *) fe->tuner_priv;
192 if (dev == NULL)
193 return -ENODEV;
194
195 *snr = dev->demod_stats.mer;
196
197 LEAVE();
198 return 0;
199}
200
201static int as102_fe_read_ber(struct dvb_frontend *fe, u32 *ber)
202{
203 struct as102_dev_t *dev;
204
205 ENTER();
206
207 dev = (struct as102_dev_t *) fe->tuner_priv;
208 if (dev == NULL)
209 return -ENODEV;
210
211 *ber = dev->ber;
212
213 LEAVE();
214 return 0;
215}
216
217static int as102_fe_read_signal_strength(struct dvb_frontend *fe,
218 u16 *strength)
219{
220 struct as102_dev_t *dev;
221
222 ENTER();
223
224 dev = (struct as102_dev_t *) fe->tuner_priv;
225 if (dev == NULL)
226 return -ENODEV;
227
228 *strength = (((0xffff * 400) * dev->signal_strength + 41000) * 2);
229
230 LEAVE();
231 return 0;
232}
233
234static int as102_fe_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
235{
236 struct as102_dev_t *dev;
237
238 ENTER();
239
240 dev = (struct as102_dev_t *) fe->tuner_priv;
241 if (dev == NULL)
242 return -ENODEV;
243
244 if (dev->demod_stats.has_started)
245 *ucblocks = dev->demod_stats.bad_frame_count;
246 else
247 *ucblocks = 0;
248
249 LEAVE();
250 return 0;
251}
252
253static int as102_fe_ts_bus_ctrl(struct dvb_frontend *fe, int acquire)
254{
255 struct as102_dev_t *dev;
256 int ret;
257
258 ENTER();
259
260 dev = (struct as102_dev_t *) fe->tuner_priv;
261 if (dev == NULL)
262 return -ENODEV;
263
264 if (mutex_lock_interruptible(&dev->bus_adap.lock))
265 return -EBUSY;
266
267 if (acquire) {
268 if (elna_enable)
269 as10x_cmd_set_context(&dev->bus_adap, 1010, 0xC0);
270
271 ret = as10x_cmd_turn_on(&dev->bus_adap);
272 } else {
273 ret = as10x_cmd_turn_off(&dev->bus_adap);
274 }
275
276 mutex_unlock(&dev->bus_adap.lock);
277
278 LEAVE();
279 return ret;
280}
281
282static struct dvb_frontend_ops as102_fe_ops = {
283 .info = {
284 .name = "Unknown AS102 device",
285 .type = FE_OFDM,
286 .frequency_min = 174000000,
287 .frequency_max = 862000000,
288 .frequency_stepsize = 166667,
289 .caps = FE_CAN_INVERSION_AUTO
290 | FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4
291 | FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO
292 | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QPSK
293 | FE_CAN_QAM_AUTO
294 | FE_CAN_TRANSMISSION_MODE_AUTO
295 | FE_CAN_GUARD_INTERVAL_AUTO
296 | FE_CAN_HIERARCHY_AUTO
297 | FE_CAN_RECOVER
298 | FE_CAN_MUTE_TS
299 },
300
301 .set_frontend = as102_fe_set_frontend,
302 .get_frontend = as102_fe_get_frontend,
303 .get_tune_settings = as102_fe_get_tune_settings,
304
305 .read_status = as102_fe_read_status,
306 .read_snr = as102_fe_read_snr,
307 .read_ber = as102_fe_read_ber,
308 .read_signal_strength = as102_fe_read_signal_strength,
309 .read_ucblocks = as102_fe_read_ucblocks,
310 .ts_bus_ctrl = as102_fe_ts_bus_ctrl,
311};
312
313int as102_dvb_unregister_fe(struct dvb_frontend *fe)
314{
315 /* unregister frontend */
316 dvb_unregister_frontend(fe);
317
318 /* detach frontend */
319 dvb_frontend_detach(fe);
320
321 return 0;
322}
323
324int as102_dvb_register_fe(struct as102_dev_t *as102_dev,
325 struct dvb_frontend *dvb_fe)
326{
327 int errno;
328 struct dvb_adapter *dvb_adap;
329
330 if (as102_dev == NULL)
331 return -EINVAL;
332
333 /* extract dvb_adapter */
334 dvb_adap = &as102_dev->dvb_adap;
335
336 /* init frontend callback ops */
337 memcpy(&dvb_fe->ops, &as102_fe_ops, sizeof(struct dvb_frontend_ops));
338 strncpy(dvb_fe->ops.info.name, as102_dev->name,
339 sizeof(dvb_fe->ops.info.name));
340
341 /* register dbvb frontend */
342 errno = dvb_register_frontend(dvb_adap, dvb_fe);
343 if (errno == 0)
344 dvb_fe->tuner_priv = as102_dev;
345
346 return errno;
347}
348
349static void as10x_fe_copy_tps_parameters(struct dvb_frontend_parameters *dst,
350 struct as10x_tps *as10x_tps)
351{
352
353 struct dvb_ofdm_parameters *fe_tps = &dst->u.ofdm;
354
355 /* extract consteallation */
356 switch (as10x_tps->constellation) {
357 case CONST_QPSK:
358 fe_tps->constellation = QPSK;
359 break;
360 case CONST_QAM16:
361 fe_tps->constellation = QAM_16;
362 break;
363 case CONST_QAM64:
364 fe_tps->constellation = QAM_64;
365 break;
366 }
367
368 /* extract hierarchy */
369 switch (as10x_tps->hierarchy) {
370 case HIER_NONE:
371 fe_tps->hierarchy_information = HIERARCHY_NONE;
372 break;
373 case HIER_ALPHA_1:
374 fe_tps->hierarchy_information = HIERARCHY_1;
375 break;
376 case HIER_ALPHA_2:
377 fe_tps->hierarchy_information = HIERARCHY_2;
378 break;
379 case HIER_ALPHA_4:
380 fe_tps->hierarchy_information = HIERARCHY_4;
381 break;
382 }
383
384 /* extract code rate HP */
385 switch (as10x_tps->code_rate_HP) {
386 case CODE_RATE_1_2:
387 fe_tps->code_rate_HP = FEC_1_2;
388 break;
389 case CODE_RATE_2_3:
390 fe_tps->code_rate_HP = FEC_2_3;
391 break;
392 case CODE_RATE_3_4:
393 fe_tps->code_rate_HP = FEC_3_4;
394 break;
395 case CODE_RATE_5_6:
396 fe_tps->code_rate_HP = FEC_5_6;
397 break;
398 case CODE_RATE_7_8:
399 fe_tps->code_rate_HP = FEC_7_8;
400 break;
401 }
402
403 /* extract code rate LP */
404 switch (as10x_tps->code_rate_LP) {
405 case CODE_RATE_1_2:
406 fe_tps->code_rate_LP = FEC_1_2;
407 break;
408 case CODE_RATE_2_3:
409 fe_tps->code_rate_LP = FEC_2_3;
410 break;
411 case CODE_RATE_3_4:
412 fe_tps->code_rate_LP = FEC_3_4;
413 break;
414 case CODE_RATE_5_6:
415 fe_tps->code_rate_LP = FEC_5_6;
416 break;
417 case CODE_RATE_7_8:
418 fe_tps->code_rate_LP = FEC_7_8;
419 break;
420 }
421
422 /* extract guard interval */
423 switch (as10x_tps->guard_interval) {
424 case GUARD_INT_1_32:
425 fe_tps->guard_interval = GUARD_INTERVAL_1_32;
426 break;
427 case GUARD_INT_1_16:
428 fe_tps->guard_interval = GUARD_INTERVAL_1_16;
429 break;
430 case GUARD_INT_1_8:
431 fe_tps->guard_interval = GUARD_INTERVAL_1_8;
432 break;
433 case GUARD_INT_1_4:
434 fe_tps->guard_interval = GUARD_INTERVAL_1_4;
435 break;
436 }
437
438 /* extract transmission mode */
439 switch (as10x_tps->transmission_mode) {
440 case TRANS_MODE_2K:
441 fe_tps->transmission_mode = TRANSMISSION_MODE_2K;
442 break;
443 case TRANS_MODE_8K:
444 fe_tps->transmission_mode = TRANSMISSION_MODE_8K;
445 break;
446 }
447}
448
449static uint8_t as102_fe_get_code_rate(fe_code_rate_t arg)
450{
451 uint8_t c;
452
453 switch (arg) {
454 case FEC_1_2:
455 c = CODE_RATE_1_2;
456 break;
457 case FEC_2_3:
458 c = CODE_RATE_2_3;
459 break;
460 case FEC_3_4:
461 c = CODE_RATE_3_4;
462 break;
463 case FEC_5_6:
464 c = CODE_RATE_5_6;
465 break;
466 case FEC_7_8:
467 c = CODE_RATE_7_8;
468 break;
469 default:
470 c = CODE_RATE_UNKNOWN;
471 break;
472 }
473
474 return c;
475}
476
477static void as102_fe_copy_tune_parameters(struct as10x_tune_args *tune_args,
478 struct dvb_frontend_parameters *params)
479{
480
481 /* set frequency */
482 tune_args->freq = params->frequency / 1000;
483
484 /* fix interleaving_mode */
485 tune_args->interleaving_mode = INTLV_NATIVE;
486
487 switch (params->u.ofdm.bandwidth) {
488 case BANDWIDTH_8_MHZ:
489 tune_args->bandwidth = BW_8_MHZ;
490 break;
491 case BANDWIDTH_7_MHZ:
492 tune_args->bandwidth = BW_7_MHZ;
493 break;
494 case BANDWIDTH_6_MHZ:
495 tune_args->bandwidth = BW_6_MHZ;
496 break;
497 default:
498 tune_args->bandwidth = BW_8_MHZ;
499 }
500
501 switch (params->u.ofdm.guard_interval) {
502 case GUARD_INTERVAL_1_32:
503 tune_args->guard_interval = GUARD_INT_1_32;
504 break;
505 case GUARD_INTERVAL_1_16:
506 tune_args->guard_interval = GUARD_INT_1_16;
507 break;
508 case GUARD_INTERVAL_1_8:
509 tune_args->guard_interval = GUARD_INT_1_8;
510 break;
511 case GUARD_INTERVAL_1_4:
512 tune_args->guard_interval = GUARD_INT_1_4;
513 break;
514 case GUARD_INTERVAL_AUTO:
515 default:
516 tune_args->guard_interval = GUARD_UNKNOWN;
517 break;
518 }
519
520 switch (params->u.ofdm.constellation) {
521 case QPSK:
522 tune_args->constellation = CONST_QPSK;
523 break;
524 case QAM_16:
525 tune_args->constellation = CONST_QAM16;
526 break;
527 case QAM_64:
528 tune_args->constellation = CONST_QAM64;
529 break;
530 default:
531 tune_args->constellation = CONST_UNKNOWN;
532 break;
533 }
534
535 switch (params->u.ofdm.transmission_mode) {
536 case TRANSMISSION_MODE_2K:
537 tune_args->transmission_mode = TRANS_MODE_2K;
538 break;
539 case TRANSMISSION_MODE_8K:
540 tune_args->transmission_mode = TRANS_MODE_8K;
541 break;
542 default:
543 tune_args->transmission_mode = TRANS_MODE_UNKNOWN;
544 }
545
546 switch (params->u.ofdm.hierarchy_information) {
547 case HIERARCHY_NONE:
548 tune_args->hierarchy = HIER_NONE;
549 break;
550 case HIERARCHY_1:
551 tune_args->hierarchy = HIER_ALPHA_1;
552 break;
553 case HIERARCHY_2:
554 tune_args->hierarchy = HIER_ALPHA_2;
555 break;
556 case HIERARCHY_4:
557 tune_args->hierarchy = HIER_ALPHA_4;
558 break;
559 case HIERARCHY_AUTO:
560 tune_args->hierarchy = HIER_UNKNOWN;
561 break;
562 }
563
564 dprintk(debug, "tuner parameters: freq: %d bw: 0x%02x gi: 0x%02x\n",
565 params->frequency,
566 tune_args->bandwidth,
567 tune_args->guard_interval);
568
569 /*
570 * Detect a hierarchy selection
571 * if HP/LP are both set to FEC_NONE, HP will be selected.
572 */
573 if ((tune_args->hierarchy != HIER_NONE) &&
574 ((params->u.ofdm.code_rate_LP == FEC_NONE) ||
575 (params->u.ofdm.code_rate_HP == FEC_NONE))) {
576
577 if (params->u.ofdm.code_rate_LP == FEC_NONE) {
578 tune_args->hier_select = HIER_HIGH_PRIORITY;
579 tune_args->code_rate =
580 as102_fe_get_code_rate(params->u.ofdm.code_rate_HP);
581 }
582
583 if (params->u.ofdm.code_rate_HP == FEC_NONE) {
584 tune_args->hier_select = HIER_LOW_PRIORITY;
585 tune_args->code_rate =
586 as102_fe_get_code_rate(params->u.ofdm.code_rate_LP);
587 }
588
589 dprintk(debug, "\thierarchy: 0x%02x "
590 "selected: %s code_rate_%s: 0x%02x\n",
591 tune_args->hierarchy,
592 tune_args->hier_select == HIER_HIGH_PRIORITY ?
593 "HP" : "LP",
594 tune_args->hier_select == HIER_HIGH_PRIORITY ?
595 "HP" : "LP",
596 tune_args->code_rate);
597 } else {
598 tune_args->code_rate =
599 as102_fe_get_code_rate(params->u.ofdm.code_rate_HP);
600 }
601}
602
603/* EOF - vim: set textwidth=80 ts=8 sw=8 sts=8 noet: */
diff --git a/drivers/staging/media/as102/as102_fw.c b/drivers/staging/media/as102/as102_fw.c
new file mode 100644
index 000000000000..c019df933cc9
--- /dev/null
+++ b/drivers/staging/media/as102/as102_fw.c
@@ -0,0 +1,251 @@
1/*
2 * Abilis Systems Single DVB-T Receiver
3 * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
4 * Copyright (C) 2010 Devin Heitmueller <dheitmueller@kernellabs.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; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20#include <linux/kernel.h>
21#include <linux/errno.h>
22#include <linux/ctype.h>
23#include <linux/delay.h>
24#include <linux/firmware.h>
25
26#include "as102_drv.h"
27#include "as102_fw.h"
28
29#if defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE)
30char as102_st_fw1[] = "as102_data1_st.hex";
31char as102_st_fw2[] = "as102_data2_st.hex";
32char as102_dt_fw1[] = "as102_data1_dt.hex";
33char as102_dt_fw2[] = "as102_data2_dt.hex";
34
35static unsigned char atohx(unsigned char *dst, char *src)
36{
37 unsigned char value = 0;
38
39 char msb = tolower(*src) - '0';
40 char lsb = tolower(*(src + 1)) - '0';
41
42 if (msb > 9)
43 msb -= 7;
44 if (lsb > 9)
45 lsb -= 7;
46
47 *dst = value = ((msb & 0xF) << 4) | (lsb & 0xF);
48 return value;
49}
50
51/*
52 * Parse INTEL HEX firmware file to extract address and data.
53 */
54static int parse_hex_line(unsigned char *fw_data, unsigned char *addr,
55 unsigned char *data, int *dataLength,
56 unsigned char *addr_has_changed) {
57
58 int count = 0;
59 unsigned char *src, dst;
60
61 if (*fw_data++ != ':') {
62 printk(KERN_ERR "invalid firmware file\n");
63 return -EFAULT;
64 }
65
66 /* locate end of line */
67 for (src = fw_data; *src != '\n'; src += 2) {
68 atohx(&dst, src);
69 /* parse line to split addr / data */
70 switch (count) {
71 case 0:
72 *dataLength = dst;
73 break;
74 case 1:
75 addr[2] = dst;
76 break;
77 case 2:
78 addr[3] = dst;
79 break;
80 case 3:
81 /* check if data is an address */
82 if (dst == 0x04)
83 *addr_has_changed = 1;
84 else
85 *addr_has_changed = 0;
86 break;
87 case 4:
88 case 5:
89 if (*addr_has_changed)
90 addr[(count - 4)] = dst;
91 else
92 data[(count - 4)] = dst;
93 break;
94 default:
95 data[(count - 4)] = dst;
96 break;
97 }
98 count++;
99 }
100
101 /* return read value + ':' + '\n' */
102 return (count * 2) + 2;
103}
104
105static int as102_firmware_upload(struct as102_bus_adapter_t *bus_adap,
106 unsigned char *cmd,
107 const struct firmware *firmware) {
108
109 struct as10x_fw_pkt_t fw_pkt;
110 int total_read_bytes = 0, errno = 0;
111 unsigned char addr_has_changed = 0;
112
113 ENTER();
114
115 for (total_read_bytes = 0; total_read_bytes < firmware->size; ) {
116 int read_bytes = 0, data_len = 0;
117
118 /* parse intel hex line */
119 read_bytes = parse_hex_line(
120 (u8 *) (firmware->data + total_read_bytes),
121 fw_pkt.raw.address,
122 fw_pkt.raw.data,
123 &data_len,
124 &addr_has_changed);
125
126 if (read_bytes <= 0)
127 goto error;
128
129 /* detect the end of file */
130 total_read_bytes += read_bytes;
131 if (total_read_bytes == firmware->size) {
132 fw_pkt.u.request[0] = 0x00;
133 fw_pkt.u.request[1] = 0x03;
134
135 /* send EOF command */
136 errno = bus_adap->ops->upload_fw_pkt(bus_adap,
137 (uint8_t *)
138 &fw_pkt, 2, 0);
139 if (errno < 0)
140 goto error;
141 } else {
142 if (!addr_has_changed) {
143 /* prepare command to send */
144 fw_pkt.u.request[0] = 0x00;
145 fw_pkt.u.request[1] = 0x01;
146
147 data_len += sizeof(fw_pkt.u.request);
148 data_len += sizeof(fw_pkt.raw.address);
149
150 /* send cmd to device */
151 errno = bus_adap->ops->upload_fw_pkt(bus_adap,
152 (uint8_t *)
153 &fw_pkt,
154 data_len,
155 0);
156 if (errno < 0)
157 goto error;
158 }
159 }
160 }
161error:
162 LEAVE();
163 return (errno == 0) ? total_read_bytes : errno;
164}
165
166int as102_fw_upload(struct as102_bus_adapter_t *bus_adap)
167{
168 int errno = -EFAULT;
169 const struct firmware *firmware;
170 unsigned char *cmd_buf = NULL;
171 char *fw1, *fw2;
172
173#if defined(CONFIG_AS102_USB)
174 struct usb_device *dev = bus_adap->usb_dev;
175#endif
176#if defined(CONFIG_AS102_SPI)
177 struct spi_device *dev = bus_adap->spi_dev;
178#endif
179 ENTER();
180
181 /* select fw file to upload */
182 if (dual_tuner) {
183 fw1 = as102_dt_fw1;
184 fw2 = as102_dt_fw2;
185 } else {
186 fw1 = as102_st_fw1;
187 fw2 = as102_st_fw2;
188 }
189
190#if defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE)
191 /* allocate buffer to store firmware upload command and data */
192 cmd_buf = kzalloc(MAX_FW_PKT_SIZE, GFP_KERNEL);
193 if (cmd_buf == NULL) {
194 errno = -ENOMEM;
195 goto error;
196 }
197
198 /* request kernel to locate firmware file: part1 */
199 errno = request_firmware(&firmware, fw1, &dev->dev);
200 if (errno < 0) {
201 printk(KERN_ERR "%s: unable to locate firmware file: %s\n",
202 DRIVER_NAME, fw1);
203 goto error;
204 }
205
206 /* initiate firmware upload */
207 errno = as102_firmware_upload(bus_adap, cmd_buf, firmware);
208 if (errno < 0) {
209 printk(KERN_ERR "%s: error during firmware upload part1\n",
210 DRIVER_NAME);
211 goto error;
212 }
213
214 printk(KERN_INFO "%s: fimrware: %s loaded with success\n",
215 DRIVER_NAME, fw1);
216 release_firmware(firmware);
217
218 /* wait for boot to complete */
219 mdelay(100);
220
221 /* request kernel to locate firmware file: part2 */
222 errno = request_firmware(&firmware, fw2, &dev->dev);
223 if (errno < 0) {
224 printk(KERN_ERR "%s: unable to locate firmware file: %s\n",
225 DRIVER_NAME, fw2);
226 goto error;
227 }
228
229 /* initiate firmware upload */
230 errno = as102_firmware_upload(bus_adap, cmd_buf, firmware);
231 if (errno < 0) {
232 printk(KERN_ERR "%s: error during firmware upload part2\n",
233 DRIVER_NAME);
234 goto error;
235 }
236
237 printk(KERN_INFO "%s: fimrware: %s loaded with success\n",
238 DRIVER_NAME, fw2);
239error:
240 /* free data buffer */
241 kfree(cmd_buf);
242 /* release firmware if needed */
243 if (firmware != NULL)
244 release_firmware(firmware);
245#endif
246 LEAVE();
247 return errno;
248}
249#endif
250
251/* EOF - vim: set textwidth=80 ts=8 sw=8 sts=8 noet: */
diff --git a/drivers/staging/media/as102/as102_fw.h b/drivers/staging/media/as102/as102_fw.h
new file mode 100644
index 000000000000..27e5347e2e19
--- /dev/null
+++ b/drivers/staging/media/as102/as102_fw.h
@@ -0,0 +1,42 @@
1/*
2 * Abilis Systems Single DVB-T Receiver
3 * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * 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#define MAX_FW_PKT_SIZE 64
20
21extern int dual_tuner;
22
23#pragma pack(1)
24struct as10x_raw_fw_pkt {
25 unsigned char address[4];
26 unsigned char data[MAX_FW_PKT_SIZE - 6];
27};
28
29struct as10x_fw_pkt_t {
30 union {
31 unsigned char request[2];
32 unsigned char length[2];
33 } u;
34 struct as10x_raw_fw_pkt raw;
35};
36#pragma pack()
37
38#ifdef __KERNEL__
39int as102_fw_upload(struct as102_bus_adapter_t *bus_adap);
40#endif
41
42/* EOF - vim: set textwidth=80 ts=8 sw=8 sts=8 noet: */
diff --git a/drivers/staging/media/as102/as102_usb_drv.c b/drivers/staging/media/as102/as102_usb_drv.c
new file mode 100644
index 000000000000..264be2dbd2a4
--- /dev/null
+++ b/drivers/staging/media/as102/as102_usb_drv.c
@@ -0,0 +1,478 @@
1/*
2 * Abilis Systems Single DVB-T Receiver
3 * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
4 * Copyright (C) 2010 Devin Heitmueller <dheitmueller@kernellabs.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; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20#include <linux/kernel.h>
21#include <linux/errno.h>
22#include <linux/slab.h>
23#include <linux/mm.h>
24#include <linux/usb.h>
25
26#include "as102_drv.h"
27#include "as102_usb_drv.h"
28#include "as102_fw.h"
29
30static void as102_usb_disconnect(struct usb_interface *interface);
31static int as102_usb_probe(struct usb_interface *interface,
32 const struct usb_device_id *id);
33
34static int as102_usb_start_stream(struct as102_dev_t *dev);
35static void as102_usb_stop_stream(struct as102_dev_t *dev);
36
37static int as102_open(struct inode *inode, struct file *file);
38static int as102_release(struct inode *inode, struct file *file);
39
40static struct usb_device_id as102_usb_id_table[] = {
41 { USB_DEVICE(AS102_USB_DEVICE_VENDOR_ID, AS102_USB_DEVICE_PID_0001) },
42 { USB_DEVICE(PCTV_74E_USB_VID, PCTV_74E_USB_PID) },
43 { USB_DEVICE(ELGATO_EYETV_DTT_USB_VID, ELGATO_EYETV_DTT_USB_PID) },
44 { USB_DEVICE(NBOX_DVBT_DONGLE_USB_VID, NBOX_DVBT_DONGLE_USB_PID) },
45 { } /* Terminating entry */
46};
47
48/* Note that this table must always have the same number of entries as the
49 as102_usb_id_table struct */
50static const char *as102_device_names[] = {
51 AS102_REFERENCE_DESIGN,
52 AS102_PCTV_74E,
53 AS102_ELGATO_EYETV_DTT_NAME,
54 AS102_NBOX_DVBT_DONGLE_NAME,
55 NULL /* Terminating entry */
56};
57
58struct usb_driver as102_usb_driver = {
59 .name = DRIVER_FULL_NAME,
60 .probe = as102_usb_probe,
61 .disconnect = as102_usb_disconnect,
62 .id_table = as102_usb_id_table
63};
64
65static const struct file_operations as102_dev_fops = {
66 .owner = THIS_MODULE,
67 .open = as102_open,
68 .release = as102_release,
69};
70
71static struct usb_class_driver as102_usb_class_driver = {
72 .name = "aton2-%d",
73 .fops = &as102_dev_fops,
74 .minor_base = AS102_DEVICE_MAJOR,
75};
76
77static int as102_usb_xfer_cmd(struct as102_bus_adapter_t *bus_adap,
78 unsigned char *send_buf, int send_buf_len,
79 unsigned char *recv_buf, int recv_buf_len)
80{
81 int ret = 0;
82 ENTER();
83
84 if (send_buf != NULL) {
85 ret = usb_control_msg(bus_adap->usb_dev,
86 usb_sndctrlpipe(bus_adap->usb_dev, 0),
87 AS102_USB_DEVICE_TX_CTRL_CMD,
88 USB_DIR_OUT | USB_TYPE_VENDOR |
89 USB_RECIP_DEVICE,
90 bus_adap->cmd_xid, /* value */
91 0, /* index */
92 send_buf, send_buf_len,
93 USB_CTRL_SET_TIMEOUT /* 200 */);
94 if (ret < 0) {
95 dprintk(debug, "usb_control_msg(send) failed, err %i\n",
96 ret);
97 return ret;
98 }
99
100 if (ret != send_buf_len) {
101 dprintk(debug, "only wrote %d of %d bytes\n",
102 ret, send_buf_len);
103 return -1;
104 }
105 }
106
107 if (recv_buf != NULL) {
108#ifdef TRACE
109 dprintk(debug, "want to read: %d bytes\n", recv_buf_len);
110#endif
111 ret = usb_control_msg(bus_adap->usb_dev,
112 usb_rcvctrlpipe(bus_adap->usb_dev, 0),
113 AS102_USB_DEVICE_RX_CTRL_CMD,
114 USB_DIR_IN | USB_TYPE_VENDOR |
115 USB_RECIP_DEVICE,
116 bus_adap->cmd_xid, /* value */
117 0, /* index */
118 recv_buf, recv_buf_len,
119 USB_CTRL_GET_TIMEOUT /* 200 */);
120 if (ret < 0) {
121 dprintk(debug, "usb_control_msg(recv) failed, err %i\n",
122 ret);
123 return ret;
124 }
125#ifdef TRACE
126 dprintk(debug, "read %d bytes\n", recv_buf_len);
127#endif
128 }
129
130 LEAVE();
131 return ret;
132}
133
134static int as102_send_ep1(struct as102_bus_adapter_t *bus_adap,
135 unsigned char *send_buf,
136 int send_buf_len,
137 int swap32)
138{
139 int ret = 0, actual_len;
140
141 ret = usb_bulk_msg(bus_adap->usb_dev,
142 usb_sndbulkpipe(bus_adap->usb_dev, 1),
143 send_buf, send_buf_len, &actual_len, 200);
144 if (ret) {
145 dprintk(debug, "usb_bulk_msg(send) failed, err %i\n", ret);
146 return ret;
147 }
148
149 if (actual_len != send_buf_len) {
150 dprintk(debug, "only wrote %d of %d bytes\n",
151 actual_len, send_buf_len);
152 return -1;
153 }
154 return ret ? ret : actual_len;
155}
156
157static int as102_read_ep2(struct as102_bus_adapter_t *bus_adap,
158 unsigned char *recv_buf, int recv_buf_len)
159{
160 int ret = 0, actual_len;
161
162 if (recv_buf == NULL)
163 return -EINVAL;
164
165 ret = usb_bulk_msg(bus_adap->usb_dev,
166 usb_rcvbulkpipe(bus_adap->usb_dev, 2),
167 recv_buf, recv_buf_len, &actual_len, 200);
168 if (ret) {
169 dprintk(debug, "usb_bulk_msg(recv) failed, err %i\n", ret);
170 return ret;
171 }
172
173 if (actual_len != recv_buf_len) {
174 dprintk(debug, "only read %d of %d bytes\n",
175 actual_len, recv_buf_len);
176 return -1;
177 }
178 return ret ? ret : actual_len;
179}
180
181struct as102_priv_ops_t as102_priv_ops = {
182 .upload_fw_pkt = as102_send_ep1,
183 .xfer_cmd = as102_usb_xfer_cmd,
184 .as102_read_ep2 = as102_read_ep2,
185 .start_stream = as102_usb_start_stream,
186 .stop_stream = as102_usb_stop_stream,
187};
188
189static int as102_submit_urb_stream(struct as102_dev_t *dev, struct urb *urb)
190{
191 int err;
192
193 usb_fill_bulk_urb(urb,
194 dev->bus_adap.usb_dev,
195 usb_rcvbulkpipe(dev->bus_adap.usb_dev, 0x2),
196 urb->transfer_buffer,
197 AS102_USB_BUF_SIZE,
198 as102_urb_stream_irq,
199 dev);
200
201 err = usb_submit_urb(urb, GFP_ATOMIC);
202 if (err)
203 dprintk(debug, "%s: usb_submit_urb failed\n", __func__);
204
205 return err;
206}
207
208void as102_urb_stream_irq(struct urb *urb)
209{
210 struct as102_dev_t *as102_dev = urb->context;
211
212 if (urb->actual_length > 0) {
213 dvb_dmx_swfilter(&as102_dev->dvb_dmx,
214 urb->transfer_buffer,
215 urb->actual_length);
216 } else {
217 if (urb->actual_length == 0)
218 memset(urb->transfer_buffer, 0, AS102_USB_BUF_SIZE);
219 }
220
221 /* is not stopped, re-submit urb */
222 if (as102_dev->streaming)
223 as102_submit_urb_stream(as102_dev, urb);
224}
225
226static void as102_free_usb_stream_buffer(struct as102_dev_t *dev)
227{
228 int i;
229
230 ENTER();
231
232 for (i = 0; i < MAX_STREAM_URB; i++)
233 usb_free_urb(dev->stream_urb[i]);
234
235 usb_free_coherent(dev->bus_adap.usb_dev,
236 MAX_STREAM_URB * AS102_USB_BUF_SIZE,
237 dev->stream,
238 dev->dma_addr);
239 LEAVE();
240}
241
242static int as102_alloc_usb_stream_buffer(struct as102_dev_t *dev)
243{
244 int i, ret = 0;
245
246 ENTER();
247
248 dev->stream = usb_alloc_coherent(dev->bus_adap.usb_dev,
249 MAX_STREAM_URB * AS102_USB_BUF_SIZE,
250 GFP_KERNEL,
251 &dev->dma_addr);
252 if (!dev->stream) {
253 dprintk(debug, "%s: usb_buffer_alloc failed\n", __func__);
254 return -ENOMEM;
255 }
256
257 memset(dev->stream, 0, MAX_STREAM_URB * AS102_USB_BUF_SIZE);
258
259 /* init urb buffers */
260 for (i = 0; i < MAX_STREAM_URB; i++) {
261 struct urb *urb;
262
263 urb = usb_alloc_urb(0, GFP_ATOMIC);
264 if (urb == NULL) {
265 dprintk(debug, "%s: usb_alloc_urb failed\n", __func__);
266 as102_free_usb_stream_buffer(dev);
267 return -ENOMEM;
268 }
269
270 urb->transfer_buffer = dev->stream + (i * AS102_USB_BUF_SIZE);
271 urb->transfer_buffer_length = AS102_USB_BUF_SIZE;
272
273 dev->stream_urb[i] = urb;
274 }
275 LEAVE();
276 return ret;
277}
278
279static void as102_usb_stop_stream(struct as102_dev_t *dev)
280{
281 int i;
282
283 for (i = 0; i < MAX_STREAM_URB; i++)
284 usb_kill_urb(dev->stream_urb[i]);
285}
286
287static int as102_usb_start_stream(struct as102_dev_t *dev)
288{
289 int i, ret = 0;
290
291 for (i = 0; i < MAX_STREAM_URB; i++) {
292 ret = as102_submit_urb_stream(dev, dev->stream_urb[i]);
293 if (ret) {
294 as102_usb_stop_stream(dev);
295 return ret;
296 }
297 }
298
299 return 0;
300}
301
302static void as102_usb_release(struct kref *kref)
303{
304 struct as102_dev_t *as102_dev;
305
306 ENTER();
307
308 as102_dev = container_of(kref, struct as102_dev_t, kref);
309 if (as102_dev != NULL) {
310 usb_put_dev(as102_dev->bus_adap.usb_dev);
311 kfree(as102_dev);
312 }
313
314 LEAVE();
315}
316
317static void as102_usb_disconnect(struct usb_interface *intf)
318{
319 struct as102_dev_t *as102_dev;
320
321 ENTER();
322
323 /* extract as102_dev_t from usb_device private data */
324 as102_dev = usb_get_intfdata(intf);
325
326 /* unregister dvb layer */
327 as102_dvb_unregister(as102_dev);
328
329 /* free usb buffers */
330 as102_free_usb_stream_buffer(as102_dev);
331
332 usb_set_intfdata(intf, NULL);
333
334 /* usb unregister device */
335 usb_deregister_dev(intf, &as102_usb_class_driver);
336
337 /* decrement usage counter */
338 kref_put(&as102_dev->kref, as102_usb_release);
339
340 printk(KERN_INFO "%s: device has been disconnected\n", DRIVER_NAME);
341
342 LEAVE();
343}
344
345static int as102_usb_probe(struct usb_interface *intf,
346 const struct usb_device_id *id)
347{
348 int ret;
349 struct as102_dev_t *as102_dev;
350 int i;
351
352 ENTER();
353
354 as102_dev = kzalloc(sizeof(struct as102_dev_t), GFP_KERNEL);
355 if (as102_dev == NULL) {
356 err("%s: kzalloc failed", __func__);
357 return -ENOMEM;
358 }
359
360 /* This should never actually happen */
361 if ((sizeof(as102_usb_id_table) / sizeof(struct usb_device_id)) !=
362 (sizeof(as102_device_names) / sizeof(const char *))) {
363 printk(KERN_ERR "Device names table invalid size");
364 return -EINVAL;
365 }
366
367 /* Assign the user-friendly device name */
368 for (i = 0; i < (sizeof(as102_usb_id_table) /
369 sizeof(struct usb_device_id)); i++) {
370 if (id == &as102_usb_id_table[i])
371 as102_dev->name = as102_device_names[i];
372 }
373
374 if (as102_dev->name == NULL)
375 as102_dev->name = "Unknown AS102 device";
376
377 /* set private callback functions */
378 as102_dev->bus_adap.ops = &as102_priv_ops;
379
380 /* init cmd token for usb bus */
381 as102_dev->bus_adap.cmd = &as102_dev->bus_adap.token.usb.c;
382 as102_dev->bus_adap.rsp = &as102_dev->bus_adap.token.usb.r;
383
384 /* init kernel device reference */
385 kref_init(&as102_dev->kref);
386
387 /* store as102 device to usb_device private data */
388 usb_set_intfdata(intf, (void *) as102_dev);
389
390 /* store in as102 device the usb_device pointer */
391 as102_dev->bus_adap.usb_dev = usb_get_dev(interface_to_usbdev(intf));
392
393 /* we can register the device now, as it is ready */
394 ret = usb_register_dev(intf, &as102_usb_class_driver);
395 if (ret < 0) {
396 /* something prevented us from registering this driver */
397 err("%s: usb_register_dev() failed (errno = %d)",
398 __func__, ret);
399 goto failed;
400 }
401
402 printk(KERN_INFO "%s: device has been detected\n", DRIVER_NAME);
403
404 /* request buffer allocation for streaming */
405 ret = as102_alloc_usb_stream_buffer(as102_dev);
406 if (ret != 0)
407 goto failed;
408
409 /* register dvb layer */
410 ret = as102_dvb_register(as102_dev);
411
412 LEAVE();
413 return ret;
414
415failed:
416 usb_set_intfdata(intf, NULL);
417 kfree(as102_dev);
418 return ret;
419}
420
421static int as102_open(struct inode *inode, struct file *file)
422{
423 int ret = 0, minor = 0;
424 struct usb_interface *intf = NULL;
425 struct as102_dev_t *dev = NULL;
426
427 ENTER();
428
429 /* read minor from inode */
430 minor = iminor(inode);
431
432 /* fetch device from usb interface */
433 intf = usb_find_interface(&as102_usb_driver, minor);
434 if (intf == NULL) {
435 printk(KERN_ERR "%s: can't find device for minor %d\n",
436 __func__, minor);
437 ret = -ENODEV;
438 goto exit;
439 }
440
441 /* get our device */
442 dev = usb_get_intfdata(intf);
443 if (dev == NULL) {
444 ret = -EFAULT;
445 goto exit;
446 }
447
448 /* save our device object in the file's private structure */
449 file->private_data = dev;
450
451 /* increment our usage count for the device */
452 kref_get(&dev->kref);
453
454exit:
455 LEAVE();
456 return ret;
457}
458
459static int as102_release(struct inode *inode, struct file *file)
460{
461 int ret = 0;
462 struct as102_dev_t *dev = NULL;
463
464 ENTER();
465
466 dev = file->private_data;
467 if (dev != NULL) {
468 /* decrement the count on our device */
469 kref_put(&dev->kref, as102_usb_release);
470 }
471
472 LEAVE();
473 return ret;
474}
475
476MODULE_DEVICE_TABLE(usb, as102_usb_id_table);
477
478/* EOF - vim: set textwidth=80 ts=8 sw=8 sts=8 noet: */
diff --git a/drivers/staging/media/as102/as102_usb_drv.h b/drivers/staging/media/as102/as102_usb_drv.h
new file mode 100644
index 000000000000..fb1fc41dcd79
--- /dev/null
+++ b/drivers/staging/media/as102/as102_usb_drv.h
@@ -0,0 +1,59 @@
1/*
2 * Abilis Systems Single DVB-T Receiver
3 * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
4 * Copyright (C) 2010 Devin Heitmueller <dheitmueller@kernellabs.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; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20#include <linux/version.h>
21
22#ifndef _AS102_USB_DRV_H_
23#define _AS102_USB_DRV_H_
24
25#define AS102_USB_DEVICE_TX_CTRL_CMD 0xF1
26#define AS102_USB_DEVICE_RX_CTRL_CMD 0xF2
27
28/* define these values to match the supported devices */
29
30/* Abilis system: "TITAN" */
31#define AS102_REFERENCE_DESIGN "Abilis Systems DVB-Titan"
32#define AS102_USB_DEVICE_VENDOR_ID 0x1BA6
33#define AS102_USB_DEVICE_PID_0001 0x0001
34
35/* PCTV Systems: PCTV picoStick (74e) */
36#define AS102_PCTV_74E "PCTV Systems picoStick (74e)"
37#define PCTV_74E_USB_VID 0x2013
38#define PCTV_74E_USB_PID 0x0246
39
40/* Elgato: EyeTV DTT Deluxe */
41#define AS102_ELGATO_EYETV_DTT_NAME "Elgato EyeTV DTT Deluxe"
42#define ELGATO_EYETV_DTT_USB_VID 0x0fd9
43#define ELGATO_EYETV_DTT_USB_PID 0x002c
44
45/* nBox: nBox DVB-T Dongle */
46#define AS102_NBOX_DVBT_DONGLE_NAME "nBox DVB-T Dongle"
47#define NBOX_DVBT_DONGLE_USB_VID 0x0b89
48#define NBOX_DVBT_DONGLE_USB_PID 0x0007
49
50void as102_urb_stream_irq(struct urb *urb);
51
52struct as10x_usb_token_cmd_t {
53 /* token cmd */
54 struct as10x_cmd_t c;
55 /* token response */
56 struct as10x_cmd_t r;
57};
58#endif
59/* EOF - vim: set textwidth=80 ts=8 sw=8 sts=8 noet: */
diff --git a/drivers/staging/media/as102/as10x_cmd.c b/drivers/staging/media/as102/as10x_cmd.c
new file mode 100644
index 000000000000..0dcba8065780
--- /dev/null
+++ b/drivers/staging/media/as102/as10x_cmd.c
@@ -0,0 +1,452 @@
1/*
2 * Abilis Systems Single DVB-T Receiver
3 * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
4 * Copyright (C) 2010 Devin Heitmueller <dheitmueller@kernellabs.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; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21#include <linux/kernel.h>
22#include "as102_drv.h"
23#include "as10x_types.h"
24#include "as10x_cmd.h"
25
26/**
27 * as10x_cmd_turn_on - send turn on command to AS10x
28 * @phandle: pointer to AS10x handle
29 *
30 * Return 0 when no error, < 0 in case of error.
31 */
32int as10x_cmd_turn_on(as10x_handle_t *phandle)
33{
34 int error;
35 struct as10x_cmd_t *pcmd, *prsp;
36
37 ENTER();
38
39 pcmd = phandle->cmd;
40 prsp = phandle->rsp;
41
42 /* prepare command */
43 as10x_cmd_build(pcmd, (++phandle->cmd_xid),
44 sizeof(pcmd->body.turn_on.req));
45
46 /* fill command */
47 pcmd->body.turn_on.req.proc_id = cpu_to_le16(CONTROL_PROC_TURNON);
48
49 /* send command */
50 if (phandle->ops->xfer_cmd) {
51 error = phandle->ops->xfer_cmd(phandle, (uint8_t *) pcmd,
52 sizeof(pcmd->body.turn_on.req) +
53 HEADER_SIZE,
54 (uint8_t *) prsp,
55 sizeof(prsp->body.turn_on.rsp) +
56 HEADER_SIZE);
57 } else {
58 error = AS10X_CMD_ERROR;
59 }
60
61 if (error < 0)
62 goto out;
63
64 /* parse response */
65 error = as10x_rsp_parse(prsp, CONTROL_PROC_TURNON_RSP);
66
67out:
68 LEAVE();
69 return error;
70}
71
72/**
73 * as10x_cmd_turn_off - send turn off command to AS10x
74 * @phandle: pointer to AS10x handle
75 *
76 * Return 0 on success or negative value in case of error.
77 */
78int as10x_cmd_turn_off(as10x_handle_t *phandle)
79{
80 int error;
81 struct as10x_cmd_t *pcmd, *prsp;
82
83 ENTER();
84
85 pcmd = phandle->cmd;
86 prsp = phandle->rsp;
87
88 /* prepare command */
89 as10x_cmd_build(pcmd, (++phandle->cmd_xid),
90 sizeof(pcmd->body.turn_off.req));
91
92 /* fill command */
93 pcmd->body.turn_off.req.proc_id = cpu_to_le16(CONTROL_PROC_TURNOFF);
94
95 /* send command */
96 if (phandle->ops->xfer_cmd) {
97 error = phandle->ops->xfer_cmd(
98 phandle, (uint8_t *) pcmd,
99 sizeof(pcmd->body.turn_off.req) + HEADER_SIZE,
100 (uint8_t *) prsp,
101 sizeof(prsp->body.turn_off.rsp) + HEADER_SIZE);
102 } else {
103 error = AS10X_CMD_ERROR;
104 }
105
106 if (error < 0)
107 goto out;
108
109 /* parse response */
110 error = as10x_rsp_parse(prsp, CONTROL_PROC_TURNOFF_RSP);
111
112out:
113 LEAVE();
114 return error;
115}
116
117/**
118 * as10x_cmd_set_tune - send set tune command to AS10x
119 * @phandle: pointer to AS10x handle
120 * @ptune: tune parameters
121 *
122 * Return 0 on success or negative value in case of error.
123 */
124int as10x_cmd_set_tune(as10x_handle_t *phandle, struct as10x_tune_args *ptune)
125{
126 int error;
127 struct as10x_cmd_t *preq, *prsp;
128
129 ENTER();
130
131 preq = phandle->cmd;
132 prsp = phandle->rsp;
133
134 /* prepare command */
135 as10x_cmd_build(preq, (++phandle->cmd_xid),
136 sizeof(preq->body.set_tune.req));
137
138 /* fill command */
139 preq->body.set_tune.req.proc_id = cpu_to_le16(CONTROL_PROC_SETTUNE);
140 preq->body.set_tune.req.args.freq = cpu_to_le32(ptune->freq);
141 preq->body.set_tune.req.args.bandwidth = ptune->bandwidth;
142 preq->body.set_tune.req.args.hier_select = ptune->hier_select;
143 preq->body.set_tune.req.args.constellation = ptune->constellation;
144 preq->body.set_tune.req.args.hierarchy = ptune->hierarchy;
145 preq->body.set_tune.req.args.interleaving_mode =
146 ptune->interleaving_mode;
147 preq->body.set_tune.req.args.code_rate = ptune->code_rate;
148 preq->body.set_tune.req.args.guard_interval = ptune->guard_interval;
149 preq->body.set_tune.req.args.transmission_mode =
150 ptune->transmission_mode;
151
152 /* send command */
153 if (phandle->ops->xfer_cmd) {
154 error = phandle->ops->xfer_cmd(phandle,
155 (uint8_t *) preq,
156 sizeof(preq->body.set_tune.req)
157 + HEADER_SIZE,
158 (uint8_t *) prsp,
159 sizeof(prsp->body.set_tune.rsp)
160 + HEADER_SIZE);
161 } else {
162 error = AS10X_CMD_ERROR;
163 }
164
165 if (error < 0)
166 goto out;
167
168 /* parse response */
169 error = as10x_rsp_parse(prsp, CONTROL_PROC_SETTUNE_RSP);
170
171out:
172 LEAVE();
173 return error;
174}
175
176/**
177 * as10x_cmd_get_tune_status - send get tune status command to AS10x
178 * @phandle: pointer to AS10x handle
179 * @pstatus: pointer to updated status structure of the current tune
180 *
181 * Return 0 on success or negative value in case of error.
182 */
183int as10x_cmd_get_tune_status(as10x_handle_t *phandle,
184 struct as10x_tune_status *pstatus)
185{
186 int error;
187 struct as10x_cmd_t *preq, *prsp;
188
189 ENTER();
190
191 preq = phandle->cmd;
192 prsp = phandle->rsp;
193
194 /* prepare command */
195 as10x_cmd_build(preq, (++phandle->cmd_xid),
196 sizeof(preq->body.get_tune_status.req));
197
198 /* fill command */
199 preq->body.get_tune_status.req.proc_id =
200 cpu_to_le16(CONTROL_PROC_GETTUNESTAT);
201
202 /* send command */
203 if (phandle->ops->xfer_cmd) {
204 error = phandle->ops->xfer_cmd(
205 phandle,
206 (uint8_t *) preq,
207 sizeof(preq->body.get_tune_status.req) + HEADER_SIZE,
208 (uint8_t *) prsp,
209 sizeof(prsp->body.get_tune_status.rsp) + HEADER_SIZE);
210 } else {
211 error = AS10X_CMD_ERROR;
212 }
213
214 if (error < 0)
215 goto out;
216
217 /* parse response */
218 error = as10x_rsp_parse(prsp, CONTROL_PROC_GETTUNESTAT_RSP);
219 if (error < 0)
220 goto out;
221
222 /* Response OK -> get response data */
223 pstatus->tune_state = prsp->body.get_tune_status.rsp.sts.tune_state;
224 pstatus->signal_strength =
225 le16_to_cpu(prsp->body.get_tune_status.rsp.sts.signal_strength);
226 pstatus->PER = le16_to_cpu(prsp->body.get_tune_status.rsp.sts.PER);
227 pstatus->BER = le16_to_cpu(prsp->body.get_tune_status.rsp.sts.BER);
228
229out:
230 LEAVE();
231 return error;
232}
233
234/**
235 * send get TPS command to AS10x
236 * @phandle: pointer to AS10x handle
237 * @ptps: pointer to TPS parameters structure
238 *
239 * Return 0 on success or negative value in case of error.
240 */
241int as10x_cmd_get_tps(as10x_handle_t *phandle, struct as10x_tps *ptps)
242{
243 int error;
244 struct as10x_cmd_t *pcmd, *prsp;
245
246 ENTER();
247
248 pcmd = phandle->cmd;
249 prsp = phandle->rsp;
250
251 /* prepare command */
252 as10x_cmd_build(pcmd, (++phandle->cmd_xid),
253 sizeof(pcmd->body.get_tps.req));
254
255 /* fill command */
256 pcmd->body.get_tune_status.req.proc_id =
257 cpu_to_le16(CONTROL_PROC_GETTPS);
258
259 /* send command */
260 if (phandle->ops->xfer_cmd) {
261 error = phandle->ops->xfer_cmd(phandle,
262 (uint8_t *) pcmd,
263 sizeof(pcmd->body.get_tps.req) +
264 HEADER_SIZE,
265 (uint8_t *) prsp,
266 sizeof(prsp->body.get_tps.rsp) +
267 HEADER_SIZE);
268 } else {
269 error = AS10X_CMD_ERROR;
270 }
271
272 if (error < 0)
273 goto out;
274
275 /* parse response */
276 error = as10x_rsp_parse(prsp, CONTROL_PROC_GETTPS_RSP);
277 if (error < 0)
278 goto out;
279
280 /* Response OK -> get response data */
281 ptps->constellation = prsp->body.get_tps.rsp.tps.constellation;
282 ptps->hierarchy = prsp->body.get_tps.rsp.tps.hierarchy;
283 ptps->interleaving_mode = prsp->body.get_tps.rsp.tps.interleaving_mode;
284 ptps->code_rate_HP = prsp->body.get_tps.rsp.tps.code_rate_HP;
285 ptps->code_rate_LP = prsp->body.get_tps.rsp.tps.code_rate_LP;
286 ptps->guard_interval = prsp->body.get_tps.rsp.tps.guard_interval;
287 ptps->transmission_mode = prsp->body.get_tps.rsp.tps.transmission_mode;
288 ptps->DVBH_mask_HP = prsp->body.get_tps.rsp.tps.DVBH_mask_HP;
289 ptps->DVBH_mask_LP = prsp->body.get_tps.rsp.tps.DVBH_mask_LP;
290 ptps->cell_ID = le16_to_cpu(prsp->body.get_tps.rsp.tps.cell_ID);
291
292out:
293 LEAVE();
294 return error;
295}
296
297/**
298 * as10x_cmd_get_demod_stats - send get demod stats command to AS10x
299 * @phandle: pointer to AS10x handle
300 * @pdemod_stats: pointer to demod stats parameters structure
301 *
302 * Return 0 on success or negative value in case of error.
303 */
304int as10x_cmd_get_demod_stats(as10x_handle_t *phandle,
305 struct as10x_demod_stats *pdemod_stats)
306{
307 int error;
308 struct as10x_cmd_t *pcmd, *prsp;
309
310 ENTER();
311
312 pcmd = phandle->cmd;
313 prsp = phandle->rsp;
314
315 /* prepare command */
316 as10x_cmd_build(pcmd, (++phandle->cmd_xid),
317 sizeof(pcmd->body.get_demod_stats.req));
318
319 /* fill command */
320 pcmd->body.get_demod_stats.req.proc_id =
321 cpu_to_le16(CONTROL_PROC_GET_DEMOD_STATS);
322
323 /* send command */
324 if (phandle->ops->xfer_cmd) {
325 error = phandle->ops->xfer_cmd(phandle,
326 (uint8_t *) pcmd,
327 sizeof(pcmd->body.get_demod_stats.req)
328 + HEADER_SIZE,
329 (uint8_t *) prsp,
330 sizeof(prsp->body.get_demod_stats.rsp)
331 + HEADER_SIZE);
332 } else {
333 error = AS10X_CMD_ERROR;
334 }
335
336 if (error < 0)
337 goto out;
338
339 /* parse response */
340 error = as10x_rsp_parse(prsp, CONTROL_PROC_GET_DEMOD_STATS_RSP);
341 if (error < 0)
342 goto out;
343
344 /* Response OK -> get response data */
345 pdemod_stats->frame_count =
346 le32_to_cpu(prsp->body.get_demod_stats.rsp.stats.frame_count);
347 pdemod_stats->bad_frame_count =
348 le32_to_cpu(prsp->body.get_demod_stats.rsp.stats.bad_frame_count);
349 pdemod_stats->bytes_fixed_by_rs =
350 le32_to_cpu(prsp->body.get_demod_stats.rsp.stats.bytes_fixed_by_rs);
351 pdemod_stats->mer =
352 le16_to_cpu(prsp->body.get_demod_stats.rsp.stats.mer);
353 pdemod_stats->has_started =
354 prsp->body.get_demod_stats.rsp.stats.has_started;
355
356out:
357 LEAVE();
358 return error;
359}
360
361/**
362 * as10x_cmd_get_impulse_resp - send get impulse response command to AS10x
363 * @phandle: pointer to AS10x handle
364 * @is_ready: pointer to value indicating when impulse
365 * response data is ready
366 *
367 * Return 0 on success or negative value in case of error.
368 */
369int as10x_cmd_get_impulse_resp(as10x_handle_t *phandle,
370 uint8_t *is_ready)
371{
372 int error;
373 struct as10x_cmd_t *pcmd, *prsp;
374
375 ENTER();
376
377 pcmd = phandle->cmd;
378 prsp = phandle->rsp;
379
380 /* prepare command */
381 as10x_cmd_build(pcmd, (++phandle->cmd_xid),
382 sizeof(pcmd->body.get_impulse_rsp.req));
383
384 /* fill command */
385 pcmd->body.get_impulse_rsp.req.proc_id =
386 cpu_to_le16(CONTROL_PROC_GET_IMPULSE_RESP);
387
388 /* send command */
389 if (phandle->ops->xfer_cmd) {
390 error = phandle->ops->xfer_cmd(phandle,
391 (uint8_t *) pcmd,
392 sizeof(pcmd->body.get_impulse_rsp.req)
393 + HEADER_SIZE,
394 (uint8_t *) prsp,
395 sizeof(prsp->body.get_impulse_rsp.rsp)
396 + HEADER_SIZE);
397 } else {
398 error = AS10X_CMD_ERROR;
399 }
400
401 if (error < 0)
402 goto out;
403
404 /* parse response */
405 error = as10x_rsp_parse(prsp, CONTROL_PROC_GET_IMPULSE_RESP_RSP);
406 if (error < 0)
407 goto out;
408
409 /* Response OK -> get response data */
410 *is_ready = prsp->body.get_impulse_rsp.rsp.is_ready;
411
412out:
413 LEAVE();
414 return error;
415}
416
417/**
418 * as10x_cmd_build - build AS10x command header
419 * @pcmd: pointer to AS10x command buffer
420 * @xid: sequence id of the command
421 * @cmd_len: length of the command
422 */
423void as10x_cmd_build(struct as10x_cmd_t *pcmd,
424 uint16_t xid, uint16_t cmd_len)
425{
426 pcmd->header.req_id = cpu_to_le16(xid);
427 pcmd->header.prog = cpu_to_le16(SERVICE_PROG_ID);
428 pcmd->header.version = cpu_to_le16(SERVICE_PROG_VERSION);
429 pcmd->header.data_len = cpu_to_le16(cmd_len);
430}
431
432/**
433 * as10x_rsp_parse - Parse command response
434 * @prsp: pointer to AS10x command buffer
435 * @proc_id: id of the command
436 *
437 * Return 0 on success or negative value in case of error.
438 */
439int as10x_rsp_parse(struct as10x_cmd_t *prsp, uint16_t proc_id)
440{
441 int error;
442
443 /* extract command error code */
444 error = prsp->body.common.rsp.error;
445
446 if ((error == 0) &&
447 (le16_to_cpu(prsp->body.common.rsp.proc_id) == proc_id)) {
448 return 0;
449 }
450
451 return AS10X_CMD_ERROR;
452}
diff --git a/drivers/staging/media/as102/as10x_cmd.h b/drivers/staging/media/as102/as10x_cmd.h
new file mode 100644
index 000000000000..01a716380e0a
--- /dev/null
+++ b/drivers/staging/media/as102/as10x_cmd.h
@@ -0,0 +1,540 @@
1/*
2 * Abilis Systems Single DVB-T Receiver
3 * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * 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#ifndef _AS10X_CMD_H_
20#define _AS10X_CMD_H_
21
22#ifdef __KERNEL__
23#include <linux/kernel.h>
24#endif
25
26#include "as10x_types.h"
27
28/*********************************/
29/* MACRO DEFINITIONS */
30/*********************************/
31#define AS10X_CMD_ERROR -1
32
33#define SERVICE_PROG_ID 0x0002
34#define SERVICE_PROG_VERSION 0x0001
35
36#define HIER_NONE 0x00
37#define HIER_LOW_PRIORITY 0x01
38
39#define HEADER_SIZE (sizeof(struct as10x_cmd_header_t))
40
41/* context request types */
42#define GET_CONTEXT_DATA 1
43#define SET_CONTEXT_DATA 2
44
45/* ODSP suspend modes */
46#define CFG_MODE_ODSP_RESUME 0
47#define CFG_MODE_ODSP_SUSPEND 1
48
49/* Dump memory size */
50#define DUMP_BLOCK_SIZE_MAX 0x20
51
52/*********************************/
53/* TYPE DEFINITION */
54/*********************************/
55typedef enum {
56 CONTROL_PROC_TURNON = 0x0001,
57 CONTROL_PROC_TURNON_RSP = 0x0100,
58 CONTROL_PROC_SET_REGISTER = 0x0002,
59 CONTROL_PROC_SET_REGISTER_RSP = 0x0200,
60 CONTROL_PROC_GET_REGISTER = 0x0003,
61 CONTROL_PROC_GET_REGISTER_RSP = 0x0300,
62 CONTROL_PROC_SETTUNE = 0x000A,
63 CONTROL_PROC_SETTUNE_RSP = 0x0A00,
64 CONTROL_PROC_GETTUNESTAT = 0x000B,
65 CONTROL_PROC_GETTUNESTAT_RSP = 0x0B00,
66 CONTROL_PROC_GETTPS = 0x000D,
67 CONTROL_PROC_GETTPS_RSP = 0x0D00,
68 CONTROL_PROC_SETFILTER = 0x000E,
69 CONTROL_PROC_SETFILTER_RSP = 0x0E00,
70 CONTROL_PROC_REMOVEFILTER = 0x000F,
71 CONTROL_PROC_REMOVEFILTER_RSP = 0x0F00,
72 CONTROL_PROC_GET_IMPULSE_RESP = 0x0012,
73 CONTROL_PROC_GET_IMPULSE_RESP_RSP = 0x1200,
74 CONTROL_PROC_START_STREAMING = 0x0013,
75 CONTROL_PROC_START_STREAMING_RSP = 0x1300,
76 CONTROL_PROC_STOP_STREAMING = 0x0014,
77 CONTROL_PROC_STOP_STREAMING_RSP = 0x1400,
78 CONTROL_PROC_GET_DEMOD_STATS = 0x0015,
79 CONTROL_PROC_GET_DEMOD_STATS_RSP = 0x1500,
80 CONTROL_PROC_ELNA_CHANGE_MODE = 0x0016,
81 CONTROL_PROC_ELNA_CHANGE_MODE_RSP = 0x1600,
82 CONTROL_PROC_ODSP_CHANGE_MODE = 0x0017,
83 CONTROL_PROC_ODSP_CHANGE_MODE_RSP = 0x1700,
84 CONTROL_PROC_AGC_CHANGE_MODE = 0x0018,
85 CONTROL_PROC_AGC_CHANGE_MODE_RSP = 0x1800,
86
87 CONTROL_PROC_CONTEXT = 0x00FC,
88 CONTROL_PROC_CONTEXT_RSP = 0xFC00,
89 CONTROL_PROC_DUMP_MEMORY = 0x00FD,
90 CONTROL_PROC_DUMP_MEMORY_RSP = 0xFD00,
91 CONTROL_PROC_DUMPLOG_MEMORY = 0x00FE,
92 CONTROL_PROC_DUMPLOG_MEMORY_RSP = 0xFE00,
93 CONTROL_PROC_TURNOFF = 0x00FF,
94 CONTROL_PROC_TURNOFF_RSP = 0xFF00
95} control_proc;
96
97
98#pragma pack(1)
99typedef union {
100 /* request */
101 struct {
102 /* request identifier */
103 uint16_t proc_id;
104 } req;
105 /* response */
106 struct {
107 /* response identifier */
108 uint16_t proc_id;
109 /* error */
110 uint8_t error;
111 } rsp;
112} TURN_ON;
113
114typedef union {
115 /* request */
116 struct {
117 /* request identifier */
118 uint16_t proc_id;
119 } req;
120 /* response */
121 struct {
122 /* response identifier */
123 uint16_t proc_id;
124 /* error */
125 uint8_t err;
126 } rsp;
127} TURN_OFF;
128
129typedef union {
130 /* request */
131 struct {
132 /* request identifier */
133 uint16_t proc_id;
134 /* tune params */
135 struct as10x_tune_args args;
136 } req;
137 /* response */
138 struct {
139 /* response identifier */
140 uint16_t proc_id;
141 /* response error */
142 uint8_t error;
143 } rsp;
144} SET_TUNE;
145
146typedef union {
147 /* request */
148 struct {
149 /* request identifier */
150 uint16_t proc_id;
151 } req;
152 /* response */
153 struct {
154 /* response identifier */
155 uint16_t proc_id;
156 /* response error */
157 uint8_t error;
158 /* tune status */
159 struct as10x_tune_status sts;
160 } rsp;
161} GET_TUNE_STATUS;
162
163typedef union {
164 /* request */
165 struct {
166 /* request identifier */
167 uint16_t proc_id;
168 } req;
169 /* response */
170 struct {
171 /* response identifier */
172 uint16_t proc_id;
173 /* response error */
174 uint8_t error;
175 /* tps details */
176 struct as10x_tps tps;
177 } rsp;
178} GET_TPS;
179
180typedef union {
181 /* request */
182 struct {
183 /* request identifier */
184 uint16_t proc_id;
185 } req;
186 /* response */
187 struct {
188 /* response identifier */
189 uint16_t proc_id;
190 /* response error */
191 uint8_t error;
192 } rsp;
193} COMMON;
194
195typedef union {
196 /* request */
197 struct {
198 /* request identifier */
199 uint16_t proc_id;
200 /* PID to filter */
201 uint16_t pid;
202 /* stream type (MPE, PSI/SI or PES )*/
203 uint8_t stream_type;
204 /* PID index in filter table */
205 uint8_t idx;
206 } req;
207 /* response */
208 struct {
209 /* response identifier */
210 uint16_t proc_id;
211 /* response error */
212 uint8_t error;
213 /* Filter id */
214 uint8_t filter_id;
215 } rsp;
216} ADD_PID_FILTER;
217
218typedef union {
219 /* request */
220 struct {
221 /* request identifier */
222 uint16_t proc_id;
223 /* PID to remove */
224 uint16_t pid;
225 } req;
226 /* response */
227 struct {
228 /* response identifier */
229 uint16_t proc_id;
230 /* response error */
231 uint8_t error;
232 } rsp;
233} DEL_PID_FILTER;
234
235typedef union {
236 /* request */
237 struct {
238 /* request identifier */
239 uint16_t proc_id;
240 } req;
241 /* response */
242 struct {
243 /* response identifier */
244 uint16_t proc_id;
245 /* error */
246 uint8_t error;
247 } rsp;
248} START_STREAMING;
249
250typedef union {
251 /* request */
252 struct {
253 /* request identifier */
254 uint16_t proc_id;
255 } req;
256 /* response */
257 struct {
258 /* response identifier */
259 uint16_t proc_id;
260 /* error */
261 uint8_t error;
262 } rsp;
263} STOP_STREAMING;
264
265typedef union {
266 /* request */
267 struct {
268 /* request identifier */
269 uint16_t proc_id;
270 } req;
271 /* response */
272 struct {
273 /* response identifier */
274 uint16_t proc_id;
275 /* error */
276 uint8_t error;
277 /* demod stats */
278 struct as10x_demod_stats stats;
279 } rsp;
280} GET_DEMOD_STATS;
281
282typedef union {
283 /* request */
284 struct {
285 /* request identifier */
286 uint16_t proc_id;
287 } req;
288 /* response */
289 struct {
290 /* response identifier */
291 uint16_t proc_id;
292 /* error */
293 uint8_t error;
294 /* impulse response ready */
295 uint8_t is_ready;
296 } rsp;
297} GET_IMPULSE_RESP;
298
299typedef union {
300 /* request */
301 struct {
302 /* request identifier */
303 uint16_t proc_id;
304 /* value to write (for set context)*/
305 struct as10x_register_value reg_val;
306 /* context tag */
307 uint16_t tag;
308 /* context request type */
309 uint16_t type;
310 } req;
311 /* response */
312 struct {
313 /* response identifier */
314 uint16_t proc_id;
315 /* value read (for get context) */
316 struct as10x_register_value reg_val;
317 /* context request type */
318 uint16_t type;
319 /* error */
320 uint8_t error;
321 } rsp;
322} FW_CONTEXT;
323
324typedef union {
325 /* request */
326 struct {
327 /* response identifier */
328 uint16_t proc_id;
329 /* register description */
330 struct as10x_register_addr reg_addr;
331 /* register content */
332 struct as10x_register_value reg_val;
333 } req;
334 /* response */
335 struct {
336 /* response identifier */
337 uint16_t proc_id;
338 /* error */
339 uint8_t error;
340 } rsp;
341} SET_REGISTER;
342
343typedef union {
344 /* request */
345 struct {
346 /* response identifier */
347 uint16_t proc_id;
348 /* register description */
349 struct as10x_register_addr reg_addr;
350 } req;
351 /* response */
352 struct {
353 /* response identifier */
354 uint16_t proc_id;
355 /* error */
356 uint8_t error;
357 /* register content */
358 struct as10x_register_value reg_val;
359 } rsp;
360} GET_REGISTER;
361
362typedef union {
363 /* request */
364 struct {
365 /* request identifier */
366 uint16_t proc_id;
367 /* mode */
368 uint8_t mode;
369 } req;
370 /* response */
371 struct {
372 /* response identifier */
373 uint16_t proc_id;
374 /* error */
375 uint8_t error;
376 } rsp;
377} CFG_CHANGE_MODE;
378
379struct as10x_cmd_header_t {
380 uint16_t req_id;
381 uint16_t prog;
382 uint16_t version;
383 uint16_t data_len;
384};
385
386#define DUMP_BLOCK_SIZE 16
387typedef union {
388 /* request */
389 struct {
390 /* request identifier */
391 uint16_t proc_id;
392 /* dump memory type request */
393 uint8_t dump_req;
394 /* register description */
395 struct as10x_register_addr reg_addr;
396 /* nb blocks to read */
397 uint16_t num_blocks;
398 } req;
399 /* response */
400 struct {
401 /* response identifier */
402 uint16_t proc_id;
403 /* error */
404 uint8_t error;
405 /* dump response */
406 uint8_t dump_rsp;
407 /* data */
408 union {
409 uint8_t data8[DUMP_BLOCK_SIZE];
410 uint16_t data16[DUMP_BLOCK_SIZE / sizeof(uint16_t)];
411 uint32_t data32[DUMP_BLOCK_SIZE / sizeof(uint32_t)];
412 } u;
413 } rsp;
414} DUMP_MEMORY;
415
416typedef union {
417 struct {
418 /* request identifier */
419 uint16_t proc_id;
420 /* dump memory type request */
421 uint8_t dump_req;
422 } req;
423 struct {
424 /* request identifier */
425 uint16_t proc_id;
426 /* error */
427 uint8_t error;
428 /* dump response */
429 uint8_t dump_rsp;
430 /* dump data */
431 uint8_t data[DUMP_BLOCK_SIZE];
432 } rsp;
433} DUMPLOG_MEMORY;
434
435typedef union {
436 /* request */
437 struct {
438 uint16_t proc_id;
439 uint8_t data[64 - sizeof(struct as10x_cmd_header_t) -2 /* proc_id */];
440 } req;
441 /* response */
442 struct {
443 uint16_t proc_id;
444 uint8_t error;
445 uint8_t data[64 - sizeof(struct as10x_cmd_header_t) /* header */
446 - 2 /* proc_id */ - 1 /* rc */];
447 } rsp;
448} RAW_DATA;
449
450struct as10x_cmd_t {
451 /* header */
452 struct as10x_cmd_header_t header;
453 /* body */
454 union {
455 TURN_ON turn_on;
456 TURN_OFF turn_off;
457 SET_TUNE set_tune;
458 GET_TUNE_STATUS get_tune_status;
459 GET_TPS get_tps;
460 COMMON common;
461 ADD_PID_FILTER add_pid_filter;
462 DEL_PID_FILTER del_pid_filter;
463 START_STREAMING start_streaming;
464 STOP_STREAMING stop_streaming;
465 GET_DEMOD_STATS get_demod_stats;
466 GET_IMPULSE_RESP get_impulse_rsp;
467 FW_CONTEXT context;
468 SET_REGISTER set_register;
469 GET_REGISTER get_register;
470 CFG_CHANGE_MODE cfg_change_mode;
471 DUMP_MEMORY dump_memory;
472 DUMPLOG_MEMORY dumplog_memory;
473 RAW_DATA raw_data;
474 } body;
475};
476
477struct as10x_token_cmd_t {
478 /* token cmd */
479 struct as10x_cmd_t c;
480 /* token response */
481 struct as10x_cmd_t r;
482};
483#pragma pack()
484
485
486/**************************/
487/* FUNCTION DECLARATION */
488/**************************/
489
490void as10x_cmd_build(struct as10x_cmd_t *pcmd, uint16_t proc_id,
491 uint16_t cmd_len);
492int as10x_rsp_parse(struct as10x_cmd_t *r, uint16_t proc_id);
493
494#ifdef __cplusplus
495extern "C" {
496#endif
497
498/* as10x cmd */
499int as10x_cmd_turn_on(as10x_handle_t *phandle);
500int as10x_cmd_turn_off(as10x_handle_t *phandle);
501
502int as10x_cmd_set_tune(as10x_handle_t *phandle,
503 struct as10x_tune_args *ptune);
504
505int as10x_cmd_get_tune_status(as10x_handle_t *phandle,
506 struct as10x_tune_status *pstatus);
507
508int as10x_cmd_get_tps(as10x_handle_t *phandle,
509 struct as10x_tps *ptps);
510
511int as10x_cmd_get_demod_stats(as10x_handle_t *phandle,
512 struct as10x_demod_stats *pdemod_stats);
513
514int as10x_cmd_get_impulse_resp(as10x_handle_t *phandle,
515 uint8_t *is_ready);
516
517/* as10x cmd stream */
518int as10x_cmd_add_PID_filter(as10x_handle_t *phandle,
519 struct as10x_ts_filter *filter);
520int as10x_cmd_del_PID_filter(as10x_handle_t *phandle,
521 uint16_t pid_value);
522
523int as10x_cmd_start_streaming(as10x_handle_t *phandle);
524int as10x_cmd_stop_streaming(as10x_handle_t *phandle);
525
526/* as10x cmd cfg */
527int as10x_cmd_set_context(as10x_handle_t *phandle,
528 uint16_t tag,
529 uint32_t value);
530int as10x_cmd_get_context(as10x_handle_t *phandle,
531 uint16_t tag,
532 uint32_t *pvalue);
533
534int as10x_cmd_eLNA_change_mode(as10x_handle_t *phandle, uint8_t mode);
535int as10x_context_rsp_parse(struct as10x_cmd_t *prsp, uint16_t proc_id);
536#ifdef __cplusplus
537}
538#endif
539#endif
540/* EOF - vim: set textwidth=80 ts=3 sw=3 sts=3 et: */
diff --git a/drivers/staging/media/as102/as10x_cmd_cfg.c b/drivers/staging/media/as102/as10x_cmd_cfg.c
new file mode 100644
index 000000000000..ec6f69fcf399
--- /dev/null
+++ b/drivers/staging/media/as102/as10x_cmd_cfg.c
@@ -0,0 +1,215 @@
1/*
2 * Abilis Systems Single DVB-T Receiver
3 * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * 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/kernel.h>
21#include "as102_drv.h"
22#include "as10x_types.h"
23#include "as10x_cmd.h"
24
25/***************************/
26/* FUNCTION DEFINITION */
27/***************************/
28
29/**
30 * as10x_cmd_get_context - Send get context command to AS10x
31 * @phandle: pointer to AS10x handle
32 * @tag: context tag
33 * @pvalue: pointer where to store context value read
34 *
35 * Return 0 on success or negative value in case of error.
36 */
37int as10x_cmd_get_context(as10x_handle_t *phandle, uint16_t tag,
38 uint32_t *pvalue)
39{
40 int error;
41 struct as10x_cmd_t *pcmd, *prsp;
42
43 ENTER();
44
45 pcmd = phandle->cmd;
46 prsp = phandle->rsp;
47
48 /* prepare command */
49 as10x_cmd_build(pcmd, (++phandle->cmd_xid),
50 sizeof(pcmd->body.context.req));
51
52 /* fill command */
53 pcmd->body.context.req.proc_id = cpu_to_le16(CONTROL_PROC_CONTEXT);
54 pcmd->body.context.req.tag = cpu_to_le16(tag);
55 pcmd->body.context.req.type = cpu_to_le16(GET_CONTEXT_DATA);
56
57 /* send command */
58 if (phandle->ops->xfer_cmd) {
59 error = phandle->ops->xfer_cmd(phandle,
60 (uint8_t *) pcmd,
61 sizeof(pcmd->body.context.req)
62 + HEADER_SIZE,
63 (uint8_t *) prsp,
64 sizeof(prsp->body.context.rsp)
65 + HEADER_SIZE);
66 } else {
67 error = AS10X_CMD_ERROR;
68 }
69
70 if (error < 0)
71 goto out;
72
73 /* parse response: context command do not follow the common response */
74 /* structure -> specific handling response parse required */
75 error = as10x_context_rsp_parse(prsp, CONTROL_PROC_CONTEXT_RSP);
76
77 if (error == 0) {
78 /* Response OK -> get response data */
79 *pvalue = le32_to_cpu(prsp->body.context.rsp.reg_val.u.value32);
80 /* value returned is always a 32-bit value */
81 }
82
83out:
84 LEAVE();
85 return error;
86}
87
88/**
89 * as10x_cmd_set_context - send set context command to AS10x
90 * @phandle: pointer to AS10x handle
91 * @tag: context tag
92 * @value: value to set in context
93 *
94 * Return 0 on success or negative value in case of error.
95 */
96int as10x_cmd_set_context(as10x_handle_t *phandle, uint16_t tag,
97 uint32_t value)
98{
99 int error;
100 struct as10x_cmd_t *pcmd, *prsp;
101
102 ENTER();
103
104 pcmd = phandle->cmd;
105 prsp = phandle->rsp;
106
107 /* prepare command */
108 as10x_cmd_build(pcmd, (++phandle->cmd_xid),
109 sizeof(pcmd->body.context.req));
110
111 /* fill command */
112 pcmd->body.context.req.proc_id = cpu_to_le16(CONTROL_PROC_CONTEXT);
113 /* pcmd->body.context.req.reg_val.mode initialization is not required */
114 pcmd->body.context.req.reg_val.u.value32 = cpu_to_le32(value);
115 pcmd->body.context.req.tag = cpu_to_le16(tag);
116 pcmd->body.context.req.type = cpu_to_le16(SET_CONTEXT_DATA);
117
118 /* send command */
119 if (phandle->ops->xfer_cmd) {
120 error = phandle->ops->xfer_cmd(phandle,
121 (uint8_t *) pcmd,
122 sizeof(pcmd->body.context.req)
123 + HEADER_SIZE,
124 (uint8_t *) prsp,
125 sizeof(prsp->body.context.rsp)
126 + HEADER_SIZE);
127 } else {
128 error = AS10X_CMD_ERROR;
129 }
130
131 if (error < 0)
132 goto out;
133
134 /* parse response: context command do not follow the common response */
135 /* structure -> specific handling response parse required */
136 error = as10x_context_rsp_parse(prsp, CONTROL_PROC_CONTEXT_RSP);
137
138out:
139 LEAVE();
140 return error;
141}
142
143/**
144 * as10x_cmd_eLNA_change_mode - send eLNA change mode command to AS10x
145 * @phandle: pointer to AS10x handle
146 * @mode: mode selected:
147 * - ON : 0x0 => eLNA always ON
148 * - OFF : 0x1 => eLNA always OFF
149 * - AUTO : 0x2 => eLNA follow hysteresis parameters
150 * to be ON or OFF
151 *
152 * Return 0 on success or negative value in case of error.
153 */
154int as10x_cmd_eLNA_change_mode(as10x_handle_t *phandle, uint8_t mode)
155{
156 int error;
157 struct as10x_cmd_t *pcmd, *prsp;
158
159 ENTER();
160
161 pcmd = phandle->cmd;
162 prsp = phandle->rsp;
163
164 /* prepare command */
165 as10x_cmd_build(pcmd, (++phandle->cmd_xid),
166 sizeof(pcmd->body.cfg_change_mode.req));
167
168 /* fill command */
169 pcmd->body.cfg_change_mode.req.proc_id =
170 cpu_to_le16(CONTROL_PROC_ELNA_CHANGE_MODE);
171 pcmd->body.cfg_change_mode.req.mode = mode;
172
173 /* send command */
174 if (phandle->ops->xfer_cmd) {
175 error = phandle->ops->xfer_cmd(phandle, (uint8_t *) pcmd,
176 sizeof(pcmd->body.cfg_change_mode.req)
177 + HEADER_SIZE, (uint8_t *) prsp,
178 sizeof(prsp->body.cfg_change_mode.rsp)
179 + HEADER_SIZE);
180 } else {
181 error = AS10X_CMD_ERROR;
182 }
183
184 if (error < 0)
185 goto out;
186
187 /* parse response */
188 error = as10x_rsp_parse(prsp, CONTROL_PROC_ELNA_CHANGE_MODE_RSP);
189
190out:
191 LEAVE();
192 return error;
193}
194
195/**
196 * as10x_context_rsp_parse - Parse context command response
197 * @prsp: pointer to AS10x command response buffer
198 * @proc_id: id of the command
199 *
200 * Since the contex command reponse does not follow the common
201 * response, a specific parse function is required.
202 * Return 0 on success or negative value in case of error.
203 */
204int as10x_context_rsp_parse(struct as10x_cmd_t *prsp, uint16_t proc_id)
205{
206 int err;
207
208 err = prsp->body.context.rsp.error;
209
210 if ((err == 0) &&
211 (le16_to_cpu(prsp->body.context.rsp.proc_id) == proc_id)) {
212 return 0;
213 }
214 return AS10X_CMD_ERROR;
215}
diff --git a/drivers/staging/media/as102/as10x_cmd_stream.c b/drivers/staging/media/as102/as10x_cmd_stream.c
new file mode 100644
index 000000000000..045c70683193
--- /dev/null
+++ b/drivers/staging/media/as102/as10x_cmd_stream.c
@@ -0,0 +1,223 @@
1/*
2 * Abilis Systems Single DVB-T Receiver
3 * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * 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/kernel.h>
21#include "as102_drv.h"
22#include "as10x_cmd.h"
23
24/**
25 * as10x_cmd_add_PID_filter - send add filter command to AS10x
26 * @phandle: pointer to AS10x handle
27 * @filter: TSFilter filter for DVB-T
28 *
29 * Return 0 on success or negative value in case of error.
30 */
31int as10x_cmd_add_PID_filter(as10x_handle_t *phandle,
32 struct as10x_ts_filter *filter)
33{
34 int error;
35 struct as10x_cmd_t *pcmd, *prsp;
36
37 ENTER();
38
39 pcmd = phandle->cmd;
40 prsp = phandle->rsp;
41
42 /* prepare command */
43 as10x_cmd_build(pcmd, (++phandle->cmd_xid),
44 sizeof(pcmd->body.add_pid_filter.req));
45
46 /* fill command */
47 pcmd->body.add_pid_filter.req.proc_id =
48 cpu_to_le16(CONTROL_PROC_SETFILTER);
49 pcmd->body.add_pid_filter.req.pid = cpu_to_le16(filter->pid);
50 pcmd->body.add_pid_filter.req.stream_type = filter->type;
51
52 if (filter->idx < 16)
53 pcmd->body.add_pid_filter.req.idx = filter->idx;
54 else
55 pcmd->body.add_pid_filter.req.idx = 0xFF;
56
57 /* send command */
58 if (phandle->ops->xfer_cmd) {
59 error = phandle->ops->xfer_cmd(phandle, (uint8_t *) pcmd,
60 sizeof(pcmd->body.add_pid_filter.req)
61 + HEADER_SIZE, (uint8_t *) prsp,
62 sizeof(prsp->body.add_pid_filter.rsp)
63 + HEADER_SIZE);
64 } else {
65 error = AS10X_CMD_ERROR;
66 }
67
68 if (error < 0)
69 goto out;
70
71 /* parse response */
72 error = as10x_rsp_parse(prsp, CONTROL_PROC_SETFILTER_RSP);
73
74 if (error == 0) {
75 /* Response OK -> get response data */
76 filter->idx = prsp->body.add_pid_filter.rsp.filter_id;
77 }
78
79out:
80 LEAVE();
81 return error;
82}
83
84/**
85 * as10x_cmd_del_PID_filter - Send delete filter command to AS10x
86 * @phandle: pointer to AS10x handle
87 * @pid_value: PID to delete
88 *
89 * Return 0 on success or negative value in case of error.
90 */
91int as10x_cmd_del_PID_filter(as10x_handle_t *phandle,
92 uint16_t pid_value)
93{
94 int error;
95 struct as10x_cmd_t *pcmd, *prsp;
96
97 ENTER();
98
99 pcmd = phandle->cmd;
100 prsp = phandle->rsp;
101
102 /* prepare command */
103 as10x_cmd_build(pcmd, (++phandle->cmd_xid),
104 sizeof(pcmd->body.del_pid_filter.req));
105
106 /* fill command */
107 pcmd->body.del_pid_filter.req.proc_id =
108 cpu_to_le16(CONTROL_PROC_REMOVEFILTER);
109 pcmd->body.del_pid_filter.req.pid = cpu_to_le16(pid_value);
110
111 /* send command */
112 if (phandle->ops->xfer_cmd) {
113 error = phandle->ops->xfer_cmd(phandle, (uint8_t *) pcmd,
114 sizeof(pcmd->body.del_pid_filter.req)
115 + HEADER_SIZE, (uint8_t *) prsp,
116 sizeof(prsp->body.del_pid_filter.rsp)
117 + HEADER_SIZE);
118 } else {
119 error = AS10X_CMD_ERROR;
120 }
121
122 if (error < 0)
123 goto out;
124
125 /* parse response */
126 error = as10x_rsp_parse(prsp, CONTROL_PROC_REMOVEFILTER_RSP);
127
128out:
129 LEAVE();
130 return error;
131}
132
133/**
134 * as10x_cmd_start_streaming - Send start streaming command to AS10x
135 * @phandle: pointer to AS10x handle
136 *
137 * Return 0 on success or negative value in case of error.
138 */
139int as10x_cmd_start_streaming(as10x_handle_t *phandle)
140{
141 int error;
142 struct as10x_cmd_t *pcmd, *prsp;
143
144 ENTER();
145
146 pcmd = phandle->cmd;
147 prsp = phandle->rsp;
148
149 /* prepare command */
150 as10x_cmd_build(pcmd, (++phandle->cmd_xid),
151 sizeof(pcmd->body.start_streaming.req));
152
153 /* fill command */
154 pcmd->body.start_streaming.req.proc_id =
155 cpu_to_le16(CONTROL_PROC_START_STREAMING);
156
157 /* send command */
158 if (phandle->ops->xfer_cmd) {
159 error = phandle->ops->xfer_cmd(phandle, (uint8_t *) pcmd,
160 sizeof(pcmd->body.start_streaming.req)
161 + HEADER_SIZE, (uint8_t *) prsp,
162 sizeof(prsp->body.start_streaming.rsp)
163 + HEADER_SIZE);
164 } else {
165 error = AS10X_CMD_ERROR;
166 }
167
168 if (error < 0)
169 goto out;
170
171 /* parse response */
172 error = as10x_rsp_parse(prsp, CONTROL_PROC_START_STREAMING_RSP);
173
174out:
175 LEAVE();
176 return error;
177}
178
179/**
180 * as10x_cmd_stop_streaming - Send stop streaming command to AS10x
181 * @phandle: pointer to AS10x handle
182 *
183 * Return 0 on success or negative value in case of error.
184 */
185int as10x_cmd_stop_streaming(as10x_handle_t *phandle)
186{
187 int8_t error;
188 struct as10x_cmd_t *pcmd, *prsp;
189
190 ENTER();
191
192 pcmd = phandle->cmd;
193 prsp = phandle->rsp;
194
195 /* prepare command */
196 as10x_cmd_build(pcmd, (++phandle->cmd_xid),
197 sizeof(pcmd->body.stop_streaming.req));
198
199 /* fill command */
200 pcmd->body.stop_streaming.req.proc_id =
201 cpu_to_le16(CONTROL_PROC_STOP_STREAMING);
202
203 /* send command */
204 if (phandle->ops->xfer_cmd) {
205 error = phandle->ops->xfer_cmd(phandle, (uint8_t *) pcmd,
206 sizeof(pcmd->body.stop_streaming.req)
207 + HEADER_SIZE, (uint8_t *) prsp,
208 sizeof(prsp->body.stop_streaming.rsp)
209 + HEADER_SIZE);
210 } else {
211 error = AS10X_CMD_ERROR;
212 }
213
214 if (error < 0)
215 goto out;
216
217 /* parse response */
218 error = as10x_rsp_parse(prsp, CONTROL_PROC_STOP_STREAMING_RSP);
219
220out:
221 LEAVE();
222 return error;
223}
diff --git a/drivers/staging/media/as102/as10x_handle.h b/drivers/staging/media/as102/as10x_handle.h
new file mode 100644
index 000000000000..4f01a76e9829
--- /dev/null
+++ b/drivers/staging/media/as102/as10x_handle.h
@@ -0,0 +1,58 @@
1/*
2 * Abilis Systems Single DVB-T Receiver
3 * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * 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#ifdef __KERNEL__
20struct as102_bus_adapter_t;
21struct as102_dev_t;
22
23#define as10x_handle_t struct as102_bus_adapter_t
24#include "as10x_cmd.h"
25
26/* values for "mode" field */
27#define REGMODE8 8
28#define REGMODE16 16
29#define REGMODE32 32
30
31struct as102_priv_ops_t {
32 int (*upload_fw_pkt) (struct as102_bus_adapter_t *bus_adap,
33 unsigned char *buf, int buflen, int swap32);
34
35 int (*send_cmd) (struct as102_bus_adapter_t *bus_adap,
36 unsigned char *buf, int buflen);
37
38 int (*xfer_cmd) (struct as102_bus_adapter_t *bus_adap,
39 unsigned char *send_buf, int send_buf_len,
40 unsigned char *recv_buf, int recv_buf_len);
41/*
42 int (*pid_filter) (struct as102_bus_adapter_t *bus_adap,
43 int index, u16 pid, int onoff);
44*/
45 int (*start_stream) (struct as102_dev_t *dev);
46 void (*stop_stream) (struct as102_dev_t *dev);
47
48 int (*reset_target) (struct as102_bus_adapter_t *bus_adap);
49
50 int (*read_write)(struct as102_bus_adapter_t *bus_adap, uint8_t mode,
51 uint32_t rd_addr, uint16_t rd_len,
52 uint32_t wr_addr, uint16_t wr_len);
53
54 int (*as102_read_ep2) (struct as102_bus_adapter_t *bus_adap,
55 unsigned char *recv_buf,
56 int recv_buf_len);
57};
58#endif
diff --git a/drivers/staging/media/as102/as10x_types.h b/drivers/staging/media/as102/as10x_types.h
new file mode 100644
index 000000000000..3dedb3c1420a
--- /dev/null
+++ b/drivers/staging/media/as102/as10x_types.h
@@ -0,0 +1,198 @@
1/*
2 * Abilis Systems Single DVB-T Receiver
3 * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
8 * 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#ifndef _AS10X_TYPES_H_
20#define _AS10X_TYPES_H_
21
22#include "as10x_handle.h"
23
24/*********************************/
25/* MACRO DEFINITIONS */
26/*********************************/
27
28/* bandwidth constant values */
29#define BW_5_MHZ 0x00
30#define BW_6_MHZ 0x01
31#define BW_7_MHZ 0x02
32#define BW_8_MHZ 0x03
33
34/* hierarchy priority selection values */
35#define HIER_NO_PRIORITY 0x00
36#define HIER_LOW_PRIORITY 0x01
37#define HIER_HIGH_PRIORITY 0x02
38
39/* constellation available values */
40#define CONST_QPSK 0x00
41#define CONST_QAM16 0x01
42#define CONST_QAM64 0x02
43#define CONST_UNKNOWN 0xFF
44
45/* hierarchy available values */
46#define HIER_NONE 0x00
47#define HIER_ALPHA_1 0x01
48#define HIER_ALPHA_2 0x02
49#define HIER_ALPHA_4 0x03
50#define HIER_UNKNOWN 0xFF
51
52/* interleaving available values */
53#define INTLV_NATIVE 0x00
54#define INTLV_IN_DEPTH 0x01
55#define INTLV_UNKNOWN 0xFF
56
57/* code rate available values */
58#define CODE_RATE_1_2 0x00
59#define CODE_RATE_2_3 0x01
60#define CODE_RATE_3_4 0x02
61#define CODE_RATE_5_6 0x03
62#define CODE_RATE_7_8 0x04
63#define CODE_RATE_UNKNOWN 0xFF
64
65/* guard interval available values */
66#define GUARD_INT_1_32 0x00
67#define GUARD_INT_1_16 0x01
68#define GUARD_INT_1_8 0x02
69#define GUARD_INT_1_4 0x03
70#define GUARD_UNKNOWN 0xFF
71
72/* transmission mode available values */
73#define TRANS_MODE_2K 0x00
74#define TRANS_MODE_8K 0x01
75#define TRANS_MODE_4K 0x02
76#define TRANS_MODE_UNKNOWN 0xFF
77
78/* DVBH signalling available values */
79#define TIMESLICING_PRESENT 0x01
80#define MPE_FEC_PRESENT 0x02
81
82/* tune state available */
83#define TUNE_STATUS_NOT_TUNED 0x00
84#define TUNE_STATUS_IDLE 0x01
85#define TUNE_STATUS_LOCKING 0x02
86#define TUNE_STATUS_SIGNAL_DVB_OK 0x03
87#define TUNE_STATUS_STREAM_DETECTED 0x04
88#define TUNE_STATUS_STREAM_TUNED 0x05
89#define TUNE_STATUS_ERROR 0xFF
90
91/* available TS FID filter types */
92#define TS_PID_TYPE_TS 0
93#define TS_PID_TYPE_PSI_SI 1
94#define TS_PID_TYPE_MPE 2
95
96/* number of echos available */
97#define MAX_ECHOS 15
98
99/* Context types */
100#define CONTEXT_LNA 1010
101#define CONTEXT_ELNA_HYSTERESIS 4003
102#define CONTEXT_ELNA_GAIN 4004
103#define CONTEXT_MER_THRESHOLD 5005
104#define CONTEXT_MER_OFFSET 5006
105#define CONTEXT_IR_STATE 7000
106#define CONTEXT_TSOUT_MSB_FIRST 7004
107#define CONTEXT_TSOUT_FALLING_EDGE 7005
108
109/* Configuration modes */
110#define CFG_MODE_ON 0
111#define CFG_MODE_OFF 1
112#define CFG_MODE_AUTO 2
113
114#pragma pack(1)
115struct as10x_tps {
116 uint8_t constellation;
117 uint8_t hierarchy;
118 uint8_t interleaving_mode;
119 uint8_t code_rate_HP;
120 uint8_t code_rate_LP;
121 uint8_t guard_interval;
122 uint8_t transmission_mode;
123 uint8_t DVBH_mask_HP;
124 uint8_t DVBH_mask_LP;
125 uint16_t cell_ID;
126};
127
128struct as10x_tune_args {
129 /* frequency */
130 uint32_t freq;
131 /* bandwidth */
132 uint8_t bandwidth;
133 /* hierarchy selection */
134 uint8_t hier_select;
135 /* constellation */
136 uint8_t constellation;
137 /* hierarchy */
138 uint8_t hierarchy;
139 /* interleaving mode */
140 uint8_t interleaving_mode;
141 /* code rate */
142 uint8_t code_rate;
143 /* guard interval */
144 uint8_t guard_interval;
145 /* transmission mode */
146 uint8_t transmission_mode;
147};
148
149struct as10x_tune_status {
150 /* tune status */
151 uint8_t tune_state;
152 /* signal strength */
153 int16_t signal_strength;
154 /* packet error rate 10^-4 */
155 uint16_t PER;
156 /* bit error rate 10^-4 */
157 uint16_t BER;
158};
159
160struct as10x_demod_stats {
161 /* frame counter */
162 uint32_t frame_count;
163 /* Bad frame counter */
164 uint32_t bad_frame_count;
165 /* Number of wrong bytes fixed by Reed-Solomon */
166 uint32_t bytes_fixed_by_rs;
167 /* Averaged MER */
168 uint16_t mer;
169 /* statistics calculation state indicator (started or not) */
170 uint8_t has_started;
171};
172
173struct as10x_ts_filter {
174 uint16_t pid; /** valid PID value 0x00 : 0x2000 */
175 uint8_t type; /** Red TS_PID_TYPE_<N> values */
176 uint8_t idx; /** index in filtering table */
177};
178
179struct as10x_register_value {
180 uint8_t mode;
181 union {
182 uint8_t value8; /* 8 bit value */
183 uint16_t value16; /* 16 bit value */
184 uint32_t value32; /* 32 bit value */
185 }u;
186};
187
188#pragma pack()
189
190struct as10x_register_addr {
191 /* register addr */
192 uint32_t addr;
193 /* register mode access */
194 uint8_t mode;
195};
196
197
198#endif
diff --git a/drivers/staging/cxd2099/Kconfig b/drivers/staging/media/cxd2099/Kconfig
index b48aefddc84c..b48aefddc84c 100644
--- a/drivers/staging/cxd2099/Kconfig
+++ b/drivers/staging/media/cxd2099/Kconfig
diff --git a/drivers/staging/cxd2099/Makefile b/drivers/staging/media/cxd2099/Makefile
index 64cfc77be357..64cfc77be357 100644
--- a/drivers/staging/cxd2099/Makefile
+++ b/drivers/staging/media/cxd2099/Makefile
diff --git a/drivers/staging/cxd2099/TODO b/drivers/staging/media/cxd2099/TODO
index 375bb6f8ee2c..375bb6f8ee2c 100644
--- a/drivers/staging/cxd2099/TODO
+++ b/drivers/staging/media/cxd2099/TODO
diff --git a/drivers/staging/cxd2099/cxd2099.c b/drivers/staging/media/cxd2099/cxd2099.c
index 1c04185bcfd7..1c04185bcfd7 100644
--- a/drivers/staging/cxd2099/cxd2099.c
+++ b/drivers/staging/media/cxd2099/cxd2099.c
diff --git a/drivers/staging/cxd2099/cxd2099.h b/drivers/staging/media/cxd2099/cxd2099.h
index 19c588a59588..19c588a59588 100644
--- a/drivers/staging/cxd2099/cxd2099.h
+++ b/drivers/staging/media/cxd2099/cxd2099.h
diff --git a/drivers/staging/dt3155v4l/Kconfig b/drivers/staging/media/dt3155v4l/Kconfig
index 226a1ca90b3c..226a1ca90b3c 100644
--- a/drivers/staging/dt3155v4l/Kconfig
+++ b/drivers/staging/media/dt3155v4l/Kconfig
diff --git a/drivers/staging/dt3155v4l/Makefile b/drivers/staging/media/dt3155v4l/Makefile
index ce7a3ec2faf3..ce7a3ec2faf3 100644
--- a/drivers/staging/dt3155v4l/Makefile
+++ b/drivers/staging/media/dt3155v4l/Makefile
diff --git a/drivers/staging/dt3155v4l/dt3155v4l.c b/drivers/staging/media/dt3155v4l/dt3155v4l.c
index 04e93c49f03a..04e93c49f03a 100644
--- a/drivers/staging/dt3155v4l/dt3155v4l.c
+++ b/drivers/staging/media/dt3155v4l/dt3155v4l.c
diff --git a/drivers/staging/dt3155v4l/dt3155v4l.h b/drivers/staging/media/dt3155v4l/dt3155v4l.h
index 2e4f89d402e4..2e4f89d402e4 100644
--- a/drivers/staging/dt3155v4l/dt3155v4l.h
+++ b/drivers/staging/media/dt3155v4l/dt3155v4l.h
diff --git a/drivers/staging/easycap/Kconfig b/drivers/staging/media/easycap/Kconfig
index a425a6f9cdca..a425a6f9cdca 100644
--- a/drivers/staging/easycap/Kconfig
+++ b/drivers/staging/media/easycap/Kconfig
diff --git a/drivers/staging/easycap/Makefile b/drivers/staging/media/easycap/Makefile
index a34e75f59c18..a34e75f59c18 100644
--- a/drivers/staging/easycap/Makefile
+++ b/drivers/staging/media/easycap/Makefile
diff --git a/drivers/staging/easycap/README b/drivers/staging/media/easycap/README
index 796b032384bd..796b032384bd 100644
--- a/drivers/staging/easycap/README
+++ b/drivers/staging/media/easycap/README
diff --git a/drivers/staging/easycap/easycap.h b/drivers/staging/media/easycap/easycap.h
index 7b256a948c27..7b256a948c27 100644
--- a/drivers/staging/easycap/easycap.h
+++ b/drivers/staging/media/easycap/easycap.h
diff --git a/drivers/staging/easycap/easycap_ioctl.c b/drivers/staging/media/easycap/easycap_ioctl.c
index c99addfb6242..c99addfb6242 100644
--- a/drivers/staging/easycap/easycap_ioctl.c
+++ b/drivers/staging/media/easycap/easycap_ioctl.c
diff --git a/drivers/staging/easycap/easycap_low.c b/drivers/staging/media/easycap/easycap_low.c
index 0385735ac6df..0385735ac6df 100644
--- a/drivers/staging/easycap/easycap_low.c
+++ b/drivers/staging/media/easycap/easycap_low.c
diff --git a/drivers/staging/easycap/easycap_main.c b/drivers/staging/media/easycap/easycap_main.c
index a45c0b507067..a45c0b507067 100644
--- a/drivers/staging/easycap/easycap_main.c
+++ b/drivers/staging/media/easycap/easycap_main.c
diff --git a/drivers/staging/easycap/easycap_settings.c b/drivers/staging/media/easycap/easycap_settings.c
index 70f59b13c34d..70f59b13c34d 100644
--- a/drivers/staging/easycap/easycap_settings.c
+++ b/drivers/staging/media/easycap/easycap_settings.c
diff --git a/drivers/staging/easycap/easycap_sound.c b/drivers/staging/media/easycap/easycap_sound.c
index b22bb39b5f69..b22bb39b5f69 100644
--- a/drivers/staging/easycap/easycap_sound.c
+++ b/drivers/staging/media/easycap/easycap_sound.c
diff --git a/drivers/staging/easycap/easycap_testcard.c b/drivers/staging/media/easycap/easycap_testcard.c
index 0f71470ace39..0f71470ace39 100644
--- a/drivers/staging/easycap/easycap_testcard.c
+++ b/drivers/staging/media/easycap/easycap_testcard.c
diff --git a/drivers/staging/go7007/Kconfig b/drivers/staging/media/go7007/Kconfig
index 7dfb2815b9ec..7dfb2815b9ec 100644
--- a/drivers/staging/go7007/Kconfig
+++ b/drivers/staging/media/go7007/Kconfig
diff --git a/drivers/staging/go7007/Makefile b/drivers/staging/media/go7007/Makefile
index 6ee837c56706..6ee837c56706 100644
--- a/drivers/staging/go7007/Makefile
+++ b/drivers/staging/media/go7007/Makefile
diff --git a/drivers/staging/go7007/README b/drivers/staging/media/go7007/README
index 48f447637817..48f447637817 100644
--- a/drivers/staging/go7007/README
+++ b/drivers/staging/media/go7007/README
diff --git a/drivers/staging/go7007/go7007-driver.c b/drivers/staging/media/go7007/go7007-driver.c
index 6c9279a6d606..6c9279a6d606 100644
--- a/drivers/staging/go7007/go7007-driver.c
+++ b/drivers/staging/media/go7007/go7007-driver.c
diff --git a/drivers/staging/go7007/go7007-fw.c b/drivers/staging/media/go7007/go7007-fw.c
index c9a6409edfe3..c9a6409edfe3 100644
--- a/drivers/staging/go7007/go7007-fw.c
+++ b/drivers/staging/media/go7007/go7007-fw.c
diff --git a/drivers/staging/go7007/go7007-i2c.c b/drivers/staging/media/go7007/go7007-i2c.c
index b8cfa1a6eaeb..b8cfa1a6eaeb 100644
--- a/drivers/staging/go7007/go7007-i2c.c
+++ b/drivers/staging/media/go7007/go7007-i2c.c
diff --git a/drivers/staging/go7007/go7007-priv.h b/drivers/staging/media/go7007/go7007-priv.h
index b58c394c6555..b58c394c6555 100644
--- a/drivers/staging/go7007/go7007-priv.h
+++ b/drivers/staging/media/go7007/go7007-priv.h
diff --git a/drivers/staging/go7007/go7007-usb.c b/drivers/staging/media/go7007/go7007-usb.c
index 3db3b0a91cc1..3db3b0a91cc1 100644
--- a/drivers/staging/go7007/go7007-usb.c
+++ b/drivers/staging/media/go7007/go7007-usb.c
diff --git a/drivers/staging/go7007/go7007-v4l2.c b/drivers/staging/media/go7007/go7007-v4l2.c
index 2b27d8da70a2..2b27d8da70a2 100644
--- a/drivers/staging/go7007/go7007-v4l2.c
+++ b/drivers/staging/media/go7007/go7007-v4l2.c
diff --git a/drivers/staging/go7007/go7007.h b/drivers/staging/media/go7007/go7007.h
index 7399c915a934..7399c915a934 100644
--- a/drivers/staging/go7007/go7007.h
+++ b/drivers/staging/media/go7007/go7007.h
diff --git a/drivers/staging/go7007/go7007.txt b/drivers/staging/media/go7007/go7007.txt
index 9db1f3952fd2..9db1f3952fd2 100644
--- a/drivers/staging/go7007/go7007.txt
+++ b/drivers/staging/media/go7007/go7007.txt
diff --git a/drivers/staging/go7007/s2250-board.c b/drivers/staging/media/go7007/s2250-board.c
index e7736a915530..e7736a915530 100644
--- a/drivers/staging/go7007/s2250-board.c
+++ b/drivers/staging/media/go7007/s2250-board.c
diff --git a/drivers/staging/go7007/s2250-loader.c b/drivers/staging/media/go7007/s2250-loader.c
index 4e132519e253..4e132519e253 100644
--- a/drivers/staging/go7007/s2250-loader.c
+++ b/drivers/staging/media/go7007/s2250-loader.c
diff --git a/drivers/staging/go7007/s2250-loader.h b/drivers/staging/media/go7007/s2250-loader.h
index b7c301af16cc..b7c301af16cc 100644
--- a/drivers/staging/go7007/s2250-loader.h
+++ b/drivers/staging/media/go7007/s2250-loader.h
diff --git a/drivers/staging/go7007/saa7134-go7007.c b/drivers/staging/media/go7007/saa7134-go7007.c
index cf7c34a99459..cf7c34a99459 100644
--- a/drivers/staging/go7007/saa7134-go7007.c
+++ b/drivers/staging/media/go7007/saa7134-go7007.c
diff --git a/drivers/staging/go7007/snd-go7007.c b/drivers/staging/media/go7007/snd-go7007.c
index deac938d8505..deac938d8505 100644
--- a/drivers/staging/go7007/snd-go7007.c
+++ b/drivers/staging/media/go7007/snd-go7007.c
diff --git a/drivers/staging/go7007/wis-i2c.h b/drivers/staging/media/go7007/wis-i2c.h
index 3c2b9be455df..3c2b9be455df 100644
--- a/drivers/staging/go7007/wis-i2c.h
+++ b/drivers/staging/media/go7007/wis-i2c.h
diff --git a/drivers/staging/go7007/wis-ov7640.c b/drivers/staging/media/go7007/wis-ov7640.c
index 6bc9470fecb6..6bc9470fecb6 100644
--- a/drivers/staging/go7007/wis-ov7640.c
+++ b/drivers/staging/media/go7007/wis-ov7640.c
diff --git a/drivers/staging/go7007/wis-saa7113.c b/drivers/staging/media/go7007/wis-saa7113.c
index 05e0e1083864..05e0e1083864 100644
--- a/drivers/staging/go7007/wis-saa7113.c
+++ b/drivers/staging/media/go7007/wis-saa7113.c
diff --git a/drivers/staging/go7007/wis-saa7115.c b/drivers/staging/media/go7007/wis-saa7115.c
index 46cff59e28b7..46cff59e28b7 100644
--- a/drivers/staging/go7007/wis-saa7115.c
+++ b/drivers/staging/media/go7007/wis-saa7115.c
diff --git a/drivers/staging/go7007/wis-sony-tuner.c b/drivers/staging/media/go7007/wis-sony-tuner.c
index 8f1b7d4f6a2e..8f1b7d4f6a2e 100644
--- a/drivers/staging/go7007/wis-sony-tuner.c
+++ b/drivers/staging/media/go7007/wis-sony-tuner.c
diff --git a/drivers/staging/go7007/wis-tw2804.c b/drivers/staging/media/go7007/wis-tw2804.c
index 9134f03e3cf0..9134f03e3cf0 100644
--- a/drivers/staging/go7007/wis-tw2804.c
+++ b/drivers/staging/media/go7007/wis-tw2804.c
diff --git a/drivers/staging/go7007/wis-tw9903.c b/drivers/staging/media/go7007/wis-tw9903.c
index 9230f4a80529..9230f4a80529 100644
--- a/drivers/staging/go7007/wis-tw9903.c
+++ b/drivers/staging/media/go7007/wis-tw9903.c
diff --git a/drivers/staging/go7007/wis-uda1342.c b/drivers/staging/media/go7007/wis-uda1342.c
index 0127be2f3be0..0127be2f3be0 100644
--- a/drivers/staging/go7007/wis-uda1342.c
+++ b/drivers/staging/media/go7007/wis-uda1342.c
diff --git a/drivers/staging/lirc/Kconfig b/drivers/staging/media/lirc/Kconfig
index 526ec0fc2f04..526ec0fc2f04 100644
--- a/drivers/staging/lirc/Kconfig
+++ b/drivers/staging/media/lirc/Kconfig
diff --git a/drivers/staging/lirc/Makefile b/drivers/staging/media/lirc/Makefile
index d76b0fa2af53..d76b0fa2af53 100644
--- a/drivers/staging/lirc/Makefile
+++ b/drivers/staging/media/lirc/Makefile
diff --git a/drivers/staging/lirc/TODO b/drivers/staging/media/lirc/TODO
index b6cb593f55c6..b6cb593f55c6 100644
--- a/drivers/staging/lirc/TODO
+++ b/drivers/staging/media/lirc/TODO
diff --git a/drivers/staging/lirc/TODO.lirc_zilog b/drivers/staging/media/lirc/TODO.lirc_zilog
index a97800a8e127..a97800a8e127 100644
--- a/drivers/staging/lirc/TODO.lirc_zilog
+++ b/drivers/staging/media/lirc/TODO.lirc_zilog
diff --git a/drivers/staging/lirc/lirc_bt829.c b/drivers/staging/media/lirc/lirc_bt829.c
index c5a0d27a02dc..c5a0d27a02dc 100644
--- a/drivers/staging/lirc/lirc_bt829.c
+++ b/drivers/staging/media/lirc/lirc_bt829.c
diff --git a/drivers/staging/lirc/lirc_ene0100.h b/drivers/staging/media/lirc/lirc_ene0100.h
index 06bebd6acc46..06bebd6acc46 100644
--- a/drivers/staging/lirc/lirc_ene0100.h
+++ b/drivers/staging/media/lirc/lirc_ene0100.h
diff --git a/drivers/staging/lirc/lirc_igorplugusb.c b/drivers/staging/media/lirc/lirc_igorplugusb.c
index 0dc2c2b22c2b..0dc2c2b22c2b 100644
--- a/drivers/staging/lirc/lirc_igorplugusb.c
+++ b/drivers/staging/media/lirc/lirc_igorplugusb.c
diff --git a/drivers/staging/lirc/lirc_imon.c b/drivers/staging/media/lirc/lirc_imon.c
index f5308d5929c6..f5308d5929c6 100644
--- a/drivers/staging/lirc/lirc_imon.c
+++ b/drivers/staging/media/lirc/lirc_imon.c
diff --git a/drivers/staging/lirc/lirc_parallel.c b/drivers/staging/media/lirc/lirc_parallel.c
index 792aac0a8e7b..792aac0a8e7b 100644
--- a/drivers/staging/lirc/lirc_parallel.c
+++ b/drivers/staging/media/lirc/lirc_parallel.c
diff --git a/drivers/staging/lirc/lirc_parallel.h b/drivers/staging/media/lirc/lirc_parallel.h
index 4bed6afe0632..4bed6afe0632 100644
--- a/drivers/staging/lirc/lirc_parallel.h
+++ b/drivers/staging/media/lirc/lirc_parallel.h
diff --git a/drivers/staging/lirc/lirc_sasem.c b/drivers/staging/media/lirc/lirc_sasem.c
index a2d18b0aa048..a2d18b0aa048 100644
--- a/drivers/staging/lirc/lirc_sasem.c
+++ b/drivers/staging/media/lirc/lirc_sasem.c
diff --git a/drivers/staging/lirc/lirc_serial.c b/drivers/staging/media/lirc/lirc_serial.c
index 8a060a8a7224..8a060a8a7224 100644
--- a/drivers/staging/lirc/lirc_serial.c
+++ b/drivers/staging/media/lirc/lirc_serial.c
diff --git a/drivers/staging/lirc/lirc_sir.c b/drivers/staging/media/lirc/lirc_sir.c
index 6903d3992eca..6903d3992eca 100644
--- a/drivers/staging/lirc/lirc_sir.c
+++ b/drivers/staging/media/lirc/lirc_sir.c
diff --git a/drivers/staging/lirc/lirc_ttusbir.c b/drivers/staging/media/lirc/lirc_ttusbir.c
index e4b329b8cafd..e4b329b8cafd 100644
--- a/drivers/staging/lirc/lirc_ttusbir.c
+++ b/drivers/staging/media/lirc/lirc_ttusbir.c
diff --git a/drivers/staging/lirc/lirc_zilog.c b/drivers/staging/media/lirc/lirc_zilog.c
index 0302d82a12f7..0302d82a12f7 100644
--- a/drivers/staging/lirc/lirc_zilog.c
+++ b/drivers/staging/media/lirc/lirc_zilog.c
diff --git a/drivers/staging/solo6x10/Kconfig b/drivers/staging/media/solo6x10/Kconfig
index 03dcac4ea4d0..03dcac4ea4d0 100644
--- a/drivers/staging/solo6x10/Kconfig
+++ b/drivers/staging/media/solo6x10/Kconfig
diff --git a/drivers/staging/solo6x10/Makefile b/drivers/staging/media/solo6x10/Makefile
index 72816cf16704..72816cf16704 100644
--- a/drivers/staging/solo6x10/Makefile
+++ b/drivers/staging/media/solo6x10/Makefile
diff --git a/drivers/staging/solo6x10/TODO b/drivers/staging/media/solo6x10/TODO
index 7e6c4fa130df..7e6c4fa130df 100644
--- a/drivers/staging/solo6x10/TODO
+++ b/drivers/staging/media/solo6x10/TODO
diff --git a/drivers/staging/solo6x10/core.c b/drivers/staging/media/solo6x10/core.c
index f974f6412ad7..f974f6412ad7 100644
--- a/drivers/staging/solo6x10/core.c
+++ b/drivers/staging/media/solo6x10/core.c
diff --git a/drivers/staging/solo6x10/disp.c b/drivers/staging/media/solo6x10/disp.c
index 884c0eb757c4..884c0eb757c4 100644
--- a/drivers/staging/solo6x10/disp.c
+++ b/drivers/staging/media/solo6x10/disp.c
diff --git a/drivers/staging/solo6x10/enc.c b/drivers/staging/media/solo6x10/enc.c
index de502599bb19..de502599bb19 100644
--- a/drivers/staging/solo6x10/enc.c
+++ b/drivers/staging/media/solo6x10/enc.c
diff --git a/drivers/staging/solo6x10/g723.c b/drivers/staging/media/solo6x10/g723.c
index 59274bfca95b..2cd0de28a633 100644
--- a/drivers/staging/solo6x10/g723.c
+++ b/drivers/staging/media/solo6x10/g723.c
@@ -23,6 +23,7 @@
23#include <linux/kthread.h> 23#include <linux/kthread.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/freezer.h> 25#include <linux/freezer.h>
26#include <linux/export.h>
26#include <sound/core.h> 27#include <sound/core.h>
27#include <sound/initval.h> 28#include <sound/initval.h>
28#include <sound/pcm.h> 29#include <sound/pcm.h>
diff --git a/drivers/staging/solo6x10/gpio.c b/drivers/staging/media/solo6x10/gpio.c
index 0925e6f33a99..0925e6f33a99 100644
--- a/drivers/staging/solo6x10/gpio.c
+++ b/drivers/staging/media/solo6x10/gpio.c
diff --git a/drivers/staging/solo6x10/i2c.c b/drivers/staging/media/solo6x10/i2c.c
index ef95a500b4da..ef95a500b4da 100644
--- a/drivers/staging/solo6x10/i2c.c
+++ b/drivers/staging/media/solo6x10/i2c.c
diff --git a/drivers/staging/solo6x10/jpeg.h b/drivers/staging/media/solo6x10/jpeg.h
index 50defec318cc..50defec318cc 100644
--- a/drivers/staging/solo6x10/jpeg.h
+++ b/drivers/staging/media/solo6x10/jpeg.h
diff --git a/drivers/staging/solo6x10/offsets.h b/drivers/staging/media/solo6x10/offsets.h
index 3d7e569f1cf8..3d7e569f1cf8 100644
--- a/drivers/staging/solo6x10/offsets.h
+++ b/drivers/staging/media/solo6x10/offsets.h
diff --git a/drivers/staging/solo6x10/osd-font.h b/drivers/staging/media/solo6x10/osd-font.h
index 591e0e82e0e8..591e0e82e0e8 100644
--- a/drivers/staging/solo6x10/osd-font.h
+++ b/drivers/staging/media/solo6x10/osd-font.h
diff --git a/drivers/staging/solo6x10/p2m.c b/drivers/staging/media/solo6x10/p2m.c
index 56210f0fc5ec..56210f0fc5ec 100644
--- a/drivers/staging/solo6x10/p2m.c
+++ b/drivers/staging/media/solo6x10/p2m.c
diff --git a/drivers/staging/solo6x10/registers.h b/drivers/staging/media/solo6x10/registers.h
index aca544472c93..aca544472c93 100644
--- a/drivers/staging/solo6x10/registers.h
+++ b/drivers/staging/media/solo6x10/registers.h
diff --git a/drivers/staging/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
index abee7213202f..abee7213202f 100644
--- a/drivers/staging/solo6x10/solo6x10.h
+++ b/drivers/staging/media/solo6x10/solo6x10.h
diff --git a/drivers/staging/solo6x10/tw28.c b/drivers/staging/media/solo6x10/tw28.c
index db56b42c56c6..db56b42c56c6 100644
--- a/drivers/staging/solo6x10/tw28.c
+++ b/drivers/staging/media/solo6x10/tw28.c
diff --git a/drivers/staging/solo6x10/tw28.h b/drivers/staging/media/solo6x10/tw28.h
index a44a03afbd30..a44a03afbd30 100644
--- a/drivers/staging/solo6x10/tw28.h
+++ b/drivers/staging/media/solo6x10/tw28.h
diff --git a/drivers/staging/solo6x10/v4l2-enc.c b/drivers/staging/media/solo6x10/v4l2-enc.c
index bee7280bbed9..bee7280bbed9 100644
--- a/drivers/staging/solo6x10/v4l2-enc.c
+++ b/drivers/staging/media/solo6x10/v4l2-enc.c
diff --git a/drivers/staging/solo6x10/v4l2.c b/drivers/staging/media/solo6x10/v4l2.c
index 571c3a348d30..571c3a348d30 100644
--- a/drivers/staging/solo6x10/v4l2.c
+++ b/drivers/staging/media/solo6x10/v4l2.c
diff --git a/drivers/staging/pohmelfs/inode.c b/drivers/staging/pohmelfs/inode.c
index f3c6060c96b8..7a1955583b7d 100644
--- a/drivers/staging/pohmelfs/inode.c
+++ b/drivers/staging/pohmelfs/inode.c
@@ -1197,7 +1197,7 @@ const struct inode_operations pohmelfs_file_inode_operations = {
1197void pohmelfs_fill_inode(struct inode *inode, struct netfs_inode_info *info) 1197void pohmelfs_fill_inode(struct inode *inode, struct netfs_inode_info *info)
1198{ 1198{
1199 inode->i_mode = info->mode; 1199 inode->i_mode = info->mode;
1200 inode->i_nlink = info->nlink; 1200 set_nlink(inode, info->nlink);
1201 inode->i_uid = info->uid; 1201 inode->i_uid = info->uid;
1202 inode->i_gid = info->gid; 1202 inode->i_gid = info->gid;
1203 inode->i_blocks = info->blocks; 1203 inode->i_blocks = info->blocks;
diff --git a/drivers/staging/rts5139/rts51x_scsi.c b/drivers/staging/rts5139/rts51x_scsi.c
index 3b32f9e6e4f0..87c9cdc8bd29 100644
--- a/drivers/staging/rts5139/rts51x_scsi.c
+++ b/drivers/staging/rts5139/rts51x_scsi.c
@@ -28,6 +28,7 @@
28#include <linux/sched.h> 28#include <linux/sched.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/vmalloc.h> 30#include <linux/vmalloc.h>
31#include <linux/export.h>
31 32
32#include <scsi/scsi.h> 33#include <scsi/scsi.h>
33#include <scsi/scsi_eh.h> 34#include <scsi/scsi_eh.h>
diff --git a/drivers/staging/usbip/usbip_common.c b/drivers/staging/usbip/usbip_common.c
index f4b53d103c54..3b7a847f4657 100644
--- a/drivers/staging/usbip/usbip_common.c
+++ b/drivers/staging/usbip/usbip_common.c
@@ -22,6 +22,7 @@
22#include <linux/fs.h> 22#include <linux/fs.h>
23#include <linux/kernel.h> 23#include <linux/kernel.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/module.h>
25#include <net/sock.h> 26#include <net/sock.h>
26 27
27#include "usbip_common.h" 28#include "usbip_common.h"
diff --git a/drivers/staging/usbip/usbip_event.c b/drivers/staging/usbip/usbip_event.c
index ecd1862539cd..d332a34ddb6d 100644
--- a/drivers/staging/usbip/usbip_event.c
+++ b/drivers/staging/usbip/usbip_event.c
@@ -18,6 +18,7 @@
18 */ 18 */
19 19
20#include <linux/kthread.h> 20#include <linux/kthread.h>
21#include <linux/export.h>
21 22
22#include "usbip_common.h" 23#include "usbip_common.h"
23 24
diff --git a/drivers/staging/winbond/wbusb.c b/drivers/staging/winbond/wbusb.c
index a2e8bd452ed9..f958eb4f0d81 100644
--- a/drivers/staging/winbond/wbusb.c
+++ b/drivers/staging/winbond/wbusb.c
@@ -11,6 +11,7 @@
11 */ 11 */
12#include <net/mac80211.h> 12#include <net/mac80211.h>
13#include <linux/usb.h> 13#include <linux/usb.h>
14#include <linux/module.h>
14 15
15#include "core.h" 16#include "core.h"
16#include "mds_f.h" 17#include "mds_f.h"
diff --git a/drivers/staging/wlags49_h2/wl_cs.c b/drivers/staging/wlags49_h2/wl_cs.c
index 321580267fed..2faee2dd4bb1 100644
--- a/drivers/staging/wlags49_h2/wl_cs.c
+++ b/drivers/staging/wlags49_h2/wl_cs.c
@@ -82,6 +82,7 @@
82#include <linux/skbuff.h> 82#include <linux/skbuff.h>
83#include <linux/if_arp.h> 83#include <linux/if_arp.h>
84#include <linux/ioport.h> 84#include <linux/ioport.h>
85#include <linux/module.h>
85 86
86#include <pcmcia/cistpl.h> 87#include <pcmcia/cistpl.h>
87#include <pcmcia/cisreg.h> 88#include <pcmcia/cisreg.h>
diff --git a/drivers/staging/zram/zram_drv.c b/drivers/staging/zram/zram_drv.c
index b9926ee0052c..09de99fbb7e0 100644
--- a/drivers/staging/zram/zram_drv.c
+++ b/drivers/staging/zram/zram_drv.c
@@ -556,7 +556,7 @@ static inline int valid_io_request(struct zram *zram, struct bio *bio)
556/* 556/*
557 * Handler function for all zram I/O requests. 557 * Handler function for all zram I/O requests.
558 */ 558 */
559static int zram_make_request(struct request_queue *queue, struct bio *bio) 559static void zram_make_request(struct request_queue *queue, struct bio *bio)
560{ 560{
561 struct zram *zram = queue->queuedata; 561 struct zram *zram = queue->queuedata;
562 562
@@ -575,13 +575,12 @@ static int zram_make_request(struct request_queue *queue, struct bio *bio)
575 __zram_make_request(zram, bio, bio_data_dir(bio)); 575 __zram_make_request(zram, bio, bio_data_dir(bio));
576 up_read(&zram->init_lock); 576 up_read(&zram->init_lock);
577 577
578 return 0; 578 return;
579 579
580error_unlock: 580error_unlock:
581 up_read(&zram->init_lock); 581 up_read(&zram->init_lock);
582error: 582error:
583 bio_io_error(bio); 583 bio_io_error(bio);
584 return 0;
585} 584}
586 585
587void __zram_reset_device(struct zram *zram) 586void __zram_reset_device(struct zram *zram)
diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
index 4d01768fcd90..0fd96c10271d 100644
--- a/drivers/target/iscsi/iscsi_target.c
+++ b/drivers/target/iscsi/iscsi_target.c
@@ -22,6 +22,7 @@
22#include <linux/kthread.h> 22#include <linux/kthread.h>
23#include <linux/crypto.h> 23#include <linux/crypto.h>
24#include <linux/completion.h> 24#include <linux/completion.h>
25#include <linux/module.h>
25#include <asm/unaligned.h> 26#include <asm/unaligned.h>
26#include <scsi/scsi_device.h> 27#include <scsi/scsi_device.h>
27#include <scsi/iscsi_proto.h> 28#include <scsi/iscsi_proto.h>
@@ -1079,7 +1080,9 @@ attach_cmd:
1079 */ 1080 */
1080 if (!cmd->immediate_data) { 1081 if (!cmd->immediate_data) {
1081 cmdsn_ret = iscsit_sequence_cmd(conn, cmd, hdr->cmdsn); 1082 cmdsn_ret = iscsit_sequence_cmd(conn, cmd, hdr->cmdsn);
1082 if (cmdsn_ret == CMDSN_ERROR_CANNOT_RECOVER) 1083 if (cmdsn_ret == CMDSN_LOWER_THAN_EXP)
1084 return 0;
1085 else if (cmdsn_ret == CMDSN_ERROR_CANNOT_RECOVER)
1083 return iscsit_add_reject_from_cmd( 1086 return iscsit_add_reject_from_cmd(
1084 ISCSI_REASON_PROTOCOL_ERROR, 1087 ISCSI_REASON_PROTOCOL_ERROR,
1085 1, 0, buf, cmd); 1088 1, 0, buf, cmd);
@@ -1819,17 +1822,16 @@ attach:
1819 int cmdsn_ret = iscsit_sequence_cmd(conn, cmd, hdr->cmdsn); 1822 int cmdsn_ret = iscsit_sequence_cmd(conn, cmd, hdr->cmdsn);
1820 if (cmdsn_ret == CMDSN_HIGHER_THAN_EXP) 1823 if (cmdsn_ret == CMDSN_HIGHER_THAN_EXP)
1821 out_of_order_cmdsn = 1; 1824 out_of_order_cmdsn = 1;
1822 else if (cmdsn_ret == CMDSN_LOWER_THAN_EXP) { 1825 else if (cmdsn_ret == CMDSN_LOWER_THAN_EXP)
1823 return 0; 1826 return 0;
1824 } else { /* (cmdsn_ret == CMDSN_ERROR_CANNOT_RECOVER) */ 1827 else if (cmdsn_ret == CMDSN_ERROR_CANNOT_RECOVER)
1825 return iscsit_add_reject_from_cmd( 1828 return iscsit_add_reject_from_cmd(
1826 ISCSI_REASON_PROTOCOL_ERROR, 1829 ISCSI_REASON_PROTOCOL_ERROR,
1827 1, 0, buf, cmd); 1830 1, 0, buf, cmd);
1828 }
1829 } 1831 }
1830 iscsit_ack_from_expstatsn(conn, hdr->exp_statsn); 1832 iscsit_ack_from_expstatsn(conn, hdr->exp_statsn);
1831 1833
1832 if (out_of_order_cmdsn) 1834 if (out_of_order_cmdsn || !(hdr->opcode & ISCSI_OP_IMMEDIATE))
1833 return 0; 1835 return 0;
1834 /* 1836 /*
1835 * Found the referenced task, send to transport for processing. 1837 * Found the referenced task, send to transport for processing.
diff --git a/drivers/target/iscsi/iscsi_target_configfs.c b/drivers/target/iscsi/iscsi_target_configfs.c
index f1643dbf6a92..db327845e46b 100644
--- a/drivers/target/iscsi/iscsi_target_configfs.c
+++ b/drivers/target/iscsi/iscsi_target_configfs.c
@@ -20,6 +20,7 @@
20 ****************************************************************************/ 20 ****************************************************************************/
21 21
22#include <linux/configfs.h> 22#include <linux/configfs.h>
23#include <linux/export.h>
23#include <target/target_core_base.h> 24#include <target/target_core_base.h>
24#include <target/target_core_transport.h> 25#include <target/target_core_transport.h>
25#include <target/target_core_fabric_ops.h> 26#include <target/target_core_fabric_ops.h>
diff --git a/drivers/target/iscsi/iscsi_target_stat.c b/drivers/target/iscsi/iscsi_target_stat.c
index bbdbe9301b27..f1db83077e0a 100644
--- a/drivers/target/iscsi/iscsi_target_stat.c
+++ b/drivers/target/iscsi/iscsi_target_stat.c
@@ -20,6 +20,7 @@
20 ******************************************************************************/ 20 ******************************************************************************/
21 21
22#include <linux/configfs.h> 22#include <linux/configfs.h>
23#include <linux/export.h>
23#include <scsi/iscsi_proto.h> 24#include <scsi/iscsi_proto.h>
24#include <target/target_core_base.h> 25#include <target/target_core_base.h>
25#include <target/target_core_transport.h> 26#include <target/target_core_transport.h>
diff --git a/drivers/target/loopback/tcm_loop.c b/drivers/target/loopback/tcm_loop.c
index b15d8cbf630b..3df1c9b8ae6b 100644
--- a/drivers/target/loopback/tcm_loop.c
+++ b/drivers/target/loopback/tcm_loop.c
@@ -174,6 +174,24 @@ static int tcm_loop_new_cmd_map(struct se_cmd *se_cmd)
174 sgl_bidi = sdb->table.sgl; 174 sgl_bidi = sdb->table.sgl;
175 sgl_bidi_count = sdb->table.nents; 175 sgl_bidi_count = sdb->table.nents;
176 } 176 }
177 /*
178 * Because some userspace code via scsi-generic do not memset their
179 * associated read buffers, go ahead and do that here for type
180 * SCF_SCSI_CONTROL_SG_IO_CDB. Also note that this is currently
181 * guaranteed to be a single SGL for SCF_SCSI_CONTROL_SG_IO_CDB
182 * by target core in transport_generic_allocate_tasks() ->
183 * transport_generic_cmd_sequencer().
184 */
185 if (se_cmd->se_cmd_flags & SCF_SCSI_CONTROL_SG_IO_CDB &&
186 se_cmd->data_direction == DMA_FROM_DEVICE) {
187 struct scatterlist *sg = scsi_sglist(sc);
188 unsigned char *buf = kmap(sg_page(sg)) + sg->offset;
189
190 if (buf != NULL) {
191 memset(buf, 0, sg->length);
192 kunmap(sg_page(sg));
193 }
194 }
177 195
178 /* Tell the core about our preallocated memory */ 196 /* Tell the core about our preallocated memory */
179 ret = transport_generic_map_mem_to_cmd(se_cmd, scsi_sglist(sc), 197 ret = transport_generic_map_mem_to_cmd(se_cmd, scsi_sglist(sc),
@@ -187,7 +205,7 @@ static int tcm_loop_new_cmd_map(struct se_cmd *se_cmd)
187/* 205/*
188 * Called from struct target_core_fabric_ops->check_stop_free() 206 * Called from struct target_core_fabric_ops->check_stop_free()
189 */ 207 */
190static void tcm_loop_check_stop_free(struct se_cmd *se_cmd) 208static int tcm_loop_check_stop_free(struct se_cmd *se_cmd)
191{ 209{
192 /* 210 /*
193 * Do not release struct se_cmd's containing a valid TMR 211 * Do not release struct se_cmd's containing a valid TMR
@@ -195,12 +213,13 @@ static void tcm_loop_check_stop_free(struct se_cmd *se_cmd)
195 * with transport_generic_free_cmd(). 213 * with transport_generic_free_cmd().
196 */ 214 */
197 if (se_cmd->se_tmr_req) 215 if (se_cmd->se_tmr_req)
198 return; 216 return 0;
199 /* 217 /*
200 * Release the struct se_cmd, which will make a callback to release 218 * Release the struct se_cmd, which will make a callback to release
201 * struct tcm_loop_cmd * in tcm_loop_deallocate_core_cmd() 219 * struct tcm_loop_cmd * in tcm_loop_deallocate_core_cmd()
202 */ 220 */
203 transport_generic_free_cmd(se_cmd, 0); 221 transport_generic_free_cmd(se_cmd, 0);
222 return 1;
204} 223}
205 224
206static void tcm_loop_release_cmd(struct se_cmd *se_cmd) 225static void tcm_loop_release_cmd(struct se_cmd *se_cmd)
diff --git a/drivers/target/target_core_alua.c b/drivers/target/target_core_alua.c
index 8f4447749c71..88f2ad43ec8b 100644
--- a/drivers/target/target_core_alua.c
+++ b/drivers/target/target_core_alua.c
@@ -27,6 +27,7 @@
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/spinlock.h> 28#include <linux/spinlock.h>
29#include <linux/configfs.h> 29#include <linux/configfs.h>
30#include <linux/export.h>
30#include <scsi/scsi.h> 31#include <scsi/scsi.h>
31#include <scsi/scsi_cmnd.h> 32#include <scsi/scsi_cmnd.h>
32 33
@@ -58,8 +59,9 @@ struct t10_alua_lu_gp *default_lu_gp;
58 * 59 *
59 * See spc4r17 section 6.27 60 * See spc4r17 section 6.27
60 */ 61 */
61int core_emulate_report_target_port_groups(struct se_cmd *cmd) 62int target_emulate_report_target_port_groups(struct se_task *task)
62{ 63{
64 struct se_cmd *cmd = task->task_se_cmd;
63 struct se_subsystem_dev *su_dev = cmd->se_dev->se_sub_dev; 65 struct se_subsystem_dev *su_dev = cmd->se_dev->se_sub_dev;
64 struct se_port *port; 66 struct se_port *port;
65 struct t10_alua_tg_pt_gp *tg_pt_gp; 67 struct t10_alua_tg_pt_gp *tg_pt_gp;
@@ -164,6 +166,8 @@ int core_emulate_report_target_port_groups(struct se_cmd *cmd)
164 166
165 transport_kunmap_first_data_page(cmd); 167 transport_kunmap_first_data_page(cmd);
166 168
169 task->task_scsi_status = GOOD;
170 transport_complete_task(task, 1);
167 return 0; 171 return 0;
168} 172}
169 173
@@ -172,8 +176,9 @@ int core_emulate_report_target_port_groups(struct se_cmd *cmd)
172 * 176 *
173 * See spc4r17 section 6.35 177 * See spc4r17 section 6.35
174 */ 178 */
175int core_emulate_set_target_port_groups(struct se_cmd *cmd) 179int target_emulate_set_target_port_groups(struct se_task *task)
176{ 180{
181 struct se_cmd *cmd = task->task_se_cmd;
177 struct se_device *dev = cmd->se_dev; 182 struct se_device *dev = cmd->se_dev;
178 struct se_subsystem_dev *su_dev = dev->se_sub_dev; 183 struct se_subsystem_dev *su_dev = dev->se_sub_dev;
179 struct se_port *port, *l_port = cmd->se_lun->lun_sep; 184 struct se_port *port, *l_port = cmd->se_lun->lun_sep;
@@ -341,7 +346,8 @@ int core_emulate_set_target_port_groups(struct se_cmd *cmd)
341 346
342out: 347out:
343 transport_kunmap_first_data_page(cmd); 348 transport_kunmap_first_data_page(cmd);
344 349 task->task_scsi_status = GOOD;
350 transport_complete_task(task, 1);
345 return 0; 351 return 0;
346} 352}
347 353
diff --git a/drivers/target/target_core_alua.h b/drivers/target/target_core_alua.h
index c86f97a081ed..c5b4ecd3e745 100644
--- a/drivers/target/target_core_alua.h
+++ b/drivers/target/target_core_alua.h
@@ -66,8 +66,8 @@ extern struct kmem_cache *t10_alua_lu_gp_mem_cache;
66extern struct kmem_cache *t10_alua_tg_pt_gp_cache; 66extern struct kmem_cache *t10_alua_tg_pt_gp_cache;
67extern struct kmem_cache *t10_alua_tg_pt_gp_mem_cache; 67extern struct kmem_cache *t10_alua_tg_pt_gp_mem_cache;
68 68
69extern int core_emulate_report_target_port_groups(struct se_cmd *); 69extern int target_emulate_report_target_port_groups(struct se_task *);
70extern int core_emulate_set_target_port_groups(struct se_cmd *); 70extern int target_emulate_set_target_port_groups(struct se_task *);
71extern int core_alua_check_nonop_delay(struct se_cmd *); 71extern int core_alua_check_nonop_delay(struct se_cmd *);
72extern int core_alua_do_port_transition(struct t10_alua_tg_pt_gp *, 72extern int core_alua_do_port_transition(struct t10_alua_tg_pt_gp *,
73 struct se_device *, struct se_port *, 73 struct se_device *, struct se_port *,
diff --git a/drivers/target/target_core_cdb.c b/drivers/target/target_core_cdb.c
index 38535eb13929..683ba02b8247 100644
--- a/drivers/target/target_core_cdb.c
+++ b/drivers/target/target_core_cdb.c
@@ -32,6 +32,7 @@
32#include <target/target_core_transport.h> 32#include <target/target_core_transport.h>
33#include <target/target_core_fabric_ops.h> 33#include <target/target_core_fabric_ops.h>
34#include "target_core_ua.h" 34#include "target_core_ua.h"
35#include "target_core_cdb.h"
35 36
36static void 37static void
37target_fill_alua_data(struct se_port *port, unsigned char *buf) 38target_fill_alua_data(struct se_port *port, unsigned char *buf)
@@ -679,16 +680,18 @@ target_emulate_evpd_00(struct se_cmd *cmd, unsigned char *buf)
679 return 0; 680 return 0;
680} 681}
681 682
682static int 683int target_emulate_inquiry(struct se_task *task)
683target_emulate_inquiry(struct se_cmd *cmd)
684{ 684{
685 struct se_cmd *cmd = task->task_se_cmd;
685 struct se_device *dev = cmd->se_dev; 686 struct se_device *dev = cmd->se_dev;
686 unsigned char *buf; 687 unsigned char *buf;
687 unsigned char *cdb = cmd->t_task_cdb; 688 unsigned char *cdb = cmd->t_task_cdb;
688 int p, ret; 689 int p, ret;
689 690
690 if (!(cdb[1] & 0x1)) 691 if (!(cdb[1] & 0x1)) {
691 return target_emulate_inquiry_std(cmd); 692 ret = target_emulate_inquiry_std(cmd);
693 goto out;
694 }
692 695
693 /* 696 /*
694 * Make sure we at least have 4 bytes of INQUIRY response 697 * Make sure we at least have 4 bytes of INQUIRY response
@@ -707,22 +710,30 @@ target_emulate_inquiry(struct se_cmd *cmd)
707 710
708 buf[0] = dev->transport->get_device_type(dev); 711 buf[0] = dev->transport->get_device_type(dev);
709 712
710 for (p = 0; p < ARRAY_SIZE(evpd_handlers); ++p) 713 for (p = 0; p < ARRAY_SIZE(evpd_handlers); ++p) {
711 if (cdb[2] == evpd_handlers[p].page) { 714 if (cdb[2] == evpd_handlers[p].page) {
712 buf[1] = cdb[2]; 715 buf[1] = cdb[2];
713 ret = evpd_handlers[p].emulate(cmd, buf); 716 ret = evpd_handlers[p].emulate(cmd, buf);
714 transport_kunmap_first_data_page(cmd); 717 goto out_unmap;
715 return ret;
716 } 718 }
719 }
717 720
718 transport_kunmap_first_data_page(cmd);
719 pr_err("Unknown VPD Code: 0x%02x\n", cdb[2]); 721 pr_err("Unknown VPD Code: 0x%02x\n", cdb[2]);
720 return -EINVAL; 722 ret = -EINVAL;
723
724out_unmap:
725 transport_kunmap_first_data_page(cmd);
726out:
727 if (!ret) {
728 task->task_scsi_status = GOOD;
729 transport_complete_task(task, 1);
730 }
731 return ret;
721} 732}
722 733
723static int 734int target_emulate_readcapacity(struct se_task *task)
724target_emulate_readcapacity(struct se_cmd *cmd)
725{ 735{
736 struct se_cmd *cmd = task->task_se_cmd;
726 struct se_device *dev = cmd->se_dev; 737 struct se_device *dev = cmd->se_dev;
727 unsigned char *buf; 738 unsigned char *buf;
728 unsigned long long blocks_long = dev->transport->get_blocks(dev); 739 unsigned long long blocks_long = dev->transport->get_blocks(dev);
@@ -751,12 +762,14 @@ target_emulate_readcapacity(struct se_cmd *cmd)
751 762
752 transport_kunmap_first_data_page(cmd); 763 transport_kunmap_first_data_page(cmd);
753 764
765 task->task_scsi_status = GOOD;
766 transport_complete_task(task, 1);
754 return 0; 767 return 0;
755} 768}
756 769
757static int 770int target_emulate_readcapacity_16(struct se_task *task)
758target_emulate_readcapacity_16(struct se_cmd *cmd)
759{ 771{
772 struct se_cmd *cmd = task->task_se_cmd;
760 struct se_device *dev = cmd->se_dev; 773 struct se_device *dev = cmd->se_dev;
761 unsigned char *buf; 774 unsigned char *buf;
762 unsigned long long blocks = dev->transport->get_blocks(dev); 775 unsigned long long blocks = dev->transport->get_blocks(dev);
@@ -784,6 +797,8 @@ target_emulate_readcapacity_16(struct se_cmd *cmd)
784 797
785 transport_kunmap_first_data_page(cmd); 798 transport_kunmap_first_data_page(cmd);
786 799
800 task->task_scsi_status = GOOD;
801 transport_complete_task(task, 1);
787 return 0; 802 return 0;
788} 803}
789 804
@@ -922,14 +937,15 @@ target_modesense_dpofua(unsigned char *buf, int type)
922 } 937 }
923} 938}
924 939
925static int 940int target_emulate_modesense(struct se_task *task)
926target_emulate_modesense(struct se_cmd *cmd, int ten)
927{ 941{
942 struct se_cmd *cmd = task->task_se_cmd;
928 struct se_device *dev = cmd->se_dev; 943 struct se_device *dev = cmd->se_dev;
929 char *cdb = cmd->t_task_cdb; 944 char *cdb = cmd->t_task_cdb;
930 unsigned char *rbuf; 945 unsigned char *rbuf;
931 int type = dev->transport->get_device_type(dev); 946 int type = dev->transport->get_device_type(dev);
932 int offset = (ten) ? 8 : 4; 947 int ten = (cmd->t_task_cdb[0] == MODE_SENSE_10);
948 int offset = ten ? 8 : 4;
933 int length = 0; 949 int length = 0;
934 unsigned char buf[SE_MODE_PAGE_BUF]; 950 unsigned char buf[SE_MODE_PAGE_BUF];
935 951
@@ -995,12 +1011,14 @@ target_emulate_modesense(struct se_cmd *cmd, int ten)
995 memcpy(rbuf, buf, offset); 1011 memcpy(rbuf, buf, offset);
996 transport_kunmap_first_data_page(cmd); 1012 transport_kunmap_first_data_page(cmd);
997 1013
1014 task->task_scsi_status = GOOD;
1015 transport_complete_task(task, 1);
998 return 0; 1016 return 0;
999} 1017}
1000 1018
1001static int 1019int target_emulate_request_sense(struct se_task *task)
1002target_emulate_request_sense(struct se_cmd *cmd)
1003{ 1020{
1021 struct se_cmd *cmd = task->task_se_cmd;
1004 unsigned char *cdb = cmd->t_task_cdb; 1022 unsigned char *cdb = cmd->t_task_cdb;
1005 unsigned char *buf; 1023 unsigned char *buf;
1006 u8 ua_asc = 0, ua_ascq = 0; 1024 u8 ua_asc = 0, ua_ascq = 0;
@@ -1059,7 +1077,8 @@ target_emulate_request_sense(struct se_cmd *cmd)
1059 1077
1060end: 1078end:
1061 transport_kunmap_first_data_page(cmd); 1079 transport_kunmap_first_data_page(cmd);
1062 1080 task->task_scsi_status = GOOD;
1081 transport_complete_task(task, 1);
1063 return 0; 1082 return 0;
1064} 1083}
1065 1084
@@ -1067,8 +1086,7 @@ end:
1067 * Used for TCM/IBLOCK and TCM/FILEIO for block/blk-lib.c level discard support. 1086 * Used for TCM/IBLOCK and TCM/FILEIO for block/blk-lib.c level discard support.
1068 * Note this is not used for TCM/pSCSI passthrough 1087 * Note this is not used for TCM/pSCSI passthrough
1069 */ 1088 */
1070static int 1089int target_emulate_unmap(struct se_task *task)
1071target_emulate_unmap(struct se_task *task)
1072{ 1090{
1073 struct se_cmd *cmd = task->task_se_cmd; 1091 struct se_cmd *cmd = task->task_se_cmd;
1074 struct se_device *dev = cmd->se_dev; 1092 struct se_device *dev = cmd->se_dev;
@@ -1079,6 +1097,12 @@ target_emulate_unmap(struct se_task *task)
1079 int ret = 0, offset; 1097 int ret = 0, offset;
1080 unsigned short dl, bd_dl; 1098 unsigned short dl, bd_dl;
1081 1099
1100 if (!dev->transport->do_discard) {
1101 pr_err("UNMAP emulation not supported for: %s\n",
1102 dev->transport->name);
1103 return PYX_TRANSPORT_UNKNOWN_SAM_OPCODE;
1104 }
1105
1082 /* First UNMAP block descriptor starts at 8 byte offset */ 1106 /* First UNMAP block descriptor starts at 8 byte offset */
1083 offset = 8; 1107 offset = 8;
1084 size -= 8; 1108 size -= 8;
@@ -1110,7 +1134,10 @@ target_emulate_unmap(struct se_task *task)
1110 1134
1111err: 1135err:
1112 transport_kunmap_first_data_page(cmd); 1136 transport_kunmap_first_data_page(cmd);
1113 1137 if (!ret) {
1138 task->task_scsi_status = GOOD;
1139 transport_complete_task(task, 1);
1140 }
1114 return ret; 1141 return ret;
1115} 1142}
1116 1143
@@ -1118,14 +1145,28 @@ err:
1118 * Used for TCM/IBLOCK and TCM/FILEIO for block/blk-lib.c level discard support. 1145 * Used for TCM/IBLOCK and TCM/FILEIO for block/blk-lib.c level discard support.
1119 * Note this is not used for TCM/pSCSI passthrough 1146 * Note this is not used for TCM/pSCSI passthrough
1120 */ 1147 */
1121static int 1148int target_emulate_write_same(struct se_task *task)
1122target_emulate_write_same(struct se_task *task, u32 num_blocks)
1123{ 1149{
1124 struct se_cmd *cmd = task->task_se_cmd; 1150 struct se_cmd *cmd = task->task_se_cmd;
1125 struct se_device *dev = cmd->se_dev; 1151 struct se_device *dev = cmd->se_dev;
1126 sector_t range; 1152 sector_t range;
1127 sector_t lba = cmd->t_task_lba; 1153 sector_t lba = cmd->t_task_lba;
1154 u32 num_blocks;
1128 int ret; 1155 int ret;
1156
1157 if (!dev->transport->do_discard) {
1158 pr_err("WRITE_SAME emulation not supported"
1159 " for: %s\n", dev->transport->name);
1160 return PYX_TRANSPORT_UNKNOWN_SAM_OPCODE;
1161 }
1162
1163 if (cmd->t_task_cdb[0] == WRITE_SAME)
1164 num_blocks = get_unaligned_be16(&cmd->t_task_cdb[7]);
1165 else if (cmd->t_task_cdb[0] == WRITE_SAME_16)
1166 num_blocks = get_unaligned_be32(&cmd->t_task_cdb[10]);
1167 else /* WRITE_SAME_32 via VARIABLE_LENGTH_CMD */
1168 num_blocks = get_unaligned_be32(&cmd->t_task_cdb[28]);
1169
1129 /* 1170 /*
1130 * Use the explicit range when non zero is supplied, otherwise calculate 1171 * Use the explicit range when non zero is supplied, otherwise calculate
1131 * the remaining range based on ->get_blocks() - starting LBA. 1172 * the remaining range based on ->get_blocks() - starting LBA.
@@ -1144,127 +1185,30 @@ target_emulate_write_same(struct se_task *task, u32 num_blocks)
1144 return ret; 1185 return ret;
1145 } 1186 }
1146 1187
1188 task->task_scsi_status = GOOD;
1189 transport_complete_task(task, 1);
1147 return 0; 1190 return 0;
1148} 1191}
1149 1192
1150int 1193int target_emulate_synchronize_cache(struct se_task *task)
1151transport_emulate_control_cdb(struct se_task *task)
1152{ 1194{
1153 struct se_cmd *cmd = task->task_se_cmd; 1195 struct se_device *dev = task->task_se_cmd->se_dev;
1154 struct se_device *dev = cmd->se_dev;
1155 unsigned short service_action;
1156 int ret = 0;
1157 1196
1158 switch (cmd->t_task_cdb[0]) { 1197 if (!dev->transport->do_sync_cache) {
1159 case INQUIRY: 1198 pr_err("SYNCHRONIZE_CACHE emulation not supported"
1160 ret = target_emulate_inquiry(cmd); 1199 " for: %s\n", dev->transport->name);
1161 break;
1162 case READ_CAPACITY:
1163 ret = target_emulate_readcapacity(cmd);
1164 break;
1165 case MODE_SENSE:
1166 ret = target_emulate_modesense(cmd, 0);
1167 break;
1168 case MODE_SENSE_10:
1169 ret = target_emulate_modesense(cmd, 1);
1170 break;
1171 case SERVICE_ACTION_IN:
1172 switch (cmd->t_task_cdb[1] & 0x1f) {
1173 case SAI_READ_CAPACITY_16:
1174 ret = target_emulate_readcapacity_16(cmd);
1175 break;
1176 default:
1177 pr_err("Unsupported SA: 0x%02x\n",
1178 cmd->t_task_cdb[1] & 0x1f);
1179 return PYX_TRANSPORT_UNKNOWN_SAM_OPCODE;
1180 }
1181 break;
1182 case REQUEST_SENSE:
1183 ret = target_emulate_request_sense(cmd);
1184 break;
1185 case UNMAP:
1186 if (!dev->transport->do_discard) {
1187 pr_err("UNMAP emulation not supported for: %s\n",
1188 dev->transport->name);
1189 return PYX_TRANSPORT_UNKNOWN_SAM_OPCODE;
1190 }
1191 ret = target_emulate_unmap(task);
1192 break;
1193 case WRITE_SAME:
1194 if (!dev->transport->do_discard) {
1195 pr_err("WRITE_SAME emulation not supported"
1196 " for: %s\n", dev->transport->name);
1197 return PYX_TRANSPORT_UNKNOWN_SAM_OPCODE;
1198 }
1199 ret = target_emulate_write_same(task,
1200 get_unaligned_be16(&cmd->t_task_cdb[7]));
1201 break;
1202 case WRITE_SAME_16:
1203 if (!dev->transport->do_discard) {
1204 pr_err("WRITE_SAME_16 emulation not supported"
1205 " for: %s\n", dev->transport->name);
1206 return PYX_TRANSPORT_UNKNOWN_SAM_OPCODE;
1207 }
1208 ret = target_emulate_write_same(task,
1209 get_unaligned_be32(&cmd->t_task_cdb[10]));
1210 break;
1211 case VARIABLE_LENGTH_CMD:
1212 service_action =
1213 get_unaligned_be16(&cmd->t_task_cdb[8]);
1214 switch (service_action) {
1215 case WRITE_SAME_32:
1216 if (!dev->transport->do_discard) {
1217 pr_err("WRITE_SAME_32 SA emulation not"
1218 " supported for: %s\n",
1219 dev->transport->name);
1220 return PYX_TRANSPORT_UNKNOWN_SAM_OPCODE;
1221 }
1222 ret = target_emulate_write_same(task,
1223 get_unaligned_be32(&cmd->t_task_cdb[28]));
1224 break;
1225 default:
1226 pr_err("Unsupported VARIABLE_LENGTH_CMD SA:"
1227 " 0x%02x\n", service_action);
1228 break;
1229 }
1230 break;
1231 case SYNCHRONIZE_CACHE:
1232 case 0x91: /* SYNCHRONIZE_CACHE_16: */
1233 if (!dev->transport->do_sync_cache) {
1234 pr_err("SYNCHRONIZE_CACHE emulation not supported"
1235 " for: %s\n", dev->transport->name);
1236 return PYX_TRANSPORT_UNKNOWN_SAM_OPCODE;
1237 }
1238 dev->transport->do_sync_cache(task);
1239 break;
1240 case ALLOW_MEDIUM_REMOVAL:
1241 case ERASE:
1242 case REZERO_UNIT:
1243 case SEEK_10:
1244 case SPACE:
1245 case START_STOP:
1246 case TEST_UNIT_READY:
1247 case VERIFY:
1248 case WRITE_FILEMARKS:
1249 break;
1250 default:
1251 pr_err("Unsupported SCSI Opcode: 0x%02x for %s\n",
1252 cmd->t_task_cdb[0], dev->transport->name);
1253 return PYX_TRANSPORT_UNKNOWN_SAM_OPCODE; 1200 return PYX_TRANSPORT_UNKNOWN_SAM_OPCODE;
1254 } 1201 }
1255 1202
1256 if (ret < 0) 1203 dev->transport->do_sync_cache(task);
1257 return ret; 1204 return 0;
1258 /* 1205}
1259 * Handle the successful completion here unless a caller
1260 * has explictly requested an asychronous completion.
1261 */
1262 if (!(cmd->se_cmd_flags & SCF_EMULATE_CDB_ASYNC)) {
1263 task->task_scsi_status = GOOD;
1264 transport_complete_task(task, 1);
1265 }
1266 1206
1267 return PYX_TRANSPORT_SENT_TO_TRANSPORT; 1207int target_emulate_noop(struct se_task *task)
1208{
1209 task->task_scsi_status = GOOD;
1210 transport_complete_task(task, 1);
1211 return 0;
1268} 1212}
1269 1213
1270/* 1214/*
diff --git a/drivers/target/target_core_cdb.h b/drivers/target/target_core_cdb.h
new file mode 100644
index 000000000000..ad6b1e393001
--- /dev/null
+++ b/drivers/target/target_core_cdb.h
@@ -0,0 +1,14 @@
1#ifndef TARGET_CORE_CDB_H
2#define TARGET_CORE_CDB_H
3
4int target_emulate_inquiry(struct se_task *task);
5int target_emulate_readcapacity(struct se_task *task);
6int target_emulate_readcapacity_16(struct se_task *task);
7int target_emulate_modesense(struct se_task *task);
8int target_emulate_request_sense(struct se_task *task);
9int target_emulate_unmap(struct se_task *task);
10int target_emulate_write_same(struct se_task *task);
11int target_emulate_synchronize_cache(struct se_task *task);
12int target_emulate_noop(struct se_task *task);
13
14#endif /* TARGET_CORE_CDB_H */
diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
index f870c3bcfd82..ba5edec2c5f8 100644
--- a/drivers/target/target_core_device.c
+++ b/drivers/target/target_core_device.c
@@ -35,6 +35,7 @@
35#include <linux/spinlock.h> 35#include <linux/spinlock.h>
36#include <linux/kthread.h> 36#include <linux/kthread.h>
37#include <linux/in.h> 37#include <linux/in.h>
38#include <linux/export.h>
38#include <net/sock.h> 39#include <net/sock.h>
39#include <net/tcp.h> 40#include <net/tcp.h>
40#include <scsi/scsi.h> 41#include <scsi/scsi.h>
@@ -651,23 +652,15 @@ void core_dev_unexport(
651 lun->lun_se_dev = NULL; 652 lun->lun_se_dev = NULL;
652} 653}
653 654
654int transport_core_report_lun_response(struct se_cmd *se_cmd) 655int target_report_luns(struct se_task *se_task)
655{ 656{
657 struct se_cmd *se_cmd = se_task->task_se_cmd;
656 struct se_dev_entry *deve; 658 struct se_dev_entry *deve;
657 struct se_lun *se_lun; 659 struct se_lun *se_lun;
658 struct se_session *se_sess = se_cmd->se_sess; 660 struct se_session *se_sess = se_cmd->se_sess;
659 struct se_task *se_task;
660 unsigned char *buf; 661 unsigned char *buf;
661 u32 cdb_offset = 0, lun_count = 0, offset = 8, i; 662 u32 cdb_offset = 0, lun_count = 0, offset = 8, i;
662 663
663 list_for_each_entry(se_task, &se_cmd->t_task_list, t_list)
664 break;
665
666 if (!se_task) {
667 pr_err("Unable to locate struct se_task for struct se_cmd\n");
668 return PYX_TRANSPORT_LU_COMM_FAILURE;
669 }
670
671 buf = transport_kmap_first_data_page(se_cmd); 664 buf = transport_kmap_first_data_page(se_cmd);
672 665
673 /* 666 /*
@@ -713,6 +706,8 @@ done:
713 buf[2] = ((lun_count >> 8) & 0xff); 706 buf[2] = ((lun_count >> 8) & 0xff);
714 buf[3] = (lun_count & 0xff); 707 buf[3] = (lun_count & 0xff);
715 708
709 se_task->task_scsi_status = GOOD;
710 transport_complete_task(se_task, 1);
716 return PYX_TRANSPORT_SENT_TO_TRANSPORT; 711 return PYX_TRANSPORT_SENT_TO_TRANSPORT;
717} 712}
718 713
diff --git a/drivers/target/target_core_fabric_lib.c b/drivers/target/target_core_fabric_lib.c
index 39f021b855ef..ec4249be617e 100644
--- a/drivers/target/target_core_fabric_lib.c
+++ b/drivers/target/target_core_fabric_lib.c
@@ -29,6 +29,7 @@
29#include <linux/string.h> 29#include <linux/string.h>
30#include <linux/ctype.h> 30#include <linux/ctype.h>
31#include <linux/spinlock.h> 31#include <linux/spinlock.h>
32#include <linux/export.h>
32#include <scsi/scsi.h> 33#include <scsi/scsi.h>
33#include <scsi/scsi_cmnd.h> 34#include <scsi/scsi_cmnd.h>
34 35
diff --git a/drivers/target/target_core_file.c b/drivers/target/target_core_file.c
index 19a0be9c6570..67cd6fe05bfa 100644
--- a/drivers/target/target_core_file.c
+++ b/drivers/target/target_core_file.c
@@ -32,6 +32,7 @@
32#include <linux/blkdev.h> 32#include <linux/blkdev.h>
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include <linux/spinlock.h> 34#include <linux/spinlock.h>
35#include <linux/module.h>
35#include <scsi/scsi.h> 36#include <scsi/scsi.h>
36#include <scsi/scsi_host.h> 37#include <scsi/scsi_host.h>
37 38
diff --git a/drivers/target/target_core_hba.c b/drivers/target/target_core_hba.c
index 0639b975d6f5..c68019d6c406 100644
--- a/drivers/target/target_core_hba.c
+++ b/drivers/target/target_core_hba.c
@@ -32,6 +32,7 @@
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/spinlock.h> 33#include <linux/spinlock.h>
34#include <linux/in.h> 34#include <linux/in.h>
35#include <linux/module.h>
35#include <net/sock.h> 36#include <net/sock.h>
36#include <net/tcp.h> 37#include <net/tcp.h>
37 38
diff --git a/drivers/target/target_core_iblock.c b/drivers/target/target_core_iblock.c
index 41ad02b5fb87..7698efe29262 100644
--- a/drivers/target/target_core_iblock.c
+++ b/drivers/target/target_core_iblock.c
@@ -37,6 +37,7 @@
37#include <linux/bio.h> 37#include <linux/bio.h>
38#include <linux/genhd.h> 38#include <linux/genhd.h>
39#include <linux/file.h> 39#include <linux/file.h>
40#include <linux/module.h>
40#include <scsi/scsi.h> 41#include <scsi/scsi.h>
41#include <scsi/scsi_host.h> 42#include <scsi/scsi_host.h>
42 43
diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c
index 0c4f783f924c..5a4ebfc3a54f 100644
--- a/drivers/target/target_core_pr.c
+++ b/drivers/target/target_core_pr.c
@@ -116,114 +116,21 @@ static int core_scsi2_reservation_check(struct se_cmd *cmd, u32 *pr_reg_type)
116 return ret; 116 return ret;
117} 117}
118 118
119static int core_scsi2_reservation_release(struct se_cmd *cmd)
120{
121 struct se_device *dev = cmd->se_dev;
122 struct se_session *sess = cmd->se_sess;
123 struct se_portal_group *tpg = sess->se_tpg;
124
125 if (!sess || !tpg)
126 return 0;
127
128 spin_lock(&dev->dev_reservation_lock);
129 if (!dev->dev_reserved_node_acl || !sess) {
130 spin_unlock(&dev->dev_reservation_lock);
131 return 0;
132 }
133
134 if (dev->dev_reserved_node_acl != sess->se_node_acl) {
135 spin_unlock(&dev->dev_reservation_lock);
136 return 0;
137 }
138 dev->dev_reserved_node_acl = NULL;
139 dev->dev_flags &= ~DF_SPC2_RESERVATIONS;
140 if (dev->dev_flags & DF_SPC2_RESERVATIONS_WITH_ISID) {
141 dev->dev_res_bin_isid = 0;
142 dev->dev_flags &= ~DF_SPC2_RESERVATIONS_WITH_ISID;
143 }
144 pr_debug("SCSI-2 Released reservation for %s LUN: %u ->"
145 " MAPPED LUN: %u for %s\n", tpg->se_tpg_tfo->get_fabric_name(),
146 cmd->se_lun->unpacked_lun, cmd->se_deve->mapped_lun,
147 sess->se_node_acl->initiatorname);
148 spin_unlock(&dev->dev_reservation_lock);
149
150 return 0;
151}
152
153static int core_scsi2_reservation_reserve(struct se_cmd *cmd)
154{
155 struct se_device *dev = cmd->se_dev;
156 struct se_session *sess = cmd->se_sess;
157 struct se_portal_group *tpg = sess->se_tpg;
158
159 if ((cmd->t_task_cdb[1] & 0x01) &&
160 (cmd->t_task_cdb[1] & 0x02)) {
161 pr_err("LongIO and Obselete Bits set, returning"
162 " ILLEGAL_REQUEST\n");
163 return PYX_TRANSPORT_ILLEGAL_REQUEST;
164 }
165 /*
166 * This is currently the case for target_core_mod passthrough struct se_cmd
167 * ops
168 */
169 if (!sess || !tpg)
170 return 0;
171
172 spin_lock(&dev->dev_reservation_lock);
173 if (dev->dev_reserved_node_acl &&
174 (dev->dev_reserved_node_acl != sess->se_node_acl)) {
175 pr_err("SCSI-2 RESERVATION CONFLIFT for %s fabric\n",
176 tpg->se_tpg_tfo->get_fabric_name());
177 pr_err("Original reserver LUN: %u %s\n",
178 cmd->se_lun->unpacked_lun,
179 dev->dev_reserved_node_acl->initiatorname);
180 pr_err("Current attempt - LUN: %u -> MAPPED LUN: %u"
181 " from %s \n", cmd->se_lun->unpacked_lun,
182 cmd->se_deve->mapped_lun,
183 sess->se_node_acl->initiatorname);
184 spin_unlock(&dev->dev_reservation_lock);
185 return PYX_TRANSPORT_RESERVATION_CONFLICT;
186 }
187
188 dev->dev_reserved_node_acl = sess->se_node_acl;
189 dev->dev_flags |= DF_SPC2_RESERVATIONS;
190 if (sess->sess_bin_isid != 0) {
191 dev->dev_res_bin_isid = sess->sess_bin_isid;
192 dev->dev_flags |= DF_SPC2_RESERVATIONS_WITH_ISID;
193 }
194 pr_debug("SCSI-2 Reserved %s LUN: %u -> MAPPED LUN: %u"
195 " for %s\n", tpg->se_tpg_tfo->get_fabric_name(),
196 cmd->se_lun->unpacked_lun, cmd->se_deve->mapped_lun,
197 sess->se_node_acl->initiatorname);
198 spin_unlock(&dev->dev_reservation_lock);
199
200 return 0;
201}
202
203static struct t10_pr_registration *core_scsi3_locate_pr_reg(struct se_device *, 119static struct t10_pr_registration *core_scsi3_locate_pr_reg(struct se_device *,
204 struct se_node_acl *, struct se_session *); 120 struct se_node_acl *, struct se_session *);
205static void core_scsi3_put_pr_reg(struct t10_pr_registration *); 121static void core_scsi3_put_pr_reg(struct t10_pr_registration *);
206 122
207/* 123static int target_check_scsi2_reservation_conflict(struct se_cmd *cmd, int *ret)
208 * Setup in target_core_transport.c:transport_generic_cmd_sequencer()
209 * and called via struct se_cmd->transport_emulate_cdb() in TCM processing
210 * thread context.
211 */
212int core_scsi2_emulate_crh(struct se_cmd *cmd)
213{ 124{
214 struct se_session *se_sess = cmd->se_sess; 125 struct se_session *se_sess = cmd->se_sess;
215 struct se_subsystem_dev *su_dev = cmd->se_dev->se_sub_dev; 126 struct se_subsystem_dev *su_dev = cmd->se_dev->se_sub_dev;
216 struct t10_pr_registration *pr_reg; 127 struct t10_pr_registration *pr_reg;
217 struct t10_reservation *pr_tmpl = &su_dev->t10_pr; 128 struct t10_reservation *pr_tmpl = &su_dev->t10_pr;
218 unsigned char *cdb = &cmd->t_task_cdb[0];
219 int crh = (su_dev->t10_pr.res_type == SPC3_PERSISTENT_RESERVATIONS); 129 int crh = (su_dev->t10_pr.res_type == SPC3_PERSISTENT_RESERVATIONS);
220 int conflict = 0; 130 int conflict = 0;
221 131
222 if (!se_sess)
223 return 0;
224
225 if (!crh) 132 if (!crh)
226 goto after_crh; 133 return false;
227 134
228 pr_reg = core_scsi3_locate_pr_reg(cmd->se_dev, se_sess->se_node_acl, 135 pr_reg = core_scsi3_locate_pr_reg(cmd->se_dev, se_sess->se_node_acl,
229 se_sess); 136 se_sess);
@@ -251,14 +158,16 @@ int core_scsi2_emulate_crh(struct se_cmd *cmd)
251 */ 158 */
252 if (pr_reg->pr_res_holder) { 159 if (pr_reg->pr_res_holder) {
253 core_scsi3_put_pr_reg(pr_reg); 160 core_scsi3_put_pr_reg(pr_reg);
254 return 0; 161 *ret = 0;
162 return false;
255 } 163 }
256 if ((pr_reg->pr_res_type == PR_TYPE_WRITE_EXCLUSIVE_REGONLY) || 164 if ((pr_reg->pr_res_type == PR_TYPE_WRITE_EXCLUSIVE_REGONLY) ||
257 (pr_reg->pr_res_type == PR_TYPE_EXCLUSIVE_ACCESS_REGONLY) || 165 (pr_reg->pr_res_type == PR_TYPE_EXCLUSIVE_ACCESS_REGONLY) ||
258 (pr_reg->pr_res_type == PR_TYPE_WRITE_EXCLUSIVE_ALLREG) || 166 (pr_reg->pr_res_type == PR_TYPE_WRITE_EXCLUSIVE_ALLREG) ||
259 (pr_reg->pr_res_type == PR_TYPE_EXCLUSIVE_ACCESS_ALLREG)) { 167 (pr_reg->pr_res_type == PR_TYPE_EXCLUSIVE_ACCESS_ALLREG)) {
260 core_scsi3_put_pr_reg(pr_reg); 168 core_scsi3_put_pr_reg(pr_reg);
261 return 0; 169 *ret = 0;
170 return true;
262 } 171 }
263 core_scsi3_put_pr_reg(pr_reg); 172 core_scsi3_put_pr_reg(pr_reg);
264 conflict = 1; 173 conflict = 1;
@@ -282,18 +191,118 @@ int core_scsi2_emulate_crh(struct se_cmd *cmd)
282 pr_err("Received legacy SPC-2 RESERVE/RELEASE" 191 pr_err("Received legacy SPC-2 RESERVE/RELEASE"
283 " while active SPC-3 registrations exist," 192 " while active SPC-3 registrations exist,"
284 " returning RESERVATION_CONFLICT\n"); 193 " returning RESERVATION_CONFLICT\n");
285 return PYX_TRANSPORT_RESERVATION_CONFLICT; 194 *ret = PYX_TRANSPORT_RESERVATION_CONFLICT;
195 return true;
286 } 196 }
287 197
288after_crh: 198 return false;
289 if ((cdb[0] == RESERVE) || (cdb[0] == RESERVE_10)) 199}
290 return core_scsi2_reservation_reserve(cmd); 200
291 else if ((cdb[0] == RELEASE) || (cdb[0] == RELEASE_10)) 201int target_scsi2_reservation_release(struct se_task *task)
292 return core_scsi2_reservation_release(cmd); 202{
293 else 203 struct se_cmd *cmd = task->task_se_cmd;
294 return PYX_TRANSPORT_INVALID_CDB_FIELD; 204 struct se_device *dev = cmd->se_dev;
205 struct se_session *sess = cmd->se_sess;
206 struct se_portal_group *tpg = sess->se_tpg;
207 int ret = 0;
208
209 if (!sess || !tpg)
210 goto out;
211 if (target_check_scsi2_reservation_conflict(cmd, &ret))
212 goto out;
213
214 ret = 0;
215 spin_lock(&dev->dev_reservation_lock);
216 if (!dev->dev_reserved_node_acl || !sess)
217 goto out_unlock;
218
219 if (dev->dev_reserved_node_acl != sess->se_node_acl)
220 goto out_unlock;
221
222 dev->dev_reserved_node_acl = NULL;
223 dev->dev_flags &= ~DF_SPC2_RESERVATIONS;
224 if (dev->dev_flags & DF_SPC2_RESERVATIONS_WITH_ISID) {
225 dev->dev_res_bin_isid = 0;
226 dev->dev_flags &= ~DF_SPC2_RESERVATIONS_WITH_ISID;
227 }
228 pr_debug("SCSI-2 Released reservation for %s LUN: %u ->"
229 " MAPPED LUN: %u for %s\n", tpg->se_tpg_tfo->get_fabric_name(),
230 cmd->se_lun->unpacked_lun, cmd->se_deve->mapped_lun,
231 sess->se_node_acl->initiatorname);
232
233out_unlock:
234 spin_unlock(&dev->dev_reservation_lock);
235out:
236 if (!ret) {
237 task->task_scsi_status = GOOD;
238 transport_complete_task(task, 1);
239 }
240 return ret;
241}
242
243int target_scsi2_reservation_reserve(struct se_task *task)
244{
245 struct se_cmd *cmd = task->task_se_cmd;
246 struct se_device *dev = cmd->se_dev;
247 struct se_session *sess = cmd->se_sess;
248 struct se_portal_group *tpg = sess->se_tpg;
249 int ret = 0;
250
251 if ((cmd->t_task_cdb[1] & 0x01) &&
252 (cmd->t_task_cdb[1] & 0x02)) {
253 pr_err("LongIO and Obselete Bits set, returning"
254 " ILLEGAL_REQUEST\n");
255 ret = PYX_TRANSPORT_ILLEGAL_REQUEST;
256 goto out;
257 }
258 /*
259 * This is currently the case for target_core_mod passthrough struct se_cmd
260 * ops
261 */
262 if (!sess || !tpg)
263 goto out;
264 if (target_check_scsi2_reservation_conflict(cmd, &ret))
265 goto out;
266
267 ret = 0;
268 spin_lock(&dev->dev_reservation_lock);
269 if (dev->dev_reserved_node_acl &&
270 (dev->dev_reserved_node_acl != sess->se_node_acl)) {
271 pr_err("SCSI-2 RESERVATION CONFLIFT for %s fabric\n",
272 tpg->se_tpg_tfo->get_fabric_name());
273 pr_err("Original reserver LUN: %u %s\n",
274 cmd->se_lun->unpacked_lun,
275 dev->dev_reserved_node_acl->initiatorname);
276 pr_err("Current attempt - LUN: %u -> MAPPED LUN: %u"
277 " from %s \n", cmd->se_lun->unpacked_lun,
278 cmd->se_deve->mapped_lun,
279 sess->se_node_acl->initiatorname);
280 ret = PYX_TRANSPORT_RESERVATION_CONFLICT;
281 goto out_unlock;
282 }
283
284 dev->dev_reserved_node_acl = sess->se_node_acl;
285 dev->dev_flags |= DF_SPC2_RESERVATIONS;
286 if (sess->sess_bin_isid != 0) {
287 dev->dev_res_bin_isid = sess->sess_bin_isid;
288 dev->dev_flags |= DF_SPC2_RESERVATIONS_WITH_ISID;
289 }
290 pr_debug("SCSI-2 Reserved %s LUN: %u -> MAPPED LUN: %u"
291 " for %s\n", tpg->se_tpg_tfo->get_fabric_name(),
292 cmd->se_lun->unpacked_lun, cmd->se_deve->mapped_lun,
293 sess->se_node_acl->initiatorname);
294
295out_unlock:
296 spin_unlock(&dev->dev_reservation_lock);
297out:
298 if (!ret) {
299 task->task_scsi_status = GOOD;
300 transport_complete_task(task, 1);
301 }
302 return ret;
295} 303}
296 304
305
297/* 306/*
298 * Begin SPC-3/SPC-4 Persistent Reservations emulation support 307 * Begin SPC-3/SPC-4 Persistent Reservations emulation support
299 * 308 *
@@ -418,12 +427,12 @@ static int core_scsi3_pr_seq_non_holder(
418 break; 427 break;
419 case RELEASE: 428 case RELEASE:
420 case RELEASE_10: 429 case RELEASE_10:
421 /* Handled by CRH=1 in core_scsi2_emulate_crh() */ 430 /* Handled by CRH=1 in target_scsi2_reservation_release() */
422 ret = 0; 431 ret = 0;
423 break; 432 break;
424 case RESERVE: 433 case RESERVE:
425 case RESERVE_10: 434 case RESERVE_10:
426 /* Handled by CRH=1 in core_scsi2_emulate_crh() */ 435 /* Handled by CRH=1 in target_scsi2_reservation_reserve() */
427 ret = 0; 436 ret = 0;
428 break; 437 break;
429 case TEST_UNIT_READY: 438 case TEST_UNIT_READY:
@@ -3739,12 +3748,33 @@ static unsigned long long core_scsi3_extract_reservation_key(unsigned char *cdb)
3739/* 3748/*
3740 * See spc4r17 section 6.14 Table 170 3749 * See spc4r17 section 6.14 Table 170
3741 */ 3750 */
3742static int core_scsi3_emulate_pr_out(struct se_cmd *cmd, unsigned char *cdb) 3751int target_scsi3_emulate_pr_out(struct se_task *task)
3743{ 3752{
3753 struct se_cmd *cmd = task->task_se_cmd;
3754 unsigned char *cdb = &cmd->t_task_cdb[0];
3744 unsigned char *buf; 3755 unsigned char *buf;
3745 u64 res_key, sa_res_key; 3756 u64 res_key, sa_res_key;
3746 int sa, scope, type, aptpl; 3757 int sa, scope, type, aptpl;
3747 int spec_i_pt = 0, all_tg_pt = 0, unreg = 0; 3758 int spec_i_pt = 0, all_tg_pt = 0, unreg = 0;
3759 int ret;
3760
3761 /*
3762 * Following spc2r20 5.5.1 Reservations overview:
3763 *
3764 * If a logical unit has been reserved by any RESERVE command and is
3765 * still reserved by any initiator, all PERSISTENT RESERVE IN and all
3766 * PERSISTENT RESERVE OUT commands shall conflict regardless of
3767 * initiator or service action and shall terminate with a RESERVATION
3768 * CONFLICT status.
3769 */
3770 if (cmd->se_dev->dev_flags & DF_SPC2_RESERVATIONS) {
3771 pr_err("Received PERSISTENT_RESERVE CDB while legacy"
3772 " SPC-2 reservation is held, returning"
3773 " RESERVATION_CONFLICT\n");
3774 ret = PYX_TRANSPORT_RESERVATION_CONFLICT;
3775 goto out;
3776 }
3777
3748 /* 3778 /*
3749 * FIXME: A NULL struct se_session pointer means an this is not coming from 3779 * FIXME: A NULL struct se_session pointer means an this is not coming from
3750 * a $FABRIC_MOD's nexus, but from internal passthrough ops. 3780 * a $FABRIC_MOD's nexus, but from internal passthrough ops.
@@ -3755,7 +3785,8 @@ static int core_scsi3_emulate_pr_out(struct se_cmd *cmd, unsigned char *cdb)
3755 if (cmd->data_length < 24) { 3785 if (cmd->data_length < 24) {
3756 pr_warn("SPC-PR: Received PR OUT parameter list" 3786 pr_warn("SPC-PR: Received PR OUT parameter list"
3757 " length too small: %u\n", cmd->data_length); 3787 " length too small: %u\n", cmd->data_length);
3758 return PYX_TRANSPORT_INVALID_PARAMETER_LIST; 3788 ret = PYX_TRANSPORT_INVALID_PARAMETER_LIST;
3789 goto out;
3759 } 3790 }
3760 /* 3791 /*
3761 * From the PERSISTENT_RESERVE_OUT command descriptor block (CDB) 3792 * From the PERSISTENT_RESERVE_OUT command descriptor block (CDB)
@@ -3788,8 +3819,11 @@ static int core_scsi3_emulate_pr_out(struct se_cmd *cmd, unsigned char *cdb)
3788 /* 3819 /*
3789 * SPEC_I_PT=1 is only valid for Service action: REGISTER 3820 * SPEC_I_PT=1 is only valid for Service action: REGISTER
3790 */ 3821 */
3791 if (spec_i_pt && ((cdb[1] & 0x1f) != PRO_REGISTER)) 3822 if (spec_i_pt && ((cdb[1] & 0x1f) != PRO_REGISTER)) {
3792 return PYX_TRANSPORT_INVALID_PARAMETER_LIST; 3823 ret = PYX_TRANSPORT_INVALID_PARAMETER_LIST;
3824 goto out;
3825 }
3826
3793 /* 3827 /*
3794 * From spc4r17 section 6.14: 3828 * From spc4r17 section 6.14:
3795 * 3829 *
@@ -3803,7 +3837,8 @@ static int core_scsi3_emulate_pr_out(struct se_cmd *cmd, unsigned char *cdb)
3803 (cmd->data_length != 24)) { 3837 (cmd->data_length != 24)) {
3804 pr_warn("SPC-PR: Received PR OUT illegal parameter" 3838 pr_warn("SPC-PR: Received PR OUT illegal parameter"
3805 " list length: %u\n", cmd->data_length); 3839 " list length: %u\n", cmd->data_length);
3806 return PYX_TRANSPORT_INVALID_PARAMETER_LIST; 3840 ret = PYX_TRANSPORT_INVALID_PARAMETER_LIST;
3841 goto out;
3807 } 3842 }
3808 /* 3843 /*
3809 * (core_scsi3_emulate_pro_* function parameters 3844 * (core_scsi3_emulate_pro_* function parameters
@@ -3812,35 +3847,47 @@ static int core_scsi3_emulate_pr_out(struct se_cmd *cmd, unsigned char *cdb)
3812 */ 3847 */
3813 switch (sa) { 3848 switch (sa) {
3814 case PRO_REGISTER: 3849 case PRO_REGISTER:
3815 return core_scsi3_emulate_pro_register(cmd, 3850 ret = core_scsi3_emulate_pro_register(cmd,
3816 res_key, sa_res_key, aptpl, all_tg_pt, spec_i_pt, 0); 3851 res_key, sa_res_key, aptpl, all_tg_pt, spec_i_pt, 0);
3852 break;
3817 case PRO_RESERVE: 3853 case PRO_RESERVE:
3818 return core_scsi3_emulate_pro_reserve(cmd, 3854 ret = core_scsi3_emulate_pro_reserve(cmd, type, scope, res_key);
3819 type, scope, res_key); 3855 break;
3820 case PRO_RELEASE: 3856 case PRO_RELEASE:
3821 return core_scsi3_emulate_pro_release(cmd, 3857 ret = core_scsi3_emulate_pro_release(cmd, type, scope, res_key);
3822 type, scope, res_key); 3858 break;
3823 case PRO_CLEAR: 3859 case PRO_CLEAR:
3824 return core_scsi3_emulate_pro_clear(cmd, res_key); 3860 ret = core_scsi3_emulate_pro_clear(cmd, res_key);
3861 break;
3825 case PRO_PREEMPT: 3862 case PRO_PREEMPT:
3826 return core_scsi3_emulate_pro_preempt(cmd, type, scope, 3863 ret = core_scsi3_emulate_pro_preempt(cmd, type, scope,
3827 res_key, sa_res_key, 0); 3864 res_key, sa_res_key, 0);
3865 break;
3828 case PRO_PREEMPT_AND_ABORT: 3866 case PRO_PREEMPT_AND_ABORT:
3829 return core_scsi3_emulate_pro_preempt(cmd, type, scope, 3867 ret = core_scsi3_emulate_pro_preempt(cmd, type, scope,
3830 res_key, sa_res_key, 1); 3868 res_key, sa_res_key, 1);
3869 break;
3831 case PRO_REGISTER_AND_IGNORE_EXISTING_KEY: 3870 case PRO_REGISTER_AND_IGNORE_EXISTING_KEY:
3832 return core_scsi3_emulate_pro_register(cmd, 3871 ret = core_scsi3_emulate_pro_register(cmd,
3833 0, sa_res_key, aptpl, all_tg_pt, spec_i_pt, 1); 3872 0, sa_res_key, aptpl, all_tg_pt, spec_i_pt, 1);
3873 break;
3834 case PRO_REGISTER_AND_MOVE: 3874 case PRO_REGISTER_AND_MOVE:
3835 return core_scsi3_emulate_pro_register_and_move(cmd, res_key, 3875 ret = core_scsi3_emulate_pro_register_and_move(cmd, res_key,
3836 sa_res_key, aptpl, unreg); 3876 sa_res_key, aptpl, unreg);
3877 break;
3837 default: 3878 default:
3838 pr_err("Unknown PERSISTENT_RESERVE_OUT service" 3879 pr_err("Unknown PERSISTENT_RESERVE_OUT service"
3839 " action: 0x%02x\n", cdb[1] & 0x1f); 3880 " action: 0x%02x\n", cdb[1] & 0x1f);
3840 return PYX_TRANSPORT_INVALID_CDB_FIELD; 3881 ret = PYX_TRANSPORT_INVALID_CDB_FIELD;
3882 break;
3841 } 3883 }
3842 3884
3843 return PYX_TRANSPORT_INVALID_CDB_FIELD; 3885out:
3886 if (!ret) {
3887 task->task_scsi_status = GOOD;
3888 transport_complete_task(task, 1);
3889 }
3890 return ret;
3844} 3891}
3845 3892
3846/* 3893/*
@@ -4190,29 +4237,11 @@ static int core_scsi3_pri_read_full_status(struct se_cmd *cmd)
4190 return 0; 4237 return 0;
4191} 4238}
4192 4239
4193static int core_scsi3_emulate_pr_in(struct se_cmd *cmd, unsigned char *cdb) 4240int target_scsi3_emulate_pr_in(struct se_task *task)
4194{ 4241{
4195 switch (cdb[1] & 0x1f) { 4242 struct se_cmd *cmd = task->task_se_cmd;
4196 case PRI_READ_KEYS: 4243 int ret;
4197 return core_scsi3_pri_read_keys(cmd);
4198 case PRI_READ_RESERVATION:
4199 return core_scsi3_pri_read_reservation(cmd);
4200 case PRI_REPORT_CAPABILITIES:
4201 return core_scsi3_pri_report_capabilities(cmd);
4202 case PRI_READ_FULL_STATUS:
4203 return core_scsi3_pri_read_full_status(cmd);
4204 default:
4205 pr_err("Unknown PERSISTENT_RESERVE_IN service"
4206 " action: 0x%02x\n", cdb[1] & 0x1f);
4207 return PYX_TRANSPORT_INVALID_CDB_FIELD;
4208 }
4209
4210}
4211 4244
4212int core_scsi3_emulate_pr(struct se_cmd *cmd)
4213{
4214 unsigned char *cdb = &cmd->t_task_cdb[0];
4215 struct se_device *dev = cmd->se_dev;
4216 /* 4245 /*
4217 * Following spc2r20 5.5.1 Reservations overview: 4246 * Following spc2r20 5.5.1 Reservations overview:
4218 * 4247 *
@@ -4222,16 +4251,38 @@ int core_scsi3_emulate_pr(struct se_cmd *cmd)
4222 * initiator or service action and shall terminate with a RESERVATION 4251 * initiator or service action and shall terminate with a RESERVATION
4223 * CONFLICT status. 4252 * CONFLICT status.
4224 */ 4253 */
4225 if (dev->dev_flags & DF_SPC2_RESERVATIONS) { 4254 if (cmd->se_dev->dev_flags & DF_SPC2_RESERVATIONS) {
4226 pr_err("Received PERSISTENT_RESERVE CDB while legacy" 4255 pr_err("Received PERSISTENT_RESERVE CDB while legacy"
4227 " SPC-2 reservation is held, returning" 4256 " SPC-2 reservation is held, returning"
4228 " RESERVATION_CONFLICT\n"); 4257 " RESERVATION_CONFLICT\n");
4229 return PYX_TRANSPORT_RESERVATION_CONFLICT; 4258 return PYX_TRANSPORT_RESERVATION_CONFLICT;
4230 } 4259 }
4231 4260
4232 return (cdb[0] == PERSISTENT_RESERVE_OUT) ? 4261 switch (cmd->t_task_cdb[1] & 0x1f) {
4233 core_scsi3_emulate_pr_out(cmd, cdb) : 4262 case PRI_READ_KEYS:
4234 core_scsi3_emulate_pr_in(cmd, cdb); 4263 ret = core_scsi3_pri_read_keys(cmd);
4264 break;
4265 case PRI_READ_RESERVATION:
4266 ret = core_scsi3_pri_read_reservation(cmd);
4267 break;
4268 case PRI_REPORT_CAPABILITIES:
4269 ret = core_scsi3_pri_report_capabilities(cmd);
4270 break;
4271 case PRI_READ_FULL_STATUS:
4272 ret = core_scsi3_pri_read_full_status(cmd);
4273 break;
4274 default:
4275 pr_err("Unknown PERSISTENT_RESERVE_IN service"
4276 " action: 0x%02x\n", cmd->t_task_cdb[1] & 0x1f);
4277 ret = PYX_TRANSPORT_INVALID_CDB_FIELD;
4278 break;
4279 }
4280
4281 if (!ret) {
4282 task->task_scsi_status = GOOD;
4283 transport_complete_task(task, 1);
4284 }
4285 return ret;
4235} 4286}
4236 4287
4237static int core_pt_reservation_check(struct se_cmd *cmd, u32 *pr_res_type) 4288static int core_pt_reservation_check(struct se_cmd *cmd, u32 *pr_res_type)
diff --git a/drivers/target/target_core_pr.h b/drivers/target/target_core_pr.h
index c8f47d064584..b97f6940dd05 100644
--- a/drivers/target/target_core_pr.h
+++ b/drivers/target/target_core_pr.h
@@ -47,7 +47,8 @@ extern struct kmem_cache *t10_pr_reg_cache;
47 47
48extern int core_pr_dump_initiator_port(struct t10_pr_registration *, 48extern int core_pr_dump_initiator_port(struct t10_pr_registration *,
49 char *, u32); 49 char *, u32);
50extern int core_scsi2_emulate_crh(struct se_cmd *); 50extern int target_scsi2_reservation_release(struct se_task *task);
51extern int target_scsi2_reservation_reserve(struct se_task *task);
51extern int core_scsi3_alloc_aptpl_registration( 52extern int core_scsi3_alloc_aptpl_registration(
52 struct t10_reservation *, u64, 53 struct t10_reservation *, u64,
53 unsigned char *, unsigned char *, u32, 54 unsigned char *, unsigned char *, u32,
@@ -61,7 +62,9 @@ extern void core_scsi3_free_all_registrations(struct se_device *);
61extern unsigned char *core_scsi3_pr_dump_type(int); 62extern unsigned char *core_scsi3_pr_dump_type(int);
62extern int core_scsi3_check_cdb_abort_and_preempt(struct list_head *, 63extern int core_scsi3_check_cdb_abort_and_preempt(struct list_head *,
63 struct se_cmd *); 64 struct se_cmd *);
64extern int core_scsi3_emulate_pr(struct se_cmd *); 65
66extern int target_scsi3_emulate_pr_in(struct se_task *task);
67extern int target_scsi3_emulate_pr_out(struct se_task *task);
65extern int core_setup_reservations(struct se_device *, int); 68extern int core_setup_reservations(struct se_device *, int);
66 69
67#endif /* TARGET_CORE_PR_H */ 70#endif /* TARGET_CORE_PR_H */
diff --git a/drivers/target/target_core_pscsi.c b/drivers/target/target_core_pscsi.c
index dad671dee9e9..ed32e1efe429 100644
--- a/drivers/target/target_core_pscsi.c
+++ b/drivers/target/target_core_pscsi.c
@@ -36,6 +36,7 @@
36#include <linux/genhd.h> 36#include <linux/genhd.h>
37#include <linux/cdrom.h> 37#include <linux/cdrom.h>
38#include <linux/file.h> 38#include <linux/file.h>
39#include <linux/module.h>
39#include <scsi/scsi.h> 40#include <scsi/scsi.h>
40#include <scsi/scsi_device.h> 41#include <scsi/scsi_device.h>
41#include <scsi/scsi_cmnd.h> 42#include <scsi/scsi_cmnd.h>
@@ -1091,7 +1092,7 @@ static int pscsi_do_task(struct se_task *task)
1091 1092
1092 req = blk_make_request(pdv->pdv_sd->request_queue, hbio, 1093 req = blk_make_request(pdv->pdv_sd->request_queue, hbio,
1093 GFP_KERNEL); 1094 GFP_KERNEL);
1094 if (!req) { 1095 if (IS_ERR(req)) {
1095 pr_err("pSCSI: blk_make_request() failed\n"); 1096 pr_err("pSCSI: blk_make_request() failed\n");
1096 goto fail; 1097 goto fail;
1097 } 1098 }
diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
index 570b144a1edb..217e29df6297 100644
--- a/drivers/target/target_core_tmr.c
+++ b/drivers/target/target_core_tmr.c
@@ -27,6 +27,7 @@
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/spinlock.h> 28#include <linux/spinlock.h>
29#include <linux/list.h> 29#include <linux/list.h>
30#include <linux/export.h>
30#include <scsi/scsi.h> 31#include <scsi/scsi.h>
31#include <scsi/scsi_cmnd.h> 32#include <scsi/scsi_cmnd.h>
32 33
@@ -118,7 +119,7 @@ static void core_tmr_drain_tmr_list(
118 /* 119 /*
119 * Allow the received TMR to return with FUNCTION_COMPLETE. 120 * Allow the received TMR to return with FUNCTION_COMPLETE.
120 */ 121 */
121 if (tmr && (tmr_p == tmr)) 122 if (tmr_p == tmr)
122 continue; 123 continue;
123 124
124 cmd = tmr_p->task_cmd; 125 cmd = tmr_p->task_cmd;
@@ -147,19 +148,18 @@ static void core_tmr_drain_tmr_list(
147 } 148 }
148 spin_unlock(&cmd->t_state_lock); 149 spin_unlock(&cmd->t_state_lock);
149 150
150 list_move_tail(&tmr->tmr_list, &drain_tmr_list); 151 list_move_tail(&tmr_p->tmr_list, &drain_tmr_list);
151 } 152 }
152 spin_unlock_irqrestore(&dev->se_tmr_lock, flags); 153 spin_unlock_irqrestore(&dev->se_tmr_lock, flags);
153 154
154 while (!list_empty(&drain_tmr_list)) { 155 list_for_each_entry_safe(tmr_p, tmr_pp, &drain_tmr_list, tmr_list) {
155 tmr = list_entry(drain_tmr_list.next, struct se_tmr_req, tmr_list); 156 list_del_init(&tmr_p->tmr_list);
156 list_del(&tmr->tmr_list);
157 cmd = tmr_p->task_cmd; 157 cmd = tmr_p->task_cmd;
158 158
159 pr_debug("LUN_RESET: %s releasing TMR %p Function: 0x%02x," 159 pr_debug("LUN_RESET: %s releasing TMR %p Function: 0x%02x,"
160 " Response: 0x%02x, t_state: %d\n", 160 " Response: 0x%02x, t_state: %d\n",
161 (preempt_and_abort_list) ? "Preempt" : "", tmr, 161 (preempt_and_abort_list) ? "Preempt" : "", tmr_p,
162 tmr->function, tmr->response, cmd->t_state); 162 tmr_p->function, tmr_p->response, cmd->t_state);
163 163
164 transport_cmd_finish_abort(cmd, 1); 164 transport_cmd_finish_abort(cmd, 1);
165 } 165 }
@@ -330,16 +330,6 @@ static void core_tmr_drain_cmd_list(
330 */ 330 */
331 if (prout_cmd == cmd) 331 if (prout_cmd == cmd)
332 continue; 332 continue;
333 /*
334 * Skip direct processing of TRANSPORT_FREE_CMD_INTR for
335 * HW target mode fabrics.
336 */
337 spin_lock(&cmd->t_state_lock);
338 if (cmd->t_state == TRANSPORT_FREE_CMD_INTR) {
339 spin_unlock(&cmd->t_state_lock);
340 continue;
341 }
342 spin_unlock(&cmd->t_state_lock);
343 333
344 atomic_set(&cmd->t_transport_queue_active, 0); 334 atomic_set(&cmd->t_transport_queue_active, 0);
345 atomic_dec(&qobj->queue_cnt); 335 atomic_dec(&qobj->queue_cnt);
diff --git a/drivers/target/target_core_tpg.c b/drivers/target/target_core_tpg.c
index 49fd0a9b0a56..8ddd133025b9 100644
--- a/drivers/target/target_core_tpg.c
+++ b/drivers/target/target_core_tpg.c
@@ -32,6 +32,7 @@
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/spinlock.h> 33#include <linux/spinlock.h>
34#include <linux/in.h> 34#include <linux/in.h>
35#include <linux/export.h>
35#include <net/sock.h> 36#include <net/sock.h>
36#include <net/tcp.h> 37#include <net/tcp.h>
37#include <scsi/scsi.h> 38#include <scsi/scsi.h>
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index d75255804481..3400ae6e93f8 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -36,6 +36,7 @@
36#include <linux/kthread.h> 36#include <linux/kthread.h>
37#include <linux/in.h> 37#include <linux/in.h>
38#include <linux/cdrom.h> 38#include <linux/cdrom.h>
39#include <linux/module.h>
39#include <asm/unaligned.h> 40#include <asm/unaligned.h>
40#include <net/sock.h> 41#include <net/sock.h>
41#include <net/tcp.h> 42#include <net/tcp.h>
@@ -52,6 +53,7 @@
52#include <target/target_core_configfs.h> 53#include <target/target_core_configfs.h>
53 54
54#include "target_core_alua.h" 55#include "target_core_alua.h"
56#include "target_core_cdb.h"
55#include "target_core_hba.h" 57#include "target_core_hba.h"
56#include "target_core_pr.h" 58#include "target_core_pr.h"
57#include "target_core_ua.h" 59#include "target_core_ua.h"
@@ -268,6 +270,9 @@ struct se_session *transport_init_session(void)
268 } 270 }
269 INIT_LIST_HEAD(&se_sess->sess_list); 271 INIT_LIST_HEAD(&se_sess->sess_list);
270 INIT_LIST_HEAD(&se_sess->sess_acl_list); 272 INIT_LIST_HEAD(&se_sess->sess_acl_list);
273 INIT_LIST_HEAD(&se_sess->sess_cmd_list);
274 INIT_LIST_HEAD(&se_sess->sess_wait_list);
275 spin_lock_init(&se_sess->sess_cmd_lock);
271 276
272 return se_sess; 277 return se_sess;
273} 278}
@@ -514,13 +519,16 @@ static int transport_cmd_check_stop(
514 * Some fabric modules like tcm_loop can release 519 * Some fabric modules like tcm_loop can release
515 * their internally allocated I/O reference now and 520 * their internally allocated I/O reference now and
516 * struct se_cmd now. 521 * struct se_cmd now.
522 *
523 * Fabric modules are expected to return '1' here if the
524 * se_cmd being passed is released at this point,
525 * or zero if not being released.
517 */ 526 */
518 if (cmd->se_tfo->check_stop_free != NULL) { 527 if (cmd->se_tfo->check_stop_free != NULL) {
519 spin_unlock_irqrestore( 528 spin_unlock_irqrestore(
520 &cmd->t_state_lock, flags); 529 &cmd->t_state_lock, flags);
521 530
522 cmd->se_tfo->check_stop_free(cmd); 531 return cmd->se_tfo->check_stop_free(cmd);
523 return 1;
524 } 532 }
525 } 533 }
526 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 534 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
@@ -730,6 +738,10 @@ void transport_complete_task(struct se_task *task, int success)
730 complete(&task->task_stop_comp); 738 complete(&task->task_stop_comp);
731 return; 739 return;
732 } 740 }
741
742 if (!success)
743 cmd->t_tasks_failed = 1;
744
733 /* 745 /*
734 * Decrement the outstanding t_task_cdbs_left count. The last 746 * Decrement the outstanding t_task_cdbs_left count. The last
735 * struct se_task from struct se_cmd will complete itself into the 747 * struct se_task from struct se_cmd will complete itself into the
@@ -740,7 +752,7 @@ void transport_complete_task(struct se_task *task, int success)
740 return; 752 return;
741 } 753 }
742 754
743 if (!success || cmd->t_tasks_failed) { 755 if (cmd->t_tasks_failed) {
744 if (!task->task_error_status) { 756 if (!task->task_error_status) {
745 task->task_error_status = 757 task->task_error_status =
746 PYX_TRANSPORT_UNKNOWN_SAM_OPCODE; 758 PYX_TRANSPORT_UNKNOWN_SAM_OPCODE;
@@ -908,7 +920,7 @@ void transport_remove_task_from_execute_queue(
908} 920}
909 921
910/* 922/*
911 * Handle QUEUE_FULL / -EAGAIN status 923 * Handle QUEUE_FULL / -EAGAIN and -ENOMEM status
912 */ 924 */
913 925
914static void target_qf_do_work(struct work_struct *work) 926static void target_qf_do_work(struct work_struct *work)
@@ -1498,11 +1510,12 @@ void transport_init_se_cmd(
1498 INIT_LIST_HEAD(&cmd->se_ordered_node); 1510 INIT_LIST_HEAD(&cmd->se_ordered_node);
1499 INIT_LIST_HEAD(&cmd->se_qf_node); 1511 INIT_LIST_HEAD(&cmd->se_qf_node);
1500 INIT_LIST_HEAD(&cmd->se_queue_node); 1512 INIT_LIST_HEAD(&cmd->se_queue_node);
1501 1513 INIT_LIST_HEAD(&cmd->se_cmd_list);
1502 INIT_LIST_HEAD(&cmd->t_task_list); 1514 INIT_LIST_HEAD(&cmd->t_task_list);
1503 init_completion(&cmd->transport_lun_fe_stop_comp); 1515 init_completion(&cmd->transport_lun_fe_stop_comp);
1504 init_completion(&cmd->transport_lun_stop_comp); 1516 init_completion(&cmd->transport_lun_stop_comp);
1505 init_completion(&cmd->t_transport_stop_comp); 1517 init_completion(&cmd->t_transport_stop_comp);
1518 init_completion(&cmd->cmd_wait_comp);
1506 spin_lock_init(&cmd->t_state_lock); 1519 spin_lock_init(&cmd->t_state_lock);
1507 atomic_set(&cmd->transport_dev_active, 1); 1520 atomic_set(&cmd->transport_dev_active, 1);
1508 1521
@@ -1645,9 +1658,7 @@ int transport_handle_cdb_direct(
1645 * and call transport_generic_request_failure() if necessary.. 1658 * and call transport_generic_request_failure() if necessary..
1646 */ 1659 */
1647 ret = transport_generic_new_cmd(cmd); 1660 ret = transport_generic_new_cmd(cmd);
1648 if (ret == -EAGAIN) 1661 if (ret < 0) {
1649 return 0;
1650 else if (ret < 0) {
1651 cmd->transport_error_status = ret; 1662 cmd->transport_error_status = ret;
1652 transport_generic_request_failure(cmd, 0, 1663 transport_generic_request_failure(cmd, 0,
1653 (cmd->data_direction != DMA_TO_DEVICE)); 1664 (cmd->data_direction != DMA_TO_DEVICE));
@@ -1717,13 +1728,6 @@ int transport_generic_handle_tmr(
1717} 1728}
1718EXPORT_SYMBOL(transport_generic_handle_tmr); 1729EXPORT_SYMBOL(transport_generic_handle_tmr);
1719 1730
1720void transport_generic_free_cmd_intr(
1721 struct se_cmd *cmd)
1722{
1723 transport_add_cmd_to_queue(cmd, TRANSPORT_FREE_CMD_INTR, false);
1724}
1725EXPORT_SYMBOL(transport_generic_free_cmd_intr);
1726
1727/* 1731/*
1728 * If the task is active, request it to be stopped and sleep until it 1732 * If the task is active, request it to be stopped and sleep until it
1729 * has completed. 1733 * has completed.
@@ -1886,7 +1890,7 @@ static void transport_generic_request_failure(
1886 ASCQ_2CH_PREVIOUS_RESERVATION_CONFLICT_STATUS); 1890 ASCQ_2CH_PREVIOUS_RESERVATION_CONFLICT_STATUS);
1887 1891
1888 ret = cmd->se_tfo->queue_status(cmd); 1892 ret = cmd->se_tfo->queue_status(cmd);
1889 if (ret == -EAGAIN) 1893 if (ret == -EAGAIN || ret == -ENOMEM)
1890 goto queue_full; 1894 goto queue_full;
1891 goto check_stop; 1895 goto check_stop;
1892 case PYX_TRANSPORT_USE_SENSE_REASON: 1896 case PYX_TRANSPORT_USE_SENSE_REASON:
@@ -1913,7 +1917,7 @@ static void transport_generic_request_failure(
1913 else { 1917 else {
1914 ret = transport_send_check_condition_and_sense(cmd, 1918 ret = transport_send_check_condition_and_sense(cmd,
1915 cmd->scsi_sense_reason, 0); 1919 cmd->scsi_sense_reason, 0);
1916 if (ret == -EAGAIN) 1920 if (ret == -EAGAIN || ret == -ENOMEM)
1917 goto queue_full; 1921 goto queue_full;
1918 } 1922 }
1919 1923
@@ -2153,62 +2157,20 @@ check_depth:
2153 atomic_set(&cmd->t_transport_sent, 1); 2157 atomic_set(&cmd->t_transport_sent, 1);
2154 2158
2155 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 2159 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
2156 /*
2157 * The struct se_cmd->transport_emulate_cdb() function pointer is used
2158 * to grab REPORT_LUNS and other CDBs we want to handle before they hit the
2159 * struct se_subsystem_api->do_task() caller below.
2160 */
2161 if (cmd->transport_emulate_cdb) {
2162 error = cmd->transport_emulate_cdb(cmd);
2163 if (error != 0) {
2164 cmd->transport_error_status = error;
2165 spin_lock_irqsave(&cmd->t_state_lock, flags);
2166 task->task_flags &= ~TF_ACTIVE;
2167 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
2168 atomic_set(&cmd->t_transport_sent, 0);
2169 transport_stop_tasks_for_cmd(cmd);
2170 atomic_inc(&dev->depth_left);
2171 transport_generic_request_failure(cmd, 0, 1);
2172 goto check_depth;
2173 }
2174 /*
2175 * Handle the successful completion for transport_emulate_cdb()
2176 * for synchronous operation, following SCF_EMULATE_CDB_ASYNC
2177 * Otherwise the caller is expected to complete the task with
2178 * proper status.
2179 */
2180 if (!(cmd->se_cmd_flags & SCF_EMULATE_CDB_ASYNC)) {
2181 cmd->scsi_status = SAM_STAT_GOOD;
2182 task->task_scsi_status = GOOD;
2183 transport_complete_task(task, 1);
2184 }
2185 } else {
2186 /*
2187 * Currently for all virtual TCM plugins including IBLOCK, FILEIO and
2188 * RAMDISK we use the internal transport_emulate_control_cdb() logic
2189 * with struct se_subsystem_api callers for the primary SPC-3 TYPE_DISK
2190 * LUN emulation code.
2191 *
2192 * For TCM/pSCSI and all other SCF_SCSI_DATA_SG_IO_CDB I/O tasks we
2193 * call ->do_task() directly and let the underlying TCM subsystem plugin
2194 * code handle the CDB emulation.
2195 */
2196 if ((dev->transport->transport_type != TRANSPORT_PLUGIN_PHBA_PDEV) &&
2197 (!(task->task_se_cmd->se_cmd_flags & SCF_SCSI_DATA_SG_IO_CDB)))
2198 error = transport_emulate_control_cdb(task);
2199 else
2200 error = dev->transport->do_task(task);
2201 2160
2202 if (error != 0) { 2161 if (cmd->execute_task)
2203 cmd->transport_error_status = error; 2162 error = cmd->execute_task(task);
2204 spin_lock_irqsave(&cmd->t_state_lock, flags); 2163 else
2205 task->task_flags &= ~TF_ACTIVE; 2164 error = dev->transport->do_task(task);
2206 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 2165 if (error != 0) {
2207 atomic_set(&cmd->t_transport_sent, 0); 2166 cmd->transport_error_status = error;
2208 transport_stop_tasks_for_cmd(cmd); 2167 spin_lock_irqsave(&cmd->t_state_lock, flags);
2209 atomic_inc(&dev->depth_left); 2168 task->task_flags &= ~TF_ACTIVE;
2210 transport_generic_request_failure(cmd, 0, 1); 2169 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
2211 } 2170 atomic_set(&cmd->t_transport_sent, 0);
2171 transport_stop_tasks_for_cmd(cmd);
2172 atomic_inc(&dev->depth_left);
2173 transport_generic_request_failure(cmd, 0, 1);
2212 } 2174 }
2213 2175
2214 goto check_depth; 2176 goto check_depth;
@@ -2642,6 +2604,13 @@ static int transport_generic_cmd_sequencer(
2642 */ 2604 */
2643 } 2605 }
2644 2606
2607 /*
2608 * If we operate in passthrough mode we skip most CDB emulation and
2609 * instead hand the commands down to the physical SCSI device.
2610 */
2611 passthrough =
2612 (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV);
2613
2645 switch (cdb[0]) { 2614 switch (cdb[0]) {
2646 case READ_6: 2615 case READ_6:
2647 sectors = transport_get_sectors_6(cdb, cmd, &sector_ret); 2616 sectors = transport_get_sectors_6(cdb, cmd, &sector_ret);
@@ -2721,9 +2690,12 @@ static int transport_generic_cmd_sequencer(
2721 cmd->t_task_lba = transport_lba_32(cdb); 2690 cmd->t_task_lba = transport_lba_32(cdb);
2722 cmd->se_cmd_flags |= SCF_SCSI_DATA_SG_IO_CDB; 2691 cmd->se_cmd_flags |= SCF_SCSI_DATA_SG_IO_CDB;
2723 2692
2724 if (dev->transport->transport_type == 2693 /*
2725 TRANSPORT_PLUGIN_PHBA_PDEV) 2694 * Do now allow BIDI commands for passthrough mode.
2695 */
2696 if (passthrough)
2726 goto out_unsupported_cdb; 2697 goto out_unsupported_cdb;
2698
2727 /* 2699 /*
2728 * Setup BIDI XOR callback to be run after I/O completion. 2700 * Setup BIDI XOR callback to be run after I/O completion.
2729 */ 2701 */
@@ -2732,13 +2704,6 @@ static int transport_generic_cmd_sequencer(
2732 break; 2704 break;
2733 case VARIABLE_LENGTH_CMD: 2705 case VARIABLE_LENGTH_CMD:
2734 service_action = get_unaligned_be16(&cdb[8]); 2706 service_action = get_unaligned_be16(&cdb[8]);
2735 /*
2736 * Determine if this is TCM/PSCSI device and we should disable
2737 * internal emulation for this CDB.
2738 */
2739 passthrough = (dev->transport->transport_type ==
2740 TRANSPORT_PLUGIN_PHBA_PDEV);
2741
2742 switch (service_action) { 2707 switch (service_action) {
2743 case XDWRITEREAD_32: 2708 case XDWRITEREAD_32:
2744 sectors = transport_get_sectors_32(cdb, cmd, &sector_ret); 2709 sectors = transport_get_sectors_32(cdb, cmd, &sector_ret);
@@ -2752,8 +2717,12 @@ static int transport_generic_cmd_sequencer(
2752 cmd->t_task_lba = transport_lba_64_ext(cdb); 2717 cmd->t_task_lba = transport_lba_64_ext(cdb);
2753 cmd->se_cmd_flags |= SCF_SCSI_DATA_SG_IO_CDB; 2718 cmd->se_cmd_flags |= SCF_SCSI_DATA_SG_IO_CDB;
2754 2719
2720 /*
2721 * Do now allow BIDI commands for passthrough mode.
2722 */
2755 if (passthrough) 2723 if (passthrough)
2756 goto out_unsupported_cdb; 2724 goto out_unsupported_cdb;
2725
2757 /* 2726 /*
2758 * Setup BIDI XOR callback to be run during after I/O 2727 * Setup BIDI XOR callback to be run during after I/O
2759 * completion. 2728 * completion.
@@ -2779,7 +2748,8 @@ static int transport_generic_cmd_sequencer(
2779 2748
2780 if (target_check_write_same_discard(&cdb[10], dev) < 0) 2749 if (target_check_write_same_discard(&cdb[10], dev) < 0)
2781 goto out_invalid_cdb_field; 2750 goto out_invalid_cdb_field;
2782 2751 if (!passthrough)
2752 cmd->execute_task = target_emulate_write_same;
2783 break; 2753 break;
2784 default: 2754 default:
2785 pr_err("VARIABLE_LENGTH_CMD service action" 2755 pr_err("VARIABLE_LENGTH_CMD service action"
@@ -2793,12 +2763,10 @@ static int transport_generic_cmd_sequencer(
2793 /* 2763 /*
2794 * Check for emulated MI_REPORT_TARGET_PGS. 2764 * Check for emulated MI_REPORT_TARGET_PGS.
2795 */ 2765 */
2796 if (cdb[1] == MI_REPORT_TARGET_PGS) { 2766 if (cdb[1] == MI_REPORT_TARGET_PGS &&
2797 cmd->transport_emulate_cdb = 2767 su_dev->t10_alua.alua_type == SPC3_ALUA_EMULATED) {
2798 (su_dev->t10_alua.alua_type == 2768 cmd->execute_task =
2799 SPC3_ALUA_EMULATED) ? 2769 target_emulate_report_target_port_groups;
2800 core_emulate_report_target_port_groups :
2801 NULL;
2802 } 2770 }
2803 size = (cdb[6] << 24) | (cdb[7] << 16) | 2771 size = (cdb[6] << 24) | (cdb[7] << 16) |
2804 (cdb[8] << 8) | cdb[9]; 2772 (cdb[8] << 8) | cdb[9];
@@ -2819,8 +2787,15 @@ static int transport_generic_cmd_sequencer(
2819 case MODE_SENSE: 2787 case MODE_SENSE:
2820 size = cdb[4]; 2788 size = cdb[4];
2821 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB; 2789 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2790 if (!passthrough)
2791 cmd->execute_task = target_emulate_modesense;
2822 break; 2792 break;
2823 case MODE_SENSE_10: 2793 case MODE_SENSE_10:
2794 size = (cdb[7] << 8) + cdb[8];
2795 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2796 if (!passthrough)
2797 cmd->execute_task = target_emulate_modesense;
2798 break;
2824 case GPCMD_READ_BUFFER_CAPACITY: 2799 case GPCMD_READ_BUFFER_CAPACITY:
2825 case GPCMD_SEND_OPC: 2800 case GPCMD_SEND_OPC:
2826 case LOG_SELECT: 2801 case LOG_SELECT:
@@ -2840,11 +2815,14 @@ static int transport_generic_cmd_sequencer(
2840 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB; 2815 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2841 break; 2816 break;
2842 case PERSISTENT_RESERVE_IN: 2817 case PERSISTENT_RESERVE_IN:
2818 if (su_dev->t10_pr.res_type == SPC3_PERSISTENT_RESERVATIONS)
2819 cmd->execute_task = target_scsi3_emulate_pr_in;
2820 size = (cdb[7] << 8) + cdb[8];
2821 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2822 break;
2843 case PERSISTENT_RESERVE_OUT: 2823 case PERSISTENT_RESERVE_OUT:
2844 cmd->transport_emulate_cdb = 2824 if (su_dev->t10_pr.res_type == SPC3_PERSISTENT_RESERVATIONS)
2845 (su_dev->t10_pr.res_type == 2825 cmd->execute_task = target_scsi3_emulate_pr_out;
2846 SPC3_PERSISTENT_RESERVATIONS) ?
2847 core_scsi3_emulate_pr : NULL;
2848 size = (cdb[7] << 8) + cdb[8]; 2826 size = (cdb[7] << 8) + cdb[8];
2849 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB; 2827 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2850 break; 2828 break;
@@ -2863,12 +2841,10 @@ static int transport_generic_cmd_sequencer(
2863 * 2841 *
2864 * Check for emulated MO_SET_TARGET_PGS. 2842 * Check for emulated MO_SET_TARGET_PGS.
2865 */ 2843 */
2866 if (cdb[1] == MO_SET_TARGET_PGS) { 2844 if (cdb[1] == MO_SET_TARGET_PGS &&
2867 cmd->transport_emulate_cdb = 2845 su_dev->t10_alua.alua_type == SPC3_ALUA_EMULATED) {
2868 (su_dev->t10_alua.alua_type == 2846 cmd->execute_task =
2869 SPC3_ALUA_EMULATED) ? 2847 target_emulate_set_target_port_groups;
2870 core_emulate_set_target_port_groups :
2871 NULL;
2872 } 2848 }
2873 2849
2874 size = (cdb[6] << 24) | (cdb[7] << 16) | 2850 size = (cdb[6] << 24) | (cdb[7] << 16) |
@@ -2888,6 +2864,8 @@ static int transport_generic_cmd_sequencer(
2888 if (cmd->se_dev->dev_task_attr_type == SAM_TASK_ATTR_EMULATED) 2864 if (cmd->se_dev->dev_task_attr_type == SAM_TASK_ATTR_EMULATED)
2889 cmd->sam_task_attr = MSG_HEAD_TAG; 2865 cmd->sam_task_attr = MSG_HEAD_TAG;
2890 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB; 2866 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2867 if (!passthrough)
2868 cmd->execute_task = target_emulate_inquiry;
2891 break; 2869 break;
2892 case READ_BUFFER: 2870 case READ_BUFFER:
2893 size = (cdb[6] << 16) + (cdb[7] << 8) + cdb[8]; 2871 size = (cdb[6] << 16) + (cdb[7] << 8) + cdb[8];
@@ -2896,6 +2874,8 @@ static int transport_generic_cmd_sequencer(
2896 case READ_CAPACITY: 2874 case READ_CAPACITY:
2897 size = READ_CAP_LEN; 2875 size = READ_CAP_LEN;
2898 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB; 2876 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2877 if (!passthrough)
2878 cmd->execute_task = target_emulate_readcapacity;
2899 break; 2879 break;
2900 case READ_MEDIA_SERIAL_NUMBER: 2880 case READ_MEDIA_SERIAL_NUMBER:
2901 case SECURITY_PROTOCOL_IN: 2881 case SECURITY_PROTOCOL_IN:
@@ -2904,6 +2884,21 @@ static int transport_generic_cmd_sequencer(
2904 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB; 2884 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2905 break; 2885 break;
2906 case SERVICE_ACTION_IN: 2886 case SERVICE_ACTION_IN:
2887 switch (cmd->t_task_cdb[1] & 0x1f) {
2888 case SAI_READ_CAPACITY_16:
2889 if (!passthrough)
2890 cmd->execute_task =
2891 target_emulate_readcapacity_16;
2892 break;
2893 default:
2894 if (passthrough)
2895 break;
2896
2897 pr_err("Unsupported SA: 0x%02x\n",
2898 cmd->t_task_cdb[1] & 0x1f);
2899 goto out_unsupported_cdb;
2900 }
2901 /*FALLTHROUGH*/
2907 case ACCESS_CONTROL_IN: 2902 case ACCESS_CONTROL_IN:
2908 case ACCESS_CONTROL_OUT: 2903 case ACCESS_CONTROL_OUT:
2909 case EXTENDED_COPY: 2904 case EXTENDED_COPY:
@@ -2934,6 +2929,8 @@ static int transport_generic_cmd_sequencer(
2934 case REQUEST_SENSE: 2929 case REQUEST_SENSE:
2935 size = cdb[4]; 2930 size = cdb[4];
2936 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB; 2931 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2932 if (!passthrough)
2933 cmd->execute_task = target_emulate_request_sense;
2937 break; 2934 break;
2938 case READ_ELEMENT_STATUS: 2935 case READ_ELEMENT_STATUS:
2939 size = 65536 * cdb[7] + 256 * cdb[8] + cdb[9]; 2936 size = 65536 * cdb[7] + 256 * cdb[8] + cdb[9];
@@ -2961,10 +2958,8 @@ static int transport_generic_cmd_sequencer(
2961 * is running in SPC_PASSTHROUGH, and wants reservations 2958 * is running in SPC_PASSTHROUGH, and wants reservations
2962 * emulation disabled. 2959 * emulation disabled.
2963 */ 2960 */
2964 cmd->transport_emulate_cdb = 2961 if (su_dev->t10_pr.res_type != SPC_PASSTHROUGH)
2965 (su_dev->t10_pr.res_type != 2962 cmd->execute_task = target_scsi2_reservation_reserve;
2966 SPC_PASSTHROUGH) ?
2967 core_scsi2_emulate_crh : NULL;
2968 cmd->se_cmd_flags |= SCF_SCSI_NON_DATA_CDB; 2963 cmd->se_cmd_flags |= SCF_SCSI_NON_DATA_CDB;
2969 break; 2964 break;
2970 case RELEASE: 2965 case RELEASE:
@@ -2978,10 +2973,8 @@ static int transport_generic_cmd_sequencer(
2978 else 2973 else
2979 size = cmd->data_length; 2974 size = cmd->data_length;
2980 2975
2981 cmd->transport_emulate_cdb = 2976 if (su_dev->t10_pr.res_type != SPC_PASSTHROUGH)
2982 (su_dev->t10_pr.res_type != 2977 cmd->execute_task = target_scsi2_reservation_release;
2983 SPC_PASSTHROUGH) ?
2984 core_scsi2_emulate_crh : NULL;
2985 cmd->se_cmd_flags |= SCF_SCSI_NON_DATA_CDB; 2978 cmd->se_cmd_flags |= SCF_SCSI_NON_DATA_CDB;
2986 break; 2979 break;
2987 case SYNCHRONIZE_CACHE: 2980 case SYNCHRONIZE_CACHE:
@@ -3002,16 +2995,9 @@ static int transport_generic_cmd_sequencer(
3002 size = transport_get_size(sectors, cdb, cmd); 2995 size = transport_get_size(sectors, cdb, cmd);
3003 cmd->se_cmd_flags |= SCF_SCSI_NON_DATA_CDB; 2996 cmd->se_cmd_flags |= SCF_SCSI_NON_DATA_CDB;
3004 2997
3005 /* 2998 if (passthrough)
3006 * For TCM/pSCSI passthrough, skip cmd->transport_emulate_cdb()
3007 */
3008 if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV)
3009 break; 2999 break;
3010 /* 3000
3011 * Set SCF_EMULATE_CDB_ASYNC to ensure asynchronous operation
3012 * for SYNCHRONIZE_CACHE* Immed=1 case in __transport_execute_tasks()
3013 */
3014 cmd->se_cmd_flags |= SCF_EMULATE_CDB_ASYNC;
3015 /* 3001 /*
3016 * Check to ensure that LBA + Range does not exceed past end of 3002 * Check to ensure that LBA + Range does not exceed past end of
3017 * device for IBLOCK and FILEIO ->do_sync_cache() backend calls 3003 * device for IBLOCK and FILEIO ->do_sync_cache() backend calls
@@ -3020,10 +3006,13 @@ static int transport_generic_cmd_sequencer(
3020 if (transport_cmd_get_valid_sectors(cmd) < 0) 3006 if (transport_cmd_get_valid_sectors(cmd) < 0)
3021 goto out_invalid_cdb_field; 3007 goto out_invalid_cdb_field;
3022 } 3008 }
3009 cmd->execute_task = target_emulate_synchronize_cache;
3023 break; 3010 break;
3024 case UNMAP: 3011 case UNMAP:
3025 size = get_unaligned_be16(&cdb[7]); 3012 size = get_unaligned_be16(&cdb[7]);
3026 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB; 3013 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
3014 if (!passthrough)
3015 cmd->execute_task = target_emulate_unmap;
3027 break; 3016 break;
3028 case WRITE_SAME_16: 3017 case WRITE_SAME_16:
3029 sectors = transport_get_sectors_16(cdb, cmd, &sector_ret); 3018 sectors = transport_get_sectors_16(cdb, cmd, &sector_ret);
@@ -3042,6 +3031,8 @@ static int transport_generic_cmd_sequencer(
3042 3031
3043 if (target_check_write_same_discard(&cdb[1], dev) < 0) 3032 if (target_check_write_same_discard(&cdb[1], dev) < 0)
3044 goto out_invalid_cdb_field; 3033 goto out_invalid_cdb_field;
3034 if (!passthrough)
3035 cmd->execute_task = target_emulate_write_same;
3045 break; 3036 break;
3046 case WRITE_SAME: 3037 case WRITE_SAME:
3047 sectors = transport_get_sectors_10(cdb, cmd, &sector_ret); 3038 sectors = transport_get_sectors_10(cdb, cmd, &sector_ret);
@@ -3063,26 +3054,31 @@ static int transport_generic_cmd_sequencer(
3063 */ 3054 */
3064 if (target_check_write_same_discard(&cdb[1], dev) < 0) 3055 if (target_check_write_same_discard(&cdb[1], dev) < 0)
3065 goto out_invalid_cdb_field; 3056 goto out_invalid_cdb_field;
3057 if (!passthrough)
3058 cmd->execute_task = target_emulate_write_same;
3066 break; 3059 break;
3067 case ALLOW_MEDIUM_REMOVAL: 3060 case ALLOW_MEDIUM_REMOVAL:
3068 case GPCMD_CLOSE_TRACK:
3069 case ERASE: 3061 case ERASE:
3070 case INITIALIZE_ELEMENT_STATUS:
3071 case GPCMD_LOAD_UNLOAD:
3072 case REZERO_UNIT: 3062 case REZERO_UNIT:
3073 case SEEK_10: 3063 case SEEK_10:
3074 case GPCMD_SET_SPEED:
3075 case SPACE: 3064 case SPACE:
3076 case START_STOP: 3065 case START_STOP:
3077 case TEST_UNIT_READY: 3066 case TEST_UNIT_READY:
3078 case VERIFY: 3067 case VERIFY:
3079 case WRITE_FILEMARKS: 3068 case WRITE_FILEMARKS:
3069 cmd->se_cmd_flags |= SCF_SCSI_NON_DATA_CDB;
3070 if (!passthrough)
3071 cmd->execute_task = target_emulate_noop;
3072 break;
3073 case GPCMD_CLOSE_TRACK:
3074 case INITIALIZE_ELEMENT_STATUS:
3075 case GPCMD_LOAD_UNLOAD:
3076 case GPCMD_SET_SPEED:
3080 case MOVE_MEDIUM: 3077 case MOVE_MEDIUM:
3081 cmd->se_cmd_flags |= SCF_SCSI_NON_DATA_CDB; 3078 cmd->se_cmd_flags |= SCF_SCSI_NON_DATA_CDB;
3082 break; 3079 break;
3083 case REPORT_LUNS: 3080 case REPORT_LUNS:
3084 cmd->transport_emulate_cdb = 3081 cmd->execute_task = target_report_luns;
3085 transport_core_report_lun_response;
3086 size = (cdb[6] << 24) | (cdb[7] << 16) | (cdb[8] << 8) | cdb[9]; 3082 size = (cdb[6] << 24) | (cdb[7] << 16) | (cdb[8] << 8) | cdb[9];
3087 /* 3083 /*
3088 * Do implict HEAD_OF_QUEUE processing for REPORT_LUNS 3084 * Do implict HEAD_OF_QUEUE processing for REPORT_LUNS
@@ -3134,6 +3130,11 @@ static int transport_generic_cmd_sequencer(
3134 cmd->data_length = size; 3130 cmd->data_length = size;
3135 } 3131 }
3136 3132
3133 /* reject any command that we don't have a handler for */
3134 if (!(passthrough || cmd->execute_task ||
3135 (cmd->se_cmd_flags & SCF_SCSI_DATA_SG_IO_CDB)))
3136 goto out_unsupported_cdb;
3137
3137 /* Let's limit control cdbs to a page, for simplicity's sake. */ 3138 /* Let's limit control cdbs to a page, for simplicity's sake. */
3138 if ((cmd->se_cmd_flags & SCF_SCSI_CONTROL_SG_IO_CDB) && 3139 if ((cmd->se_cmd_flags & SCF_SCSI_CONTROL_SG_IO_CDB) &&
3139 size > PAGE_SIZE) 3140 size > PAGE_SIZE)
@@ -3308,7 +3309,7 @@ static void target_complete_ok_work(struct work_struct *work)
3308 if (cmd->scsi_status) { 3309 if (cmd->scsi_status) {
3309 ret = transport_send_check_condition_and_sense( 3310 ret = transport_send_check_condition_and_sense(
3310 cmd, reason, 1); 3311 cmd, reason, 1);
3311 if (ret == -EAGAIN) 3312 if (ret == -EAGAIN || ret == -ENOMEM)
3312 goto queue_full; 3313 goto queue_full;
3313 3314
3314 transport_lun_remove_cmd(cmd); 3315 transport_lun_remove_cmd(cmd);
@@ -3333,7 +3334,7 @@ static void target_complete_ok_work(struct work_struct *work)
3333 spin_unlock(&cmd->se_lun->lun_sep_lock); 3334 spin_unlock(&cmd->se_lun->lun_sep_lock);
3334 3335
3335 ret = cmd->se_tfo->queue_data_in(cmd); 3336 ret = cmd->se_tfo->queue_data_in(cmd);
3336 if (ret == -EAGAIN) 3337 if (ret == -EAGAIN || ret == -ENOMEM)
3337 goto queue_full; 3338 goto queue_full;
3338 break; 3339 break;
3339 case DMA_TO_DEVICE: 3340 case DMA_TO_DEVICE:
@@ -3354,14 +3355,14 @@ static void target_complete_ok_work(struct work_struct *work)
3354 } 3355 }
3355 spin_unlock(&cmd->se_lun->lun_sep_lock); 3356 spin_unlock(&cmd->se_lun->lun_sep_lock);
3356 ret = cmd->se_tfo->queue_data_in(cmd); 3357 ret = cmd->se_tfo->queue_data_in(cmd);
3357 if (ret == -EAGAIN) 3358 if (ret == -EAGAIN || ret == -ENOMEM)
3358 goto queue_full; 3359 goto queue_full;
3359 break; 3360 break;
3360 } 3361 }
3361 /* Fall through for DMA_TO_DEVICE */ 3362 /* Fall through for DMA_TO_DEVICE */
3362 case DMA_NONE: 3363 case DMA_NONE:
3363 ret = cmd->se_tfo->queue_status(cmd); 3364 ret = cmd->se_tfo->queue_status(cmd);
3364 if (ret == -EAGAIN) 3365 if (ret == -EAGAIN || ret == -ENOMEM)
3365 goto queue_full; 3366 goto queue_full;
3366 break; 3367 break;
3367 default: 3368 default:
@@ -3890,7 +3891,10 @@ EXPORT_SYMBOL(transport_generic_process_write);
3890 3891
3891static void transport_write_pending_qf(struct se_cmd *cmd) 3892static void transport_write_pending_qf(struct se_cmd *cmd)
3892{ 3893{
3893 if (cmd->se_tfo->write_pending(cmd) == -EAGAIN) { 3894 int ret;
3895
3896 ret = cmd->se_tfo->write_pending(cmd);
3897 if (ret == -EAGAIN || ret == -ENOMEM) {
3894 pr_debug("Handling write_pending QUEUE__FULL: se_cmd: %p\n", 3898 pr_debug("Handling write_pending QUEUE__FULL: se_cmd: %p\n",
3895 cmd); 3899 cmd);
3896 transport_handle_queue_full(cmd, cmd->se_dev); 3900 transport_handle_queue_full(cmd, cmd->se_dev);
@@ -3920,7 +3924,7 @@ static int transport_generic_write_pending(struct se_cmd *cmd)
3920 * frontend know that WRITE buffers are ready. 3924 * frontend know that WRITE buffers are ready.
3921 */ 3925 */
3922 ret = cmd->se_tfo->write_pending(cmd); 3926 ret = cmd->se_tfo->write_pending(cmd);
3923 if (ret == -EAGAIN) 3927 if (ret == -EAGAIN || ret == -ENOMEM)
3924 goto queue_full; 3928 goto queue_full;
3925 else if (ret < 0) 3929 else if (ret < 0)
3926 return ret; 3930 return ret;
@@ -3931,7 +3935,7 @@ queue_full:
3931 pr_debug("Handling write_pending QUEUE__FULL: se_cmd: %p\n", cmd); 3935 pr_debug("Handling write_pending QUEUE__FULL: se_cmd: %p\n", cmd);
3932 cmd->t_state = TRANSPORT_COMPLETE_QF_WP; 3936 cmd->t_state = TRANSPORT_COMPLETE_QF_WP;
3933 transport_handle_queue_full(cmd, cmd->se_dev); 3937 transport_handle_queue_full(cmd, cmd->se_dev);
3934 return ret; 3938 return 0;
3935} 3939}
3936 3940
3937/** 3941/**
@@ -3949,6 +3953,14 @@ void transport_release_cmd(struct se_cmd *cmd)
3949 core_tmr_release_req(cmd->se_tmr_req); 3953 core_tmr_release_req(cmd->se_tmr_req);
3950 if (cmd->t_task_cdb != cmd->__t_task_cdb) 3954 if (cmd->t_task_cdb != cmd->__t_task_cdb)
3951 kfree(cmd->t_task_cdb); 3955 kfree(cmd->t_task_cdb);
3956 /*
3957 * Check if target_wait_for_sess_cmds() is expecting to
3958 * release se_cmd directly here..
3959 */
3960 if (cmd->check_release != 0 && cmd->se_tfo->check_release_cmd)
3961 if (cmd->se_tfo->check_release_cmd(cmd) != 0)
3962 return;
3963
3952 cmd->se_tfo->release_cmd(cmd); 3964 cmd->se_tfo->release_cmd(cmd);
3953} 3965}
3954EXPORT_SYMBOL(transport_release_cmd); 3966EXPORT_SYMBOL(transport_release_cmd);
@@ -3976,6 +3988,114 @@ void transport_generic_free_cmd(struct se_cmd *cmd, int wait_for_tasks)
3976} 3988}
3977EXPORT_SYMBOL(transport_generic_free_cmd); 3989EXPORT_SYMBOL(transport_generic_free_cmd);
3978 3990
3991/* target_get_sess_cmd - Add command to active ->sess_cmd_list
3992 * @se_sess: session to reference
3993 * @se_cmd: command descriptor to add
3994 */
3995void target_get_sess_cmd(struct se_session *se_sess, struct se_cmd *se_cmd)
3996{
3997 unsigned long flags;
3998
3999 spin_lock_irqsave(&se_sess->sess_cmd_lock, flags);
4000 list_add_tail(&se_cmd->se_cmd_list, &se_sess->sess_cmd_list);
4001 se_cmd->check_release = 1;
4002 spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags);
4003}
4004EXPORT_SYMBOL(target_get_sess_cmd);
4005
4006/* target_put_sess_cmd - Check for active I/O shutdown or list delete
4007 * @se_sess: session to reference
4008 * @se_cmd: command descriptor to drop
4009 */
4010int target_put_sess_cmd(struct se_session *se_sess, struct se_cmd *se_cmd)
4011{
4012 unsigned long flags;
4013
4014 spin_lock_irqsave(&se_sess->sess_cmd_lock, flags);
4015 if (list_empty(&se_cmd->se_cmd_list)) {
4016 spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags);
4017 WARN_ON(1);
4018 return 0;
4019 }
4020
4021 if (se_sess->sess_tearing_down && se_cmd->cmd_wait_set) {
4022 spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags);
4023 complete(&se_cmd->cmd_wait_comp);
4024 return 1;
4025 }
4026 list_del(&se_cmd->se_cmd_list);
4027 spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags);
4028
4029 return 0;
4030}
4031EXPORT_SYMBOL(target_put_sess_cmd);
4032
4033/* target_splice_sess_cmd_list - Split active cmds into sess_wait_list
4034 * @se_sess: session to split
4035 */
4036void target_splice_sess_cmd_list(struct se_session *se_sess)
4037{
4038 struct se_cmd *se_cmd;
4039 unsigned long flags;
4040
4041 WARN_ON(!list_empty(&se_sess->sess_wait_list));
4042 INIT_LIST_HEAD(&se_sess->sess_wait_list);
4043
4044 spin_lock_irqsave(&se_sess->sess_cmd_lock, flags);
4045 se_sess->sess_tearing_down = 1;
4046
4047 list_splice_init(&se_sess->sess_cmd_list, &se_sess->sess_wait_list);
4048
4049 list_for_each_entry(se_cmd, &se_sess->sess_wait_list, se_cmd_list)
4050 se_cmd->cmd_wait_set = 1;
4051
4052 spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags);
4053}
4054EXPORT_SYMBOL(target_splice_sess_cmd_list);
4055
4056/* target_wait_for_sess_cmds - Wait for outstanding descriptors
4057 * @se_sess: session to wait for active I/O
4058 * @wait_for_tasks: Make extra transport_wait_for_tasks call
4059 */
4060void target_wait_for_sess_cmds(
4061 struct se_session *se_sess,
4062 int wait_for_tasks)
4063{
4064 struct se_cmd *se_cmd, *tmp_cmd;
4065 bool rc = false;
4066
4067 list_for_each_entry_safe(se_cmd, tmp_cmd,
4068 &se_sess->sess_wait_list, se_cmd_list) {
4069 list_del(&se_cmd->se_cmd_list);
4070
4071 pr_debug("Waiting for se_cmd: %p t_state: %d, fabric state:"
4072 " %d\n", se_cmd, se_cmd->t_state,
4073 se_cmd->se_tfo->get_cmd_state(se_cmd));
4074
4075 if (wait_for_tasks) {
4076 pr_debug("Calling transport_wait_for_tasks se_cmd: %p t_state: %d,"
4077 " fabric state: %d\n", se_cmd, se_cmd->t_state,
4078 se_cmd->se_tfo->get_cmd_state(se_cmd));
4079
4080 rc = transport_wait_for_tasks(se_cmd);
4081
4082 pr_debug("After transport_wait_for_tasks se_cmd: %p t_state: %d,"
4083 " fabric state: %d\n", se_cmd, se_cmd->t_state,
4084 se_cmd->se_tfo->get_cmd_state(se_cmd));
4085 }
4086
4087 if (!rc) {
4088 wait_for_completion(&se_cmd->cmd_wait_comp);
4089 pr_debug("After cmd_wait_comp: se_cmd: %p t_state: %d"
4090 " fabric state: %d\n", se_cmd, se_cmd->t_state,
4091 se_cmd->se_tfo->get_cmd_state(se_cmd));
4092 }
4093
4094 se_cmd->se_tfo->release_cmd(se_cmd);
4095 }
4096}
4097EXPORT_SYMBOL(target_wait_for_sess_cmds);
4098
3979/* transport_lun_wait_for_tasks(): 4099/* transport_lun_wait_for_tasks():
3980 * 4100 *
3981 * Called from ConfigFS context to stop the passed struct se_cmd to allow 4101 * Called from ConfigFS context to stop the passed struct se_cmd to allow
@@ -4152,14 +4272,14 @@ int transport_clear_lun_from_sessions(struct se_lun *lun)
4152 * Called from frontend fabric context to wait for storage engine 4272 * Called from frontend fabric context to wait for storage engine
4153 * to pause and/or release frontend generated struct se_cmd. 4273 * to pause and/or release frontend generated struct se_cmd.
4154 */ 4274 */
4155void transport_wait_for_tasks(struct se_cmd *cmd) 4275bool transport_wait_for_tasks(struct se_cmd *cmd)
4156{ 4276{
4157 unsigned long flags; 4277 unsigned long flags;
4158 4278
4159 spin_lock_irqsave(&cmd->t_state_lock, flags); 4279 spin_lock_irqsave(&cmd->t_state_lock, flags);
4160 if (!(cmd->se_cmd_flags & SCF_SE_LUN_CMD) && !(cmd->se_tmr_req)) { 4280 if (!(cmd->se_cmd_flags & SCF_SE_LUN_CMD) && !(cmd->se_tmr_req)) {
4161 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 4281 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
4162 return; 4282 return false;
4163 } 4283 }
4164 /* 4284 /*
4165 * Only perform a possible wait_for_tasks if SCF_SUPPORTED_SAM_OPCODE 4285 * Only perform a possible wait_for_tasks if SCF_SUPPORTED_SAM_OPCODE
@@ -4167,7 +4287,7 @@ void transport_wait_for_tasks(struct se_cmd *cmd)
4167 */ 4287 */
4168 if (!(cmd->se_cmd_flags & SCF_SUPPORTED_SAM_OPCODE) && !cmd->se_tmr_req) { 4288 if (!(cmd->se_cmd_flags & SCF_SUPPORTED_SAM_OPCODE) && !cmd->se_tmr_req) {
4169 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 4289 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
4170 return; 4290 return false;
4171 } 4291 }
4172 /* 4292 /*
4173 * If we are already stopped due to an external event (ie: LUN shutdown) 4293 * If we are already stopped due to an external event (ie: LUN shutdown)
@@ -4210,7 +4330,7 @@ void transport_wait_for_tasks(struct se_cmd *cmd)
4210 if (!atomic_read(&cmd->t_transport_active) || 4330 if (!atomic_read(&cmd->t_transport_active) ||
4211 atomic_read(&cmd->t_transport_aborted)) { 4331 atomic_read(&cmd->t_transport_aborted)) {
4212 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 4332 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
4213 return; 4333 return false;
4214 } 4334 }
4215 4335
4216 atomic_set(&cmd->t_transport_stop, 1); 4336 atomic_set(&cmd->t_transport_stop, 1);
@@ -4235,6 +4355,8 @@ void transport_wait_for_tasks(struct se_cmd *cmd)
4235 cmd->se_tfo->get_task_tag(cmd)); 4355 cmd->se_tfo->get_task_tag(cmd));
4236 4356
4237 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 4357 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
4358
4359 return true;
4238} 4360}
4239EXPORT_SYMBOL(transport_wait_for_tasks); 4361EXPORT_SYMBOL(transport_wait_for_tasks);
4240 4362
@@ -4583,9 +4705,7 @@ get_cmd:
4583 break; 4705 break;
4584 } 4706 }
4585 ret = transport_generic_new_cmd(cmd); 4707 ret = transport_generic_new_cmd(cmd);
4586 if (ret == -EAGAIN) 4708 if (ret < 0) {
4587 break;
4588 else if (ret < 0) {
4589 cmd->transport_error_status = ret; 4709 cmd->transport_error_status = ret;
4590 transport_generic_request_failure(cmd, 4710 transport_generic_request_failure(cmd,
4591 0, (cmd->data_direction != 4711 0, (cmd->data_direction !=
@@ -4595,9 +4715,6 @@ get_cmd:
4595 case TRANSPORT_PROCESS_WRITE: 4715 case TRANSPORT_PROCESS_WRITE:
4596 transport_generic_process_write(cmd); 4716 transport_generic_process_write(cmd);
4597 break; 4717 break;
4598 case TRANSPORT_FREE_CMD_INTR:
4599 transport_generic_free_cmd(cmd, 0);
4600 break;
4601 case TRANSPORT_PROCESS_TMR: 4718 case TRANSPORT_PROCESS_TMR:
4602 transport_generic_do_tmr(cmd); 4719 transport_generic_do_tmr(cmd);
4603 break; 4720 break;
diff --git a/drivers/target/tcm_fc/tcm_fc.h b/drivers/target/tcm_fc/tcm_fc.h
index 3749d8b4b423..e05c55100ec6 100644
--- a/drivers/target/tcm_fc/tcm_fc.h
+++ b/drivers/target/tcm_fc/tcm_fc.h
@@ -156,7 +156,7 @@ int ft_lport_notify(struct notifier_block *, unsigned long, void *);
156/* 156/*
157 * IO methods. 157 * IO methods.
158 */ 158 */
159void ft_check_stop_free(struct se_cmd *); 159int ft_check_stop_free(struct se_cmd *);
160void ft_release_cmd(struct se_cmd *); 160void ft_release_cmd(struct se_cmd *);
161int ft_queue_status(struct se_cmd *); 161int ft_queue_status(struct se_cmd *);
162int ft_queue_data_in(struct se_cmd *); 162int ft_queue_data_in(struct se_cmd *);
diff --git a/drivers/target/tcm_fc/tfc_cmd.c b/drivers/target/tcm_fc/tfc_cmd.c
index 6195026cc7b0..4fac37c4c615 100644
--- a/drivers/target/tcm_fc/tfc_cmd.c
+++ b/drivers/target/tcm_fc/tfc_cmd.c
@@ -112,9 +112,10 @@ void ft_release_cmd(struct se_cmd *se_cmd)
112 ft_free_cmd(cmd); 112 ft_free_cmd(cmd);
113} 113}
114 114
115void ft_check_stop_free(struct se_cmd *se_cmd) 115int ft_check_stop_free(struct se_cmd *se_cmd)
116{ 116{
117 transport_generic_free_cmd(se_cmd, 0); 117 transport_generic_free_cmd(se_cmd, 0);
118 return 1;
118} 119}
119 120
120/* 121/*
diff --git a/drivers/tty/Kconfig b/drivers/tty/Kconfig
index 8816f53e004d..b3d17416d86a 100644
--- a/drivers/tty/Kconfig
+++ b/drivers/tty/Kconfig
@@ -1,6 +1,6 @@
1config VT 1config VT
2 bool "Virtual terminal" if EXPERT 2 bool "Virtual terminal" if EXPERT
3 depends on !S390 3 depends on !S390 && !UML
4 select INPUT 4 select INPUT
5 default y 5 default y
6 ---help--- 6 ---help---
diff --git a/drivers/tty/hvc/Kconfig b/drivers/tty/hvc/Kconfig
index e371753ba921..4222035acfb7 100644
--- a/drivers/tty/hvc/Kconfig
+++ b/drivers/tty/hvc/Kconfig
@@ -34,6 +34,15 @@ config HVC_ISERIES
34 help 34 help
35 iSeries machines support a hypervisor virtual console. 35 iSeries machines support a hypervisor virtual console.
36 36
37config HVC_OPAL
38 bool "OPAL Console support"
39 depends on PPC_POWERNV
40 select HVC_DRIVER
41 select HVC_IRQ
42 default y
43 help
44 PowerNV machines running under OPAL need that driver to get a console
45
37config HVC_RTAS 46config HVC_RTAS
38 bool "IBM RTAS Console support" 47 bool "IBM RTAS Console support"
39 depends on PPC_RTAS 48 depends on PPC_RTAS
diff --git a/drivers/tty/hvc/Makefile b/drivers/tty/hvc/Makefile
index e29205316376..89abf40bc73d 100644
--- a/drivers/tty/hvc/Makefile
+++ b/drivers/tty/hvc/Makefile
@@ -1,4 +1,5 @@
1obj-$(CONFIG_HVC_CONSOLE) += hvc_vio.o hvsi_lib.o 1obj-$(CONFIG_HVC_CONSOLE) += hvc_vio.o hvsi_lib.o
2obj-$(CONFIG_HVC_OPAL) += hvc_opal.o hvsi_lib.o
2obj-$(CONFIG_HVC_OLD_HVSI) += hvsi.o 3obj-$(CONFIG_HVC_OLD_HVSI) += hvsi.o
3obj-$(CONFIG_HVC_ISERIES) += hvc_iseries.o 4obj-$(CONFIG_HVC_ISERIES) += hvc_iseries.o
4obj-$(CONFIG_HVC_RTAS) += hvc_rtas.o 5obj-$(CONFIG_HVC_RTAS) += hvc_rtas.o
diff --git a/drivers/tty/hvc/hvc_iseries.c b/drivers/tty/hvc/hvc_iseries.c
index 21c54955084e..3f4a897bf4d7 100644
--- a/drivers/tty/hvc/hvc_iseries.c
+++ b/drivers/tty/hvc/hvc_iseries.c
@@ -23,6 +23,7 @@
23#include <linux/types.h> 23#include <linux/types.h>
24#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/module.h>
26#include <linux/spinlock.h> 27#include <linux/spinlock.h>
27#include <linux/console.h> 28#include <linux/console.h>
28 29
diff --git a/drivers/tty/hvc/hvc_opal.c b/drivers/tty/hvc/hvc_opal.c
new file mode 100644
index 000000000000..7b38512d6c41
--- /dev/null
+++ b/drivers/tty/hvc/hvc_opal.c
@@ -0,0 +1,424 @@
1/*
2 * opal driver interface to hvc_console.c
3 *
4 * Copyright 2011 Benjamin Herrenschmidt <benh@kernel.crashing.org>, IBM Corp.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#undef DEBUG
23
24#include <linux/types.h>
25#include <linux/init.h>
26#include <linux/delay.h>
27#include <linux/slab.h>
28#include <linux/console.h>
29#include <linux/of.h>
30#include <linux/of_platform.h>
31
32#include <asm/hvconsole.h>
33#include <asm/prom.h>
34#include <asm/firmware.h>
35#include <asm/hvsi.h>
36#include <asm/udbg.h>
37#include <asm/opal.h>
38
39#include "hvc_console.h"
40
41static const char hvc_opal_name[] = "hvc_opal";
42
43static struct of_device_id hvc_opal_match[] __devinitdata = {
44 { .name = "serial", .compatible = "ibm,opal-console-raw" },
45 { .name = "serial", .compatible = "ibm,opal-console-hvsi" },
46 { },
47};
48
49typedef enum hv_protocol {
50 HV_PROTOCOL_RAW,
51 HV_PROTOCOL_HVSI
52} hv_protocol_t;
53
54struct hvc_opal_priv {
55 hv_protocol_t proto; /* Raw data or HVSI packets */
56 struct hvsi_priv hvsi; /* HVSI specific data */
57};
58static struct hvc_opal_priv *hvc_opal_privs[MAX_NR_HVC_CONSOLES];
59
60/* For early boot console */
61static struct hvc_opal_priv hvc_opal_boot_priv;
62static u32 hvc_opal_boot_termno;
63
64static const struct hv_ops hvc_opal_raw_ops = {
65 .get_chars = opal_get_chars,
66 .put_chars = opal_put_chars,
67 .notifier_add = notifier_add_irq,
68 .notifier_del = notifier_del_irq,
69 .notifier_hangup = notifier_hangup_irq,
70};
71
72static int hvc_opal_hvsi_get_chars(uint32_t vtermno, char *buf, int count)
73{
74 struct hvc_opal_priv *pv = hvc_opal_privs[vtermno];
75
76 if (WARN_ON(!pv))
77 return -ENODEV;
78
79 return hvsilib_get_chars(&pv->hvsi, buf, count);
80}
81
82static int hvc_opal_hvsi_put_chars(uint32_t vtermno, const char *buf, int count)
83{
84 struct hvc_opal_priv *pv = hvc_opal_privs[vtermno];
85
86 if (WARN_ON(!pv))
87 return -ENODEV;
88
89 return hvsilib_put_chars(&pv->hvsi, buf, count);
90}
91
92static int hvc_opal_hvsi_open(struct hvc_struct *hp, int data)
93{
94 struct hvc_opal_priv *pv = hvc_opal_privs[hp->vtermno];
95 int rc;
96
97 pr_devel("HVSI@%x: do open !\n", hp->vtermno);
98
99 rc = notifier_add_irq(hp, data);
100 if (rc)
101 return rc;
102
103 return hvsilib_open(&pv->hvsi, hp);
104}
105
106static void hvc_opal_hvsi_close(struct hvc_struct *hp, int data)
107{
108 struct hvc_opal_priv *pv = hvc_opal_privs[hp->vtermno];
109
110 pr_devel("HVSI@%x: do close !\n", hp->vtermno);
111
112 hvsilib_close(&pv->hvsi, hp);
113
114 notifier_del_irq(hp, data);
115}
116
117void hvc_opal_hvsi_hangup(struct hvc_struct *hp, int data)
118{
119 struct hvc_opal_priv *pv = hvc_opal_privs[hp->vtermno];
120
121 pr_devel("HVSI@%x: do hangup !\n", hp->vtermno);
122
123 hvsilib_close(&pv->hvsi, hp);
124
125 notifier_hangup_irq(hp, data);
126}
127
128static int hvc_opal_hvsi_tiocmget(struct hvc_struct *hp)
129{
130 struct hvc_opal_priv *pv = hvc_opal_privs[hp->vtermno];
131
132 if (!pv)
133 return -EINVAL;
134 return pv->hvsi.mctrl;
135}
136
137static int hvc_opal_hvsi_tiocmset(struct hvc_struct *hp, unsigned int set,
138 unsigned int clear)
139{
140 struct hvc_opal_priv *pv = hvc_opal_privs[hp->vtermno];
141
142 pr_devel("HVSI@%x: Set modem control, set=%x,clr=%x\n",
143 hp->vtermno, set, clear);
144
145 if (set & TIOCM_DTR)
146 hvsilib_write_mctrl(&pv->hvsi, 1);
147 else if (clear & TIOCM_DTR)
148 hvsilib_write_mctrl(&pv->hvsi, 0);
149
150 return 0;
151}
152
153static const struct hv_ops hvc_opal_hvsi_ops = {
154 .get_chars = hvc_opal_hvsi_get_chars,
155 .put_chars = hvc_opal_hvsi_put_chars,
156 .notifier_add = hvc_opal_hvsi_open,
157 .notifier_del = hvc_opal_hvsi_close,
158 .notifier_hangup = hvc_opal_hvsi_hangup,
159 .tiocmget = hvc_opal_hvsi_tiocmget,
160 .tiocmset = hvc_opal_hvsi_tiocmset,
161};
162
163static int __devinit hvc_opal_probe(struct platform_device *dev)
164{
165 const struct hv_ops *ops;
166 struct hvc_struct *hp;
167 struct hvc_opal_priv *pv;
168 hv_protocol_t proto;
169 unsigned int termno, boot = 0;
170 const __be32 *reg;
171
172 if (of_device_is_compatible(dev->dev.of_node, "ibm,opal-console-raw")) {
173 proto = HV_PROTOCOL_RAW;
174 ops = &hvc_opal_raw_ops;
175 } else if (of_device_is_compatible(dev->dev.of_node,
176 "ibm,opal-console-hvsi")) {
177 proto = HV_PROTOCOL_HVSI;
178 ops = &hvc_opal_hvsi_ops;
179 } else {
180 pr_err("hvc_opal: Unkown protocol for %s\n",
181 dev->dev.of_node->full_name);
182 return -ENXIO;
183 }
184
185 reg = of_get_property(dev->dev.of_node, "reg", NULL);
186 termno = reg ? be32_to_cpup(reg) : 0;
187
188 /* Is it our boot one ? */
189 if (hvc_opal_privs[termno] == &hvc_opal_boot_priv) {
190 pv = hvc_opal_privs[termno];
191 boot = 1;
192 } else if (hvc_opal_privs[termno] == NULL) {
193 pv = kzalloc(sizeof(struct hvc_opal_priv), GFP_KERNEL);
194 if (!pv)
195 return -ENOMEM;
196 pv->proto = proto;
197 hvc_opal_privs[termno] = pv;
198 if (proto == HV_PROTOCOL_HVSI)
199 hvsilib_init(&pv->hvsi, opal_get_chars, opal_put_chars,
200 termno, 0);
201
202 /* Instanciate now to establish a mapping index==vtermno */
203 hvc_instantiate(termno, termno, ops);
204 } else {
205 pr_err("hvc_opal: Device %s has duplicate terminal number #%d\n",
206 dev->dev.of_node->full_name, termno);
207 return -ENXIO;
208 }
209
210 pr_info("hvc%d: %s protocol on %s%s\n", termno,
211 proto == HV_PROTOCOL_RAW ? "raw" : "hvsi",
212 dev->dev.of_node->full_name,
213 boot ? " (boot console)" : "");
214
215 /* We don't do IRQ yet */
216 hp = hvc_alloc(termno, 0, ops, MAX_VIO_PUT_CHARS);
217 if (IS_ERR(hp))
218 return PTR_ERR(hp);
219 dev_set_drvdata(&dev->dev, hp);
220
221 return 0;
222}
223
224static int __devexit hvc_opal_remove(struct platform_device *dev)
225{
226 struct hvc_struct *hp = dev_get_drvdata(&dev->dev);
227 int rc, termno;
228
229 termno = hp->vtermno;
230 rc = hvc_remove(hp);
231 if (rc == 0) {
232 if (hvc_opal_privs[termno] != &hvc_opal_boot_priv)
233 kfree(hvc_opal_privs[termno]);
234 hvc_opal_privs[termno] = NULL;
235 }
236 return rc;
237}
238
239static struct platform_driver hvc_opal_driver = {
240 .probe = hvc_opal_probe,
241 .remove = __devexit_p(hvc_opal_remove),
242 .driver = {
243 .name = hvc_opal_name,
244 .owner = THIS_MODULE,
245 .of_match_table = hvc_opal_match,
246 }
247};
248
249static int __init hvc_opal_init(void)
250{
251 if (!firmware_has_feature(FW_FEATURE_OPAL))
252 return -ENODEV;
253
254 /* Register as a vio device to receive callbacks */
255 return platform_driver_register(&hvc_opal_driver);
256}
257module_init(hvc_opal_init);
258
259static void __exit hvc_opal_exit(void)
260{
261 platform_driver_unregister(&hvc_opal_driver);
262}
263module_exit(hvc_opal_exit);
264
265static void udbg_opal_putc(char c)
266{
267 unsigned int termno = hvc_opal_boot_termno;
268 int count = -1;
269
270 if (c == '\n')
271 udbg_opal_putc('\r');
272
273 do {
274 switch(hvc_opal_boot_priv.proto) {
275 case HV_PROTOCOL_RAW:
276 count = opal_put_chars(termno, &c, 1);
277 break;
278 case HV_PROTOCOL_HVSI:
279 count = hvc_opal_hvsi_put_chars(termno, &c, 1);
280 break;
281 }
282 } while(count == 0 || count == -EAGAIN);
283}
284
285static int udbg_opal_getc_poll(void)
286{
287 unsigned int termno = hvc_opal_boot_termno;
288 int rc = 0;
289 char c;
290
291 switch(hvc_opal_boot_priv.proto) {
292 case HV_PROTOCOL_RAW:
293 rc = opal_get_chars(termno, &c, 1);
294 break;
295 case HV_PROTOCOL_HVSI:
296 rc = hvc_opal_hvsi_get_chars(termno, &c, 1);
297 break;
298 }
299 if (!rc)
300 return -1;
301 return c;
302}
303
304static int udbg_opal_getc(void)
305{
306 int ch;
307 for (;;) {
308 ch = udbg_opal_getc_poll();
309 if (ch == -1) {
310 /* This shouldn't be needed...but... */
311 volatile unsigned long delay;
312 for (delay=0; delay < 2000000; delay++)
313 ;
314 } else {
315 return ch;
316 }
317 }
318}
319
320static void udbg_init_opal_common(void)
321{
322 udbg_putc = udbg_opal_putc;
323 udbg_getc = udbg_opal_getc;
324 udbg_getc_poll = udbg_opal_getc_poll;
325 tb_ticks_per_usec = 0x200; /* Make udelay not suck */
326}
327
328void __init hvc_opal_init_early(void)
329{
330 struct device_node *stdout_node = NULL;
331 const u32 *termno;
332 const char *name = NULL;
333 const struct hv_ops *ops;
334 u32 index;
335
336 /* find the boot console from /chosen/stdout */
337 if (of_chosen)
338 name = of_get_property(of_chosen, "linux,stdout-path", NULL);
339 if (name) {
340 stdout_node = of_find_node_by_path(name);
341 if (!stdout_node) {
342 pr_err("hvc_opal: Failed to locate default console!\n");
343 return;
344 }
345 } else {
346 struct device_node *opal, *np;
347
348 /* Current OPAL takeover doesn't provide the stdout
349 * path, so we hard wire it
350 */
351 opal = of_find_node_by_path("/ibm,opal/consoles");
352 if (opal)
353 pr_devel("hvc_opal: Found consoles in new location\n");
354 if (!opal) {
355 opal = of_find_node_by_path("/ibm,opal");
356 if (opal)
357 pr_devel("hvc_opal: "
358 "Found consoles in old location\n");
359 }
360 if (!opal)
361 return;
362 for_each_child_of_node(opal, np) {
363 if (!strcmp(np->name, "serial")) {
364 stdout_node = np;
365 break;
366 }
367 }
368 of_node_put(opal);
369 }
370 if (!stdout_node)
371 return;
372 termno = of_get_property(stdout_node, "reg", NULL);
373 index = termno ? *termno : 0;
374 if (index >= MAX_NR_HVC_CONSOLES)
375 return;
376 hvc_opal_privs[index] = &hvc_opal_boot_priv;
377
378 /* Check the protocol */
379 if (of_device_is_compatible(stdout_node, "ibm,opal-console-raw")) {
380 hvc_opal_boot_priv.proto = HV_PROTOCOL_RAW;
381 ops = &hvc_opal_raw_ops;
382 pr_devel("hvc_opal: Found RAW console\n");
383 }
384 else if (of_device_is_compatible(stdout_node,"ibm,opal-console-hvsi")) {
385 hvc_opal_boot_priv.proto = HV_PROTOCOL_HVSI;
386 ops = &hvc_opal_hvsi_ops;
387 hvsilib_init(&hvc_opal_boot_priv.hvsi, opal_get_chars,
388 opal_put_chars, index, 1);
389 /* HVSI, perform the handshake now */
390 hvsilib_establish(&hvc_opal_boot_priv.hvsi);
391 pr_devel("hvc_opal: Found HVSI console\n");
392 } else
393 goto out;
394 hvc_opal_boot_termno = index;
395 udbg_init_opal_common();
396 add_preferred_console("hvc", index, NULL);
397 hvc_instantiate(index, index, ops);
398out:
399 of_node_put(stdout_node);
400}
401
402#ifdef CONFIG_PPC_EARLY_DEBUG_OPAL_RAW
403void __init udbg_init_debug_opal(void)
404{
405 u32 index = CONFIG_PPC_EARLY_DEBUG_OPAL_VTERMNO;
406 hvc_opal_privs[index] = &hvc_opal_boot_priv;
407 hvc_opal_boot_priv.proto = HV_PROTOCOL_RAW;
408 hvc_opal_boot_termno = index;
409 udbg_init_opal_common();
410}
411#endif /* CONFIG_PPC_EARLY_DEBUG_OPAL_RAW */
412
413#ifdef CONFIG_PPC_EARLY_DEBUG_OPAL_HVSI
414void __init udbg_init_debug_opal_hvsi(void)
415{
416 u32 index = CONFIG_PPC_EARLY_DEBUG_OPAL_VTERMNO;
417 hvc_opal_privs[index] = &hvc_opal_boot_priv;
418 hvc_opal_boot_termno = index;
419 udbg_init_opal_common();
420 hvsilib_init(&hvc_opal_boot_priv.hvsi, opal_get_chars, opal_put_chars,
421 index, 1);
422 hvsilib_establish(&hvc_opal_boot_priv.hvsi);
423}
424#endif /* CONFIG_PPC_EARLY_DEBUG_OPAL_HVSI */
diff --git a/drivers/tty/hvc/hvc_vio.c b/drivers/tty/hvc/hvc_vio.c
index 130aace67f31..fc3c3ad6c072 100644
--- a/drivers/tty/hvc/hvc_vio.c
+++ b/drivers/tty/hvc/hvc_vio.c
@@ -41,6 +41,7 @@
41#include <linux/delay.h> 41#include <linux/delay.h>
42#include <linux/slab.h> 42#include <linux/slab.h>
43#include <linux/console.h> 43#include <linux/console.h>
44#include <linux/module.h>
44 45
45#include <asm/hvconsole.h> 46#include <asm/hvconsole.h>
46#include <asm/vio.h> 47#include <asm/vio.h>
diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
index 55882b5930a6..b9040bec36bd 100644
--- a/drivers/tty/hvc/hvcs.c
+++ b/drivers/tty/hvc/hvcs.c
@@ -1532,7 +1532,7 @@ static int __devinit hvcs_initialize(void)
1532 goto register_fail; 1532 goto register_fail;
1533 } 1533 }
1534 1534
1535 hvcs_pi_buff = kmalloc(PAGE_SIZE, GFP_KERNEL); 1535 hvcs_pi_buff = (unsigned long *) __get_free_page(GFP_KERNEL);
1536 if (!hvcs_pi_buff) { 1536 if (!hvcs_pi_buff) {
1537 rc = -ENOMEM; 1537 rc = -ENOMEM;
1538 goto buff_alloc_fail; 1538 goto buff_alloc_fail;
@@ -1548,7 +1548,7 @@ static int __devinit hvcs_initialize(void)
1548 return 0; 1548 return 0;
1549 1549
1550kthread_fail: 1550kthread_fail:
1551 kfree(hvcs_pi_buff); 1551 free_page((unsigned long)hvcs_pi_buff);
1552buff_alloc_fail: 1552buff_alloc_fail:
1553 tty_unregister_driver(hvcs_tty_driver); 1553 tty_unregister_driver(hvcs_tty_driver);
1554register_fail: 1554register_fail:
@@ -1597,7 +1597,7 @@ static void __exit hvcs_module_exit(void)
1597 kthread_stop(hvcs_task); 1597 kthread_stop(hvcs_task);
1598 1598
1599 spin_lock(&hvcs_pi_lock); 1599 spin_lock(&hvcs_pi_lock);
1600 kfree(hvcs_pi_buff); 1600 free_page((unsigned long)hvcs_pi_buff);
1601 hvcs_pi_buff = NULL; 1601 hvcs_pi_buff = NULL;
1602 spin_unlock(&hvcs_pi_lock); 1602 spin_unlock(&hvcs_pi_lock);
1603 1603
diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
index bd9b09827b24..6f4dd83d8695 100644
--- a/drivers/tty/hvc/hvsi_lib.c
+++ b/drivers/tty/hvc/hvsi_lib.c
@@ -183,7 +183,7 @@ int hvsilib_get_chars(struct hvsi_priv *pv, char *buf, int count)
183 unsigned int tries, read = 0; 183 unsigned int tries, read = 0;
184 184
185 if (WARN_ON(!pv)) 185 if (WARN_ON(!pv))
186 return 0; 186 return -ENXIO;
187 187
188 /* If we aren't open, don't do anything in order to avoid races 188 /* If we aren't open, don't do anything in order to avoid races
189 * with connection establishment. The hvc core will call this 189 * with connection establishment. The hvc core will call this
@@ -234,7 +234,7 @@ int hvsilib_put_chars(struct hvsi_priv *pv, const char *buf, int count)
234 int rc, adjcount = min(count, HVSI_MAX_OUTGOING_DATA); 234 int rc, adjcount = min(count, HVSI_MAX_OUTGOING_DATA);
235 235
236 if (WARN_ON(!pv)) 236 if (WARN_ON(!pv))
237 return 0; 237 return -ENODEV;
238 238
239 dp.hdr.type = VS_DATA_PACKET_HEADER; 239 dp.hdr.type = VS_DATA_PACKET_HEADER;
240 dp.hdr.len = adjcount + sizeof(struct hvsi_header); 240 dp.hdr.len = adjcount + sizeof(struct hvsi_header);
diff --git a/drivers/tty/serial/8250.c b/drivers/tty/serial/8250.c
index a87a56cb5417..eeadf1b8e093 100644
--- a/drivers/tty/serial/8250.c
+++ b/drivers/tty/serial/8250.c
@@ -450,24 +450,6 @@ static void au_serial_out(struct uart_port *p, int offset, int value)
450 __raw_writel(value, p->membase + offset); 450 __raw_writel(value, p->membase + offset);
451} 451}
452 452
453static unsigned int tsi_serial_in(struct uart_port *p, int offset)
454{
455 unsigned int tmp;
456 offset = map_8250_in_reg(p, offset) << p->regshift;
457 if (offset == UART_IIR) {
458 tmp = readl(p->membase + (UART_IIR & ~3));
459 return (tmp >> 16) & 0xff; /* UART_IIR % 4 == 2 */
460 } else
461 return readb(p->membase + offset);
462}
463
464static void tsi_serial_out(struct uart_port *p, int offset, int value)
465{
466 offset = map_8250_out_reg(p, offset) << p->regshift;
467 if (!((offset == UART_IER) && (value & UART_IER_UUE)))
468 writeb(value, p->membase + offset);
469}
470
471static unsigned int io_serial_in(struct uart_port *p, int offset) 453static unsigned int io_serial_in(struct uart_port *p, int offset)
472{ 454{
473 offset = map_8250_in_reg(p, offset) << p->regshift; 455 offset = map_8250_in_reg(p, offset) << p->regshift;
@@ -508,11 +490,6 @@ static void set_io_from_upio(struct uart_port *p)
508 p->serial_out = au_serial_out; 490 p->serial_out = au_serial_out;
509 break; 491 break;
510 492
511 case UPIO_TSI:
512 p->serial_in = tsi_serial_in;
513 p->serial_out = tsi_serial_out;
514 break;
515
516 default: 493 default:
517 p->serial_in = io_serial_in; 494 p->serial_in = io_serial_in;
518 p->serial_out = io_serial_out; 495 p->serial_out = io_serial_out;
diff --git a/drivers/tty/serial/jsm/jsm_driver.c b/drivers/tty/serial/jsm/jsm_driver.c
index 648b6a3efa32..7c867a046c97 100644
--- a/drivers/tty/serial/jsm/jsm_driver.c
+++ b/drivers/tty/serial/jsm/jsm_driver.c
@@ -24,7 +24,7 @@
24 * 24 *
25 * 25 *
26 ***********************************************************************/ 26 ***********************************************************************/
27#include <linux/moduleparam.h> 27#include <linux/module.h>
28#include <linux/pci.h> 28#include <linux/pci.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30 30
diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
index 87e7e6c876d4..2b42a01a81c6 100644
--- a/drivers/tty/serial/kgdboc.c
+++ b/drivers/tty/serial/kgdboc.c
@@ -19,6 +19,7 @@
19#include <linux/console.h> 19#include <linux/console.h>
20#include <linux/vt_kern.h> 20#include <linux/vt_kern.h>
21#include <linux/input.h> 21#include <linux/input.h>
22#include <linux/module.h>
22 23
23#define MAX_CONFIG_LEN 40 24#define MAX_CONFIG_LEN 40
24 25
diff --git a/drivers/tty/serial/max3100.c b/drivers/tty/serial/max3100.c
index 2af5aa5f3a80..8a6cc8c30b5a 100644
--- a/drivers/tty/serial/max3100.c
+++ b/drivers/tty/serial/max3100.c
@@ -43,6 +43,7 @@
43#include <linux/delay.h> 43#include <linux/delay.h>
44#include <linux/slab.h> 44#include <linux/slab.h>
45#include <linux/device.h> 45#include <linux/device.h>
46#include <linux/module.h>
46#include <linux/serial_core.h> 47#include <linux/serial_core.h>
47#include <linux/serial.h> 48#include <linux/serial.h>
48#include <linux/spi/spi.h> 49#include <linux/spi/spi.h>
diff --git a/drivers/tty/serial/max3107-aava.c b/drivers/tty/serial/max3107-aava.c
index d73aadd7a9ad..90c40f22ec70 100644
--- a/drivers/tty/serial/max3107-aava.c
+++ b/drivers/tty/serial/max3107-aava.c
@@ -36,6 +36,7 @@
36#include <linux/platform_device.h> 36#include <linux/platform_device.h>
37#include <linux/gpio.h> 37#include <linux/gpio.h>
38#include <linux/sfi.h> 38#include <linux/sfi.h>
39#include <linux/module.h>
39#include <asm/mrst.h> 40#include <asm/mrst.h>
40#include "max3107.h" 41#include "max3107.h"
41 42
diff --git a/drivers/tty/serial/max3107.c b/drivers/tty/serial/max3107.c
index db00b595cab0..7827000db4f5 100644
--- a/drivers/tty/serial/max3107.c
+++ b/drivers/tty/serial/max3107.c
@@ -36,6 +36,7 @@
36#include <linux/gpio.h> 36#include <linux/gpio.h>
37#include <linux/spi/spi.h> 37#include <linux/spi/spi.h>
38#include <linux/freezer.h> 38#include <linux/freezer.h>
39#include <linux/module.h>
39#include "max3107.h" 40#include "max3107.h"
40 41
41static const struct baud_table brg26_ext[] = { 42static const struct baud_table brg26_ext[] = {
diff --git a/drivers/tty/serial/nwpserial.c b/drivers/tty/serial/nwpserial.c
index 9beaff1cec24..dd4c31d1aee5 100644
--- a/drivers/tty/serial/nwpserial.c
+++ b/drivers/tty/serial/nwpserial.c
@@ -10,6 +10,7 @@
10 * 10 *
11 */ 11 */
12#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/export.h>
13#include <linux/console.h> 14#include <linux/console.h>
14#include <linux/serial.h> 15#include <linux/serial.h>
15#include <linux/serial_reg.h> 16#include <linux/serial_reg.h>
diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 9871c57b348e..1945c70539c2 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1446,12 +1446,8 @@ static bool filter(struct dma_chan *chan, void *slave)
1446 dev_dbg(chan->device->dev, "%s: slave ID %d\n", __func__, 1446 dev_dbg(chan->device->dev, "%s: slave ID %d\n", __func__,
1447 param->slave_id); 1447 param->slave_id);
1448 1448
1449 if (param->dma_dev == chan->device->dev) { 1449 chan->private = param;
1450 chan->private = param; 1450 return true;
1451 return true;
1452 } else {
1453 return false;
1454 }
1455} 1451}
1456 1452
1457static void rx_timer_fn(unsigned long arg) 1453static void rx_timer_fn(unsigned long arg)
@@ -1477,10 +1473,10 @@ static void sci_request_dma(struct uart_port *port)
1477 dma_cap_mask_t mask; 1473 dma_cap_mask_t mask;
1478 int nent; 1474 int nent;
1479 1475
1480 dev_dbg(port->dev, "%s: port %d DMA %p\n", __func__, 1476 dev_dbg(port->dev, "%s: port %d\n", __func__,
1481 port->line, s->cfg->dma_dev); 1477 port->line);
1482 1478
1483 if (!s->cfg->dma_dev) 1479 if (s->cfg->dma_slave_tx <= 0 || s->cfg->dma_slave_rx <= 0)
1484 return; 1480 return;
1485 1481
1486 dma_cap_zero(mask); 1482 dma_cap_zero(mask);
@@ -1490,7 +1486,6 @@ static void sci_request_dma(struct uart_port *port)
1490 1486
1491 /* Slave ID, e.g., SHDMA_SLAVE_SCIF0_TX */ 1487 /* Slave ID, e.g., SHDMA_SLAVE_SCIF0_TX */
1492 param->slave_id = s->cfg->dma_slave_tx; 1488 param->slave_id = s->cfg->dma_slave_tx;
1493 param->dma_dev = s->cfg->dma_dev;
1494 1489
1495 s->cookie_tx = -EINVAL; 1490 s->cookie_tx = -EINVAL;
1496 chan = dma_request_channel(mask, filter, param); 1491 chan = dma_request_channel(mask, filter, param);
@@ -1519,7 +1514,6 @@ static void sci_request_dma(struct uart_port *port)
1519 1514
1520 /* Slave ID, e.g., SHDMA_SLAVE_SCIF0_RX */ 1515 /* Slave ID, e.g., SHDMA_SLAVE_SCIF0_RX */
1521 param->slave_id = s->cfg->dma_slave_rx; 1516 param->slave_id = s->cfg->dma_slave_rx;
1522 param->dma_dev = s->cfg->dma_dev;
1523 1517
1524 chan = dma_request_channel(mask, filter, param); 1518 chan = dma_request_channel(mask, filter, param);
1525 dev_dbg(port->dev, "%s: RX: got channel %p\n", __func__, chan); 1519 dev_dbg(port->dev, "%s: RX: got channel %p\n", __func__, chan);
@@ -1564,9 +1558,6 @@ static void sci_free_dma(struct uart_port *port)
1564{ 1558{
1565 struct sci_port *s = to_sci_port(port); 1559 struct sci_port *s = to_sci_port(port);
1566 1560
1567 if (!s->cfg->dma_dev)
1568 return;
1569
1570 if (s->chan_tx) 1561 if (s->chan_tx)
1571 sci_tx_dma_release(s, false); 1562 sci_tx_dma_release(s, false);
1572 if (s->chan_rx) 1563 if (s->chan_rx)
@@ -1981,9 +1972,9 @@ static int __devinit sci_init_single(struct platform_device *dev,
1981 port->serial_in = sci_serial_in; 1972 port->serial_in = sci_serial_in;
1982 port->serial_out = sci_serial_out; 1973 port->serial_out = sci_serial_out;
1983 1974
1984 if (p->dma_dev) 1975 if (p->dma_slave_tx > 0 && p->dma_slave_rx > 0)
1985 dev_dbg(port->dev, "DMA device %p, tx %d, rx %d\n", 1976 dev_dbg(port->dev, "DMA tx %d, rx %d\n",
1986 p->dma_dev, p->dma_slave_tx, p->dma_slave_rx); 1977 p->dma_slave_tx, p->dma_slave_rx);
1987 1978
1988 return 0; 1979 return 0;
1989} 1980}
diff --git a/drivers/tty/serial/timbuart.c b/drivers/tty/serial/timbuart.c
index a4b63bfeaa2f..e76c8b747fb8 100644
--- a/drivers/tty/serial/timbuart.c
+++ b/drivers/tty/serial/timbuart.c
@@ -29,6 +29,7 @@
29#include <linux/platform_device.h> 29#include <linux/platform_device.h>
30#include <linux/ioport.h> 30#include <linux/ioport.h>
31#include <linux/slab.h> 31#include <linux/slab.h>
32#include <linux/module.h>
32 33
33#include "timbuart.h" 34#include "timbuart.h"
34 35
diff --git a/drivers/tty/serial/xilinx_uartps.c b/drivers/tty/serial/xilinx_uartps.c
index 8c03b127fd03..b627363352e5 100644
--- a/drivers/tty/serial/xilinx_uartps.c
+++ b/drivers/tty/serial/xilinx_uartps.c
@@ -20,6 +20,7 @@
20#include <linux/irq.h> 20#include <linux/irq.h>
21#include <linux/io.h> 21#include <linux/io.h>
22#include <linux/of.h> 22#include <linux/of.h>
23#include <linux/module.h>
23 24
24#define XUARTPS_TTY_NAME "ttyPS" 25#define XUARTPS_TTY_NAME "ttyPS"
25#define XUARTPS_NAME "xuartps" 26#define XUARTPS_NAME "xuartps"
diff --git a/drivers/tty/vt/vc_screen.c b/drivers/tty/vt/vc_screen.c
index 66825c9f516a..7a367ff5122b 100644
--- a/drivers/tty/vt/vc_screen.c
+++ b/drivers/tty/vt/vc_screen.c
@@ -22,6 +22,7 @@
22#include <linux/kernel.h> 22#include <linux/kernel.h>
23#include <linux/major.h> 23#include <linux/major.h>
24#include <linux/errno.h> 24#include <linux/errno.h>
25#include <linux/export.h>
25#include <linux/tty.h> 26#include <linux/tty.h>
26#include <linux/interrupt.h> 27#include <linux/interrupt.h>
27#include <linux/mm.h> 28#include <linux/mm.h>
diff --git a/drivers/uio/uio_pdrv.c b/drivers/uio/uio_pdrv.c
index bdc3db946122..ff5059517351 100644
--- a/drivers/uio/uio_pdrv.c
+++ b/drivers/uio/uio_pdrv.c
@@ -11,6 +11,7 @@
11#include <linux/platform_device.h> 11#include <linux/platform_device.h>
12#include <linux/uio_driver.h> 12#include <linux/uio_driver.h>
13#include <linux/stringify.h> 13#include <linux/stringify.h>
14#include <linux/module.h>
14#include <linux/slab.h> 15#include <linux/slab.h>
15 16
16#define DRIVER_NAME "uio_pdrv" 17#define DRIVER_NAME "uio_pdrv"
diff --git a/drivers/uio/uio_pdrv_genirq.c b/drivers/uio/uio_pdrv_genirq.c
index 0b2ed71e3bfa..25de302009a1 100644
--- a/drivers/uio/uio_pdrv_genirq.c
+++ b/drivers/uio/uio_pdrv_genirq.c
@@ -18,6 +18,7 @@
18#include <linux/uio_driver.h> 18#include <linux/uio_driver.h>
19#include <linux/spinlock.h> 19#include <linux/spinlock.h>
20#include <linux/bitops.h> 20#include <linux/bitops.h>
21#include <linux/module.h>
21#include <linux/interrupt.h> 22#include <linux/interrupt.h>
22#include <linux/stringify.h> 23#include <linux/stringify.h>
23#include <linux/pm_runtime.h> 24#include <linux/pm_runtime.h>
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index 4ac2750491de..791f11bed606 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -62,7 +62,6 @@ config USB_ARCH_HAS_EHCI
62 boolean 62 boolean
63 default y if FSL_SOC 63 default y if FSL_SOC
64 default y if PPC_MPC512x 64 default y if PPC_MPC512x
65 default y if SOC_AU1200
66 default y if ARCH_IXP4XX 65 default y if ARCH_IXP4XX
67 default y if ARCH_W90X900 66 default y if ARCH_W90X900
68 default y if ARCH_AT91SAM9G45 67 default y if ARCH_AT91SAM9G45
diff --git a/drivers/usb/c67x00/c67x00-drv.c b/drivers/usb/c67x00/c67x00-drv.c
index 62050f7a4f97..57ae44cd0b88 100644
--- a/drivers/usb/c67x00/c67x00-drv.c
+++ b/drivers/usb/c67x00/c67x00-drv.c
@@ -38,6 +38,7 @@
38#include <linux/io.h> 38#include <linux/io.h>
39#include <linux/list.h> 39#include <linux/list.h>
40#include <linux/slab.h> 40#include <linux/slab.h>
41#include <linux/module.h>
41#include <linux/usb.h> 42#include <linux/usb.h>
42#include <linux/usb/c67x00.h> 43#include <linux/usb/c67x00.h>
43 44
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index 3b029a0a4787..45887a0ff873 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -24,6 +24,7 @@
24 24
25#include <linux/device.h> 25#include <linux/device.h>
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/export.h>
27#include <linux/usb.h> 28#include <linux/usb.h>
28#include <linux/usb/quirks.h> 29#include <linux/usb/quirks.h>
29#include <linux/usb/hcd.h> 30#include <linux/usb/hcd.h>
@@ -1667,6 +1668,11 @@ int usb_runtime_suspend(struct device *dev)
1667 return -EAGAIN; 1668 return -EAGAIN;
1668 1669
1669 status = usb_suspend_both(udev, PMSG_AUTO_SUSPEND); 1670 status = usb_suspend_both(udev, PMSG_AUTO_SUSPEND);
1671
1672 /* Allow a retry if autosuspend failed temporarily */
1673 if (status == -EAGAIN || status == -EBUSY)
1674 usb_mark_last_busy(udev);
1675
1670 /* The PM core reacts badly unless the return code is 0, 1676 /* The PM core reacts badly unless the return code is 0,
1671 * -EAGAIN, or -EBUSY, so always return -EBUSY on an error. 1677 * -EAGAIN, or -EBUSY, so always return -EBUSY on an error.
1672 */ 1678 */
diff --git a/drivers/usb/core/notify.c b/drivers/usb/core/notify.c
index 7542dce3f5a1..7728c91dfa2e 100644
--- a/drivers/usb/core/notify.c
+++ b/drivers/usb/core/notify.c
@@ -10,6 +10,7 @@
10 10
11 11
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/export.h>
13#include <linux/notifier.h> 14#include <linux/notifier.h>
14#include <linux/usb.h> 15#include <linux/usb.h>
15#include <linux/mutex.h> 16#include <linux/mutex.h>
diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c
index 672674c2fb3d..725550f06fab 100644
--- a/drivers/usb/gadget/cdc2.c
+++ b/drivers/usb/gadget/cdc2.c
@@ -12,6 +12,7 @@
12 12
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/utsname.h> 14#include <linux/utsname.h>
15#include <linux/module.h>
15 16
16#include "u_ether.h" 17#include "u_ether.h"
17#include "u_serial.h" 18#include "u_serial.h"
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 8a5529d214fb..f71b0787983f 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -14,6 +14,7 @@
14#include <linux/kallsyms.h> 14#include <linux/kallsyms.h>
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <linux/module.h>
17#include <linux/device.h> 18#include <linux/device.h>
18#include <linux/utsname.h> 19#include <linux/utsname.h>
19 20
diff --git a/drivers/usb/gadget/dbgp.c b/drivers/usb/gadget/dbgp.c
index f855ecf7a637..6256420089f3 100644
--- a/drivers/usb/gadget/dbgp.c
+++ b/drivers/usb/gadget/dbgp.c
@@ -9,6 +9,7 @@
9/* verbose messages */ 9/* verbose messages */
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <linux/device.h> 11#include <linux/device.h>
12#include <linux/module.h>
12#include <linux/usb/ch9.h> 13#include <linux/usb/ch9.h>
13#include <linux/usb/gadget.h> 14#include <linux/usb/gadget.h>
14 15
diff --git a/drivers/usb/gadget/f_fs.c b/drivers/usb/gadget/f_fs.c
index 6b1c20b6c9b2..acb38004eec0 100644
--- a/drivers/usb/gadget/f_fs.c
+++ b/drivers/usb/gadget/f_fs.c
@@ -20,6 +20,7 @@
20 20
21#include <linux/blkdev.h> 21#include <linux/blkdev.h>
22#include <linux/pagemap.h> 22#include <linux/pagemap.h>
23#include <linux/export.h>
23#include <asm/unaligned.h> 24#include <asm/unaligned.h>
24 25
25#include <linux/usb/composite.h> 26#include <linux/usb/composite.h>
diff --git a/drivers/usb/gadget/f_obex.c b/drivers/usb/gadget/f_obex.c
index e3f74bf5da2d..5f400f66aa9b 100644
--- a/drivers/usb/gadget/f_obex.c
+++ b/drivers/usb/gadget/f_obex.c
@@ -17,6 +17,7 @@
17#include <linux/slab.h> 17#include <linux/slab.h>
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/device.h> 19#include <linux/device.h>
20#include <linux/module.h>
20 21
21#include "u_serial.h" 22#include "u_serial.h"
22#include "gadget_chips.h" 23#include "gadget_chips.h"
diff --git a/drivers/usb/gadget/f_sourcesink.c b/drivers/usb/gadget/f_sourcesink.c
index 168906d2b5d4..7aa7ac82c02c 100644
--- a/drivers/usb/gadget/f_sourcesink.c
+++ b/drivers/usb/gadget/f_sourcesink.c
@@ -15,6 +15,7 @@
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/device.h> 17#include <linux/device.h>
18#include <linux/module.h>
18 19
19#include "g_zero.h" 20#include "g_zero.h"
20#include "gadget_chips.h" 21#include "gadget_chips.h"
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index 3ac4f51cd0bb..f7e39b0365ce 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -243,6 +243,7 @@
243#include <linux/kref.h> 243#include <linux/kref.h>
244#include <linux/kthread.h> 244#include <linux/kthread.h>
245#include <linux/limits.h> 245#include <linux/limits.h>
246#include <linux/module.h>
246#include <linux/rwsem.h> 247#include <linux/rwsem.h>
247#include <linux/slab.h> 248#include <linux/slab.h>
248#include <linux/spinlock.h> 249#include <linux/spinlock.h>
diff --git a/drivers/usb/gadget/fusb300_udc.c b/drivers/usb/gadget/fusb300_udc.c
index e593f2849fa9..74da206c8406 100644
--- a/drivers/usb/gadget/fusb300_udc.c
+++ b/drivers/usb/gadget/fusb300_udc.c
@@ -13,6 +13,7 @@
13#include <linux/err.h> 13#include <linux/err.h>
14#include <linux/interrupt.h> 14#include <linux/interrupt.h>
15#include <linux/io.h> 15#include <linux/io.h>
16#include <linux/module.h>
16#include <linux/platform_device.h> 17#include <linux/platform_device.h>
17#include <linux/usb/ch9.h> 18#include <linux/usb/ch9.h>
18#include <linux/usb/gadget.h> 19#include <linux/usb/gadget.h>
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c
index 8fcde37aa6d4..681bd038b1d8 100644
--- a/drivers/usb/gadget/gmidi.c
+++ b/drivers/usb/gadget/gmidi.c
@@ -23,6 +23,7 @@
23#include <linux/kernel.h> 23#include <linux/kernel.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/utsname.h> 25#include <linux/utsname.h>
26#include <linux/module.h>
26#include <linux/device.h> 27#include <linux/device.h>
27 28
28#include <sound/core.h> 29#include <sound/core.h>
diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
index 3a4a664bab44..6597a6813e43 100644
--- a/drivers/usb/gadget/u_serial.c
+++ b/drivers/usb/gadget/u_serial.c
@@ -25,6 +25,7 @@
25#include <linux/tty.h> 25#include <linux/tty.h>
26#include <linux/tty_flip.h> 26#include <linux/tty_flip.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/export.h>
28 29
29#include "u_serial.h" 30#include "u_serial.h"
30 31
diff --git a/drivers/usb/host/Makefile b/drivers/usb/host/Makefile
index ed48a5d79e16..7ca290fcb070 100644
--- a/drivers/usb/host/Makefile
+++ b/drivers/usb/host/Makefile
@@ -36,3 +36,4 @@ obj-$(CONFIG_USB_HWA_HCD) += hwa-hc.o
36obj-$(CONFIG_USB_IMX21_HCD) += imx21-hcd.o 36obj-$(CONFIG_USB_IMX21_HCD) += imx21-hcd.o
37obj-$(CONFIG_USB_FSL_MPH_DR_OF) += fsl-mph-dr-of.o 37obj-$(CONFIG_USB_FSL_MPH_DR_OF) += fsl-mph-dr-of.o
38obj-$(CONFIG_USB_OCTEON2_COMMON) += octeon2-common.o 38obj-$(CONFIG_USB_OCTEON2_COMMON) += octeon2-common.o
39obj-$(CONFIG_MIPS_ALCHEMY) += alchemy-common.o
diff --git a/drivers/usb/host/alchemy-common.c b/drivers/usb/host/alchemy-common.c
new file mode 100644
index 000000000000..b4192c964d0d
--- /dev/null
+++ b/drivers/usb/host/alchemy-common.c
@@ -0,0 +1,337 @@
1/*
2 * USB block power/access management abstraction.
3 *
4 * Au1000+: The OHCI block control register is at the far end of the OHCI memory
5 * area. Au1550 has OHCI on different base address. No need to handle
6 * UDC here.
7 * Au1200: one register to control access and clocks to O/EHCI, UDC and OTG
8 * as well as the PHY for EHCI and UDC.
9 *
10 */
11
12#include <linux/init.h>
13#include <linux/io.h>
14#include <linux/module.h>
15#include <linux/spinlock.h>
16#include <linux/syscore_ops.h>
17#include <asm/mach-au1x00/au1000.h>
18
19/* control register offsets */
20#define AU1000_OHCICFG 0x7fffc
21#define AU1550_OHCICFG 0x07ffc
22#define AU1200_USBCFG 0x04
23
24/* Au1000 USB block config bits */
25#define USBHEN_RD (1 << 4) /* OHCI reset-done indicator */
26#define USBHEN_CE (1 << 3) /* OHCI block clock enable */
27#define USBHEN_E (1 << 2) /* OHCI block enable */
28#define USBHEN_C (1 << 1) /* OHCI block coherency bit */
29#define USBHEN_BE (1 << 0) /* OHCI Big-Endian */
30
31/* Au1200 USB config bits */
32#define USBCFG_PFEN (1 << 31) /* prefetch enable (undoc) */
33#define USBCFG_RDCOMB (1 << 30) /* read combining (undoc) */
34#define USBCFG_UNKNOWN (5 << 20) /* unknown, leave this way */
35#define USBCFG_SSD (1 << 23) /* serial short detect en */
36#define USBCFG_PPE (1 << 19) /* HS PHY PLL */
37#define USBCFG_UCE (1 << 18) /* UDC clock enable */
38#define USBCFG_ECE (1 << 17) /* EHCI clock enable */
39#define USBCFG_OCE (1 << 16) /* OHCI clock enable */
40#define USBCFG_FLA(x) (((x) & 0x3f) << 8)
41#define USBCFG_UCAM (1 << 7) /* coherent access (undoc) */
42#define USBCFG_GME (1 << 6) /* OTG mem access */
43#define USBCFG_DBE (1 << 5) /* UDC busmaster enable */
44#define USBCFG_DME (1 << 4) /* UDC mem enable */
45#define USBCFG_EBE (1 << 3) /* EHCI busmaster enable */
46#define USBCFG_EME (1 << 2) /* EHCI mem enable */
47#define USBCFG_OBE (1 << 1) /* OHCI busmaster enable */
48#define USBCFG_OME (1 << 0) /* OHCI mem enable */
49#define USBCFG_INIT_AU1200 (USBCFG_PFEN | USBCFG_RDCOMB | USBCFG_UNKNOWN |\
50 USBCFG_SSD | USBCFG_FLA(0x20) | USBCFG_UCAM | \
51 USBCFG_GME | USBCFG_DBE | USBCFG_DME | \
52 USBCFG_EBE | USBCFG_EME | USBCFG_OBE | \
53 USBCFG_OME)
54
55
56static DEFINE_SPINLOCK(alchemy_usb_lock);
57
58
59static inline void __au1200_ohci_control(void __iomem *base, int enable)
60{
61 unsigned long r = __raw_readl(base + AU1200_USBCFG);
62 if (enable) {
63 __raw_writel(r | USBCFG_OCE, base + AU1200_USBCFG);
64 wmb();
65 udelay(2000);
66 } else {
67 __raw_writel(r & ~USBCFG_OCE, base + AU1200_USBCFG);
68 wmb();
69 udelay(1000);
70 }
71}
72
73static inline void __au1200_ehci_control(void __iomem *base, int enable)
74{
75 unsigned long r = __raw_readl(base + AU1200_USBCFG);
76 if (enable) {
77 __raw_writel(r | USBCFG_ECE | USBCFG_PPE, base + AU1200_USBCFG);
78 wmb();
79 udelay(1000);
80 } else {
81 if (!(r & USBCFG_UCE)) /* UDC also off? */
82 r &= ~USBCFG_PPE; /* yes: disable HS PHY PLL */
83 __raw_writel(r & ~USBCFG_ECE, base + AU1200_USBCFG);
84 wmb();
85 udelay(1000);
86 }
87}
88
89static inline void __au1200_udc_control(void __iomem *base, int enable)
90{
91 unsigned long r = __raw_readl(base + AU1200_USBCFG);
92 if (enable) {
93 __raw_writel(r | USBCFG_UCE | USBCFG_PPE, base + AU1200_USBCFG);
94 wmb();
95 } else {
96 if (!(r & USBCFG_ECE)) /* EHCI also off? */
97 r &= ~USBCFG_PPE; /* yes: disable HS PHY PLL */
98 __raw_writel(r & ~USBCFG_UCE, base + AU1200_USBCFG);
99 wmb();
100 }
101}
102
103static inline int au1200_coherency_bug(void)
104{
105#if defined(CONFIG_DMA_COHERENT)
106 /* Au1200 AB USB does not support coherent memory */
107 if (!(read_c0_prid() & 0xff)) {
108 printk(KERN_INFO "Au1200 USB: this is chip revision AB !!\n");
109 printk(KERN_INFO "Au1200 USB: update your board or re-configure"
110 " the kernel\n");
111 return -ENODEV;
112 }
113#endif
114 return 0;
115}
116
117static inline int au1200_usb_control(int block, int enable)
118{
119 void __iomem *base =
120 (void __iomem *)KSEG1ADDR(AU1200_USB_CTL_PHYS_ADDR);
121 int ret = 0;
122
123 switch (block) {
124 case ALCHEMY_USB_OHCI0:
125 ret = au1200_coherency_bug();
126 if (ret && enable)
127 goto out;
128 __au1200_ohci_control(base, enable);
129 break;
130 case ALCHEMY_USB_UDC0:
131 __au1200_udc_control(base, enable);
132 break;
133 case ALCHEMY_USB_EHCI0:
134 ret = au1200_coherency_bug();
135 if (ret && enable)
136 goto out;
137 __au1200_ehci_control(base, enable);
138 break;
139 default:
140 ret = -ENODEV;
141 }
142out:
143 return ret;
144}
145
146
147/* initialize USB block(s) to a known working state */
148static inline void au1200_usb_init(void)
149{
150 void __iomem *base =
151 (void __iomem *)KSEG1ADDR(AU1200_USB_CTL_PHYS_ADDR);
152 __raw_writel(USBCFG_INIT_AU1200, base + AU1200_USBCFG);
153 wmb();
154 udelay(1000);
155}
156
157static inline void au1000_usb_init(unsigned long rb, int reg)
158{
159 void __iomem *base = (void __iomem *)KSEG1ADDR(rb + reg);
160 unsigned long r = __raw_readl(base);
161
162#if defined(__BIG_ENDIAN)
163 r |= USBHEN_BE;
164#endif
165 r |= USBHEN_C;
166
167 __raw_writel(r, base);
168 wmb();
169 udelay(1000);
170}
171
172
173static inline void __au1xx0_ohci_control(int enable, unsigned long rb, int creg)
174{
175 void __iomem *base = (void __iomem *)KSEG1ADDR(rb);
176 unsigned long r = __raw_readl(base + creg);
177
178 if (enable) {
179 __raw_writel(r | USBHEN_CE, base + creg);
180 wmb();
181 udelay(1000);
182 __raw_writel(r | USBHEN_CE | USBHEN_E, base + creg);
183 wmb();
184 udelay(1000);
185
186 /* wait for reset complete (read reg twice: au1500 erratum) */
187 while (__raw_readl(base + creg),
188 !(__raw_readl(base + creg) & USBHEN_RD))
189 udelay(1000);
190 } else {
191 __raw_writel(r & ~(USBHEN_CE | USBHEN_E), base + creg);
192 wmb();
193 }
194}
195
196static inline int au1000_usb_control(int block, int enable, unsigned long rb,
197 int creg)
198{
199 int ret = 0;
200
201 switch (block) {
202 case ALCHEMY_USB_OHCI0:
203 __au1xx0_ohci_control(enable, rb, creg);
204 break;
205 default:
206 ret = -ENODEV;
207 }
208 return ret;
209}
210
211/*
212 * alchemy_usb_control - control Alchemy on-chip USB blocks
213 * @block: USB block to target
214 * @enable: set 1 to enable a block, 0 to disable
215 */
216int alchemy_usb_control(int block, int enable)
217{
218 unsigned long flags;
219 int ret;
220
221 spin_lock_irqsave(&alchemy_usb_lock, flags);
222 switch (alchemy_get_cputype()) {
223 case ALCHEMY_CPU_AU1000:
224 case ALCHEMY_CPU_AU1500:
225 case ALCHEMY_CPU_AU1100:
226 ret = au1000_usb_control(block, enable,
227 AU1000_USB_OHCI_PHYS_ADDR, AU1000_OHCICFG);
228 break;
229 case ALCHEMY_CPU_AU1550:
230 ret = au1000_usb_control(block, enable,
231 AU1550_USB_OHCI_PHYS_ADDR, AU1550_OHCICFG);
232 break;
233 case ALCHEMY_CPU_AU1200:
234 ret = au1200_usb_control(block, enable);
235 break;
236 default:
237 ret = -ENODEV;
238 }
239 spin_unlock_irqrestore(&alchemy_usb_lock, flags);
240 return ret;
241}
242EXPORT_SYMBOL_GPL(alchemy_usb_control);
243
244
245static unsigned long alchemy_usb_pmdata[2];
246
247static void au1000_usb_pm(unsigned long br, int creg, int susp)
248{
249 void __iomem *base = (void __iomem *)KSEG1ADDR(br);
250
251 if (susp) {
252 alchemy_usb_pmdata[0] = __raw_readl(base + creg);
253 /* There appears to be some undocumented reset register.... */
254 __raw_writel(0, base + 0x04);
255 wmb();
256 __raw_writel(0, base + creg);
257 wmb();
258 } else {
259 __raw_writel(alchemy_usb_pmdata[0], base + creg);
260 wmb();
261 }
262}
263
264static void au1200_usb_pm(int susp)
265{
266 void __iomem *base =
267 (void __iomem *)KSEG1ADDR(AU1200_USB_OTG_PHYS_ADDR);
268 if (susp) {
269 /* save OTG_CAP/MUX registers which indicate port routing */
270 /* FIXME: write an OTG driver to do that */
271 alchemy_usb_pmdata[0] = __raw_readl(base + 0x00);
272 alchemy_usb_pmdata[1] = __raw_readl(base + 0x04);
273 } else {
274 /* restore access to all MMIO areas */
275 au1200_usb_init();
276
277 /* restore OTG_CAP/MUX registers */
278 __raw_writel(alchemy_usb_pmdata[0], base + 0x00);
279 __raw_writel(alchemy_usb_pmdata[1], base + 0x04);
280 wmb();
281 }
282}
283
284static void alchemy_usb_pm(int susp)
285{
286 switch (alchemy_get_cputype()) {
287 case ALCHEMY_CPU_AU1000:
288 case ALCHEMY_CPU_AU1500:
289 case ALCHEMY_CPU_AU1100:
290 au1000_usb_pm(AU1000_USB_OHCI_PHYS_ADDR, AU1000_OHCICFG, susp);
291 break;
292 case ALCHEMY_CPU_AU1550:
293 au1000_usb_pm(AU1550_USB_OHCI_PHYS_ADDR, AU1550_OHCICFG, susp);
294 break;
295 case ALCHEMY_CPU_AU1200:
296 au1200_usb_pm(susp);
297 break;
298 }
299}
300
301static int alchemy_usb_suspend(void)
302{
303 alchemy_usb_pm(1);
304 return 0;
305}
306
307static void alchemy_usb_resume(void)
308{
309 alchemy_usb_pm(0);
310}
311
312static struct syscore_ops alchemy_usb_pm_ops = {
313 .suspend = alchemy_usb_suspend,
314 .resume = alchemy_usb_resume,
315};
316
317static int __init alchemy_usb_init(void)
318{
319 switch (alchemy_get_cputype()) {
320 case ALCHEMY_CPU_AU1000:
321 case ALCHEMY_CPU_AU1500:
322 case ALCHEMY_CPU_AU1100:
323 au1000_usb_init(AU1000_USB_OHCI_PHYS_ADDR, AU1000_OHCICFG);
324 break;
325 case ALCHEMY_CPU_AU1550:
326 au1000_usb_init(AU1550_USB_OHCI_PHYS_ADDR, AU1550_OHCICFG);
327 break;
328 case ALCHEMY_CPU_AU1200:
329 au1200_usb_init();
330 break;
331 }
332
333 register_syscore_ops(&alchemy_usb_pm_ops);
334
335 return 0;
336}
337arch_initcall(alchemy_usb_init);
diff --git a/drivers/usb/host/ehci-au1xxx.c b/drivers/usb/host/ehci-au1xxx.c
index 65719e8d24e4..18bafa99fe57 100644
--- a/drivers/usb/host/ehci-au1xxx.c
+++ b/drivers/usb/host/ehci-au1xxx.c
@@ -14,61 +14,9 @@
14#include <linux/platform_device.h> 14#include <linux/platform_device.h>
15#include <asm/mach-au1x00/au1000.h> 15#include <asm/mach-au1x00/au1000.h>
16 16
17#define USB_HOST_CONFIG (USB_MSR_BASE + USB_MSR_MCFG)
18#define USB_MCFG_PFEN (1<<31)
19#define USB_MCFG_RDCOMB (1<<30)
20#define USB_MCFG_SSDEN (1<<23)
21#define USB_MCFG_PHYPLLEN (1<<19)
22#define USB_MCFG_UCECLKEN (1<<18)
23#define USB_MCFG_EHCCLKEN (1<<17)
24#ifdef CONFIG_DMA_COHERENT
25#define USB_MCFG_UCAM (1<<7)
26#else
27#define USB_MCFG_UCAM (0)
28#endif
29#define USB_MCFG_EBMEN (1<<3)
30#define USB_MCFG_EMEMEN (1<<2)
31
32#define USBH_ENABLE_CE (USB_MCFG_PHYPLLEN | USB_MCFG_EHCCLKEN)
33#define USBH_ENABLE_INIT (USB_MCFG_PFEN | USB_MCFG_RDCOMB | \
34 USBH_ENABLE_CE | USB_MCFG_SSDEN | \
35 USB_MCFG_UCAM | USB_MCFG_EBMEN | \
36 USB_MCFG_EMEMEN)
37
38#define USBH_DISABLE (USB_MCFG_EBMEN | USB_MCFG_EMEMEN)
39 17
40extern int usb_disabled(void); 18extern int usb_disabled(void);
41 19
42static void au1xxx_start_ehc(void)
43{
44 /* enable clock to EHCI block and HS PHY PLL*/
45 au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_CE, USB_HOST_CONFIG);
46 au_sync();
47 udelay(1000);
48
49 /* enable EHCI mmio */
50 au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_INIT, USB_HOST_CONFIG);
51 au_sync();
52 udelay(1000);
53}
54
55static void au1xxx_stop_ehc(void)
56{
57 unsigned long c;
58
59 /* Disable mem */
60 au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_DISABLE, USB_HOST_CONFIG);
61 au_sync();
62 udelay(1000);
63
64 /* Disable EHC clock. If the HS PHY is unused disable it too. */
65 c = au_readl(USB_HOST_CONFIG) & ~USB_MCFG_EHCCLKEN;
66 if (!(c & USB_MCFG_UCECLKEN)) /* UDC disabled? */
67 c &= ~USB_MCFG_PHYPLLEN; /* yes: disable HS PHY PLL */
68 au_writel(c, USB_HOST_CONFIG);
69 au_sync();
70}
71
72static int au1xxx_ehci_setup(struct usb_hcd *hcd) 20static int au1xxx_ehci_setup(struct usb_hcd *hcd)
73{ 21{
74 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 22 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
@@ -136,16 +84,6 @@ static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
136 if (usb_disabled()) 84 if (usb_disabled())
137 return -ENODEV; 85 return -ENODEV;
138 86
139#if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT)
140 /* Au1200 AB USB does not support coherent memory */
141 if (!(read_c0_prid() & 0xff)) {
142 printk(KERN_INFO "%s: this is chip revision AB!\n", pdev->name);
143 printk(KERN_INFO "%s: update your board or re-configure"
144 " the kernel\n", pdev->name);
145 return -ENODEV;
146 }
147#endif
148
149 if (pdev->resource[1].flags != IORESOURCE_IRQ) { 87 if (pdev->resource[1].flags != IORESOURCE_IRQ) {
150 pr_debug("resource[1] is not IORESOURCE_IRQ"); 88 pr_debug("resource[1] is not IORESOURCE_IRQ");
151 return -ENOMEM; 89 return -ENOMEM;
@@ -171,7 +109,11 @@ static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
171 goto err2; 109 goto err2;
172 } 110 }
173 111
174 au1xxx_start_ehc(); 112 if (alchemy_usb_control(ALCHEMY_USB_EHCI0, 1)) {
113 printk(KERN_INFO "%s: controller init failed!\n", pdev->name);
114 ret = -ENODEV;
115 goto err3;
116 }
175 117
176 ehci = hcd_to_ehci(hcd); 118 ehci = hcd_to_ehci(hcd);
177 ehci->caps = hcd->regs; 119 ehci->caps = hcd->regs;
@@ -187,7 +129,8 @@ static int ehci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
187 return ret; 129 return ret;
188 } 130 }
189 131
190 au1xxx_stop_ehc(); 132 alchemy_usb_control(ALCHEMY_USB_EHCI0, 0);
133err3:
191 iounmap(hcd->regs); 134 iounmap(hcd->regs);
192err2: 135err2:
193 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 136 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
@@ -201,10 +144,10 @@ static int ehci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
201 struct usb_hcd *hcd = platform_get_drvdata(pdev); 144 struct usb_hcd *hcd = platform_get_drvdata(pdev);
202 145
203 usb_remove_hcd(hcd); 146 usb_remove_hcd(hcd);
147 alchemy_usb_control(ALCHEMY_USB_EHCI0, 0);
204 iounmap(hcd->regs); 148 iounmap(hcd->regs);
205 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 149 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
206 usb_put_hcd(hcd); 150 usb_put_hcd(hcd);
207 au1xxx_stop_ehc();
208 platform_set_drvdata(pdev, NULL); 151 platform_set_drvdata(pdev, NULL);
209 152
210 return 0; 153 return 0;
@@ -236,7 +179,7 @@ static int ehci_hcd_au1xxx_drv_suspend(struct device *dev)
236 // could save FLADJ in case of Vaux power loss 179 // could save FLADJ in case of Vaux power loss
237 // ... we'd only use it to handle clock skew 180 // ... we'd only use it to handle clock skew
238 181
239 au1xxx_stop_ehc(); 182 alchemy_usb_control(ALCHEMY_USB_EHCI0, 0);
240 183
241 return rc; 184 return rc;
242} 185}
@@ -246,7 +189,7 @@ static int ehci_hcd_au1xxx_drv_resume(struct device *dev)
246 struct usb_hcd *hcd = dev_get_drvdata(dev); 189 struct usb_hcd *hcd = dev_get_drvdata(dev);
247 struct ehci_hcd *ehci = hcd_to_ehci(hcd); 190 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
248 191
249 au1xxx_start_ehc(); 192 alchemy_usb_control(ALCHEMY_USB_EHCI0, 1);
250 193
251 // maybe restore FLADJ 194 // maybe restore FLADJ
252 195
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 59e81615e09c..3ff9f82f7263 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -1224,7 +1224,7 @@ MODULE_LICENSE ("GPL");
1224#define PLATFORM_DRIVER ehci_hcd_sh_driver 1224#define PLATFORM_DRIVER ehci_hcd_sh_driver
1225#endif 1225#endif
1226 1226
1227#ifdef CONFIG_SOC_AU1200 1227#ifdef CONFIG_MIPS_ALCHEMY
1228#include "ehci-au1xxx.c" 1228#include "ehci-au1xxx.c"
1229#define PLATFORM_DRIVER ehci_hcd_au1xxx_driver 1229#define PLATFORM_DRIVER ehci_hcd_au1xxx_driver
1230#endif 1230#endif
diff --git a/drivers/usb/host/fsl-mph-dr-of.c b/drivers/usb/host/fsl-mph-dr-of.c
index 79a66d622f9c..9037035ad1e4 100644
--- a/drivers/usb/host/fsl-mph-dr-of.c
+++ b/drivers/usb/host/fsl-mph-dr-of.c
@@ -16,6 +16,7 @@
16#include <linux/io.h> 16#include <linux/io.h>
17#include <linux/of_platform.h> 17#include <linux/of_platform.h>
18#include <linux/clk.h> 18#include <linux/clk.h>
19#include <linux/module.h>
19 20
20struct fsl_usb2_dev_data { 21struct fsl_usb2_dev_data {
21 char *dr_mode; /* controller mode */ 22 char *dr_mode; /* controller mode */
diff --git a/drivers/usb/host/isp1760-if.c b/drivers/usb/host/isp1760-if.c
index 2c7fc830c9e4..a7dc1e1d45f2 100644
--- a/drivers/usb/host/isp1760-if.c
+++ b/drivers/usb/host/isp1760-if.c
@@ -11,6 +11,7 @@
11 11
12#include <linux/usb.h> 12#include <linux/usb.h>
13#include <linux/io.h> 13#include <linux/io.h>
14#include <linux/module.h>
14#include <linux/platform_device.h> 15#include <linux/platform_device.h>
15#include <linux/usb/isp1760.h> 16#include <linux/usb/isp1760.h>
16#include <linux/usb/hcd.h> 17#include <linux/usb/hcd.h>
diff --git a/drivers/usb/host/ohci-au1xxx.c b/drivers/usb/host/ohci-au1xxx.c
index 6b7bc50dfeaa..9b66df8278f3 100644
--- a/drivers/usb/host/ohci-au1xxx.c
+++ b/drivers/usb/host/ohci-au1xxx.c
@@ -23,92 +23,9 @@
23 23
24#include <asm/mach-au1x00/au1000.h> 24#include <asm/mach-au1x00/au1000.h>
25 25
26#ifndef CONFIG_SOC_AU1200
27
28#define USBH_ENABLE_BE (1<<0)
29#define USBH_ENABLE_C (1<<1)
30#define USBH_ENABLE_E (1<<2)
31#define USBH_ENABLE_CE (1<<3)
32#define USBH_ENABLE_RD (1<<4)
33
34#ifdef __LITTLE_ENDIAN
35#define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C)
36#elif defined(__BIG_ENDIAN)
37#define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C | \
38 USBH_ENABLE_BE)
39#else
40#error not byte order defined
41#endif
42
43#else /* Au1200 */
44
45#define USB_HOST_CONFIG (USB_MSR_BASE + USB_MSR_MCFG)
46#define USB_MCFG_PFEN (1<<31)
47#define USB_MCFG_RDCOMB (1<<30)
48#define USB_MCFG_SSDEN (1<<23)
49#define USB_MCFG_OHCCLKEN (1<<16)
50#ifdef CONFIG_DMA_COHERENT
51#define USB_MCFG_UCAM (1<<7)
52#else
53#define USB_MCFG_UCAM (0)
54#endif
55#define USB_MCFG_OBMEN (1<<1)
56#define USB_MCFG_OMEMEN (1<<0)
57
58#define USBH_ENABLE_CE USB_MCFG_OHCCLKEN
59
60#define USBH_ENABLE_INIT (USB_MCFG_PFEN | USB_MCFG_RDCOMB | \
61 USBH_ENABLE_CE | USB_MCFG_SSDEN | \
62 USB_MCFG_UCAM | \
63 USB_MCFG_OBMEN | USB_MCFG_OMEMEN)
64
65#define USBH_DISABLE (USB_MCFG_OBMEN | USB_MCFG_OMEMEN)
66
67#endif /* Au1200 */
68 26
69extern int usb_disabled(void); 27extern int usb_disabled(void);
70 28
71static void au1xxx_start_ohc(void)
72{
73 /* enable host controller */
74#ifndef CONFIG_SOC_AU1200
75 au_writel(USBH_ENABLE_CE, USB_HOST_CONFIG);
76 au_sync();
77 udelay(1000);
78
79 au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_INIT, USB_HOST_CONFIG);
80 au_sync();
81 udelay(1000);
82
83 /* wait for reset complete (read register twice; see au1500 errata) */
84 while (au_readl(USB_HOST_CONFIG),
85 !(au_readl(USB_HOST_CONFIG) & USBH_ENABLE_RD))
86 udelay(1000);
87
88#else /* Au1200 */
89 au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_CE, USB_HOST_CONFIG);
90 au_sync();
91 udelay(1000);
92
93 au_writel(au_readl(USB_HOST_CONFIG) | USBH_ENABLE_INIT, USB_HOST_CONFIG);
94 au_sync();
95 udelay(2000);
96#endif /* Au1200 */
97}
98
99static void au1xxx_stop_ohc(void)
100{
101#ifdef CONFIG_SOC_AU1200
102 /* Disable mem */
103 au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_DISABLE, USB_HOST_CONFIG);
104 au_sync();
105 udelay(1000);
106#endif
107 /* Disable clock */
108 au_writel(au_readl(USB_HOST_CONFIG) & ~USBH_ENABLE_CE, USB_HOST_CONFIG);
109 au_sync();
110}
111
112static int __devinit ohci_au1xxx_start(struct usb_hcd *hcd) 29static int __devinit ohci_au1xxx_start(struct usb_hcd *hcd)
113{ 30{
114 struct ohci_hcd *ohci = hcd_to_ohci(hcd); 31 struct ohci_hcd *ohci = hcd_to_ohci(hcd);
@@ -178,17 +95,6 @@ static int ohci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
178 if (usb_disabled()) 95 if (usb_disabled())
179 return -ENODEV; 96 return -ENODEV;
180 97
181#if defined(CONFIG_SOC_AU1200) && defined(CONFIG_DMA_COHERENT)
182 /* Au1200 AB USB does not support coherent memory */
183 if (!(read_c0_prid() & 0xff)) {
184 printk(KERN_INFO "%s: this is chip revision AB !!\n",
185 pdev->name);
186 printk(KERN_INFO "%s: update your board or re-configure "
187 "the kernel\n", pdev->name);
188 return -ENODEV;
189 }
190#endif
191
192 if (pdev->resource[1].flags != IORESOURCE_IRQ) { 98 if (pdev->resource[1].flags != IORESOURCE_IRQ) {
193 pr_debug("resource[1] is not IORESOURCE_IRQ\n"); 99 pr_debug("resource[1] is not IORESOURCE_IRQ\n");
194 return -ENOMEM; 100 return -ENOMEM;
@@ -214,7 +120,12 @@ static int ohci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
214 goto err2; 120 goto err2;
215 } 121 }
216 122
217 au1xxx_start_ohc(); 123 if (alchemy_usb_control(ALCHEMY_USB_OHCI0, 1)) {
124 printk(KERN_INFO "%s: controller init failed!\n", pdev->name);
125 ret = -ENODEV;
126 goto err3;
127 }
128
218 ohci_hcd_init(hcd_to_ohci(hcd)); 129 ohci_hcd_init(hcd_to_ohci(hcd));
219 130
220 ret = usb_add_hcd(hcd, pdev->resource[1].start, 131 ret = usb_add_hcd(hcd, pdev->resource[1].start,
@@ -224,7 +135,8 @@ static int ohci_hcd_au1xxx_drv_probe(struct platform_device *pdev)
224 return ret; 135 return ret;
225 } 136 }
226 137
227 au1xxx_stop_ohc(); 138 alchemy_usb_control(ALCHEMY_USB_OHCI0, 0);
139err3:
228 iounmap(hcd->regs); 140 iounmap(hcd->regs);
229err2: 141err2:
230 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 142 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
@@ -238,7 +150,7 @@ static int ohci_hcd_au1xxx_drv_remove(struct platform_device *pdev)
238 struct usb_hcd *hcd = platform_get_drvdata(pdev); 150 struct usb_hcd *hcd = platform_get_drvdata(pdev);
239 151
240 usb_remove_hcd(hcd); 152 usb_remove_hcd(hcd);
241 au1xxx_stop_ohc(); 153 alchemy_usb_control(ALCHEMY_USB_OHCI0, 0);
242 iounmap(hcd->regs); 154 iounmap(hcd->regs);
243 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 155 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
244 usb_put_hcd(hcd); 156 usb_put_hcd(hcd);
@@ -275,7 +187,7 @@ static int ohci_hcd_au1xxx_drv_suspend(struct device *dev)
275 187
276 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 188 clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
277 189
278 au1xxx_stop_ohc(); 190 alchemy_usb_control(ALCHEMY_USB_OHCI0, 0);
279bail: 191bail:
280 spin_unlock_irqrestore(&ohci->lock, flags); 192 spin_unlock_irqrestore(&ohci->lock, flags);
281 193
@@ -286,7 +198,7 @@ static int ohci_hcd_au1xxx_drv_resume(struct device *dev)
286{ 198{
287 struct usb_hcd *hcd = dev_get_drvdata(dev); 199 struct usb_hcd *hcd = dev_get_drvdata(dev);
288 200
289 au1xxx_start_ohc(); 201 alchemy_usb_control(ALCHEMY_USB_OHCI0, 1);
290 202
291 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); 203 set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
292 ohci_finish_controller_resume(hcd); 204 ohci_finish_controller_resume(hcd);
diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
index 629a96813fd6..27a3dec32fa2 100644
--- a/drivers/usb/host/pci-quirks.c
+++ b/drivers/usb/host/pci-quirks.c
@@ -13,6 +13,7 @@
13#include <linux/pci.h> 13#include <linux/pci.h>
14#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/delay.h> 15#include <linux/delay.h>
16#include <linux/export.h>
16#include <linux/acpi.h> 17#include <linux/acpi.h>
17#include <linux/dmi.h> 18#include <linux/dmi.h>
18#include "pci-quirks.h" 19#include "pci-quirks.h"
diff --git a/drivers/usb/host/whci/debug.c b/drivers/usb/host/whci/debug.c
index 767af265e002..ba61dae9e4d2 100644
--- a/drivers/usb/host/whci/debug.c
+++ b/drivers/usb/host/whci/debug.c
@@ -19,6 +19,7 @@
19#include <linux/kernel.h> 19#include <linux/kernel.h>
20#include <linux/debugfs.h> 20#include <linux/debugfs.h>
21#include <linux/seq_file.h> 21#include <linux/seq_file.h>
22#include <linux/export.h>
22 23
23#include "../../wusbcore/wusbhc.h" 24#include "../../wusbcore/wusbhc.h"
24 25
diff --git a/drivers/usb/host/whci/hcd.c b/drivers/usb/host/whci/hcd.c
index 9546f6cd01f0..1e141f755b26 100644
--- a/drivers/usb/host/whci/hcd.c
+++ b/drivers/usb/host/whci/hcd.c
@@ -17,6 +17,7 @@
17 */ 17 */
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/module.h>
20#include <linux/uwb/umc.h> 21#include <linux/uwb/umc.h>
21 22
22#include "../../wusbcore/wusbhc.h" 23#include "../../wusbcore/wusbhc.h"
diff --git a/drivers/usb/host/xhci-hub.c b/drivers/usb/host/xhci-hub.c
index 431efe72b1f7..430e88fd3f6c 100644
--- a/drivers/usb/host/xhci-hub.c
+++ b/drivers/usb/host/xhci-hub.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/gfp.h>
23#include <asm/unaligned.h> 24#include <asm/unaligned.h>
24 25
25#include "xhci.h" 26#include "xhci.h"
diff --git a/drivers/usb/host/xhci-pci.c b/drivers/usb/host/xhci-pci.c
index 9f51f88cc0f5..ef98b38626fb 100644
--- a/drivers/usb/host/xhci-pci.c
+++ b/drivers/usb/host/xhci-pci.c
@@ -22,6 +22,7 @@
22 22
23#include <linux/pci.h> 23#include <linux/pci.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/module.h>
25 26
26#include "xhci.h" 27#include "xhci.h"
27 28
diff --git a/drivers/usb/mon/mon_bin.c b/drivers/usb/mon/mon_bin.c
index a04b2ff9dd83..91cd85076a44 100644
--- a/drivers/usb/mon/mon_bin.c
+++ b/drivers/usb/mon/mon_bin.c
@@ -11,6 +11,7 @@
11#include <linux/types.h> 11#include <linux/types.h>
12#include <linux/fs.h> 12#include <linux/fs.h>
13#include <linux/cdev.h> 13#include <linux/cdev.h>
14#include <linux/export.h>
14#include <linux/usb.h> 15#include <linux/usb.h>
15#include <linux/poll.h> 16#include <linux/poll.h>
16#include <linux/compat.h> 17#include <linux/compat.h>
diff --git a/drivers/usb/mon/mon_stat.c b/drivers/usb/mon/mon_stat.c
index e5ce42bd316e..ebd6189a5014 100644
--- a/drivers/usb/mon/mon_stat.c
+++ b/drivers/usb/mon/mon_stat.c
@@ -9,6 +9,7 @@
9 9
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <linux/slab.h> 11#include <linux/slab.h>
12#include <linux/export.h>
12#include <linux/usb.h> 13#include <linux/usb.h>
13#include <linux/fs.h> 14#include <linux/fs.h>
14#include <asm/uaccess.h> 15#include <asm/uaccess.h>
diff --git a/drivers/usb/mon/mon_text.c b/drivers/usb/mon/mon_text.c
index 1c3afcc11bd9..ad408251d955 100644
--- a/drivers/usb/mon/mon_text.c
+++ b/drivers/usb/mon/mon_text.c
@@ -9,6 +9,7 @@
9#include <linux/usb.h> 9#include <linux/usb.h>
10#include <linux/slab.h> 10#include <linux/slab.h>
11#include <linux/time.h> 11#include <linux/time.h>
12#include <linux/export.h>
12#include <linux/mutex.h> 13#include <linux/mutex.h>
13#include <linux/debugfs.h> 14#include <linux/debugfs.h>
14#include <linux/scatterlist.h> 15#include <linux/scatterlist.h>
diff --git a/drivers/usb/otg/gpio_vbus.c b/drivers/usb/otg/gpio_vbus.c
index 52733d9959b4..fb644c107ded 100644
--- a/drivers/usb/otg/gpio_vbus.c
+++ b/drivers/usb/otg/gpio_vbus.c
@@ -11,6 +11,7 @@
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/platform_device.h> 12#include <linux/platform_device.h>
13#include <linux/gpio.h> 13#include <linux/gpio.h>
14#include <linux/module.h>
14#include <linux/slab.h> 15#include <linux/slab.h>
15#include <linux/interrupt.h> 16#include <linux/interrupt.h>
16#include <linux/usb.h> 17#include <linux/usb.h>
diff --git a/drivers/usb/otg/otg.c b/drivers/usb/otg/otg.c
index fb7adeff9ffa..307c27bc51eb 100644
--- a/drivers/usb/otg/otg.c
+++ b/drivers/usb/otg/otg.c
@@ -10,6 +10,7 @@
10 */ 10 */
11 11
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/export.h>
13#include <linux/device.h> 14#include <linux/device.h>
14 15
15#include <linux/usb/otg.h> 16#include <linux/usb/otg.h>
diff --git a/drivers/usb/otg/ulpi.c b/drivers/usb/otg/ulpi.c
index 770d799d5afb..0b0466728fdc 100644
--- a/drivers/usb/otg/ulpi.c
+++ b/drivers/usb/otg/ulpi.c
@@ -25,6 +25,7 @@
25 25
26#include <linux/kernel.h> 26#include <linux/kernel.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/export.h>
28#include <linux/usb.h> 29#include <linux/usb.h>
29#include <linux/usb/otg.h> 30#include <linux/usb/otg.h>
30#include <linux/usb/ulpi.h> 31#include <linux/usb/ulpi.h>
diff --git a/drivers/usb/serial/aircable.c b/drivers/usb/serial/aircable.c
index aba201cb872c..b43d07df4c44 100644
--- a/drivers/usb/serial/aircable.c
+++ b/drivers/usb/serial/aircable.c
@@ -47,6 +47,7 @@
47#include <asm/unaligned.h> 47#include <asm/unaligned.h>
48#include <linux/tty.h> 48#include <linux/tty.h>
49#include <linux/slab.h> 49#include <linux/slab.h>
50#include <linux/module.h>
50#include <linux/tty_flip.h> 51#include <linux/tty_flip.h>
51#include <linux/usb.h> 52#include <linux/usb.h>
52#include <linux/usb/serial.h> 53#include <linux/usb/serial.h>
diff --git a/drivers/usb/serial/qcserial.c b/drivers/usb/serial/qcserial.c
index b9bb24729c99..aa9367f5b421 100644
--- a/drivers/usb/serial/qcserial.c
+++ b/drivers/usb/serial/qcserial.c
@@ -13,6 +13,7 @@
13 13
14#include <linux/tty.h> 14#include <linux/tty.h>
15#include <linux/tty_flip.h> 15#include <linux/tty_flip.h>
16#include <linux/module.h>
16#include <linux/usb.h> 17#include <linux/usb.h>
17#include <linux/usb/serial.h> 18#include <linux/usb/serial.h>
18#include <linux/slab.h> 19#include <linux/slab.h>
diff --git a/drivers/usb/storage/option_ms.c b/drivers/usb/storage/option_ms.c
index 89460181d122..e0f76bb05915 100644
--- a/drivers/usb/storage/option_ms.c
+++ b/drivers/usb/storage/option_ms.c
@@ -22,6 +22,7 @@
22 22
23#include <linux/usb.h> 23#include <linux/usb.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/module.h>
25 26
26#include "usb.h" 27#include "usb.h"
27#include "transport.h" 28#include "transport.h"
diff --git a/drivers/usb/storage/protocol.c b/drivers/usb/storage/protocol.c
index fc310f75eada..93c1a4d86f51 100644
--- a/drivers/usb/storage/protocol.c
+++ b/drivers/usb/storage/protocol.c
@@ -43,6 +43,7 @@
43 */ 43 */
44 44
45#include <linux/highmem.h> 45#include <linux/highmem.h>
46#include <linux/export.h>
46#include <scsi/scsi.h> 47#include <scsi/scsi.h>
47#include <scsi/scsi_cmnd.h> 48#include <scsi/scsi_cmnd.h>
48 49
diff --git a/drivers/usb/storage/sierra_ms.c b/drivers/usb/storage/sierra_ms.c
index 1deca07c8265..37539c89e3ba 100644
--- a/drivers/usb/storage/sierra_ms.c
+++ b/drivers/usb/storage/sierra_ms.c
@@ -3,6 +3,7 @@
3#include <scsi/scsi_cmnd.h> 3#include <scsi/scsi_cmnd.h>
4#include <scsi/scsi_device.h> 4#include <scsi/scsi_device.h>
5#include <linux/usb.h> 5#include <linux/usb.h>
6#include <linux/module.h>
6#include <linux/slab.h> 7#include <linux/slab.h>
7 8
8#include "usb.h" 9#include "usb.h"
diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
index ff32390d61e5..0e5c91c6187f 100644
--- a/drivers/usb/storage/transport.c
+++ b/drivers/usb/storage/transport.c
@@ -46,6 +46,7 @@
46#include <linux/sched.h> 46#include <linux/sched.h>
47#include <linux/gfp.h> 47#include <linux/gfp.h>
48#include <linux/errno.h> 48#include <linux/errno.h>
49#include <linux/export.h>
49 50
50#include <linux/usb/quirks.h> 51#include <linux/usb/quirks.h>
51 52
diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c
index 23f0dd9c36d4..1d10d5b8204c 100644
--- a/drivers/usb/storage/uas.c
+++ b/drivers/usb/storage/uas.c
@@ -11,6 +11,7 @@
11#include <linux/blkdev.h> 11#include <linux/blkdev.h>
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/types.h> 13#include <linux/types.h>
14#include <linux/module.h>
14#include <linux/usb.h> 15#include <linux/usb.h>
15#include <linux/usb/storage.h> 16#include <linux/usb/storage.h>
16 17
diff --git a/drivers/usb/wusbcore/devconnect.c b/drivers/usb/wusbcore/devconnect.c
index 7ec24e46b34b..231009af65a3 100644
--- a/drivers/usb/wusbcore/devconnect.c
+++ b/drivers/usb/wusbcore/devconnect.c
@@ -90,6 +90,7 @@
90#include <linux/ctype.h> 90#include <linux/ctype.h>
91#include <linux/slab.h> 91#include <linux/slab.h>
92#include <linux/workqueue.h> 92#include <linux/workqueue.h>
93#include <linux/export.h>
93#include "wusbhc.h" 94#include "wusbhc.h"
94 95
95static void wusbhc_devconnect_acked_work(struct work_struct *work); 96static void wusbhc_devconnect_acked_work(struct work_struct *work);
diff --git a/drivers/usb/wusbcore/mmc.c b/drivers/usb/wusbcore/mmc.c
index 0a57ff0a0b0c..b8c72583c040 100644
--- a/drivers/usb/wusbcore/mmc.c
+++ b/drivers/usb/wusbcore/mmc.c
@@ -38,6 +38,7 @@
38 */ 38 */
39#include <linux/usb/wusb.h> 39#include <linux/usb/wusb.h>
40#include <linux/slab.h> 40#include <linux/slab.h>
41#include <linux/export.h>
41#include "wusbhc.h" 42#include "wusbhc.h"
42 43
43/* Initialize the MMCIEs handling mechanism */ 44/* Initialize the MMCIEs handling mechanism */
diff --git a/drivers/usb/wusbcore/rh.c b/drivers/usb/wusbcore/rh.c
index 39de3900ad20..59ff254dfb6f 100644
--- a/drivers/usb/wusbcore/rh.c
+++ b/drivers/usb/wusbcore/rh.c
@@ -70,6 +70,7 @@
70 * wusbhc_rh_start_port_reset() ??? unimplemented 70 * wusbhc_rh_start_port_reset() ??? unimplemented
71 */ 71 */
72#include <linux/slab.h> 72#include <linux/slab.h>
73#include <linux/export.h>
73#include "wusbhc.h" 74#include "wusbhc.h"
74 75
75/* 76/*
diff --git a/drivers/usb/wusbcore/security.c b/drivers/usb/wusbcore/security.c
index b60799b811c1..371f61733f05 100644
--- a/drivers/usb/wusbcore/security.c
+++ b/drivers/usb/wusbcore/security.c
@@ -26,6 +26,7 @@
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/usb/ch9.h> 27#include <linux/usb/ch9.h>
28#include <linux/random.h> 28#include <linux/random.h>
29#include <linux/export.h>
29#include "wusbhc.h" 30#include "wusbhc.h"
30 31
31static void wusbhc_set_gtk_callback(struct urb *urb); 32static void wusbhc_set_gtk_callback(struct urb *urb);
diff --git a/drivers/usb/wusbcore/wa-hc.c b/drivers/usb/wusbcore/wa-hc.c
index 0d1863c9edde..9e4a92461688 100644
--- a/drivers/usb/wusbcore/wa-hc.c
+++ b/drivers/usb/wusbcore/wa-hc.c
@@ -23,6 +23,7 @@
23 * FIXME: docs 23 * FIXME: docs
24 */ 24 */
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/module.h>
26#include "wusbhc.h" 27#include "wusbhc.h"
27#include "wa-hc.h" 28#include "wa-hc.h"
28 29
diff --git a/drivers/usb/wusbcore/wa-rpipe.c b/drivers/usb/wusbcore/wa-rpipe.c
index 2acc7f504c51..f0d546c5a089 100644
--- a/drivers/usb/wusbcore/wa-rpipe.c
+++ b/drivers/usb/wusbcore/wa-rpipe.c
@@ -61,6 +61,7 @@
61#include <linux/atomic.h> 61#include <linux/atomic.h>
62#include <linux/bitmap.h> 62#include <linux/bitmap.h>
63#include <linux/slab.h> 63#include <linux/slab.h>
64#include <linux/export.h>
64 65
65#include "wusbhc.h" 66#include "wusbhc.h"
66#include "wa-hc.h" 67#include "wa-hc.h"
diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
index 419334568be6..57c01ab09ad8 100644
--- a/drivers/usb/wusbcore/wa-xfer.c
+++ b/drivers/usb/wusbcore/wa-xfer.c
@@ -84,6 +84,7 @@
84#include <linux/slab.h> 84#include <linux/slab.h>
85#include <linux/hash.h> 85#include <linux/hash.h>
86#include <linux/ratelimit.h> 86#include <linux/ratelimit.h>
87#include <linux/export.h>
87 88
88#include "wa-hc.h" 89#include "wa-hc.h"
89#include "wusbhc.h" 90#include "wusbhc.h"
diff --git a/drivers/uwb/est.c b/drivers/uwb/est.c
index a2eaa3c33b0b..de81ebf51784 100644
--- a/drivers/uwb/est.c
+++ b/drivers/uwb/est.c
@@ -41,6 +41,7 @@
41 */ 41 */
42#include <linux/spinlock.h> 42#include <linux/spinlock.h>
43#include <linux/slab.h> 43#include <linux/slab.h>
44#include <linux/export.h>
44 45
45#include "uwb-internal.h" 46#include "uwb-internal.h"
46 47
diff --git a/drivers/uwb/i1480/dfu/dfu.c b/drivers/uwb/i1480/dfu/dfu.c
index da7b1d08003c..b08d1c2ee3fa 100644
--- a/drivers/uwb/i1480/dfu/dfu.c
+++ b/drivers/uwb/i1480/dfu/dfu.c
@@ -33,6 +33,7 @@
33#include <linux/device.h> 33#include <linux/device.h>
34#include <linux/uwb.h> 34#include <linux/uwb.h>
35#include <linux/random.h> 35#include <linux/random.h>
36#include <linux/export.h>
36 37
37/* 38/*
38 * i1480_rceb_check - Check RCEB for expected field values 39 * i1480_rceb_check - Check RCEB for expected field values
diff --git a/drivers/uwb/ie.c b/drivers/uwb/ie.c
index 30acec740425..902b0f2f961e 100644
--- a/drivers/uwb/ie.c
+++ b/drivers/uwb/ie.c
@@ -25,6 +25,7 @@
25 */ 25 */
26 26
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/export.h>
28#include "uwb-internal.h" 29#include "uwb-internal.h"
29 30
30/** 31/**
diff --git a/drivers/uwb/lc-dev.c b/drivers/uwb/lc-dev.c
index 90113bafefca..5241f1d0ef7a 100644
--- a/drivers/uwb/lc-dev.c
+++ b/drivers/uwb/lc-dev.c
@@ -25,9 +25,11 @@
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/device.h> 27#include <linux/device.h>
28#include <linux/export.h>
28#include <linux/err.h> 29#include <linux/err.h>
29#include <linux/kdev_t.h> 30#include <linux/kdev_t.h>
30#include <linux/random.h> 31#include <linux/random.h>
32#include <linux/stat.h>
31#include "uwb-internal.h" 33#include "uwb-internal.h"
32 34
33/* We initialize addresses to 0xff (invalid, as it is bcast) */ 35/* We initialize addresses to 0xff (invalid, as it is bcast) */
diff --git a/drivers/uwb/lc-rc.c b/drivers/uwb/lc-rc.c
index b4395f41a007..4d688c750801 100644
--- a/drivers/uwb/lc-rc.c
+++ b/drivers/uwb/lc-rc.c
@@ -36,6 +36,7 @@
36#include <linux/etherdevice.h> 36#include <linux/etherdevice.h>
37#include <linux/usb.h> 37#include <linux/usb.h>
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/export.h>
39 40
40#include "uwb-internal.h" 41#include "uwb-internal.h"
41 42
diff --git a/drivers/uwb/neh.c b/drivers/uwb/neh.c
index 697e56a5bcdd..a269937be1b8 100644
--- a/drivers/uwb/neh.c
+++ b/drivers/uwb/neh.c
@@ -85,6 +85,7 @@
85#include <linux/timer.h> 85#include <linux/timer.h>
86#include <linux/slab.h> 86#include <linux/slab.h>
87#include <linux/err.h> 87#include <linux/err.h>
88#include <linux/export.h>
88 89
89#include "uwb-internal.h" 90#include "uwb-internal.h"
90 91
diff --git a/drivers/uwb/pal.c b/drivers/uwb/pal.c
index 99a19c199095..8ee7d90a8c68 100644
--- a/drivers/uwb/pal.c
+++ b/drivers/uwb/pal.c
@@ -18,6 +18,7 @@
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/debugfs.h> 19#include <linux/debugfs.h>
20#include <linux/uwb.h> 20#include <linux/uwb.h>
21#include <linux/export.h>
21 22
22#include "uwb-internal.h" 23#include "uwb-internal.h"
23 24
diff --git a/drivers/uwb/radio.c b/drivers/uwb/radio.c
index f0d55495f5e9..d58dfecf9a79 100644
--- a/drivers/uwb/radio.c
+++ b/drivers/uwb/radio.c
@@ -17,6 +17,7 @@
17 */ 17 */
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/uwb.h> 19#include <linux/uwb.h>
20#include <linux/export.h>
20 21
21#include "uwb-internal.h" 22#include "uwb-internal.h"
22 23
diff --git a/drivers/uwb/reset.c b/drivers/uwb/reset.c
index 3de630b0f691..703228559e89 100644
--- a/drivers/uwb/reset.c
+++ b/drivers/uwb/reset.c
@@ -32,6 +32,7 @@
32#include <linux/err.h> 32#include <linux/err.h>
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include <linux/delay.h> 34#include <linux/delay.h>
35#include <linux/export.h>
35 36
36#include "uwb-internal.h" 37#include "uwb-internal.h"
37 38
diff --git a/drivers/uwb/rsv.c b/drivers/uwb/rsv.c
index 78c892233cf1..0b0d8bce842e 100644
--- a/drivers/uwb/rsv.c
+++ b/drivers/uwb/rsv.c
@@ -19,6 +19,7 @@
19#include <linux/uwb.h> 19#include <linux/uwb.h>
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/random.h> 21#include <linux/random.h>
22#include <linux/export.h>
22 23
23#include "uwb-internal.h" 24#include "uwb-internal.h"
24 25
diff --git a/drivers/uwb/scan.c b/drivers/uwb/scan.c
index 367aa12786b9..cbb6a5e703d2 100644
--- a/drivers/uwb/scan.c
+++ b/drivers/uwb/scan.c
@@ -36,6 +36,7 @@
36#include <linux/device.h> 36#include <linux/device.h>
37#include <linux/err.h> 37#include <linux/err.h>
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/stat.h>
39#include "uwb-internal.h" 40#include "uwb-internal.h"
40 41
41 42
diff --git a/drivers/uwb/umc-bus.c b/drivers/uwb/umc-bus.c
index 5fad4e791b3e..82a84d53120f 100644
--- a/drivers/uwb/umc-bus.c
+++ b/drivers/uwb/umc-bus.c
@@ -8,6 +8,7 @@
8#include <linux/kernel.h> 8#include <linux/kernel.h>
9#include <linux/sysfs.h> 9#include <linux/sysfs.h>
10#include <linux/workqueue.h> 10#include <linux/workqueue.h>
11#include <linux/module.h>
11#include <linux/uwb/umc.h> 12#include <linux/uwb/umc.h>
12#include <linux/pci.h> 13#include <linux/pci.h>
13 14
diff --git a/drivers/uwb/umc-dev.c b/drivers/uwb/umc-dev.c
index b2948ec57878..4613c13cd851 100644
--- a/drivers/uwb/umc-dev.c
+++ b/drivers/uwb/umc-dev.c
@@ -6,6 +6,7 @@
6 * This file is released under the GNU GPL v2. 6 * This file is released under the GNU GPL v2.
7 */ 7 */
8#include <linux/kernel.h> 8#include <linux/kernel.h>
9#include <linux/export.h>
9#include <linux/slab.h> 10#include <linux/slab.h>
10#include <linux/uwb/umc.h> 11#include <linux/uwb/umc.h>
11 12
diff --git a/drivers/uwb/umc-drv.c b/drivers/uwb/umc-drv.c
index 367b5eb85d60..26d0ae1816bd 100644
--- a/drivers/uwb/umc-drv.c
+++ b/drivers/uwb/umc-drv.c
@@ -6,6 +6,7 @@
6 * This file is released under the GNU GPL v2. 6 * This file is released under the GNU GPL v2.
7 */ 7 */
8#include <linux/kernel.h> 8#include <linux/kernel.h>
9#include <linux/export.h>
9#include <linux/uwb/umc.h> 10#include <linux/uwb/umc.h>
10 11
11int __umc_driver_register(struct umc_driver *umc_drv, struct module *module, 12int __umc_driver_register(struct umc_driver *umc_drv, struct module *module,
diff --git a/drivers/uwb/whci.c b/drivers/uwb/whci.c
index b221142446a2..f48093e649e4 100644
--- a/drivers/uwb/whci.c
+++ b/drivers/uwb/whci.c
@@ -7,6 +7,7 @@
7 */ 7 */
8#include <linux/delay.h> 8#include <linux/delay.h>
9#include <linux/kernel.h> 9#include <linux/kernel.h>
10#include <linux/module.h>
10#include <linux/pci.h> 11#include <linux/pci.h>
11#include <linux/dma-mapping.h> 12#include <linux/dma-mapping.h>
12#include <linux/slab.h> 13#include <linux/slab.h>
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 8165c5577d71..d83e967e4e15 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -1753,7 +1753,7 @@ endchoice
1753 1753
1754config FB_AU1100 1754config FB_AU1100
1755 bool "Au1100 LCD Driver" 1755 bool "Au1100 LCD Driver"
1756 depends on (FB = y) && MIPS && SOC_AU1100 1756 depends on (FB = y) && MIPS_ALCHEMY
1757 select FB_CFB_FILLRECT 1757 select FB_CFB_FILLRECT
1758 select FB_CFB_COPYAREA 1758 select FB_CFB_COPYAREA
1759 select FB_CFB_IMAGEBLIT 1759 select FB_CFB_IMAGEBLIT
@@ -1764,7 +1764,7 @@ config FB_AU1100
1764 1764
1765config FB_AU1200 1765config FB_AU1200
1766 bool "Au1200 LCD Driver" 1766 bool "Au1200 LCD Driver"
1767 depends on (FB = y) && MIPS && SOC_AU1200 1767 depends on (FB = y) && MIPS_ALCHEMY
1768 select FB_SYS_FILLRECT 1768 select FB_SYS_FILLRECT
1769 select FB_SYS_COPYAREA 1769 select FB_SYS_COPYAREA
1770 select FB_SYS_IMAGEBLIT 1770 select FB_SYS_IMAGEBLIT
diff --git a/drivers/video/atmel_lcdfb.c b/drivers/video/atmel_lcdfb.c
index 4ac48d9ee665..63409c122ae8 100644
--- a/drivers/video/atmel_lcdfb.c
+++ b/drivers/video/atmel_lcdfb.c
@@ -18,6 +18,7 @@
18#include <linux/delay.h> 18#include <linux/delay.h>
19#include <linux/backlight.h> 19#include <linux/backlight.h>
20#include <linux/gfp.h> 20#include <linux/gfp.h>
21#include <linux/module.h>
21 22
22#include <mach/board.h> 23#include <mach/board.h>
23#include <mach/cpu.h> 24#include <mach/cpu.h>
diff --git a/drivers/video/backlight/88pm860x_bl.c b/drivers/video/backlight/88pm860x_bl.c
index c04b94da81f7..1105fa1ed7f4 100644
--- a/drivers/video/backlight/88pm860x_bl.c
+++ b/drivers/video/backlight/88pm860x_bl.c
@@ -17,6 +17,7 @@
17#include <linux/i2c.h> 17#include <linux/i2c.h>
18#include <linux/backlight.h> 18#include <linux/backlight.h>
19#include <linux/mfd/88pm860x.h> 19#include <linux/mfd/88pm860x.h>
20#include <linux/module.h>
20 21
21#define MAX_BRIGHTNESS (0xFF) 22#define MAX_BRIGHTNESS (0xFF)
22#define MIN_BRIGHTNESS (0) 23#define MIN_BRIGHTNESS (0)
diff --git a/drivers/video/backlight/adp5520_bl.c b/drivers/video/backlight/adp5520_bl.c
index d1aee730d7d8..dfb763e9147f 100644
--- a/drivers/video/backlight/adp5520_bl.c
+++ b/drivers/video/backlight/adp5520_bl.c
@@ -13,6 +13,7 @@
13#include <linux/backlight.h> 13#include <linux/backlight.h>
14#include <linux/mfd/adp5520.h> 14#include <linux/mfd/adp5520.h>
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/module.h>
16 17
17struct adp5520_bl { 18struct adp5520_bl {
18 struct device *master; 19 struct device *master;
diff --git a/drivers/video/backlight/ams369fg06.c b/drivers/video/backlight/ams369fg06.c
index 9f0a491e2a05..7838a23fbdd1 100644
--- a/drivers/video/backlight/ams369fg06.c
+++ b/drivers/video/backlight/ams369fg06.c
@@ -22,6 +22,7 @@
22 */ 22 */
23 23
24#include <linux/wait.h> 24#include <linux/wait.h>
25#include <linux/module.h>
25#include <linux/fb.h> 26#include <linux/fb.h>
26#include <linux/delay.h> 27#include <linux/delay.h>
27#include <linux/gpio.h> 28#include <linux/gpio.h>
diff --git a/drivers/video/backlight/da903x_bl.c b/drivers/video/backlight/da903x_bl.c
index 62043f12a5a4..d68f14bbb687 100644
--- a/drivers/video/backlight/da903x_bl.c
+++ b/drivers/video/backlight/da903x_bl.c
@@ -19,6 +19,7 @@
19#include <linux/backlight.h> 19#include <linux/backlight.h>
20#include <linux/mfd/da903x.h> 20#include <linux/mfd/da903x.h>
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/module.h>
22 23
23#define DA9030_WLED_CONTROL 0x25 24#define DA9030_WLED_CONTROL 0x25
24#define DA9030_WLED_CP_EN (1 << 6) 25#define DA9030_WLED_CP_EN (1 << 6)
diff --git a/drivers/video/backlight/ep93xx_bl.c b/drivers/video/backlight/ep93xx_bl.c
index b0582917f0c8..c74a6f4baa12 100644
--- a/drivers/video/backlight/ep93xx_bl.c
+++ b/drivers/video/backlight/ep93xx_bl.c
@@ -13,6 +13,7 @@
13 13
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/platform_device.h> 15#include <linux/platform_device.h>
16#include <linux/module.h>
16#include <linux/io.h> 17#include <linux/io.h>
17#include <linux/fb.h> 18#include <linux/fb.h>
18#include <linux/backlight.h> 19#include <linux/backlight.h>
diff --git a/drivers/video/backlight/l4f00242t03.c b/drivers/video/backlight/l4f00242t03.c
index 3543f1b7d5f1..4f5d1c4cb6ab 100644
--- a/drivers/video/backlight/l4f00242t03.c
+++ b/drivers/video/backlight/l4f00242t03.c
@@ -14,6 +14,7 @@
14#include <linux/device.h> 14#include <linux/device.h>
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/delay.h> 16#include <linux/delay.h>
17#include <linux/module.h>
17#include <linux/gpio.h> 18#include <linux/gpio.h>
18#include <linux/lcd.h> 19#include <linux/lcd.h>
19#include <linux/slab.h> 20#include <linux/slab.h>
diff --git a/drivers/video/backlight/ld9040.c b/drivers/video/backlight/ld9040.c
index 5934655eb1ff..da9a5ce0ccb8 100644
--- a/drivers/video/backlight/ld9040.c
+++ b/drivers/video/backlight/ld9040.c
@@ -30,6 +30,7 @@
30#include <linux/kernel.h> 30#include <linux/kernel.h>
31#include <linux/lcd.h> 31#include <linux/lcd.h>
32#include <linux/backlight.h> 32#include <linux/backlight.h>
33#include <linux/module.h>
33 34
34#include "ld9040_gamma.h" 35#include "ld9040_gamma.h"
35 36
diff --git a/drivers/video/backlight/lms283gf05.c b/drivers/video/backlight/lms283gf05.c
index 5d3cf33953ac..4ec78cfe26ea 100644
--- a/drivers/video/backlight/lms283gf05.c
+++ b/drivers/video/backlight/lms283gf05.c
@@ -17,6 +17,7 @@
17 17
18#include <linux/spi/spi.h> 18#include <linux/spi/spi.h>
19#include <linux/spi/lms283gf05.h> 19#include <linux/spi/lms283gf05.h>
20#include <linux/module.h>
20 21
21struct lms283gf05_state { 22struct lms283gf05_state {
22 struct spi_device *spi; 23 struct spi_device *spi;
diff --git a/drivers/video/backlight/max8925_bl.c b/drivers/video/backlight/max8925_bl.c
index 07e8e273ced0..7bbc802560ea 100644
--- a/drivers/video/backlight/max8925_bl.c
+++ b/drivers/video/backlight/max8925_bl.c
@@ -17,6 +17,7 @@
17#include <linux/backlight.h> 17#include <linux/backlight.h>
18#include <linux/mfd/max8925.h> 18#include <linux/mfd/max8925.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/module.h>
20 21
21#define MAX_BRIGHTNESS (0xff) 22#define MAX_BRIGHTNESS (0xff)
22#define MIN_BRIGHTNESS (0) 23#define MIN_BRIGHTNESS (0)
diff --git a/drivers/video/backlight/s6e63m0.c b/drivers/video/backlight/s6e63m0.c
index 694e5aab0d69..e132157d8545 100644
--- a/drivers/video/backlight/s6e63m0.c
+++ b/drivers/video/backlight/s6e63m0.c
@@ -30,6 +30,7 @@
30#include <linux/kernel.h> 30#include <linux/kernel.h>
31#include <linux/lcd.h> 31#include <linux/lcd.h>
32#include <linux/backlight.h> 32#include <linux/backlight.h>
33#include <linux/module.h>
33 34
34#include "s6e63m0_gamma.h" 35#include "s6e63m0_gamma.h"
35 36
diff --git a/drivers/video/backlight/wm831x_bl.c b/drivers/video/backlight/wm831x_bl.c
index d4c6eb248ff9..fbe9e9316f3b 100644
--- a/drivers/video/backlight/wm831x_bl.c
+++ b/drivers/video/backlight/wm831x_bl.c
@@ -11,6 +11,7 @@
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/platform_device.h> 13#include <linux/platform_device.h>
14#include <linux/module.h>
14#include <linux/fb.h> 15#include <linux/fb.h>
15#include <linux/backlight.h> 16#include <linux/backlight.h>
16#include <linux/slab.h> 17#include <linux/slab.h>
diff --git a/drivers/video/carminefb.c b/drivers/video/carminefb.c
index cb09aa1fa138..2c76fdf23f2a 100644
--- a/drivers/video/carminefb.c
+++ b/drivers/video/carminefb.c
@@ -12,6 +12,7 @@
12#include <linux/interrupt.h> 12#include <linux/interrupt.h>
13#include <linux/pci.h> 13#include <linux/pci.h>
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/module.h>
15 16
16#include "carminefb.h" 17#include "carminefb.h"
17#include "carminefb_regs.h" 18#include "carminefb_regs.h"
diff --git a/drivers/video/cobalt_lcdfb.c b/drivers/video/cobalt_lcdfb.c
index e02764319ff7..f56699d8122a 100644
--- a/drivers/video/cobalt_lcdfb.c
+++ b/drivers/video/cobalt_lcdfb.c
@@ -24,6 +24,7 @@
24#include <linux/ioport.h> 24#include <linux/ioport.h>
25#include <linux/uaccess.h> 25#include <linux/uaccess.h>
26#include <linux/platform_device.h> 26#include <linux/platform_device.h>
27#include <linux/module.h>
27 28
28/* 29/*
29 * Cursor position address 30 * Cursor position address
diff --git a/drivers/video/ep93xx-fb.c b/drivers/video/ep93xx-fb.c
index 40e5f17d1e4b..2e830ec52a5a 100644
--- a/drivers/video/ep93xx-fb.c
+++ b/drivers/video/ep93xx-fb.c
@@ -18,6 +18,7 @@
18 */ 18 */
19 19
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/module.h>
21#include <linux/dma-mapping.h> 22#include <linux/dma-mapping.h>
22#include <linux/slab.h> 23#include <linux/slab.h>
23#include <linux/clk.h> 24#include <linux/clk.h>
diff --git a/drivers/video/fb_ddc.c b/drivers/video/fb_ddc.c
index 4a874c8d039c..2b106f046fde 100644
--- a/drivers/video/fb_ddc.c
+++ b/drivers/video/fb_ddc.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * driver/vide/fb_ddc.c - DDC/EDID read support. 2 * drivers/video/fb_ddc.c - DDC/EDID read support.
3 * 3 *
4 * Copyright (C) 2006 Dennis Munsie <dmunsie@cecropia.com> 4 * Copyright (C) 2006 Dennis Munsie <dmunsie@cecropia.com>
5 * 5 *
@@ -10,6 +10,7 @@
10 10
11#include <linux/delay.h> 11#include <linux/delay.h>
12#include <linux/device.h> 12#include <linux/device.h>
13#include <linux/module.h>
13#include <linux/fb.h> 14#include <linux/fb.h>
14#include <linux/i2c-algo-bit.h> 15#include <linux/i2c-algo-bit.h>
15#include <linux/slab.h> 16#include <linux/slab.h>
diff --git a/drivers/video/fb_notify.c b/drivers/video/fb_notify.c
index 8c020389e4fa..74c2da528884 100644
--- a/drivers/video/fb_notify.c
+++ b/drivers/video/fb_notify.c
@@ -12,6 +12,7 @@
12 */ 12 */
13#include <linux/fb.h> 13#include <linux/fb.h>
14#include <linux/notifier.h> 14#include <linux/notifier.h>
15#include <linux/export.h>
15 16
16static BLOCKING_NOTIFIER_HEAD(fb_notifier_list); 17static BLOCKING_NOTIFIER_HEAD(fb_notifier_list);
17 18
diff --git a/drivers/video/mb862xx/mb862xx-i2c.c b/drivers/video/mb862xx/mb862xx-i2c.c
index 934081d2b7ae..273769bb8deb 100644
--- a/drivers/video/mb862xx/mb862xx-i2c.c
+++ b/drivers/video/mb862xx/mb862xx-i2c.c
@@ -13,6 +13,7 @@
13#include <linux/i2c.h> 13#include <linux/i2c.h>
14#include <linux/io.h> 14#include <linux/io.h>
15#include <linux/delay.h> 15#include <linux/delay.h>
16#include <linux/export.h>
16 17
17#include "mb862xxfb.h" 18#include "mb862xxfb.h"
18#include "mb862xx_reg.h" 19#include "mb862xx_reg.h"
diff --git a/drivers/video/mb862xx/mb862xxfbdrv.c b/drivers/video/mb862xx/mb862xxfbdrv.c
index c16ff1d62e91..11a7a333701d 100644
--- a/drivers/video/mb862xx/mb862xxfbdrv.c
+++ b/drivers/video/mb862xx/mb862xxfbdrv.c
@@ -17,6 +17,7 @@
17#include <linux/fb.h> 17#include <linux/fb.h>
18#include <linux/delay.h> 18#include <linux/delay.h>
19#include <linux/uaccess.h> 19#include <linux/uaccess.h>
20#include <linux/module.h>
20#include <linux/init.h> 21#include <linux/init.h>
21#include <linux/interrupt.h> 22#include <linux/interrupt.h>
22#include <linux/pci.h> 23#include <linux/pci.h>
diff --git a/drivers/video/msm/mdp.c b/drivers/video/msm/mdp.c
index b9344772bac9..cb2ddf164c98 100644
--- a/drivers/video/msm/mdp.c
+++ b/drivers/video/msm/mdp.c
@@ -28,6 +28,7 @@
28#include <mach/msm_iomap.h> 28#include <mach/msm_iomap.h>
29#include <mach/msm_fb.h> 29#include <mach/msm_fb.h>
30#include <linux/platform_device.h> 30#include <linux/platform_device.h>
31#include <linux/export.h>
31 32
32#include "mdp_hw.h" 33#include "mdp_hw.h"
33 34
diff --git a/drivers/video/omap/lcd_mipid.c b/drivers/video/omap/lcd_mipid.c
index 90e3bdd1b7ab..eb381db7fe51 100644
--- a/drivers/video/omap/lcd_mipid.c
+++ b/drivers/video/omap/lcd_mipid.c
@@ -23,6 +23,7 @@
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/workqueue.h> 24#include <linux/workqueue.h>
25#include <linux/spi/spi.h> 25#include <linux/spi/spi.h>
26#include <linux/module.h>
26 27
27#include <plat/lcd_mipid.h> 28#include <plat/lcd_mipid.h>
28 29
diff --git a/drivers/video/omap/omapfb_main.c b/drivers/video/omap/omapfb_main.c
index b3ddd743d8a6..25d8e5103193 100644
--- a/drivers/video/omap/omapfb_main.c
+++ b/drivers/video/omap/omapfb_main.c
@@ -28,6 +28,7 @@
28#include <linux/mm.h> 28#include <linux/mm.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30#include <linux/uaccess.h> 30#include <linux/uaccess.h>
31#include <linux/module.h>
31 32
32#include <plat/dma.h> 33#include <plat/dma.h>
33 34
diff --git a/drivers/video/omap2/dss/dispc.c b/drivers/video/omap2/dss/dispc.c
index 6892cfd2e3b7..3532782551cb 100644
--- a/drivers/video/omap2/dss/dispc.c
+++ b/drivers/video/omap2/dss/dispc.c
@@ -25,6 +25,7 @@
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/dma-mapping.h> 26#include <linux/dma-mapping.h>
27#include <linux/vmalloc.h> 27#include <linux/vmalloc.h>
28#include <linux/export.h>
28#include <linux/clk.h> 29#include <linux/clk.h>
29#include <linux/io.h> 30#include <linux/io.h>
30#include <linux/jiffies.h> 31#include <linux/jiffies.h>
diff --git a/drivers/video/omap2/dss/dpi.c b/drivers/video/omap2/dss/dpi.c
index 483888a85cfd..976ac23dcd0c 100644
--- a/drivers/video/omap2/dss/dpi.c
+++ b/drivers/video/omap2/dss/dpi.c
@@ -24,6 +24,7 @@
24 24
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/delay.h> 26#include <linux/delay.h>
27#include <linux/export.h>
27#include <linux/err.h> 28#include <linux/err.h>
28#include <linux/errno.h> 29#include <linux/errno.h>
29#include <linux/platform_device.h> 30#include <linux/platform_device.h>
diff --git a/drivers/video/omap2/dss/dsi.c b/drivers/video/omap2/dss/dsi.c
index 43c04a9889c4..5abf8e7e7456 100644
--- a/drivers/video/omap2/dss/dsi.c
+++ b/drivers/video/omap2/dss/dsi.c
@@ -27,6 +27,7 @@
27#include <linux/interrupt.h> 27#include <linux/interrupt.h>
28#include <linux/delay.h> 28#include <linux/delay.h>
29#include <linux/mutex.h> 29#include <linux/mutex.h>
30#include <linux/module.h>
30#include <linux/semaphore.h> 31#include <linux/semaphore.h>
31#include <linux/seq_file.h> 32#include <linux/seq_file.h>
32#include <linux/platform_device.h> 33#include <linux/platform_device.h>
diff --git a/drivers/video/omap2/dss/dss.c b/drivers/video/omap2/dss/dss.c
index 3e09726d32c7..17033457ee89 100644
--- a/drivers/video/omap2/dss/dss.c
+++ b/drivers/video/omap2/dss/dss.c
@@ -24,6 +24,7 @@
24 24
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/io.h> 26#include <linux/io.h>
27#include <linux/export.h>
27#include <linux/err.h> 28#include <linux/err.h>
28#include <linux/delay.h> 29#include <linux/delay.h>
29#include <linux/seq_file.h> 30#include <linux/seq_file.h>
diff --git a/drivers/video/omap2/dss/rfbi.c b/drivers/video/omap2/dss/rfbi.c
index 1bd3703e42ff..1130c608a561 100644
--- a/drivers/video/omap2/dss/rfbi.c
+++ b/drivers/video/omap2/dss/rfbi.c
@@ -24,6 +24,7 @@
24 24
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/dma-mapping.h> 26#include <linux/dma-mapping.h>
27#include <linux/export.h>
27#include <linux/vmalloc.h> 28#include <linux/vmalloc.h>
28#include <linux/clk.h> 29#include <linux/clk.h>
29#include <linux/io.h> 30#include <linux/io.h>
diff --git a/drivers/video/omap2/dss/sdi.c b/drivers/video/omap2/dss/sdi.c
index 695dc04cabba..40305ad7841e 100644
--- a/drivers/video/omap2/dss/sdi.c
+++ b/drivers/video/omap2/dss/sdi.c
@@ -23,6 +23,7 @@
23#include <linux/delay.h> 23#include <linux/delay.h>
24#include <linux/err.h> 24#include <linux/err.h>
25#include <linux/regulator/consumer.h> 25#include <linux/regulator/consumer.h>
26#include <linux/export.h>
26 27
27#include <video/omapdss.h> 28#include <video/omapdss.h>
28#include "dss.h" 29#include "dss.h"
diff --git a/drivers/video/omap2/omapfb/omapfb-ioctl.c b/drivers/video/omap2/omapfb/omapfb-ioctl.c
index 6b1ac23dbbd3..df7bcce5b107 100644
--- a/drivers/video/omap2/omapfb/omapfb-ioctl.c
+++ b/drivers/video/omap2/omapfb/omapfb-ioctl.c
@@ -27,6 +27,7 @@
27#include <linux/mm.h> 27#include <linux/mm.h>
28#include <linux/omapfb.h> 28#include <linux/omapfb.h>
29#include <linux/vmalloc.h> 29#include <linux/vmalloc.h>
30#include <linux/export.h>
30 31
31#include <video/omapdss.h> 32#include <video/omapdss.h>
32#include <plat/vrfb.h> 33#include <plat/vrfb.h>
diff --git a/drivers/video/savage/savagefb_accel.c b/drivers/video/savage/savagefb_accel.c
index bbcc055d3bb7..bfefa6234cf0 100644
--- a/drivers/video/savage/savagefb_accel.c
+++ b/drivers/video/savage/savagefb_accel.c
@@ -11,6 +11,7 @@
11#include <linux/kernel.h> 11#include <linux/kernel.h>
12#include <linux/string.h> 12#include <linux/string.h>
13#include <linux/fb.h> 13#include <linux/fb.h>
14#include <linux/module.h>
14 15
15#include "savagefb.h" 16#include "savagefb.h"
16 17
diff --git a/drivers/video/sh_mipi_dsi.c b/drivers/video/sh_mipi_dsi.c
index 24640c8458ab..72ee96bc6b3e 100644
--- a/drivers/video/sh_mipi_dsi.c
+++ b/drivers/video/sh_mipi_dsi.c
@@ -17,6 +17,7 @@
17#include <linux/slab.h> 17#include <linux/slab.h>
18#include <linux/string.h> 18#include <linux/string.h>
19#include <linux/types.h> 19#include <linux/types.h>
20#include <linux/module.h>
20 21
21#include <video/mipi_display.h> 22#include <video/mipi_display.h>
22#include <video/sh_mipi_dsi.h> 23#include <video/sh_mipi_dsi.h>
diff --git a/drivers/video/sh_mobile_lcdcfb.c b/drivers/video/sh_mobile_lcdcfb.c
index 3a41c013d031..facffc254976 100644
--- a/drivers/video/sh_mobile_lcdcfb.c
+++ b/drivers/video/sh_mobile_lcdcfb.c
@@ -23,6 +23,7 @@
23#include <linux/console.h> 23#include <linux/console.h>
24#include <linux/backlight.h> 24#include <linux/backlight.h>
25#include <linux/gpio.h> 25#include <linux/gpio.h>
26#include <linux/module.h>
26#include <video/sh_mobile_lcdc.h> 27#include <video/sh_mobile_lcdc.h>
27#include <video/sh_mobile_meram.h> 28#include <video/sh_mobile_meram.h>
28#include <linux/atomic.h> 29#include <linux/atomic.h>
diff --git a/drivers/video/via/via-gpio.c b/drivers/video/via/via-gpio.c
index ab5341814c74..d69cfef7c338 100644
--- a/drivers/video/via/via-gpio.c
+++ b/drivers/video/via/via-gpio.c
@@ -10,6 +10,7 @@
10#include <linux/platform_device.h> 10#include <linux/platform_device.h>
11#include <linux/via-core.h> 11#include <linux/via-core.h>
12#include <linux/via-gpio.h> 12#include <linux/via-gpio.h>
13#include <linux/export.h>
13 14
14/* 15/*
15 * The ports we know about. Note that the port-25 gpios are not 16 * The ports we know about. Note that the port-25 gpios are not
diff --git a/drivers/video/w100fb.c b/drivers/video/w100fb.c
index c8be8af0cc6d..2375e5bbf572 100644
--- a/drivers/video/w100fb.c
+++ b/drivers/video/w100fb.c
@@ -33,6 +33,7 @@
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include <linux/string.h> 34#include <linux/string.h>
35#include <linux/vmalloc.h> 35#include <linux/vmalloc.h>
36#include <linux/module.h>
36#include <asm/io.h> 37#include <asm/io.h>
37#include <asm/uaccess.h> 38#include <asm/uaccess.h>
38#include <video/w100fb.h> 39#include <video/w100fb.h>
diff --git a/drivers/virt/fsl_hypervisor.c b/drivers/virt/fsl_hypervisor.c
index 3d9162151fd2..4939e0ccc4e5 100644
--- a/drivers/virt/fsl_hypervisor.c
+++ b/drivers/virt/fsl_hypervisor.c
@@ -706,6 +706,7 @@ static const struct file_operations fsl_hv_fops = {
706 .poll = fsl_hv_poll, 706 .poll = fsl_hv_poll,
707 .read = fsl_hv_read, 707 .read = fsl_hv_read,
708 .unlocked_ioctl = fsl_hv_ioctl, 708 .unlocked_ioctl = fsl_hv_ioctl,
709 .compat_ioctl = fsl_hv_ioctl,
709}; 710};
710 711
711static struct miscdevice fsl_hv_misc_dev = { 712static struct miscdevice fsl_hv_misc_dev = {
diff --git a/drivers/virtio/Kconfig b/drivers/virtio/Kconfig
index 57e493b1bd20..816ed08e7cf3 100644
--- a/drivers/virtio/Kconfig
+++ b/drivers/virtio/Kconfig
@@ -35,4 +35,15 @@ config VIRTIO_BALLOON
35 35
36 If unsure, say M. 36 If unsure, say M.
37 37
38 config VIRTIO_MMIO
39 tristate "Platform bus driver for memory mapped virtio devices (EXPERIMENTAL)"
40 depends on EXPERIMENTAL
41 select VIRTIO
42 select VIRTIO_RING
43 ---help---
44 This drivers provides support for memory mapped virtio
45 platform device driver.
46
47 If unsure, say N.
48
38endmenu 49endmenu
diff --git a/drivers/virtio/Makefile b/drivers/virtio/Makefile
index 6738c446c199..5a4c63cfd380 100644
--- a/drivers/virtio/Makefile
+++ b/drivers/virtio/Makefile
@@ -1,4 +1,5 @@
1obj-$(CONFIG_VIRTIO) += virtio.o 1obj-$(CONFIG_VIRTIO) += virtio.o
2obj-$(CONFIG_VIRTIO_RING) += virtio_ring.o 2obj-$(CONFIG_VIRTIO_RING) += virtio_ring.o
3obj-$(CONFIG_VIRTIO_MMIO) += virtio_mmio.o
3obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o 4obj-$(CONFIG_VIRTIO_PCI) += virtio_pci.o
4obj-$(CONFIG_VIRTIO_BALLOON) += virtio_balloon.o 5obj-$(CONFIG_VIRTIO_BALLOON) += virtio_balloon.o
diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index efb35aa8309a..984c501c258f 100644
--- a/drivers/virtio/virtio.c
+++ b/drivers/virtio/virtio.c
@@ -1,6 +1,7 @@
1#include <linux/virtio.h> 1#include <linux/virtio.h>
2#include <linux/spinlock.h> 2#include <linux/spinlock.h>
3#include <linux/virtio_config.h> 3#include <linux/virtio_config.h>
4#include <linux/module.h>
4 5
5/* Unique numbering for virtio devices. */ 6/* Unique numbering for virtio devices. */
6static unsigned int dev_index; 7static unsigned int dev_index;
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index e058ace2a4ad..94fd738a7741 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -25,6 +25,7 @@
25#include <linux/freezer.h> 25#include <linux/freezer.h>
26#include <linux/delay.h> 26#include <linux/delay.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/module.h>
28 29
29struct virtio_balloon 30struct virtio_balloon
30{ 31{
diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
new file mode 100644
index 000000000000..acc5e43c373e
--- /dev/null
+++ b/drivers/virtio/virtio_mmio.c
@@ -0,0 +1,479 @@
1/*
2 * Virtio memory mapped device driver
3 *
4 * Copyright 2011, ARM Ltd.
5 *
6 * This module allows virtio devices to be used over a virtual, memory mapped
7 * platform device.
8 *
9 * Registers layout (all 32-bit wide):
10 *
11 * offset d. name description
12 * ------ -- ---------------- -----------------
13 *
14 * 0x000 R MagicValue Magic value "virt"
15 * 0x004 R Version Device version (current max. 1)
16 * 0x008 R DeviceID Virtio device ID
17 * 0x00c R VendorID Virtio vendor ID
18 *
19 * 0x010 R HostFeatures Features supported by the host
20 * 0x014 W HostFeaturesSel Set of host features to access via HostFeatures
21 *
22 * 0x020 W GuestFeatures Features activated by the guest
23 * 0x024 W GuestFeaturesSel Set of activated features to set via GuestFeatures
24 * 0x028 W GuestPageSize Size of guest's memory page in bytes
25 *
26 * 0x030 W QueueSel Queue selector
27 * 0x034 R QueueNumMax Maximum size of the currently selected queue
28 * 0x038 W QueueNum Queue size for the currently selected queue
29 * 0x03c W QueueAlign Used Ring alignment for the current queue
30 * 0x040 RW QueuePFN PFN for the currently selected queue
31 *
32 * 0x050 W QueueNotify Queue notifier
33 * 0x060 R InterruptStatus Interrupt status register
34 * 0x060 W InterruptACK Interrupt acknowledge register
35 * 0x070 RW Status Device status register
36 *
37 * 0x100+ RW Device-specific configuration space
38 *
39 * Based on Virtio PCI driver by Anthony Liguori, copyright IBM Corp. 2007
40 *
41 * This work is licensed under the terms of the GNU GPL, version 2 or later.
42 * See the COPYING file in the top-level directory.
43 */
44
45#include <linux/highmem.h>
46#include <linux/interrupt.h>
47#include <linux/io.h>
48#include <linux/list.h>
49#include <linux/module.h>
50#include <linux/platform_device.h>
51#include <linux/slab.h>
52#include <linux/spinlock.h>
53#include <linux/virtio.h>
54#include <linux/virtio_config.h>
55#include <linux/virtio_mmio.h>
56#include <linux/virtio_ring.h>
57
58
59
60/* The alignment to use between consumer and producer parts of vring.
61 * Currently hardcoded to the page size. */
62#define VIRTIO_MMIO_VRING_ALIGN PAGE_SIZE
63
64
65
66#define to_virtio_mmio_device(_plat_dev) \
67 container_of(_plat_dev, struct virtio_mmio_device, vdev)
68
69struct virtio_mmio_device {
70 struct virtio_device vdev;
71 struct platform_device *pdev;
72
73 void __iomem *base;
74 unsigned long version;
75
76 /* a list of queues so we can dispatch IRQs */
77 spinlock_t lock;
78 struct list_head virtqueues;
79};
80
81struct virtio_mmio_vq_info {
82 /* the actual virtqueue */
83 struct virtqueue *vq;
84
85 /* the number of entries in the queue */
86 unsigned int num;
87
88 /* the index of the queue */
89 int queue_index;
90
91 /* the virtual address of the ring queue */
92 void *queue;
93
94 /* the list node for the virtqueues list */
95 struct list_head node;
96};
97
98
99
100/* Configuration interface */
101
102static u32 vm_get_features(struct virtio_device *vdev)
103{
104 struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
105
106 /* TODO: Features > 32 bits */
107 writel(0, vm_dev->base + VIRTIO_MMIO_HOST_FEATURES_SEL);
108
109 return readl(vm_dev->base + VIRTIO_MMIO_HOST_FEATURES);
110}
111
112static void vm_finalize_features(struct virtio_device *vdev)
113{
114 struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
115 int i;
116
117 /* Give virtio_ring a chance to accept features. */
118 vring_transport_features(vdev);
119
120 for (i = 0; i < ARRAY_SIZE(vdev->features); i++) {
121 writel(i, vm_dev->base + VIRTIO_MMIO_GUEST_FEATURES_SET);
122 writel(vdev->features[i],
123 vm_dev->base + VIRTIO_MMIO_GUEST_FEATURES);
124 }
125}
126
127static void vm_get(struct virtio_device *vdev, unsigned offset,
128 void *buf, unsigned len)
129{
130 struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
131 u8 *ptr = buf;
132 int i;
133
134 for (i = 0; i < len; i++)
135 ptr[i] = readb(vm_dev->base + VIRTIO_MMIO_CONFIG + offset + i);
136}
137
138static void vm_set(struct virtio_device *vdev, unsigned offset,
139 const void *buf, unsigned len)
140{
141 struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
142 const u8 *ptr = buf;
143 int i;
144
145 for (i = 0; i < len; i++)
146 writeb(ptr[i], vm_dev->base + VIRTIO_MMIO_CONFIG + offset + i);
147}
148
149static u8 vm_get_status(struct virtio_device *vdev)
150{
151 struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
152
153 return readl(vm_dev->base + VIRTIO_MMIO_STATUS) & 0xff;
154}
155
156static void vm_set_status(struct virtio_device *vdev, u8 status)
157{
158 struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
159
160 /* We should never be setting status to 0. */
161 BUG_ON(status == 0);
162
163 writel(status, vm_dev->base + VIRTIO_MMIO_STATUS);
164}
165
166static void vm_reset(struct virtio_device *vdev)
167{
168 struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
169
170 /* 0 status means a reset. */
171 writel(0, vm_dev->base + VIRTIO_MMIO_STATUS);
172}
173
174
175
176/* Transport interface */
177
178/* the notify function used when creating a virt queue */
179static void vm_notify(struct virtqueue *vq)
180{
181 struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vq->vdev);
182 struct virtio_mmio_vq_info *info = vq->priv;
183
184 /* We write the queue's selector into the notification register to
185 * signal the other end */
186 writel(info->queue_index, vm_dev->base + VIRTIO_MMIO_QUEUE_NOTIFY);
187}
188
189/* Notify all virtqueues on an interrupt. */
190static irqreturn_t vm_interrupt(int irq, void *opaque)
191{
192 struct virtio_mmio_device *vm_dev = opaque;
193 struct virtio_mmio_vq_info *info;
194 struct virtio_driver *vdrv = container_of(vm_dev->vdev.dev.driver,
195 struct virtio_driver, driver);
196 unsigned long status;
197 unsigned long flags;
198 irqreturn_t ret = IRQ_NONE;
199
200 /* Read and acknowledge interrupts */
201 status = readl(vm_dev->base + VIRTIO_MMIO_INTERRUPT_STATUS);
202 writel(status, vm_dev->base + VIRTIO_MMIO_INTERRUPT_ACK);
203
204 if (unlikely(status & VIRTIO_MMIO_INT_CONFIG)
205 && vdrv && vdrv->config_changed) {
206 vdrv->config_changed(&vm_dev->vdev);
207 ret = IRQ_HANDLED;
208 }
209
210 if (likely(status & VIRTIO_MMIO_INT_VRING)) {
211 spin_lock_irqsave(&vm_dev->lock, flags);
212 list_for_each_entry(info, &vm_dev->virtqueues, node)
213 ret |= vring_interrupt(irq, info->vq);
214 spin_unlock_irqrestore(&vm_dev->lock, flags);
215 }
216
217 return ret;
218}
219
220
221
222static void vm_del_vq(struct virtqueue *vq)
223{
224 struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vq->vdev);
225 struct virtio_mmio_vq_info *info = vq->priv;
226 unsigned long flags, size;
227
228 spin_lock_irqsave(&vm_dev->lock, flags);
229 list_del(&info->node);
230 spin_unlock_irqrestore(&vm_dev->lock, flags);
231
232 vring_del_virtqueue(vq);
233
234 /* Select and deactivate the queue */
235 writel(info->queue_index, vm_dev->base + VIRTIO_MMIO_QUEUE_SEL);
236 writel(0, vm_dev->base + VIRTIO_MMIO_QUEUE_PFN);
237
238 size = PAGE_ALIGN(vring_size(info->num, VIRTIO_MMIO_VRING_ALIGN));
239 free_pages_exact(info->queue, size);
240 kfree(info);
241}
242
243static void vm_del_vqs(struct virtio_device *vdev)
244{
245 struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
246 struct virtqueue *vq, *n;
247
248 list_for_each_entry_safe(vq, n, &vdev->vqs, list)
249 vm_del_vq(vq);
250
251 free_irq(platform_get_irq(vm_dev->pdev, 0), vm_dev);
252}
253
254
255
256static struct virtqueue *vm_setup_vq(struct virtio_device *vdev, unsigned index,
257 void (*callback)(struct virtqueue *vq),
258 const char *name)
259{
260 struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
261 struct virtio_mmio_vq_info *info;
262 struct virtqueue *vq;
263 unsigned long flags, size;
264 int err;
265
266 /* Select the queue we're interested in */
267 writel(index, vm_dev->base + VIRTIO_MMIO_QUEUE_SEL);
268
269 /* Queue shouldn't already be set up. */
270 if (readl(vm_dev->base + VIRTIO_MMIO_QUEUE_PFN)) {
271 err = -ENOENT;
272 goto error_available;
273 }
274
275 /* Allocate and fill out our active queue description */
276 info = kmalloc(sizeof(*info), GFP_KERNEL);
277 if (!info) {
278 err = -ENOMEM;
279 goto error_kmalloc;
280 }
281 info->queue_index = index;
282
283 /* Allocate pages for the queue - start with a queue as big as
284 * possible (limited by maximum size allowed by device), drop down
285 * to a minimal size, just big enough to fit descriptor table
286 * and two rings (which makes it "alignment_size * 2")
287 */
288 info->num = readl(vm_dev->base + VIRTIO_MMIO_QUEUE_NUM_MAX);
289 while (1) {
290 size = PAGE_ALIGN(vring_size(info->num,
291 VIRTIO_MMIO_VRING_ALIGN));
292 /* Already smallest possible allocation? */
293 if (size <= VIRTIO_MMIO_VRING_ALIGN * 2) {
294 err = -ENOMEM;
295 goto error_alloc_pages;
296 }
297
298 info->queue = alloc_pages_exact(size, GFP_KERNEL | __GFP_ZERO);
299 if (info->queue)
300 break;
301
302 info->num /= 2;
303 }
304
305 /* Activate the queue */
306 writel(info->num, vm_dev->base + VIRTIO_MMIO_QUEUE_NUM);
307 writel(VIRTIO_MMIO_VRING_ALIGN,
308 vm_dev->base + VIRTIO_MMIO_QUEUE_ALIGN);
309 writel(virt_to_phys(info->queue) >> PAGE_SHIFT,
310 vm_dev->base + VIRTIO_MMIO_QUEUE_PFN);
311
312 /* Create the vring */
313 vq = vring_new_virtqueue(info->num, VIRTIO_MMIO_VRING_ALIGN,
314 vdev, info->queue, vm_notify, callback, name);
315 if (!vq) {
316 err = -ENOMEM;
317 goto error_new_virtqueue;
318 }
319
320 vq->priv = info;
321 info->vq = vq;
322
323 spin_lock_irqsave(&vm_dev->lock, flags);
324 list_add(&info->node, &vm_dev->virtqueues);
325 spin_unlock_irqrestore(&vm_dev->lock, flags);
326
327 return vq;
328
329error_new_virtqueue:
330 writel(0, vm_dev->base + VIRTIO_MMIO_QUEUE_PFN);
331 free_pages_exact(info->queue, size);
332error_alloc_pages:
333 kfree(info);
334error_kmalloc:
335error_available:
336 return ERR_PTR(err);
337}
338
339static int vm_find_vqs(struct virtio_device *vdev, unsigned nvqs,
340 struct virtqueue *vqs[],
341 vq_callback_t *callbacks[],
342 const char *names[])
343{
344 struct virtio_mmio_device *vm_dev = to_virtio_mmio_device(vdev);
345 unsigned int irq = platform_get_irq(vm_dev->pdev, 0);
346 int i, err;
347
348 err = request_irq(irq, vm_interrupt, IRQF_SHARED,
349 dev_name(&vdev->dev), vm_dev);
350 if (err)
351 return err;
352
353 for (i = 0; i < nvqs; ++i) {
354 vqs[i] = vm_setup_vq(vdev, i, callbacks[i], names[i]);
355 if (IS_ERR(vqs[i])) {
356 vm_del_vqs(vdev);
357 return PTR_ERR(vqs[i]);
358 }
359 }
360
361 return 0;
362}
363
364
365
366static struct virtio_config_ops virtio_mmio_config_ops = {
367 .get = vm_get,
368 .set = vm_set,
369 .get_status = vm_get_status,
370 .set_status = vm_set_status,
371 .reset = vm_reset,
372 .find_vqs = vm_find_vqs,
373 .del_vqs = vm_del_vqs,
374 .get_features = vm_get_features,
375 .finalize_features = vm_finalize_features,
376};
377
378
379
380/* Platform device */
381
382static int __devinit virtio_mmio_probe(struct platform_device *pdev)
383{
384 struct virtio_mmio_device *vm_dev;
385 struct resource *mem;
386 unsigned long magic;
387
388 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
389 if (!mem)
390 return -EINVAL;
391
392 if (!devm_request_mem_region(&pdev->dev, mem->start,
393 resource_size(mem), pdev->name))
394 return -EBUSY;
395
396 vm_dev = devm_kzalloc(&pdev->dev, sizeof(*vm_dev), GFP_KERNEL);
397 if (!vm_dev)
398 return -ENOMEM;
399
400 vm_dev->vdev.dev.parent = &pdev->dev;
401 vm_dev->vdev.config = &virtio_mmio_config_ops;
402 vm_dev->pdev = pdev;
403 INIT_LIST_HEAD(&vm_dev->virtqueues);
404 spin_lock_init(&vm_dev->lock);
405
406 vm_dev->base = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
407 if (vm_dev->base == NULL)
408 return -EFAULT;
409
410 /* Check magic value */
411 magic = readl(vm_dev->base + VIRTIO_MMIO_MAGIC_VALUE);
412 if (memcmp(&magic, "virt", 4) != 0) {
413 dev_warn(&pdev->dev, "Wrong magic value 0x%08lx!\n", magic);
414 return -ENODEV;
415 }
416
417 /* Check device version */
418 vm_dev->version = readl(vm_dev->base + VIRTIO_MMIO_VERSION);
419 if (vm_dev->version != 1) {
420 dev_err(&pdev->dev, "Version %ld not supported!\n",
421 vm_dev->version);
422 return -ENXIO;
423 }
424
425 vm_dev->vdev.id.device = readl(vm_dev->base + VIRTIO_MMIO_DEVICE_ID);
426 vm_dev->vdev.id.vendor = readl(vm_dev->base + VIRTIO_MMIO_VENDOR_ID);
427
428 writel(PAGE_SIZE, vm_dev->base + VIRTIO_MMIO_GUEST_PAGE_SIZE);
429
430 platform_set_drvdata(pdev, vm_dev);
431
432 return register_virtio_device(&vm_dev->vdev);
433}
434
435static int __devexit virtio_mmio_remove(struct platform_device *pdev)
436{
437 struct virtio_mmio_device *vm_dev = platform_get_drvdata(pdev);
438
439 unregister_virtio_device(&vm_dev->vdev);
440
441 return 0;
442}
443
444
445
446/* Platform driver */
447
448static struct of_device_id virtio_mmio_match[] = {
449 { .compatible = "virtio,mmio", },
450 {},
451};
452MODULE_DEVICE_TABLE(of, virtio_mmio_match);
453
454static struct platform_driver virtio_mmio_driver = {
455 .probe = virtio_mmio_probe,
456 .remove = __devexit_p(virtio_mmio_remove),
457 .driver = {
458 .name = "virtio-mmio",
459 .owner = THIS_MODULE,
460 .of_match_table = virtio_mmio_match,
461 },
462};
463
464static int __init virtio_mmio_init(void)
465{
466 return platform_driver_register(&virtio_mmio_driver);
467}
468
469static void __exit virtio_mmio_exit(void)
470{
471 platform_driver_unregister(&virtio_mmio_driver);
472}
473
474module_init(virtio_mmio_init);
475module_exit(virtio_mmio_exit);
476
477MODULE_AUTHOR("Pawel Moll <pawel.moll@arm.com>");
478MODULE_DESCRIPTION("Platform bus driver for memory mapped virtio devices");
479MODULE_LICENSE("GPL");
diff --git a/drivers/virtio/virtio_pci.c b/drivers/virtio/virtio_pci.c
index 4bcc8b82640b..79a31e5b4b68 100644
--- a/drivers/virtio/virtio_pci.c
+++ b/drivers/virtio/virtio_pci.c
@@ -415,9 +415,13 @@ static struct virtqueue *setup_vq(struct virtio_device *vdev, unsigned index,
415 } 415 }
416 } 416 }
417 417
418 spin_lock_irqsave(&vp_dev->lock, flags); 418 if (callback) {
419 list_add(&info->node, &vp_dev->virtqueues); 419 spin_lock_irqsave(&vp_dev->lock, flags);
420 spin_unlock_irqrestore(&vp_dev->lock, flags); 420 list_add(&info->node, &vp_dev->virtqueues);
421 spin_unlock_irqrestore(&vp_dev->lock, flags);
422 } else {
423 INIT_LIST_HEAD(&info->node);
424 }
421 425
422 return vq; 426 return vq;
423 427
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 4acf88884f9b..c7a2c208f6ea 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -21,6 +21,7 @@
21#include <linux/virtio_config.h> 21#include <linux/virtio_config.h>
22#include <linux/device.h> 22#include <linux/device.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/module.h>
24 25
25/* virtio guest is communicating with a virtual "device" that actually runs on 26/* virtio guest is communicating with a virtual "device" that actually runs on
26 * a host processor. Memory barriers are used to control SMP effects. */ 27 * a host processor. Memory barriers are used to control SMP effects. */
diff --git a/drivers/w1/slaves/w1_ds2760.c b/drivers/w1/slaves/w1_ds2760.c
index 483d45180911..5754c9a4f58b 100644
--- a/drivers/w1/slaves/w1_ds2760.c
+++ b/drivers/w1/slaves/w1_ds2760.c
@@ -114,43 +114,7 @@ static struct bin_attribute w1_ds2760_bin_attr = {
114 .read = w1_ds2760_read_bin, 114 .read = w1_ds2760_read_bin,
115}; 115};
116 116
117static DEFINE_IDR(bat_idr); 117static DEFINE_IDA(bat_ida);
118static DEFINE_MUTEX(bat_idr_lock);
119
120static int new_bat_id(void)
121{
122 int ret;
123
124 while (1) {
125 int id;
126
127 ret = idr_pre_get(&bat_idr, GFP_KERNEL);
128 if (ret == 0)
129 return -ENOMEM;
130
131 mutex_lock(&bat_idr_lock);
132 ret = idr_get_new(&bat_idr, NULL, &id);
133 mutex_unlock(&bat_idr_lock);
134
135 if (ret == 0) {
136 ret = id & MAX_ID_MASK;
137 break;
138 } else if (ret == -EAGAIN) {
139 continue;
140 } else {
141 break;
142 }
143 }
144
145 return ret;
146}
147
148static void release_bat_id(int id)
149{
150 mutex_lock(&bat_idr_lock);
151 idr_remove(&bat_idr, id);
152 mutex_unlock(&bat_idr_lock);
153}
154 118
155static int w1_ds2760_add_slave(struct w1_slave *sl) 119static int w1_ds2760_add_slave(struct w1_slave *sl)
156{ 120{
@@ -158,7 +122,7 @@ static int w1_ds2760_add_slave(struct w1_slave *sl)
158 int id; 122 int id;
159 struct platform_device *pdev; 123 struct platform_device *pdev;
160 124
161 id = new_bat_id(); 125 id = ida_simple_get(&bat_ida, 0, 0, GFP_KERNEL);
162 if (id < 0) { 126 if (id < 0) {
163 ret = id; 127 ret = id;
164 goto noid; 128 goto noid;
@@ -187,7 +151,7 @@ bin_attr_failed:
187pdev_add_failed: 151pdev_add_failed:
188 platform_device_unregister(pdev); 152 platform_device_unregister(pdev);
189pdev_alloc_failed: 153pdev_alloc_failed:
190 release_bat_id(id); 154 ida_simple_remove(&bat_ida, id);
191noid: 155noid:
192success: 156success:
193 return ret; 157 return ret;
@@ -199,7 +163,7 @@ static void w1_ds2760_remove_slave(struct w1_slave *sl)
199 int id = pdev->id; 163 int id = pdev->id;
200 164
201 platform_device_unregister(pdev); 165 platform_device_unregister(pdev);
202 release_bat_id(id); 166 ida_simple_remove(&bat_ida, id);
203 sysfs_remove_bin_file(&sl->dev.kobj, &w1_ds2760_bin_attr); 167 sysfs_remove_bin_file(&sl->dev.kobj, &w1_ds2760_bin_attr);
204} 168}
205 169
@@ -217,14 +181,14 @@ static int __init w1_ds2760_init(void)
217{ 181{
218 printk(KERN_INFO "1-Wire driver for the DS2760 battery monitor " 182 printk(KERN_INFO "1-Wire driver for the DS2760 battery monitor "
219 " chip - (c) 2004-2005, Szabolcs Gyurko\n"); 183 " chip - (c) 2004-2005, Szabolcs Gyurko\n");
220 idr_init(&bat_idr); 184 ida_init(&bat_ida);
221 return w1_register_family(&w1_ds2760_family); 185 return w1_register_family(&w1_ds2760_family);
222} 186}
223 187
224static void __exit w1_ds2760_exit(void) 188static void __exit w1_ds2760_exit(void)
225{ 189{
226 w1_unregister_family(&w1_ds2760_family); 190 w1_unregister_family(&w1_ds2760_family);
227 idr_destroy(&bat_idr); 191 ida_destroy(&bat_ida);
228} 192}
229 193
230EXPORT_SYMBOL(w1_ds2760_read); 194EXPORT_SYMBOL(w1_ds2760_read);
diff --git a/drivers/w1/slaves/w1_ds2780.c b/drivers/w1/slaves/w1_ds2780.c
index 274c8f38303f..39f78c0b143c 100644
--- a/drivers/w1/slaves/w1_ds2780.c
+++ b/drivers/w1/slaves/w1_ds2780.c
@@ -26,20 +26,14 @@
26#include "../w1_family.h" 26#include "../w1_family.h"
27#include "w1_ds2780.h" 27#include "w1_ds2780.h"
28 28
29int w1_ds2780_io(struct device *dev, char *buf, int addr, size_t count, 29static int w1_ds2780_do_io(struct device *dev, char *buf, int addr,
30 int io) 30 size_t count, int io)
31{ 31{
32 struct w1_slave *sl = container_of(dev, struct w1_slave, dev); 32 struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
33 33
34 if (!dev) 34 if (addr > DS2780_DATA_SIZE || addr < 0)
35 return -ENODEV; 35 return 0;
36 36
37 mutex_lock(&sl->master->mutex);
38
39 if (addr > DS2780_DATA_SIZE || addr < 0) {
40 count = 0;
41 goto out;
42 }
43 count = min_t(int, count, DS2780_DATA_SIZE - addr); 37 count = min_t(int, count, DS2780_DATA_SIZE - addr);
44 38
45 if (w1_reset_select_slave(sl) == 0) { 39 if (w1_reset_select_slave(sl) == 0) {
@@ -47,7 +41,6 @@ int w1_ds2780_io(struct device *dev, char *buf, int addr, size_t count,
47 w1_write_8(sl->master, W1_DS2780_WRITE_DATA); 41 w1_write_8(sl->master, W1_DS2780_WRITE_DATA);
48 w1_write_8(sl->master, addr); 42 w1_write_8(sl->master, addr);
49 w1_write_block(sl->master, buf, count); 43 w1_write_block(sl->master, buf, count);
50 /* XXX w1_write_block returns void, not n_written */
51 } else { 44 } else {
52 w1_write_8(sl->master, W1_DS2780_READ_DATA); 45 w1_write_8(sl->master, W1_DS2780_READ_DATA);
53 w1_write_8(sl->master, addr); 46 w1_write_8(sl->master, addr);
@@ -55,13 +48,42 @@ int w1_ds2780_io(struct device *dev, char *buf, int addr, size_t count,
55 } 48 }
56 } 49 }
57 50
58out: 51 return count;
52}
53
54int w1_ds2780_io(struct device *dev, char *buf, int addr, size_t count,
55 int io)
56{
57 struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
58 int ret;
59
60 if (!dev)
61 return -ENODEV;
62
63 mutex_lock(&sl->master->mutex);
64
65 ret = w1_ds2780_do_io(dev, buf, addr, count, io);
66
59 mutex_unlock(&sl->master->mutex); 67 mutex_unlock(&sl->master->mutex);
60 68
61 return count; 69 return ret;
62} 70}
63EXPORT_SYMBOL(w1_ds2780_io); 71EXPORT_SYMBOL(w1_ds2780_io);
64 72
73int w1_ds2780_io_nolock(struct device *dev, char *buf, int addr, size_t count,
74 int io)
75{
76 int ret;
77
78 if (!dev)
79 return -ENODEV;
80
81 ret = w1_ds2780_do_io(dev, buf, addr, count, io);
82
83 return ret;
84}
85EXPORT_SYMBOL(w1_ds2780_io_nolock);
86
65int w1_ds2780_eeprom_cmd(struct device *dev, int addr, int cmd) 87int w1_ds2780_eeprom_cmd(struct device *dev, int addr, int cmd)
66{ 88{
67 struct w1_slave *sl = container_of(dev, struct w1_slave, dev); 89 struct w1_slave *sl = container_of(dev, struct w1_slave, dev);
@@ -99,43 +121,7 @@ static struct bin_attribute w1_ds2780_bin_attr = {
99 .read = w1_ds2780_read_bin, 121 .read = w1_ds2780_read_bin,
100}; 122};
101 123
102static DEFINE_IDR(bat_idr); 124static DEFINE_IDA(bat_ida);
103static DEFINE_MUTEX(bat_idr_lock);
104
105static int new_bat_id(void)
106{
107 int ret;
108
109 while (1) {
110 int id;
111
112 ret = idr_pre_get(&bat_idr, GFP_KERNEL);
113 if (ret == 0)
114 return -ENOMEM;
115
116 mutex_lock(&bat_idr_lock);
117 ret = idr_get_new(&bat_idr, NULL, &id);
118 mutex_unlock(&bat_idr_lock);
119
120 if (ret == 0) {
121 ret = id & MAX_ID_MASK;
122 break;
123 } else if (ret == -EAGAIN) {
124 continue;
125 } else {
126 break;
127 }
128 }
129
130 return ret;
131}
132
133static void release_bat_id(int id)
134{
135 mutex_lock(&bat_idr_lock);
136 idr_remove(&bat_idr, id);
137 mutex_unlock(&bat_idr_lock);
138}
139 125
140static int w1_ds2780_add_slave(struct w1_slave *sl) 126static int w1_ds2780_add_slave(struct w1_slave *sl)
141{ 127{
@@ -143,7 +129,7 @@ static int w1_ds2780_add_slave(struct w1_slave *sl)
143 int id; 129 int id;
144 struct platform_device *pdev; 130 struct platform_device *pdev;
145 131
146 id = new_bat_id(); 132 id = ida_simple_get(&bat_ida, 0, 0, GFP_KERNEL);
147 if (id < 0) { 133 if (id < 0) {
148 ret = id; 134 ret = id;
149 goto noid; 135 goto noid;
@@ -172,7 +158,7 @@ bin_attr_failed:
172pdev_add_failed: 158pdev_add_failed:
173 platform_device_unregister(pdev); 159 platform_device_unregister(pdev);
174pdev_alloc_failed: 160pdev_alloc_failed:
175 release_bat_id(id); 161 ida_simple_remove(&bat_ida, id);
176noid: 162noid:
177 return ret; 163 return ret;
178} 164}
@@ -183,7 +169,7 @@ static void w1_ds2780_remove_slave(struct w1_slave *sl)
183 int id = pdev->id; 169 int id = pdev->id;
184 170
185 platform_device_unregister(pdev); 171 platform_device_unregister(pdev);
186 release_bat_id(id); 172 ida_simple_remove(&bat_ida, id);
187 sysfs_remove_bin_file(&sl->dev.kobj, &w1_ds2780_bin_attr); 173 sysfs_remove_bin_file(&sl->dev.kobj, &w1_ds2780_bin_attr);
188} 174}
189 175
@@ -199,14 +185,14 @@ static struct w1_family w1_ds2780_family = {
199 185
200static int __init w1_ds2780_init(void) 186static int __init w1_ds2780_init(void)
201{ 187{
202 idr_init(&bat_idr); 188 ida_init(&bat_ida);
203 return w1_register_family(&w1_ds2780_family); 189 return w1_register_family(&w1_ds2780_family);
204} 190}
205 191
206static void __exit w1_ds2780_exit(void) 192static void __exit w1_ds2780_exit(void)
207{ 193{
208 w1_unregister_family(&w1_ds2780_family); 194 w1_unregister_family(&w1_ds2780_family);
209 idr_destroy(&bat_idr); 195 ida_destroy(&bat_ida);
210} 196}
211 197
212module_init(w1_ds2780_init); 198module_init(w1_ds2780_init);
diff --git a/drivers/w1/slaves/w1_ds2780.h b/drivers/w1/slaves/w1_ds2780.h
index a1fba79eb1b5..737379365021 100644
--- a/drivers/w1/slaves/w1_ds2780.h
+++ b/drivers/w1/slaves/w1_ds2780.h
@@ -124,6 +124,8 @@
124 124
125extern int w1_ds2780_io(struct device *dev, char *buf, int addr, size_t count, 125extern int w1_ds2780_io(struct device *dev, char *buf, int addr, size_t count,
126 int io); 126 int io);
127extern int w1_ds2780_io_nolock(struct device *dev, char *buf, int addr,
128 size_t count, int io);
127extern int w1_ds2780_eeprom_cmd(struct device *dev, int addr, int cmd); 129extern int w1_ds2780_eeprom_cmd(struct device *dev, int addr, int cmd);
128 130
129#endif /* !_W1_DS2780_H */ 131#endif /* !_W1_DS2780_H */
diff --git a/drivers/w1/w1_family.c b/drivers/w1/w1_family.c
index 63359797c8b1..e9309778ee72 100644
--- a/drivers/w1/w1_family.c
+++ b/drivers/w1/w1_family.c
@@ -23,6 +23,7 @@
23#include <linux/list.h> 23#include <linux/list.h>
24#include <linux/sched.h> /* schedule_timeout() */ 24#include <linux/sched.h> /* schedule_timeout() */
25#include <linux/delay.h> 25#include <linux/delay.h>
26#include <linux/export.h>
26 27
27#include "w1_family.h" 28#include "w1_family.h"
28#include "w1.h" 29#include "w1.h"
diff --git a/drivers/w1/w1_int.c b/drivers/w1/w1_int.c
index d220bce2cee4..68288355727a 100644
--- a/drivers/w1/w1_int.c
+++ b/drivers/w1/w1_int.c
@@ -24,6 +24,8 @@
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <linux/kthread.h> 25#include <linux/kthread.h>
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/export.h>
28#include <linux/moduleparam.h>
27 29
28#include "w1.h" 30#include "w1.h"
29#include "w1_log.h" 31#include "w1_log.h"
@@ -78,6 +80,7 @@ static struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl,
78 memcpy(&dev->dev, device, sizeof(struct device)); 80 memcpy(&dev->dev, device, sizeof(struct device));
79 dev_set_name(&dev->dev, "w1_bus_master%u", dev->id); 81 dev_set_name(&dev->dev, "w1_bus_master%u", dev->id);
80 snprintf(dev->name, sizeof(dev->name), "w1_bus_master%u", dev->id); 82 snprintf(dev->name, sizeof(dev->name), "w1_bus_master%u", dev->id);
83 dev->dev.init_name = dev->name;
81 84
82 dev->driver = driver; 85 dev->driver = driver;
83 86
diff --git a/drivers/w1/w1_io.c b/drivers/w1/w1_io.c
index 765b37b62a4f..3135b2c63998 100644
--- a/drivers/w1/w1_io.c
+++ b/drivers/w1/w1_io.c
@@ -158,13 +158,18 @@ EXPORT_SYMBOL_GPL(w1_write_8);
158static u8 w1_read_bit(struct w1_master *dev) 158static u8 w1_read_bit(struct w1_master *dev)
159{ 159{
160 int result; 160 int result;
161 unsigned long flags;
161 162
163 /* sample timing is critical here */
164 local_irq_save(flags);
162 dev->bus_master->write_bit(dev->bus_master->data, 0); 165 dev->bus_master->write_bit(dev->bus_master->data, 0);
163 w1_delay(6); 166 w1_delay(6);
164 dev->bus_master->write_bit(dev->bus_master->data, 1); 167 dev->bus_master->write_bit(dev->bus_master->data, 1);
165 w1_delay(9); 168 w1_delay(9);
166 169
167 result = dev->bus_master->read_bit(dev->bus_master->data); 170 result = dev->bus_master->read_bit(dev->bus_master->data);
171 local_irq_restore(flags);
172
168 w1_delay(55); 173 w1_delay(55);
169 174
170 return result & 0x1; 175 return result & 0x1;
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 86b0735e6aa0..6285867a9356 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -66,6 +66,7 @@ config SOFT_WATCHDOG
66config WM831X_WATCHDOG 66config WM831X_WATCHDOG
67 tristate "WM831x watchdog" 67 tristate "WM831x watchdog"
68 depends on MFD_WM831X 68 depends on MFD_WM831X
69 select WATCHDOG_CORE
69 help 70 help
70 Support for the watchdog in the WM831x AudioPlus PMICs. When 71 Support for the watchdog in the WM831x AudioPlus PMICs. When
71 the watchdog triggers the system will be reset. 72 the watchdog triggers the system will be reset.
@@ -170,6 +171,7 @@ config HAVE_S3C2410_WATCHDOG
170config S3C2410_WATCHDOG 171config S3C2410_WATCHDOG
171 tristate "S3C2410 Watchdog" 172 tristate "S3C2410 Watchdog"
172 depends on ARCH_S3C2410 || HAVE_S3C2410_WATCHDOG 173 depends on ARCH_S3C2410 || HAVE_S3C2410_WATCHDOG
174 select WATCHDOG_CORE
173 help 175 help
174 Watchdog timer block in the Samsung SoCs. This will reboot 176 Watchdog timer block in the Samsung SoCs. This will reboot
175 the system when the timer expires with the watchdog enabled. 177 the system when the timer expires with the watchdog enabled.
@@ -726,7 +728,7 @@ config SBC8360_WDT
726 728
727config SBC7240_WDT 729config SBC7240_WDT
728 tristate "SBC Nano 7240 Watchdog Timer" 730 tristate "SBC Nano 7240 Watchdog Timer"
729 depends on X86_32 731 depends on X86_32 && !UML
730 ---help--- 732 ---help---
731 This is the driver for the hardware watchdog found on the IEI 733 This is the driver for the hardware watchdog found on the IEI
732 single board computers EPIC Nano 7240 (and likely others). This 734 single board computers EPIC Nano 7240 (and likely others). This
@@ -1174,6 +1176,10 @@ config XEN_WDT
1174 by Xen 4.0 and newer. The watchdog timeout period is normally one 1176 by Xen 4.0 and newer. The watchdog timeout period is normally one
1175 minute but can be changed with a boot-time parameter. 1177 minute but can be changed with a boot-time parameter.
1176 1178
1179config UML_WATCHDOG
1180 tristate "UML watchdog"
1181 depends on UML
1182
1177# 1183#
1178# ISA-based Watchdog Cards 1184# ISA-based Watchdog Cards
1179# 1185#
diff --git a/drivers/watchdog/coh901327_wdt.c b/drivers/watchdog/coh901327_wdt.c
index 9291506b8b23..03f449a430d2 100644
--- a/drivers/watchdog/coh901327_wdt.c
+++ b/drivers/watchdog/coh901327_wdt.c
@@ -429,7 +429,7 @@ static int __init coh901327_probe(struct platform_device *pdev)
429 writew(U300_WDOG_SR_RESET_STATUS_RESET, virtbase + U300_WDOG_SR); 429 writew(U300_WDOG_SR_RESET_STATUS_RESET, virtbase + U300_WDOG_SR);
430 430
431 irq = platform_get_irq(pdev, 0); 431 irq = platform_get_irq(pdev, 0);
432 if (request_irq(irq, coh901327_interrupt, IRQF_DISABLED, 432 if (request_irq(irq, coh901327_interrupt, 0,
433 DRV_NAME " Bark", pdev)) { 433 DRV_NAME " Bark", pdev)) {
434 ret = -EIO; 434 ret = -EIO;
435 goto out_no_irq; 435 goto out_no_irq;
diff --git a/drivers/watchdog/eurotechwdt.c b/drivers/watchdog/eurotechwdt.c
index f1d1da662fbe..41018d429abb 100644
--- a/drivers/watchdog/eurotechwdt.c
+++ b/drivers/watchdog/eurotechwdt.c
@@ -427,7 +427,7 @@ static int __init eurwdt_init(void)
427{ 427{
428 int ret; 428 int ret;
429 429
430 ret = request_irq(irq, eurwdt_interrupt, IRQF_DISABLED, "eurwdt", NULL); 430 ret = request_irq(irq, eurwdt_interrupt, 0, "eurwdt", NULL);
431 if (ret) { 431 if (ret) {
432 printk(KERN_ERR "eurwdt: IRQ %d is not free.\n", irq); 432 printk(KERN_ERR "eurwdt: IRQ %d is not free.\n", irq);
433 goto out; 433 goto out;
diff --git a/drivers/watchdog/iTCO_wdt.c b/drivers/watchdog/iTCO_wdt.c
index 751a591684da..ba6ad662635a 100644
--- a/drivers/watchdog/iTCO_wdt.c
+++ b/drivers/watchdog/iTCO_wdt.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * intel TCO Watchdog Driver 2 * intel TCO Watchdog Driver
3 * 3 *
4 * (c) Copyright 2006-2010 Wim Van Sebroeck <wim@iguana.be>. 4 * (c) Copyright 2006-2011 Wim Van Sebroeck <wim@iguana.be>.
5 * 5 *
6 * This program is free software; you can redistribute it and/or 6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License 7 * modify it under the terms of the GNU General Public License
@@ -44,7 +44,7 @@
44 44
45/* Module and version information */ 45/* Module and version information */
46#define DRV_NAME "iTCO_wdt" 46#define DRV_NAME "iTCO_wdt"
47#define DRV_VERSION "1.06" 47#define DRV_VERSION "1.07"
48#define PFX DRV_NAME ": " 48#define PFX DRV_NAME ": "
49 49
50/* Includes */ 50/* Includes */
@@ -384,6 +384,11 @@ MODULE_PARM_DESC(nowayout,
384 "Watchdog cannot be stopped once started (default=" 384 "Watchdog cannot be stopped once started (default="
385 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); 385 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
386 386
387static int turn_SMI_watchdog_clear_off = 0;
388module_param(turn_SMI_watchdog_clear_off, int, 0);
389MODULE_PARM_DESC(turn_SMI_watchdog_clear_off,
390 "Turn off SMI clearing watchdog (default=0)");
391
387/* 392/*
388 * Some TCO specific functions 393 * Some TCO specific functions
389 */ 394 */
@@ -808,10 +813,12 @@ static int __devinit iTCO_wdt_init(struct pci_dev *pdev,
808 ret = -EIO; 813 ret = -EIO;
809 goto out_unmap; 814 goto out_unmap;
810 } 815 }
811 /* Bit 13: TCO_EN -> 0 = Disables TCO logic generating an SMI# */ 816 if (turn_SMI_watchdog_clear_off) {
812 val32 = inl(SMI_EN); 817 /* Bit 13: TCO_EN -> 0 = Disables TCO logic generating an SMI# */
813 val32 &= 0xffffdfff; /* Turn off SMI clearing watchdog */ 818 val32 = inl(SMI_EN);
814 outl(val32, SMI_EN); 819 val32 &= 0xffffdfff; /* Turn off SMI clearing watchdog */
820 outl(val32, SMI_EN);
821 }
815 822
816 /* The TCO I/O registers reside in a 32-byte range pointed to 823 /* The TCO I/O registers reside in a 32-byte range pointed to
817 by the TCOBASE value */ 824 by the TCOBASE value */
diff --git a/drivers/watchdog/mpcore_wdt.c b/drivers/watchdog/mpcore_wdt.c
index 4dc31024d26c..82ccd36e2c90 100644
--- a/drivers/watchdog/mpcore_wdt.c
+++ b/drivers/watchdog/mpcore_wdt.c
@@ -367,8 +367,7 @@ static int __devinit mpcore_wdt_probe(struct platform_device *dev)
367 goto err_misc; 367 goto err_misc;
368 } 368 }
369 369
370 ret = request_irq(wdt->irq, mpcore_wdt_fire, IRQF_DISABLED, 370 ret = request_irq(wdt->irq, mpcore_wdt_fire, 0, "mpcore_wdt", wdt);
371 "mpcore_wdt", wdt);
372 if (ret) { 371 if (ret) {
373 dev_printk(KERN_ERR, wdt->dev, 372 dev_printk(KERN_ERR, wdt->dev,
374 "cannot register IRQ%d for watchdog\n", wdt->irq); 373 "cannot register IRQ%d for watchdog\n", wdt->irq);
diff --git a/drivers/watchdog/octeon-wdt-main.c b/drivers/watchdog/octeon-wdt-main.c
index 945ee8300306..7c0d8630e641 100644
--- a/drivers/watchdog/octeon-wdt-main.c
+++ b/drivers/watchdog/octeon-wdt-main.c
@@ -402,7 +402,7 @@ static void octeon_wdt_setup_interrupt(int cpu)
402 irq = OCTEON_IRQ_WDOG0 + core; 402 irq = OCTEON_IRQ_WDOG0 + core;
403 403
404 if (request_irq(irq, octeon_wdt_poke_irq, 404 if (request_irq(irq, octeon_wdt_poke_irq,
405 IRQF_DISABLED, "octeon_wdt", octeon_wdt_poke_irq)) 405 IRQF_NO_THREAD, "octeon_wdt", octeon_wdt_poke_irq))
406 panic("octeon_wdt: Couldn't obtain irq %d", irq); 406 panic("octeon_wdt: Couldn't obtain irq %d", irq);
407 407
408 cpumask_set_cpu(cpu, &irq_enabled_cpus); 408 cpumask_set_cpu(cpu, &irq_enabled_cpus);
diff --git a/drivers/watchdog/s3c2410_wdt.c b/drivers/watchdog/s3c2410_wdt.c
index 30da88f47cd3..5de7e4fa5b8a 100644
--- a/drivers/watchdog/s3c2410_wdt.c
+++ b/drivers/watchdog/s3c2410_wdt.c
@@ -27,9 +27,8 @@
27#include <linux/moduleparam.h> 27#include <linux/moduleparam.h>
28#include <linux/types.h> 28#include <linux/types.h>
29#include <linux/timer.h> 29#include <linux/timer.h>
30#include <linux/miscdevice.h> 30#include <linux/miscdevice.h> /* for MODULE_ALIAS_MISCDEV */
31#include <linux/watchdog.h> 31#include <linux/watchdog.h>
32#include <linux/fs.h>
33#include <linux/init.h> 32#include <linux/init.h>
34#include <linux/platform_device.h> 33#include <linux/platform_device.h>
35#include <linux/interrupt.h> 34#include <linux/interrupt.h>
@@ -38,6 +37,7 @@
38#include <linux/io.h> 37#include <linux/io.h>
39#include <linux/cpufreq.h> 38#include <linux/cpufreq.h>
40#include <linux/slab.h> 39#include <linux/slab.h>
40#include <linux/err.h>
41 41
42#include <mach/map.h> 42#include <mach/map.h>
43 43
@@ -74,14 +74,12 @@ MODULE_PARM_DESC(soft_noboot, "Watchdog action, set to 1 to ignore reboots, "
74 "0 to reboot (default 0)"); 74 "0 to reboot (default 0)");
75MODULE_PARM_DESC(debug, "Watchdog debug, set to >1 for debug (default 0)"); 75MODULE_PARM_DESC(debug, "Watchdog debug, set to >1 for debug (default 0)");
76 76
77static unsigned long open_lock;
78static struct device *wdt_dev; /* platform device attached to */ 77static struct device *wdt_dev; /* platform device attached to */
79static struct resource *wdt_mem; 78static struct resource *wdt_mem;
80static struct resource *wdt_irq; 79static struct resource *wdt_irq;
81static struct clk *wdt_clock; 80static struct clk *wdt_clock;
82static void __iomem *wdt_base; 81static void __iomem *wdt_base;
83static unsigned int wdt_count; 82static unsigned int wdt_count;
84static char expect_close;
85static DEFINE_SPINLOCK(wdt_lock); 83static DEFINE_SPINLOCK(wdt_lock);
86 84
87/* watchdog control routines */ 85/* watchdog control routines */
@@ -93,11 +91,13 @@ static DEFINE_SPINLOCK(wdt_lock);
93 91
94/* functions */ 92/* functions */
95 93
96static void s3c2410wdt_keepalive(void) 94static int s3c2410wdt_keepalive(struct watchdog_device *wdd)
97{ 95{
98 spin_lock(&wdt_lock); 96 spin_lock(&wdt_lock);
99 writel(wdt_count, wdt_base + S3C2410_WTCNT); 97 writel(wdt_count, wdt_base + S3C2410_WTCNT);
100 spin_unlock(&wdt_lock); 98 spin_unlock(&wdt_lock);
99
100 return 0;
101} 101}
102 102
103static void __s3c2410wdt_stop(void) 103static void __s3c2410wdt_stop(void)
@@ -109,14 +109,16 @@ static void __s3c2410wdt_stop(void)
109 writel(wtcon, wdt_base + S3C2410_WTCON); 109 writel(wtcon, wdt_base + S3C2410_WTCON);
110} 110}
111 111
112static void s3c2410wdt_stop(void) 112static int s3c2410wdt_stop(struct watchdog_device *wdd)
113{ 113{
114 spin_lock(&wdt_lock); 114 spin_lock(&wdt_lock);
115 __s3c2410wdt_stop(); 115 __s3c2410wdt_stop();
116 spin_unlock(&wdt_lock); 116 spin_unlock(&wdt_lock);
117
118 return 0;
117} 119}
118 120
119static void s3c2410wdt_start(void) 121static int s3c2410wdt_start(struct watchdog_device *wdd)
120{ 122{
121 unsigned long wtcon; 123 unsigned long wtcon;
122 124
@@ -142,6 +144,8 @@ static void s3c2410wdt_start(void)
142 writel(wdt_count, wdt_base + S3C2410_WTCNT); 144 writel(wdt_count, wdt_base + S3C2410_WTCNT);
143 writel(wtcon, wdt_base + S3C2410_WTCON); 145 writel(wtcon, wdt_base + S3C2410_WTCON);
144 spin_unlock(&wdt_lock); 146 spin_unlock(&wdt_lock);
147
148 return 0;
145} 149}
146 150
147static inline int s3c2410wdt_is_running(void) 151static inline int s3c2410wdt_is_running(void)
@@ -149,7 +153,7 @@ static inline int s3c2410wdt_is_running(void)
149 return readl(wdt_base + S3C2410_WTCON) & S3C2410_WTCON_ENABLE; 153 return readl(wdt_base + S3C2410_WTCON) & S3C2410_WTCON_ENABLE;
150} 154}
151 155
152static int s3c2410wdt_set_heartbeat(int timeout) 156static int s3c2410wdt_set_heartbeat(struct watchdog_device *wdd, unsigned timeout)
153{ 157{
154 unsigned long freq = clk_get_rate(wdt_clock); 158 unsigned long freq = clk_get_rate(wdt_clock);
155 unsigned int count; 159 unsigned int count;
@@ -182,8 +186,6 @@ static int s3c2410wdt_set_heartbeat(int timeout)
182 } 186 }
183 } 187 }
184 188
185 tmr_margin = timeout;
186
187 DBG("%s: timeout=%d, divisor=%d, count=%d (%08x)\n", 189 DBG("%s: timeout=%d, divisor=%d, count=%d (%08x)\n",
188 __func__, timeout, divisor, count, count/divisor); 190 __func__, timeout, divisor, count, count/divisor);
189 191
@@ -201,70 +203,6 @@ static int s3c2410wdt_set_heartbeat(int timeout)
201 return 0; 203 return 0;
202} 204}
203 205
204/*
205 * /dev/watchdog handling
206 */
207
208static int s3c2410wdt_open(struct inode *inode, struct file *file)
209{
210 if (test_and_set_bit(0, &open_lock))
211 return -EBUSY;
212
213 if (nowayout)
214 __module_get(THIS_MODULE);
215
216 expect_close = 0;
217
218 /* start the timer */
219 s3c2410wdt_start();
220 return nonseekable_open(inode, file);
221}
222
223static int s3c2410wdt_release(struct inode *inode, struct file *file)
224{
225 /*
226 * Shut off the timer.
227 * Lock it in if it's a module and we set nowayout
228 */
229
230 if (expect_close == 42)
231 s3c2410wdt_stop();
232 else {
233 dev_err(wdt_dev, "Unexpected close, not stopping watchdog\n");
234 s3c2410wdt_keepalive();
235 }
236 expect_close = 0;
237 clear_bit(0, &open_lock);
238 return 0;
239}
240
241static ssize_t s3c2410wdt_write(struct file *file, const char __user *data,
242 size_t len, loff_t *ppos)
243{
244 /*
245 * Refresh the timer.
246 */
247 if (len) {
248 if (!nowayout) {
249 size_t i;
250
251 /* In case it was set long ago */
252 expect_close = 0;
253
254 for (i = 0; i != len; i++) {
255 char c;
256
257 if (get_user(c, data + i))
258 return -EFAULT;
259 if (c == 'V')
260 expect_close = 42;
261 }
262 }
263 s3c2410wdt_keepalive();
264 }
265 return len;
266}
267
268#define OPTIONS (WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE) 206#define OPTIONS (WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE)
269 207
270static const struct watchdog_info s3c2410_wdt_ident = { 208static const struct watchdog_info s3c2410_wdt_ident = {
@@ -273,53 +211,17 @@ static const struct watchdog_info s3c2410_wdt_ident = {
273 .identity = "S3C2410 Watchdog", 211 .identity = "S3C2410 Watchdog",
274}; 212};
275 213
276 214static struct watchdog_ops s3c2410wdt_ops = {
277static long s3c2410wdt_ioctl(struct file *file, unsigned int cmd, 215 .owner = THIS_MODULE,
278 unsigned long arg) 216 .start = s3c2410wdt_start,
279{ 217 .stop = s3c2410wdt_stop,
280 void __user *argp = (void __user *)arg; 218 .ping = s3c2410wdt_keepalive,
281 int __user *p = argp; 219 .set_timeout = s3c2410wdt_set_heartbeat,
282 int new_margin;
283
284 switch (cmd) {
285 case WDIOC_GETSUPPORT:
286 return copy_to_user(argp, &s3c2410_wdt_ident,
287 sizeof(s3c2410_wdt_ident)) ? -EFAULT : 0;
288 case WDIOC_GETSTATUS:
289 case WDIOC_GETBOOTSTATUS:
290 return put_user(0, p);
291 case WDIOC_KEEPALIVE:
292 s3c2410wdt_keepalive();
293 return 0;
294 case WDIOC_SETTIMEOUT:
295 if (get_user(new_margin, p))
296 return -EFAULT;
297 if (s3c2410wdt_set_heartbeat(new_margin))
298 return -EINVAL;
299 s3c2410wdt_keepalive();
300 return put_user(tmr_margin, p);
301 case WDIOC_GETTIMEOUT:
302 return put_user(tmr_margin, p);
303 default:
304 return -ENOTTY;
305 }
306}
307
308/* kernel interface */
309
310static const struct file_operations s3c2410wdt_fops = {
311 .owner = THIS_MODULE,
312 .llseek = no_llseek,
313 .write = s3c2410wdt_write,
314 .unlocked_ioctl = s3c2410wdt_ioctl,
315 .open = s3c2410wdt_open,
316 .release = s3c2410wdt_release,
317}; 220};
318 221
319static struct miscdevice s3c2410wdt_miscdev = { 222static struct watchdog_device s3c2410_wdd = {
320 .minor = WATCHDOG_MINOR, 223 .info = &s3c2410_wdt_ident,
321 .name = "watchdog", 224 .ops = &s3c2410wdt_ops,
322 .fops = &s3c2410wdt_fops,
323}; 225};
324 226
325/* interrupt handler code */ 227/* interrupt handler code */
@@ -328,7 +230,7 @@ static irqreturn_t s3c2410wdt_irq(int irqno, void *param)
328{ 230{
329 dev_info(wdt_dev, "watchdog timer expired (irq)\n"); 231 dev_info(wdt_dev, "watchdog timer expired (irq)\n");
330 232
331 s3c2410wdt_keepalive(); 233 s3c2410wdt_keepalive(&s3c2410_wdd);
332 return IRQ_HANDLED; 234 return IRQ_HANDLED;
333} 235}
334 236
@@ -349,14 +251,14 @@ static int s3c2410wdt_cpufreq_transition(struct notifier_block *nb,
349 * the watchdog is running. 251 * the watchdog is running.
350 */ 252 */
351 253
352 s3c2410wdt_keepalive(); 254 s3c2410wdt_keepalive(&s3c2410_wdd);
353 } else if (val == CPUFREQ_POSTCHANGE) { 255 } else if (val == CPUFREQ_POSTCHANGE) {
354 s3c2410wdt_stop(); 256 s3c2410wdt_stop(&s3c2410_wdd);
355 257
356 ret = s3c2410wdt_set_heartbeat(tmr_margin); 258 ret = s3c2410wdt_set_heartbeat(&s3c2410_wdd, s3c2410_wdd.timeout);
357 259
358 if (ret >= 0) 260 if (ret >= 0)
359 s3c2410wdt_start(); 261 s3c2410wdt_start(&s3c2410_wdd);
360 else 262 else
361 goto err; 263 goto err;
362 } 264 }
@@ -365,7 +267,8 @@ done:
365 return 0; 267 return 0;
366 268
367 err: 269 err:
368 dev_err(wdt_dev, "cannot set new value for timeout %d\n", tmr_margin); 270 dev_err(wdt_dev, "cannot set new value for timeout %d\n",
271 s3c2410_wdd.timeout);
369 return ret; 272 return ret;
370} 273}
371 274
@@ -396,10 +299,6 @@ static inline void s3c2410wdt_cpufreq_deregister(void)
396} 299}
397#endif 300#endif
398 301
399
400
401/* device interface */
402
403static int __devinit s3c2410wdt_probe(struct platform_device *pdev) 302static int __devinit s3c2410wdt_probe(struct platform_device *pdev)
404{ 303{
405 struct device *dev; 304 struct device *dev;
@@ -466,8 +365,8 @@ static int __devinit s3c2410wdt_probe(struct platform_device *pdev)
466 /* see if we can actually set the requested timer margin, and if 365 /* see if we can actually set the requested timer margin, and if
467 * not, try the default value */ 366 * not, try the default value */
468 367
469 if (s3c2410wdt_set_heartbeat(tmr_margin)) { 368 if (s3c2410wdt_set_heartbeat(&s3c2410_wdd, tmr_margin)) {
470 started = s3c2410wdt_set_heartbeat( 369 started = s3c2410wdt_set_heartbeat(&s3c2410_wdd,
471 CONFIG_S3C2410_WATCHDOG_DEFAULT_TIME); 370 CONFIG_S3C2410_WATCHDOG_DEFAULT_TIME);
472 371
473 if (started == 0) 372 if (started == 0)
@@ -479,22 +378,21 @@ static int __devinit s3c2410wdt_probe(struct platform_device *pdev)
479 "cannot start\n"); 378 "cannot start\n");
480 } 379 }
481 380
482 ret = misc_register(&s3c2410wdt_miscdev); 381 ret = watchdog_register_device(&s3c2410_wdd);
483 if (ret) { 382 if (ret) {
484 dev_err(dev, "cannot register miscdev on minor=%d (%d)\n", 383 dev_err(dev, "cannot register watchdog (%d)\n", ret);
485 WATCHDOG_MINOR, ret);
486 goto err_cpufreq; 384 goto err_cpufreq;
487 } 385 }
488 386
489 if (tmr_atboot && started == 0) { 387 if (tmr_atboot && started == 0) {
490 dev_info(dev, "starting watchdog timer\n"); 388 dev_info(dev, "starting watchdog timer\n");
491 s3c2410wdt_start(); 389 s3c2410wdt_start(&s3c2410_wdd);
492 } else if (!tmr_atboot) { 390 } else if (!tmr_atboot) {
493 /* if we're not enabling the watchdog, then ensure it is 391 /* if we're not enabling the watchdog, then ensure it is
494 * disabled if it has been left running from the bootloader 392 * disabled if it has been left running from the bootloader
495 * or other source */ 393 * or other source */
496 394
497 s3c2410wdt_stop(); 395 s3c2410wdt_stop(&s3c2410_wdd);
498 } 396 }
499 397
500 /* print out a statement of readiness */ 398 /* print out a statement of readiness */
@@ -530,7 +428,7 @@ static int __devinit s3c2410wdt_probe(struct platform_device *pdev)
530 428
531static int __devexit s3c2410wdt_remove(struct platform_device *dev) 429static int __devexit s3c2410wdt_remove(struct platform_device *dev)
532{ 430{
533 misc_deregister(&s3c2410wdt_miscdev); 431 watchdog_unregister_device(&s3c2410_wdd);
534 432
535 s3c2410wdt_cpufreq_deregister(); 433 s3c2410wdt_cpufreq_deregister();
536 434
@@ -550,7 +448,7 @@ static int __devexit s3c2410wdt_remove(struct platform_device *dev)
550 448
551static void s3c2410wdt_shutdown(struct platform_device *dev) 449static void s3c2410wdt_shutdown(struct platform_device *dev)
552{ 450{
553 s3c2410wdt_stop(); 451 s3c2410wdt_stop(&s3c2410_wdd);
554} 452}
555 453
556#ifdef CONFIG_PM 454#ifdef CONFIG_PM
@@ -565,7 +463,7 @@ static int s3c2410wdt_suspend(struct platform_device *dev, pm_message_t state)
565 wtdat_save = readl(wdt_base + S3C2410_WTDAT); 463 wtdat_save = readl(wdt_base + S3C2410_WTDAT);
566 464
567 /* Note that WTCNT doesn't need to be saved. */ 465 /* Note that WTCNT doesn't need to be saved. */
568 s3c2410wdt_stop(); 466 s3c2410wdt_stop(&s3c2410_wdd);
569 467
570 return 0; 468 return 0;
571} 469}
diff --git a/drivers/watchdog/sb_wdog.c b/drivers/watchdog/sb_wdog.c
index f31493e65b38..b01a30e5a663 100644
--- a/drivers/watchdog/sb_wdog.c
+++ b/drivers/watchdog/sb_wdog.c
@@ -300,7 +300,7 @@ static int __init sbwdog_init(void)
300 * get the resources 300 * get the resources
301 */ 301 */
302 302
303 ret = request_irq(1, sbwdog_interrupt, IRQF_DISABLED | IRQF_SHARED, 303 ret = request_irq(1, sbwdog_interrupt, IRQF_SHARED,
304 ident.identity, (void *)user_dog); 304 ident.identity, (void *)user_dog);
305 if (ret) { 305 if (ret) {
306 printk(KERN_ERR "%s: failed to request irq 1 - %d\n", 306 printk(KERN_ERR "%s: failed to request irq 1 - %d\n",
@@ -350,7 +350,7 @@ void platform_wd_setup(void)
350{ 350{
351 int ret; 351 int ret;
352 352
353 ret = request_irq(1, sbwdog_interrupt, IRQF_DISABLED | IRQF_SHARED, 353 ret = request_irq(1, sbwdog_interrupt, IRQF_SHARED,
354 "Kernel Watchdog", IOADDR(A_SCD_WDOG_CFG_0)); 354 "Kernel Watchdog", IOADDR(A_SCD_WDOG_CFG_0));
355 if (ret) { 355 if (ret) {
356 printk(KERN_CRIT 356 printk(KERN_CRIT
diff --git a/drivers/watchdog/sc520_wdt.c b/drivers/watchdog/sc520_wdt.c
index 52b63f2f0dac..b2840409ebc7 100644
--- a/drivers/watchdog/sc520_wdt.c
+++ b/drivers/watchdog/sc520_wdt.c
@@ -398,7 +398,7 @@ static int __init sc520_wdt_init(void)
398 WATCHDOG_TIMEOUT); 398 WATCHDOG_TIMEOUT);
399 } 399 }
400 400
401 wdtmrctl = ioremap((unsigned long)(MMCR_BASE + OFFS_WDTMRCTL), 2); 401 wdtmrctl = ioremap(MMCR_BASE + OFFS_WDTMRCTL, 2);
402 if (!wdtmrctl) { 402 if (!wdtmrctl) {
403 printk(KERN_ERR PFX "Unable to remap memory\n"); 403 printk(KERN_ERR PFX "Unable to remap memory\n");
404 rc = -ENOMEM; 404 rc = -ENOMEM;
diff --git a/drivers/watchdog/stmp3xxx_wdt.c b/drivers/watchdog/stmp3xxx_wdt.c
index b3421fd2cda8..ac2346a452e5 100644
--- a/drivers/watchdog/stmp3xxx_wdt.c
+++ b/drivers/watchdog/stmp3xxx_wdt.c
@@ -14,6 +14,7 @@
14#include <linux/platform_device.h> 14#include <linux/platform_device.h>
15#include <linux/spinlock.h> 15#include <linux/spinlock.h>
16#include <linux/uaccess.h> 16#include <linux/uaccess.h>
17#include <linux/module.h>
17 18
18#include <mach/platform.h> 19#include <mach/platform.h>
19#include <mach/regs-rtc.h> 20#include <mach/regs-rtc.h>
diff --git a/drivers/watchdog/w83627hf_wdt.c b/drivers/watchdog/w83627hf_wdt.c
index e5c91d4404ed..dd5d67548758 100644
--- a/drivers/watchdog/w83627hf_wdt.c
+++ b/drivers/watchdog/w83627hf_wdt.c
@@ -142,7 +142,7 @@ static void w83627hf_init(void)
142 w83627hf_unselect_wd_register(); 142 w83627hf_unselect_wd_register();
143} 143}
144 144
145static void wdt_ctrl(int timeout) 145static void wdt_set_time(int timeout)
146{ 146{
147 spin_lock(&io_lock); 147 spin_lock(&io_lock);
148 148
@@ -158,13 +158,13 @@ static void wdt_ctrl(int timeout)
158 158
159static int wdt_ping(void) 159static int wdt_ping(void)
160{ 160{
161 wdt_ctrl(timeout); 161 wdt_set_time(timeout);
162 return 0; 162 return 0;
163} 163}
164 164
165static int wdt_disable(void) 165static int wdt_disable(void)
166{ 166{
167 wdt_ctrl(0); 167 wdt_set_time(0);
168 return 0; 168 return 0;
169} 169}
170 170
@@ -176,6 +176,24 @@ static int wdt_set_heartbeat(int t)
176 return 0; 176 return 0;
177} 177}
178 178
179static int wdt_get_time(void)
180{
181 int timeleft;
182
183 spin_lock(&io_lock);
184
185 w83627hf_select_wd_register();
186
187 outb_p(0xF6, WDT_EFER); /* Select CRF6 */
188 timeleft = inb_p(WDT_EFDR); /* Read Timeout counter to CRF6 */
189
190 w83627hf_unselect_wd_register();
191
192 spin_unlock(&io_lock);
193
194 return timeleft;
195}
196
179static ssize_t wdt_write(struct file *file, const char __user *buf, 197static ssize_t wdt_write(struct file *file, const char __user *buf,
180 size_t count, loff_t *ppos) 198 size_t count, loff_t *ppos)
181{ 199{
@@ -202,7 +220,7 @@ static long wdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
202{ 220{
203 void __user *argp = (void __user *)arg; 221 void __user *argp = (void __user *)arg;
204 int __user *p = argp; 222 int __user *p = argp;
205 int new_timeout; 223 int timeval;
206 static const struct watchdog_info ident = { 224 static const struct watchdog_info ident = {
207 .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | 225 .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT |
208 WDIOF_MAGICCLOSE, 226 WDIOF_MAGICCLOSE,
@@ -238,14 +256,17 @@ static long wdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
238 wdt_ping(); 256 wdt_ping();
239 break; 257 break;
240 case WDIOC_SETTIMEOUT: 258 case WDIOC_SETTIMEOUT:
241 if (get_user(new_timeout, p)) 259 if (get_user(timeval, p))
242 return -EFAULT; 260 return -EFAULT;
243 if (wdt_set_heartbeat(new_timeout)) 261 if (wdt_set_heartbeat(timeval))
244 return -EINVAL; 262 return -EINVAL;
245 wdt_ping(); 263 wdt_ping();
246 /* Fall */ 264 /* Fall */
247 case WDIOC_GETTIMEOUT: 265 case WDIOC_GETTIMEOUT:
248 return put_user(timeout, p); 266 return put_user(timeout, p);
267 case WDIOC_GETTIMELEFT:
268 timeval = wdt_get_time();
269 return put_user(timeval, p);
249 default: 270 default:
250 return -ENOTTY; 271 return -ENOTTY;
251 } 272 }
diff --git a/drivers/watchdog/wdt.c b/drivers/watchdog/wdt.c
index bb03e151a1d0..d2ef002be96b 100644
--- a/drivers/watchdog/wdt.c
+++ b/drivers/watchdog/wdt.c
@@ -612,7 +612,7 @@ static int __init wdt_init(void)
612 goto out; 612 goto out;
613 } 613 }
614 614
615 ret = request_irq(irq, wdt_interrupt, IRQF_DISABLED, "wdt501p", NULL); 615 ret = request_irq(irq, wdt_interrupt, 0, "wdt501p", NULL);
616 if (ret) { 616 if (ret) {
617 printk(KERN_ERR "wdt: IRQ %d is not free.\n", irq); 617 printk(KERN_ERR "wdt: IRQ %d is not free.\n", irq);
618 goto outreg; 618 goto outreg;
diff --git a/drivers/watchdog/wdt_pci.c b/drivers/watchdog/wdt_pci.c
index 172dad6c7693..e0fc3baa9197 100644
--- a/drivers/watchdog/wdt_pci.c
+++ b/drivers/watchdog/wdt_pci.c
@@ -643,7 +643,7 @@ static int __devinit wdtpci_init_one(struct pci_dev *dev,
643 irq = dev->irq; 643 irq = dev->irq;
644 io = pci_resource_start(dev, 2); 644 io = pci_resource_start(dev, 2);
645 645
646 if (request_irq(irq, wdtpci_interrupt, IRQF_DISABLED | IRQF_SHARED, 646 if (request_irq(irq, wdtpci_interrupt, IRQF_SHARED,
647 "wdt_pci", &wdtpci_miscdev)) { 647 "wdt_pci", &wdtpci_miscdev)) {
648 printk(KERN_ERR PFX "IRQ %d is not free\n", irq); 648 printk(KERN_ERR PFX "IRQ %d is not free\n", irq);
649 goto out_reg; 649 goto out_reg;
diff --git a/drivers/watchdog/wm831x_wdt.c b/drivers/watchdog/wm831x_wdt.c
index 871caea4e1c6..7be38556aed0 100644
--- a/drivers/watchdog/wm831x_wdt.c
+++ b/drivers/watchdog/wm831x_wdt.c
@@ -12,8 +12,7 @@
12#include <linux/moduleparam.h> 12#include <linux/moduleparam.h>
13#include <linux/types.h> 13#include <linux/types.h>
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/fs.h> 15#include <linux/slab.h>
16#include <linux/miscdevice.h>
17#include <linux/platform_device.h> 16#include <linux/platform_device.h>
18#include <linux/watchdog.h> 17#include <linux/watchdog.h>
19#include <linux/uaccess.h> 18#include <linux/uaccess.h>
@@ -29,19 +28,19 @@ MODULE_PARM_DESC(nowayout,
29 "Watchdog cannot be stopped once started (default=" 28 "Watchdog cannot be stopped once started (default="
30 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); 29 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
31 30
32static unsigned long wm831x_wdt_users; 31struct wm831x_wdt_drvdata {
33static struct miscdevice wm831x_wdt_miscdev; 32 struct watchdog_device wdt;
34static int wm831x_wdt_expect_close; 33 struct wm831x *wm831x;
35static DEFINE_MUTEX(wdt_mutex); 34 struct mutex lock;
36static struct wm831x *wm831x; 35 int update_gpio;
37static unsigned int update_gpio; 36 int update_state;
38static unsigned int update_state; 37};
39 38
40/* We can't use the sub-second values here but they're included 39/* We can't use the sub-second values here but they're included
41 * for completeness. */ 40 * for completeness. */
42static struct { 41static struct {
43 int time; /* Seconds */ 42 unsigned int time; /* Seconds */
44 u16 val; /* WDOG_TO value */ 43 u16 val; /* WDOG_TO value */
45} wm831x_wdt_cfgs[] = { 44} wm831x_wdt_cfgs[] = {
46 { 1, 2 }, 45 { 1, 2 },
47 { 2, 3 }, 46 { 2, 3 },
@@ -52,32 +51,13 @@ static struct {
52 { 33, 7 }, /* Actually 32.768s so include both, others round down */ 51 { 33, 7 }, /* Actually 32.768s so include both, others round down */
53}; 52};
54 53
55static int wm831x_wdt_set_timeout(struct wm831x *wm831x, u16 value) 54static int wm831x_wdt_start(struct watchdog_device *wdt_dev)
56{
57 int ret;
58
59 mutex_lock(&wdt_mutex);
60
61 ret = wm831x_reg_unlock(wm831x);
62 if (ret == 0) {
63 ret = wm831x_set_bits(wm831x, WM831X_WATCHDOG,
64 WM831X_WDOG_TO_MASK, value);
65 wm831x_reg_lock(wm831x);
66 } else {
67 dev_err(wm831x->dev, "Failed to unlock security key: %d\n",
68 ret);
69 }
70
71 mutex_unlock(&wdt_mutex);
72
73 return ret;
74}
75
76static int wm831x_wdt_start(struct wm831x *wm831x)
77{ 55{
56 struct wm831x_wdt_drvdata *driver_data = watchdog_get_drvdata(wdt_dev);
57 struct wm831x *wm831x = driver_data->wm831x;
78 int ret; 58 int ret;
79 59
80 mutex_lock(&wdt_mutex); 60 mutex_lock(&driver_data->lock);
81 61
82 ret = wm831x_reg_unlock(wm831x); 62 ret = wm831x_reg_unlock(wm831x);
83 if (ret == 0) { 63 if (ret == 0) {
@@ -89,16 +69,18 @@ static int wm831x_wdt_start(struct wm831x *wm831x)
89 ret); 69 ret);
90 } 70 }
91 71
92 mutex_unlock(&wdt_mutex); 72 mutex_unlock(&driver_data->lock);
93 73
94 return ret; 74 return ret;
95} 75}
96 76
97static int wm831x_wdt_stop(struct wm831x *wm831x) 77static int wm831x_wdt_stop(struct watchdog_device *wdt_dev)
98{ 78{
79 struct wm831x_wdt_drvdata *driver_data = watchdog_get_drvdata(wdt_dev);
80 struct wm831x *wm831x = driver_data->wm831x;
99 int ret; 81 int ret;
100 82
101 mutex_lock(&wdt_mutex); 83 mutex_lock(&driver_data->lock);
102 84
103 ret = wm831x_reg_unlock(wm831x); 85 ret = wm831x_reg_unlock(wm831x);
104 if (ret == 0) { 86 if (ret == 0) {
@@ -110,26 +92,28 @@ static int wm831x_wdt_stop(struct wm831x *wm831x)
110 ret); 92 ret);
111 } 93 }
112 94
113 mutex_unlock(&wdt_mutex); 95 mutex_unlock(&driver_data->lock);
114 96
115 return ret; 97 return ret;
116} 98}
117 99
118static int wm831x_wdt_kick(struct wm831x *wm831x) 100static int wm831x_wdt_ping(struct watchdog_device *wdt_dev)
119{ 101{
102 struct wm831x_wdt_drvdata *driver_data = watchdog_get_drvdata(wdt_dev);
103 struct wm831x *wm831x = driver_data->wm831x;
120 int ret; 104 int ret;
121 u16 reg; 105 u16 reg;
122 106
123 mutex_lock(&wdt_mutex); 107 mutex_lock(&driver_data->lock);
124 108
125 if (update_gpio) { 109 if (driver_data->update_gpio) {
126 gpio_set_value_cansleep(update_gpio, update_state); 110 gpio_set_value_cansleep(driver_data->update_gpio,
127 update_state = !update_state; 111 driver_data->update_state);
112 driver_data->update_state = !driver_data->update_state;
128 ret = 0; 113 ret = 0;
129 goto out; 114 goto out;
130 } 115 }
131 116
132
133 reg = wm831x_reg_read(wm831x, WM831X_WATCHDOG); 117 reg = wm831x_reg_read(wm831x, WM831X_WATCHDOG);
134 118
135 if (!(reg & WM831X_WDOG_RST_SRC)) { 119 if (!(reg & WM831X_WDOG_RST_SRC)) {
@@ -150,182 +134,59 @@ static int wm831x_wdt_kick(struct wm831x *wm831x)
150 } 134 }
151 135
152out: 136out:
153 mutex_unlock(&wdt_mutex); 137 mutex_unlock(&driver_data->lock);
154 138
155 return ret; 139 return ret;
156} 140}
157 141
158static int wm831x_wdt_open(struct inode *inode, struct file *file) 142static int wm831x_wdt_set_timeout(struct watchdog_device *wdt_dev,
143 unsigned int timeout)
159{ 144{
160 int ret; 145 struct wm831x_wdt_drvdata *driver_data = watchdog_get_drvdata(wdt_dev);
161 146 struct wm831x *wm831x = driver_data->wm831x;
162 if (!wm831x) 147 int ret, i;
163 return -ENODEV;
164
165 if (test_and_set_bit(0, &wm831x_wdt_users))
166 return -EBUSY;
167 148
168 ret = wm831x_wdt_start(wm831x); 149 for (i = 0; i < ARRAY_SIZE(wm831x_wdt_cfgs); i++)
169 if (ret != 0) 150 if (wm831x_wdt_cfgs[i].time == timeout)
170 return ret; 151 break;
171 152 if (i == ARRAY_SIZE(wm831x_wdt_cfgs))
172 return nonseekable_open(inode, file); 153 ret = -EINVAL;
173}
174 154
175static int wm831x_wdt_release(struct inode *inode, struct file *file) 155 ret = wm831x_reg_unlock(wm831x);
176{ 156 if (ret == 0) {
177 if (wm831x_wdt_expect_close) 157 ret = wm831x_set_bits(wm831x, WM831X_WATCHDOG,
178 wm831x_wdt_stop(wm831x); 158 WM831X_WDOG_TO_MASK,
179 else { 159 wm831x_wdt_cfgs[i].val);
180 dev_warn(wm831x->dev, "Watchdog device closed uncleanly\n"); 160 wm831x_reg_lock(wm831x);
181 wm831x_wdt_kick(wm831x); 161 } else {
162 dev_err(wm831x->dev, "Failed to unlock security key: %d\n",
163 ret);
182 } 164 }
183 165
184 clear_bit(0, &wm831x_wdt_users); 166 return ret;
185
186 return 0;
187}
188
189static ssize_t wm831x_wdt_write(struct file *file,
190 const char __user *data, size_t count,
191 loff_t *ppos)
192{
193 size_t i;
194
195 if (count) {
196 wm831x_wdt_kick(wm831x);
197
198 if (!nowayout) {
199 /* In case it was set long ago */
200 wm831x_wdt_expect_close = 0;
201
202 /* scan to see whether or not we got the magic
203 character */
204 for (i = 0; i != count; i++) {
205 char c;
206 if (get_user(c, data + i))
207 return -EFAULT;
208 if (c == 'V')
209 wm831x_wdt_expect_close = 42;
210 }
211 }
212 }
213 return count;
214} 167}
215 168
216static const struct watchdog_info ident = { 169static const struct watchdog_info wm831x_wdt_info = {
217 .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE, 170 .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
218 .identity = "WM831x Watchdog", 171 .identity = "WM831x Watchdog",
219}; 172};
220 173
221static long wm831x_wdt_ioctl(struct file *file, unsigned int cmd, 174static const struct watchdog_ops wm831x_wdt_ops = {
222 unsigned long arg)
223{
224 int ret = -ENOTTY, time, i;
225 void __user *argp = (void __user *)arg;
226 int __user *p = argp;
227 u16 reg;
228
229 switch (cmd) {
230 case WDIOC_GETSUPPORT:
231 ret = copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
232 break;
233
234 case WDIOC_GETSTATUS:
235 case WDIOC_GETBOOTSTATUS:
236 ret = put_user(0, p);
237 break;
238
239 case WDIOC_SETOPTIONS:
240 {
241 int options;
242
243 if (get_user(options, p))
244 return -EFAULT;
245
246 ret = -EINVAL;
247
248 /* Setting both simultaneously means at least one must fail */
249 if (options == WDIOS_DISABLECARD)
250 ret = wm831x_wdt_start(wm831x);
251
252 if (options == WDIOS_ENABLECARD)
253 ret = wm831x_wdt_stop(wm831x);
254 break;
255 }
256
257 case WDIOC_KEEPALIVE:
258 ret = wm831x_wdt_kick(wm831x);
259 break;
260
261 case WDIOC_SETTIMEOUT:
262 ret = get_user(time, p);
263 if (ret)
264 break;
265
266 if (time == 0) {
267 if (nowayout)
268 ret = -EINVAL;
269 else
270 wm831x_wdt_stop(wm831x);
271 break;
272 }
273
274 for (i = 0; i < ARRAY_SIZE(wm831x_wdt_cfgs); i++)
275 if (wm831x_wdt_cfgs[i].time == time)
276 break;
277 if (i == ARRAY_SIZE(wm831x_wdt_cfgs))
278 ret = -EINVAL;
279 else
280 ret = wm831x_wdt_set_timeout(wm831x,
281 wm831x_wdt_cfgs[i].val);
282 break;
283
284 case WDIOC_GETTIMEOUT:
285 reg = wm831x_reg_read(wm831x, WM831X_WATCHDOG);
286 reg &= WM831X_WDOG_TO_MASK;
287 for (i = 0; i < ARRAY_SIZE(wm831x_wdt_cfgs); i++)
288 if (wm831x_wdt_cfgs[i].val == reg)
289 break;
290 if (i == ARRAY_SIZE(wm831x_wdt_cfgs)) {
291 dev_warn(wm831x->dev,
292 "Unknown watchdog configuration: %x\n", reg);
293 ret = -EINVAL;
294 } else
295 ret = put_user(wm831x_wdt_cfgs[i].time, p);
296
297 }
298
299 return ret;
300}
301
302static const struct file_operations wm831x_wdt_fops = {
303 .owner = THIS_MODULE, 175 .owner = THIS_MODULE,
304 .llseek = no_llseek, 176 .start = wm831x_wdt_start,
305 .write = wm831x_wdt_write, 177 .stop = wm831x_wdt_stop,
306 .unlocked_ioctl = wm831x_wdt_ioctl, 178 .ping = wm831x_wdt_ping,
307 .open = wm831x_wdt_open, 179 .set_timeout = wm831x_wdt_set_timeout,
308 .release = wm831x_wdt_release,
309};
310
311static struct miscdevice wm831x_wdt_miscdev = {
312 .minor = WATCHDOG_MINOR,
313 .name = "watchdog",
314 .fops = &wm831x_wdt_fops,
315}; 180};
316 181
317static int __devinit wm831x_wdt_probe(struct platform_device *pdev) 182static int __devinit wm831x_wdt_probe(struct platform_device *pdev)
318{ 183{
184 struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent);
319 struct wm831x_pdata *chip_pdata; 185 struct wm831x_pdata *chip_pdata;
320 struct wm831x_watchdog_pdata *pdata; 186 struct wm831x_watchdog_pdata *pdata;
321 int reg, ret; 187 struct wm831x_wdt_drvdata *driver_data;
322 188 struct watchdog_device *wm831x_wdt;
323 if (wm831x) { 189 int reg, ret, i;
324 dev_err(&pdev->dev, "wm831x watchdog already registered\n");
325 return -EBUSY;
326 }
327
328 wm831x = dev_get_drvdata(pdev->dev.parent);
329 190
330 ret = wm831x_reg_read(wm831x, WM831X_WATCHDOG); 191 ret = wm831x_reg_read(wm831x, WM831X_WATCHDOG);
331 if (ret < 0) { 192 if (ret < 0) {
@@ -338,6 +199,36 @@ static int __devinit wm831x_wdt_probe(struct platform_device *pdev)
338 if (reg & WM831X_WDOG_DEBUG) 199 if (reg & WM831X_WDOG_DEBUG)
339 dev_warn(wm831x->dev, "Watchdog is paused\n"); 200 dev_warn(wm831x->dev, "Watchdog is paused\n");
340 201
202 driver_data = kzalloc(sizeof(*driver_data), GFP_KERNEL);
203 if (!driver_data) {
204 dev_err(wm831x->dev, "Unable to alloacate watchdog device\n");
205 ret = -ENOMEM;
206 goto err;
207 }
208
209 mutex_init(&driver_data->lock);
210 driver_data->wm831x = wm831x;
211
212 wm831x_wdt = &driver_data->wdt;
213
214 wm831x_wdt->info = &wm831x_wdt_info;
215 wm831x_wdt->ops = &wm831x_wdt_ops;
216 watchdog_set_drvdata(wm831x_wdt, driver_data);
217
218 if (nowayout)
219 wm831x_wdt->status |= WDOG_NO_WAY_OUT;
220
221 reg = wm831x_reg_read(wm831x, WM831X_WATCHDOG);
222 reg &= WM831X_WDOG_TO_MASK;
223 for (i = 0; i < ARRAY_SIZE(wm831x_wdt_cfgs); i++)
224 if (wm831x_wdt_cfgs[i].val == reg)
225 break;
226 if (i == ARRAY_SIZE(wm831x_wdt_cfgs))
227 dev_warn(wm831x->dev,
228 "Unknown watchdog timeout: %x\n", reg);
229 else
230 wm831x_wdt->timeout = wm831x_wdt_cfgs[i].time;
231
341 /* Apply any configuration */ 232 /* Apply any configuration */
342 if (pdev->dev.parent->platform_data) { 233 if (pdev->dev.parent->platform_data) {
343 chip_pdata = pdev->dev.parent->platform_data; 234 chip_pdata = pdev->dev.parent->platform_data;
@@ -361,7 +252,7 @@ static int __devinit wm831x_wdt_probe(struct platform_device *pdev)
361 dev_err(wm831x->dev, 252 dev_err(wm831x->dev,
362 "Failed to request update GPIO: %d\n", 253 "Failed to request update GPIO: %d\n",
363 ret); 254 ret);
364 goto err; 255 goto err_alloc;
365 } 256 }
366 257
367 ret = gpio_direction_output(pdata->update_gpio, 0); 258 ret = gpio_direction_output(pdata->update_gpio, 0);
@@ -372,7 +263,7 @@ static int __devinit wm831x_wdt_probe(struct platform_device *pdev)
372 goto err_gpio; 263 goto err_gpio;
373 } 264 }
374 265
375 update_gpio = pdata->update_gpio; 266 driver_data->update_gpio = pdata->update_gpio;
376 267
377 /* Make sure the watchdog takes hardware updates */ 268 /* Make sure the watchdog takes hardware updates */
378 reg |= WM831X_WDOG_RST_SRC; 269 reg |= WM831X_WDOG_RST_SRC;
@@ -389,33 +280,34 @@ static int __devinit wm831x_wdt_probe(struct platform_device *pdev)
389 } 280 }
390 } 281 }
391 282
392 wm831x_wdt_miscdev.parent = &pdev->dev; 283 ret = watchdog_register_device(&driver_data->wdt);
393
394 ret = misc_register(&wm831x_wdt_miscdev);
395 if (ret != 0) { 284 if (ret != 0) {
396 dev_err(wm831x->dev, "Failed to register miscdev: %d\n", ret); 285 dev_err(wm831x->dev, "watchdog_register_device() failed: %d\n",
286 ret);
397 goto err_gpio; 287 goto err_gpio;
398 } 288 }
399 289
290 dev_set_drvdata(&pdev->dev, driver_data);
291
400 return 0; 292 return 0;
401 293
402err_gpio: 294err_gpio:
403 if (update_gpio) { 295 if (driver_data->update_gpio)
404 gpio_free(update_gpio); 296 gpio_free(driver_data->update_gpio);
405 update_gpio = 0; 297err_alloc:
406 } 298 kfree(driver_data);
407err: 299err:
408 return ret; 300 return ret;
409} 301}
410 302
411static int __devexit wm831x_wdt_remove(struct platform_device *pdev) 303static int __devexit wm831x_wdt_remove(struct platform_device *pdev)
412{ 304{
413 if (update_gpio) { 305 struct wm831x_wdt_drvdata *driver_data = dev_get_drvdata(&pdev->dev);
414 gpio_free(update_gpio); 306
415 update_gpio = 0; 307 watchdog_unregister_device(&driver_data->wdt);
416 }
417 308
418 misc_deregister(&wm831x_wdt_miscdev); 309 if (driver_data->update_gpio)
310 gpio_free(driver_data->update_gpio);
419 311
420 return 0; 312 return 0;
421} 313}
diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
index 5876e1ae6c2d..1779338e1d86 100644
--- a/drivers/xen/balloon.c
+++ b/drivers/xen/balloon.c
@@ -39,6 +39,7 @@
39#include <linux/kernel.h> 39#include <linux/kernel.h>
40#include <linux/sched.h> 40#include <linux/sched.h>
41#include <linux/errno.h> 41#include <linux/errno.h>
42#include <linux/module.h>
42#include <linux/mm.h> 43#include <linux/mm.h>
43#include <linux/bootmem.h> 44#include <linux/bootmem.h>
44#include <linux/pagemap.h> 45#include <linux/pagemap.h>
diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c
index 0b5366b5be20..ce4fa0831860 100644
--- a/drivers/xen/manage.c
+++ b/drivers/xen/manage.c
@@ -9,6 +9,7 @@
9#include <linux/stop_machine.h> 9#include <linux/stop_machine.h>
10#include <linux/freezer.h> 10#include <linux/freezer.h>
11#include <linux/syscore_ops.h> 11#include <linux/syscore_ops.h>
12#include <linux/export.h>
12 13
13#include <xen/xen.h> 14#include <xen/xen.h>
14#include <xen/xenbus.h> 15#include <xen/xenbus.h>
diff --git a/drivers/xen/swiotlb-xen.c b/drivers/xen/swiotlb-xen.c
index c984768d98ca..8e964b91c447 100644
--- a/drivers/xen/swiotlb-xen.c
+++ b/drivers/xen/swiotlb-xen.c
@@ -35,6 +35,7 @@
35 35
36#include <linux/bootmem.h> 36#include <linux/bootmem.h>
37#include <linux/dma-mapping.h> 37#include <linux/dma-mapping.h>
38#include <linux/export.h>
38#include <xen/swiotlb-xen.h> 39#include <xen/swiotlb-xen.h>
39#include <xen/page.h> 40#include <xen/page.h>
40#include <xen/xen-ops.h> 41#include <xen/xen-ops.h>
diff --git a/drivers/xen/xen-pciback/conf_space.c b/drivers/xen/xen-pciback/conf_space.c
index 444345afbd5c..52fed16d8701 100644
--- a/drivers/xen/xen-pciback/conf_space.c
+++ b/drivers/xen/xen-pciback/conf_space.c
@@ -10,6 +10,7 @@
10 */ 10 */
11 11
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/module.h>
13#include <linux/pci.h> 14#include <linux/pci.h>
14#include "pciback.h" 15#include "pciback.h"
15#include "conf_space.h" 16#include "conf_space.h"
diff --git a/drivers/xen/xenbus/xenbus_client.c b/drivers/xen/xenbus/xenbus_client.c
index cdacf923e073..81c3ce6b8bbe 100644
--- a/drivers/xen/xenbus/xenbus_client.c
+++ b/drivers/xen/xenbus/xenbus_client.c
@@ -33,6 +33,7 @@
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include <linux/types.h> 34#include <linux/types.h>
35#include <linux/vmalloc.h> 35#include <linux/vmalloc.h>
36#include <linux/export.h>
36#include <asm/xen/hypervisor.h> 37#include <asm/xen/hypervisor.h>
37#include <xen/interface/xen.h> 38#include <xen/interface/xen.h>
38#include <xen/interface/event_channel.h> 39#include <xen/interface/event_channel.h>
@@ -443,7 +444,7 @@ int xenbus_map_ring_valloc(struct xenbus_device *dev, int gnt_ref, void **vaddr)
443 444
444 *vaddr = NULL; 445 *vaddr = NULL;
445 446
446 area = xen_alloc_vm_area(PAGE_SIZE); 447 area = alloc_vm_area(PAGE_SIZE);
447 if (!area) 448 if (!area)
448 return -ENOMEM; 449 return -ENOMEM;
449 450
@@ -453,7 +454,7 @@ int xenbus_map_ring_valloc(struct xenbus_device *dev, int gnt_ref, void **vaddr)
453 BUG(); 454 BUG();
454 455
455 if (op.status != GNTST_okay) { 456 if (op.status != GNTST_okay) {
456 xen_free_vm_area(area); 457 free_vm_area(area);
457 xenbus_dev_fatal(dev, op.status, 458 xenbus_dev_fatal(dev, op.status,
458 "mapping in shared page %d from domain %d", 459 "mapping in shared page %d from domain %d",
459 gnt_ref, dev->otherend_id); 460 gnt_ref, dev->otherend_id);
@@ -552,7 +553,7 @@ int xenbus_unmap_ring_vfree(struct xenbus_device *dev, void *vaddr)
552 BUG(); 553 BUG();
553 554
554 if (op.status == GNTST_okay) 555 if (op.status == GNTST_okay)
555 xen_free_vm_area(area); 556 free_vm_area(area);
556 else 557 else
557 xenbus_dev_error(dev, op.status, 558 xenbus_dev_error(dev, op.status,
558 "unmapping page at handle %d error %d", 559 "unmapping page at handle %d error %d",
diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c
index cef9b0bf63d5..0e867eeecb04 100644
--- a/drivers/xen/xenbus/xenbus_probe.c
+++ b/drivers/xen/xenbus/xenbus_probe.c
@@ -46,6 +46,7 @@
46#include <linux/mutex.h> 46#include <linux/mutex.h>
47#include <linux/io.h> 47#include <linux/io.h>
48#include <linux/slab.h> 48#include <linux/slab.h>
49#include <linux/module.h>
49 50
50#include <asm/page.h> 51#include <asm/page.h>
51#include <asm/pgtable.h> 52#include <asm/pgtable.h>
diff --git a/drivers/xen/xenbus/xenbus_probe_backend.c b/drivers/xen/xenbus/xenbus_probe_backend.c
index 32417b5064fd..c3c7cd195c11 100644
--- a/drivers/xen/xenbus/xenbus_probe_backend.c
+++ b/drivers/xen/xenbus/xenbus_probe_backend.c
@@ -42,6 +42,7 @@
42#include <linux/fcntl.h> 42#include <linux/fcntl.h>
43#include <linux/mm.h> 43#include <linux/mm.h>
44#include <linux/notifier.h> 44#include <linux/notifier.h>
45#include <linux/export.h>
45 46
46#include <asm/page.h> 47#include <asm/page.h>
47#include <asm/pgtable.h> 48#include <asm/pgtable.h>
diff --git a/drivers/xen/xenbus/xenbus_probe_frontend.c b/drivers/xen/xenbus/xenbus_probe_frontend.c
index 540587e18a94..2f73195512b4 100644
--- a/drivers/xen/xenbus/xenbus_probe_frontend.c
+++ b/drivers/xen/xenbus/xenbus_probe_frontend.c
@@ -13,6 +13,7 @@
13#include <linux/kthread.h> 13#include <linux/kthread.h>
14#include <linux/mutex.h> 14#include <linux/mutex.h>
15#include <linux/io.h> 15#include <linux/io.h>
16#include <linux/module.h>
16 17
17#include <asm/page.h> 18#include <asm/page.h>
18#include <asm/pgtable.h> 19#include <asm/pgtable.h>
diff --git a/drivers/zorro/proc.c b/drivers/zorro/proc.c
index e0c84725d3e9..988880dcee75 100644
--- a/drivers/zorro/proc.c
+++ b/drivers/zorro/proc.c
@@ -13,6 +13,7 @@
13#include <linux/proc_fs.h> 13#include <linux/proc_fs.h>
14#include <linux/seq_file.h> 14#include <linux/seq_file.h>
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/export.h>
16#include <asm/uaccess.h> 17#include <asm/uaccess.h>
17#include <asm/amigahw.h> 18#include <asm/amigahw.h>
18#include <asm/setup.h> 19#include <asm/setup.h>